@ai-sdk/google 3.0.126 → 3.0.128
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 +19 -0
- package/dist/index.js +335 -216
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +234 -106
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +198 -105
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +118 -17
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/convert-to-google-generative-ai-messages.ts +34 -12
- package/src/download-tool-result-files.ts +103 -0
- package/src/google-generative-ai-embedding-model.ts +39 -8
- package/src/google-generative-ai-language-model.ts +22 -1
- package/src/google-generative-ai-prompt.ts +7 -3
package/dist/index.mjs
CHANGED
|
@@ -90,14 +90,14 @@ var GoogleTranscriptionModel = class {
|
|
|
90
90
|
});
|
|
91
91
|
}
|
|
92
92
|
async doGenerate(options) {
|
|
93
|
-
var
|
|
93
|
+
var _a2, _b, _c, _d, _e, _f;
|
|
94
94
|
if (isLiveTranscriptionModelId(this.modelId)) {
|
|
95
95
|
throw new InvalidArgumentError({
|
|
96
96
|
argument: "modelId",
|
|
97
97
|
message: `Model '${this.modelId}' only supports streaming transcription, which requires AI SDK v7. Use a unary model such as 'gemini-3.5-transcribe'.`
|
|
98
98
|
});
|
|
99
99
|
}
|
|
100
|
-
const currentDate = (_c = (_b = (
|
|
100
|
+
const currentDate = (_c = (_b = (_a2 = this.config._internal) == null ? void 0 : _a2.currentDate) == null ? void 0 : _b.call(_a2)) != null ? _c : /* @__PURE__ */ new Date();
|
|
101
101
|
const warnings = [];
|
|
102
102
|
const googleOptions = await this.parseOptions(options.providerOptions);
|
|
103
103
|
const transcriptionConfig = buildTranscriptionConfig(googleOptions);
|
|
@@ -168,7 +168,7 @@ var GoogleTranscriptionModel = class {
|
|
|
168
168
|
}
|
|
169
169
|
};
|
|
170
170
|
function buildTranscriptionConfig(options) {
|
|
171
|
-
var
|
|
171
|
+
var _a2;
|
|
172
172
|
if (options == null) return void 0;
|
|
173
173
|
const config = {};
|
|
174
174
|
if (options.languageCodes != null) {
|
|
@@ -179,7 +179,7 @@ function buildTranscriptionConfig(options) {
|
|
|
179
179
|
}
|
|
180
180
|
if (options.mode != null || options.diarization === true || options.wordTimestamp === true) {
|
|
181
181
|
config.mode = {
|
|
182
|
-
type: ((
|
|
182
|
+
type: ((_a2 = options.mode) != null ? _a2 : "VERBATIM").toLowerCase(),
|
|
183
183
|
...options.diarization === true ? { diarization_mode: "speaker" } : {},
|
|
184
184
|
...options.wordTimestamp === true ? { timestamp_granularities: ["word"] } : {}
|
|
185
185
|
};
|
|
@@ -224,7 +224,7 @@ import {
|
|
|
224
224
|
} from "@ai-sdk/provider-utils";
|
|
225
225
|
|
|
226
226
|
// src/version.ts
|
|
227
|
-
var VERSION = true ? "3.0.
|
|
227
|
+
var VERSION = true ? "3.0.128" : "0.0.0-test";
|
|
228
228
|
|
|
229
229
|
// src/google-generative-ai-embedding-model.ts
|
|
230
230
|
import {
|
|
@@ -233,6 +233,7 @@ import {
|
|
|
233
233
|
import {
|
|
234
234
|
combineHeaders as combineHeaders2,
|
|
235
235
|
createJsonResponseHandler as createJsonResponseHandler2,
|
|
236
|
+
EXPERIMENTAL_EMBEDDING_MODEL_PROVIDER_OPTIONS_TRANSFORMER,
|
|
236
237
|
lazySchema as lazySchema3,
|
|
237
238
|
parseProviderOptions as parseProviderOptions2,
|
|
238
239
|
postJsonToApi as postJsonToApi2,
|
|
@@ -307,11 +308,31 @@ var googleEmbeddingModelOptions = lazySchema2(
|
|
|
307
308
|
);
|
|
308
309
|
|
|
309
310
|
// src/google-generative-ai-embedding-model.ts
|
|
311
|
+
var _a;
|
|
312
|
+
_a = EXPERIMENTAL_EMBEDDING_MODEL_PROVIDER_OPTIONS_TRANSFORMER;
|
|
310
313
|
var GoogleGenerativeAIEmbeddingModel = class {
|
|
311
314
|
constructor(modelId, config) {
|
|
312
315
|
this.specificationVersion = "v3";
|
|
313
316
|
this.maxEmbeddingsPerCall = 100;
|
|
314
317
|
this.supportsParallelCalls = true;
|
|
318
|
+
this[_a] = ({ providerOptions, values, startIndex, endIndex }) => {
|
|
319
|
+
var _a2;
|
|
320
|
+
const multimodalContent = (_a2 = providerOptions == null ? void 0 : providerOptions.google) == null ? void 0 : _a2.content;
|
|
321
|
+
if (!Array.isArray(multimodalContent)) {
|
|
322
|
+
return providerOptions;
|
|
323
|
+
}
|
|
324
|
+
validateMultimodalContentLength({
|
|
325
|
+
multimodalContent,
|
|
326
|
+
values
|
|
327
|
+
});
|
|
328
|
+
return {
|
|
329
|
+
...providerOptions,
|
|
330
|
+
google: {
|
|
331
|
+
...providerOptions == null ? void 0 : providerOptions.google,
|
|
332
|
+
content: multimodalContent.slice(startIndex, endIndex)
|
|
333
|
+
}
|
|
334
|
+
};
|
|
335
|
+
};
|
|
315
336
|
this.modelId = modelId;
|
|
316
337
|
this.config = config;
|
|
317
338
|
}
|
|
@@ -342,11 +363,7 @@ var GoogleGenerativeAIEmbeddingModel = class {
|
|
|
342
363
|
headers
|
|
343
364
|
);
|
|
344
365
|
const multimodalContent = googleOptions == null ? void 0 : googleOptions.content;
|
|
345
|
-
|
|
346
|
-
throw new Error(
|
|
347
|
-
`The number of multimodal content entries (${multimodalContent.length}) must match the number of values (${values.length}).`
|
|
348
|
-
);
|
|
349
|
-
}
|
|
366
|
+
validateMultimodalContentLength({ multimodalContent, values });
|
|
350
367
|
if (values.length === 1) {
|
|
351
368
|
const valueParts = multimodalContent == null ? void 0 : multimodalContent[0];
|
|
352
369
|
const textPart = values[0] ? [{ text: values[0] }] : [];
|
|
@@ -431,6 +448,16 @@ var googleGenerativeAISingleEmbeddingResponseSchema = lazySchema3(
|
|
|
431
448
|
})
|
|
432
449
|
)
|
|
433
450
|
);
|
|
451
|
+
function validateMultimodalContentLength({
|
|
452
|
+
multimodalContent,
|
|
453
|
+
values
|
|
454
|
+
}) {
|
|
455
|
+
if (multimodalContent != null && multimodalContent.length !== values.length) {
|
|
456
|
+
throw new Error(
|
|
457
|
+
`The number of multimodal content entries (${multimodalContent.length}) must match the number of values (${values.length}).`
|
|
458
|
+
);
|
|
459
|
+
}
|
|
460
|
+
}
|
|
434
461
|
|
|
435
462
|
// src/google-generative-ai-language-model.ts
|
|
436
463
|
import {
|
|
@@ -448,7 +475,7 @@ import { z as z7 } from "zod/v4";
|
|
|
448
475
|
|
|
449
476
|
// src/convert-google-generative-ai-usage.ts
|
|
450
477
|
function convertGoogleGenerativeAIUsage(usage) {
|
|
451
|
-
var
|
|
478
|
+
var _a2, _b, _c, _d;
|
|
452
479
|
if (usage == null) {
|
|
453
480
|
return {
|
|
454
481
|
inputTokens: {
|
|
@@ -465,7 +492,7 @@ function convertGoogleGenerativeAIUsage(usage) {
|
|
|
465
492
|
raw: void 0
|
|
466
493
|
};
|
|
467
494
|
}
|
|
468
|
-
const promptTokens = (
|
|
495
|
+
const promptTokens = (_a2 = usage.promptTokenCount) != null ? _a2 : 0;
|
|
469
496
|
const candidatesTokens = (_b = usage.candidatesTokenCount) != null ? _b : 0;
|
|
470
497
|
const cachedContentTokens = (_c = usage.cachedContentTokenCount) != null ? _c : 0;
|
|
471
498
|
const thoughtsTokens = (_d = usage.thoughtsTokenCount) != null ? _d : 0;
|
|
@@ -761,7 +788,11 @@ function isEmptyObjectSchema(jsonSchema) {
|
|
|
761
788
|
import {
|
|
762
789
|
UnsupportedFunctionalityError as UnsupportedFunctionalityError2
|
|
763
790
|
} from "@ai-sdk/provider";
|
|
764
|
-
import {
|
|
791
|
+
import {
|
|
792
|
+
convertToBase64 as convertToBase642,
|
|
793
|
+
isUrlSupported,
|
|
794
|
+
secureJsonParse
|
|
795
|
+
} from "@ai-sdk/provider-utils";
|
|
765
796
|
var SKIP_THOUGHT_SIGNATURE_VALIDATOR = "skip_thought_signature_validator";
|
|
766
797
|
function getGoogleProviderOptions(providerOptions, providerOptionsName) {
|
|
767
798
|
const namespaces = [
|
|
@@ -790,19 +821,28 @@ function parseBase64DataUrl(value) {
|
|
|
790
821
|
data: match[2]
|
|
791
822
|
};
|
|
792
823
|
}
|
|
793
|
-
function convertUrlToolResultPart(url) {
|
|
824
|
+
function convertUrlToolResultPart(url, mediaType, supportedFunctionResponseUrls) {
|
|
794
825
|
const parsedDataUrl = parseBase64DataUrl(url);
|
|
795
|
-
if (parsedDataUrl
|
|
796
|
-
return
|
|
826
|
+
if (parsedDataUrl != null) {
|
|
827
|
+
return {
|
|
828
|
+
inlineData: {
|
|
829
|
+
mimeType: parsedDataUrl.mediaType,
|
|
830
|
+
data: parsedDataUrl.data
|
|
831
|
+
}
|
|
832
|
+
};
|
|
797
833
|
}
|
|
798
|
-
return {
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
834
|
+
return mediaType != null && isUrlSupported({
|
|
835
|
+
url,
|
|
836
|
+
mediaType,
|
|
837
|
+
supportedUrls: supportedFunctionResponseUrls
|
|
838
|
+
}) ? {
|
|
839
|
+
fileData: {
|
|
840
|
+
mimeType: mediaType,
|
|
841
|
+
fileUri: url
|
|
802
842
|
}
|
|
803
|
-
};
|
|
843
|
+
} : void 0;
|
|
804
844
|
}
|
|
805
|
-
function appendToolResultParts(parts, toolName, outputValue, toolCallId, includeFunctionCallIds = true) {
|
|
845
|
+
function appendToolResultParts(parts, toolName, outputValue, toolCallId, includeFunctionCallIds = true, supportedFunctionResponseUrls = {}) {
|
|
806
846
|
const functionResponseParts = [];
|
|
807
847
|
const responseTextParts = [];
|
|
808
848
|
for (const contentPart of outputValue) {
|
|
@@ -824,7 +864,9 @@ function appendToolResultParts(parts, toolName, outputValue, toolCallId, include
|
|
|
824
864
|
case "image-url":
|
|
825
865
|
case "file-url": {
|
|
826
866
|
const functionResponsePart = convertUrlToolResultPart(
|
|
827
|
-
contentPart.url
|
|
867
|
+
contentPart.url,
|
|
868
|
+
contentPart.mediaType,
|
|
869
|
+
supportedFunctionResponseUrls
|
|
828
870
|
);
|
|
829
871
|
if (functionResponsePart != null) {
|
|
830
872
|
functionResponseParts.push(functionResponsePart);
|
|
@@ -889,16 +931,17 @@ function appendLegacyToolResultParts(parts, toolName, outputValue, toolCallId, i
|
|
|
889
931
|
}
|
|
890
932
|
}
|
|
891
933
|
function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
892
|
-
var
|
|
934
|
+
var _a2, _b, _c, _d, _e, _f, _g;
|
|
893
935
|
const systemInstructionParts = [];
|
|
894
936
|
const contents = [];
|
|
895
937
|
let systemMessagesAllowed = true;
|
|
896
|
-
const isGemmaModel = (
|
|
938
|
+
const isGemmaModel = (_a2 = options == null ? void 0 : options.isGemmaModel) != null ? _a2 : false;
|
|
897
939
|
const isGemini3Model = (_b = options == null ? void 0 : options.isGemini3Model) != null ? _b : false;
|
|
898
940
|
const providerOptionsName = (_c = options == null ? void 0 : options.providerOptionsName) != null ? _c : "google";
|
|
899
941
|
const supportsFunctionResponseParts = (_d = options == null ? void 0 : options.supportsFunctionResponseParts) != null ? _d : true;
|
|
900
942
|
const onWarning = options == null ? void 0 : options.onWarning;
|
|
901
943
|
const includeFunctionCallIds = (_e = options == null ? void 0 : options.includeFunctionCallIds) != null ? _e : true;
|
|
944
|
+
const supportedFunctionResponseUrls = (_f = options == null ? void 0 : options.supportedFunctionResponseUrls) != null ? _f : {};
|
|
902
945
|
let sentinelInjected = false;
|
|
903
946
|
const missingSignatureToolNames = [];
|
|
904
947
|
const injectSkipSignature = (toolName) => {
|
|
@@ -1080,7 +1123,8 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
1080
1123
|
part.toolName,
|
|
1081
1124
|
output.value,
|
|
1082
1125
|
part.toolCallId,
|
|
1083
|
-
includeFunctionCallIds
|
|
1126
|
+
includeFunctionCallIds,
|
|
1127
|
+
supportedFunctionResponseUrls
|
|
1084
1128
|
);
|
|
1085
1129
|
} else {
|
|
1086
1130
|
appendLegacyToolResultParts(
|
|
@@ -1098,7 +1142,7 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
1098
1142
|
name: part.toolName,
|
|
1099
1143
|
response: {
|
|
1100
1144
|
name: part.toolName,
|
|
1101
|
-
content: output.type === "execution-denied" ? (
|
|
1145
|
+
content: output.type === "execution-denied" ? (_g = output.reason) != null ? _g : "Tool call execution denied." : output.value
|
|
1102
1146
|
}
|
|
1103
1147
|
}
|
|
1104
1148
|
});
|
|
@@ -1129,6 +1173,76 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
1129
1173
|
};
|
|
1130
1174
|
}
|
|
1131
1175
|
|
|
1176
|
+
// src/download-tool-result-files.ts
|
|
1177
|
+
import {
|
|
1178
|
+
convertUint8ArrayToBase64,
|
|
1179
|
+
downloadBlob,
|
|
1180
|
+
isUrlSupported as isUrlSupported2
|
|
1181
|
+
} from "@ai-sdk/provider-utils";
|
|
1182
|
+
async function downloadToolResultFiles(prompt, {
|
|
1183
|
+
abortSignal,
|
|
1184
|
+
supportedUrls = {}
|
|
1185
|
+
}) {
|
|
1186
|
+
async function downloadOutput(output) {
|
|
1187
|
+
if (output.type !== "content") {
|
|
1188
|
+
return output;
|
|
1189
|
+
}
|
|
1190
|
+
return {
|
|
1191
|
+
...output,
|
|
1192
|
+
value: await Promise.all(
|
|
1193
|
+
output.value.map(async (part) => {
|
|
1194
|
+
var _a2;
|
|
1195
|
+
if (part.type !== "file-url" && part.type !== "image-url") {
|
|
1196
|
+
return part;
|
|
1197
|
+
}
|
|
1198
|
+
if (part.type === "file-url" && part.mediaType != null && isUrlSupported2({
|
|
1199
|
+
url: part.url,
|
|
1200
|
+
mediaType: part.mediaType,
|
|
1201
|
+
supportedUrls
|
|
1202
|
+
})) {
|
|
1203
|
+
return part;
|
|
1204
|
+
}
|
|
1205
|
+
const blob = await downloadBlob(part.url, { abortSignal });
|
|
1206
|
+
return {
|
|
1207
|
+
type: part.type === "file-url" ? "file-data" : "image-data",
|
|
1208
|
+
data: convertUint8ArrayToBase64(
|
|
1209
|
+
new Uint8Array(await blob.arrayBuffer())
|
|
1210
|
+
),
|
|
1211
|
+
mediaType: blob.type || (part.type === "file-url" ? (_a2 = part.mediaType) != null ? _a2 : "application/octet-stream" : "image/*"),
|
|
1212
|
+
providerOptions: part.providerOptions
|
|
1213
|
+
};
|
|
1214
|
+
})
|
|
1215
|
+
)
|
|
1216
|
+
};
|
|
1217
|
+
}
|
|
1218
|
+
return Promise.all(
|
|
1219
|
+
prompt.map(async (message) => {
|
|
1220
|
+
switch (message.role) {
|
|
1221
|
+
case "assistant":
|
|
1222
|
+
return {
|
|
1223
|
+
...message,
|
|
1224
|
+
content: await Promise.all(
|
|
1225
|
+
message.content.map(
|
|
1226
|
+
async (part) => part.type === "tool-result" ? { ...part, output: await downloadOutput(part.output) } : part
|
|
1227
|
+
)
|
|
1228
|
+
)
|
|
1229
|
+
};
|
|
1230
|
+
case "tool":
|
|
1231
|
+
return {
|
|
1232
|
+
...message,
|
|
1233
|
+
content: await Promise.all(
|
|
1234
|
+
message.content.map(
|
|
1235
|
+
async (part) => part.type === "tool-result" ? { ...part, output: await downloadOutput(part.output) } : part
|
|
1236
|
+
)
|
|
1237
|
+
)
|
|
1238
|
+
};
|
|
1239
|
+
default:
|
|
1240
|
+
return message;
|
|
1241
|
+
}
|
|
1242
|
+
})
|
|
1243
|
+
);
|
|
1244
|
+
}
|
|
1245
|
+
|
|
1132
1246
|
// src/get-model-path.ts
|
|
1133
1247
|
function getModelPath(modelId) {
|
|
1134
1248
|
return modelId.includes("/") ? modelId : `models/${modelId}`;
|
|
@@ -1585,10 +1699,10 @@ function prepareTools({
|
|
|
1585
1699
|
}
|
|
1586
1700
|
}
|
|
1587
1701
|
function prepareFunctionDeclaration(tool) {
|
|
1588
|
-
var
|
|
1702
|
+
var _a2;
|
|
1589
1703
|
const declaration = {
|
|
1590
1704
|
name: tool.name,
|
|
1591
|
-
description: (
|
|
1705
|
+
description: (_a2 = tool.description) != null ? _a2 : ""
|
|
1592
1706
|
};
|
|
1593
1707
|
try {
|
|
1594
1708
|
return {
|
|
@@ -1836,8 +1950,8 @@ function setNestedValue(obj, segments, value) {
|
|
|
1836
1950
|
defineOwnProperty(current, segments[segments.length - 1], value);
|
|
1837
1951
|
}
|
|
1838
1952
|
function resolvePartialArgValue(arg) {
|
|
1839
|
-
var
|
|
1840
|
-
const value = (_b = (
|
|
1953
|
+
var _a2, _b;
|
|
1954
|
+
const value = (_b = (_a2 = arg.stringValue) != null ? _a2 : arg.numberValue) != null ? _b : arg.boolValue;
|
|
1841
1955
|
if (value != null) return { value, json: JSON.stringify(value) };
|
|
1842
1956
|
if ("nullValue" in arg) return { value: null, json: "null" };
|
|
1843
1957
|
return void 0;
|
|
@@ -1877,20 +1991,27 @@ var configurableSafetySettingCategories = [
|
|
|
1877
1991
|
"HARM_CATEGORY_SEXUALLY_EXPLICIT"
|
|
1878
1992
|
];
|
|
1879
1993
|
var gemini25ModelPattern2 = /(^|\/)gemini-2\.5(?:[.-]|$)/i;
|
|
1994
|
+
var googleCloudStorageFunctionResponseUrls = {
|
|
1995
|
+
"image/png": [/^gs:\/\/.*$/],
|
|
1996
|
+
"image/jpeg": [/^gs:\/\/.*$/],
|
|
1997
|
+
"image/webp": [/^gs:\/\/.*$/],
|
|
1998
|
+
"application/pdf": [/^gs:\/\/.*$/],
|
|
1999
|
+
"text/plain": [/^gs:\/\/.*$/]
|
|
2000
|
+
};
|
|
1880
2001
|
var GoogleGenerativeAILanguageModel = class {
|
|
1881
2002
|
constructor(modelId, config) {
|
|
1882
2003
|
this.specificationVersion = "v3";
|
|
1883
|
-
var
|
|
2004
|
+
var _a2;
|
|
1884
2005
|
this.modelId = modelId;
|
|
1885
2006
|
this.config = config;
|
|
1886
|
-
this.generateId = (
|
|
2007
|
+
this.generateId = (_a2 = config.generateId) != null ? _a2 : generateId;
|
|
1887
2008
|
}
|
|
1888
2009
|
get provider() {
|
|
1889
2010
|
return this.config.provider;
|
|
1890
2011
|
}
|
|
1891
2012
|
get supportedUrls() {
|
|
1892
|
-
var
|
|
1893
|
-
return (_c = (_b = (
|
|
2013
|
+
var _a2, _b, _c;
|
|
2014
|
+
return (_c = (_b = (_a2 = this.config).supportedUrls) == null ? void 0 : _b.call(_a2)) != null ? _c : {};
|
|
1894
2015
|
}
|
|
1895
2016
|
async getArgs({
|
|
1896
2017
|
prompt,
|
|
@@ -1905,9 +2026,10 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1905
2026
|
seed,
|
|
1906
2027
|
tools,
|
|
1907
2028
|
toolChoice,
|
|
1908
|
-
providerOptions
|
|
2029
|
+
providerOptions,
|
|
2030
|
+
abortSignal
|
|
1909
2031
|
}, { isStreaming = false } = {}) {
|
|
1910
|
-
var
|
|
2032
|
+
var _a2, _b, _c;
|
|
1911
2033
|
const warnings = [];
|
|
1912
2034
|
const providerOptionsName = this.config.provider.includes("vertex") ? "vertex" : "google";
|
|
1913
2035
|
let googleOptions = await parseProviderOptions3({
|
|
@@ -1994,15 +2116,21 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1994
2116
|
});
|
|
1995
2117
|
}
|
|
1996
2118
|
const { usesGemini3Features } = getGoogleModelCapabilities(this.modelId);
|
|
2119
|
+
const supportedFunctionResponseUrls = usesGemini3Features && isVertexProvider ? googleCloudStorageFunctionResponseUrls : void 0;
|
|
2120
|
+
const promptWithDownloadedToolResultFiles = isVertexProvider ? await downloadToolResultFiles(prompt, {
|
|
2121
|
+
abortSignal,
|
|
2122
|
+
supportedUrls: supportedFunctionResponseUrls
|
|
2123
|
+
}) : prompt;
|
|
1997
2124
|
const { contents, systemInstruction } = convertToGoogleGenerativeAIMessages(
|
|
1998
|
-
|
|
2125
|
+
promptWithDownloadedToolResultFiles,
|
|
1999
2126
|
{
|
|
2000
2127
|
isGemmaModel,
|
|
2001
2128
|
isGemini3Model: usesGemini3Features,
|
|
2002
2129
|
providerOptionsName,
|
|
2003
2130
|
supportsFunctionResponseParts: usesGemini3Features,
|
|
2004
2131
|
onWarning: (warning) => warnings.push(warning),
|
|
2005
|
-
includeFunctionCallIds: !isVertexProvider
|
|
2132
|
+
includeFunctionCallIds: !isVertexProvider,
|
|
2133
|
+
supportedFunctionResponseUrls
|
|
2006
2134
|
}
|
|
2007
2135
|
);
|
|
2008
2136
|
const {
|
|
@@ -2015,7 +2143,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2015
2143
|
modelId: this.modelId,
|
|
2016
2144
|
isVertexProvider
|
|
2017
2145
|
});
|
|
2018
|
-
const streamFunctionCallArguments = isStreaming && isVertexProvider ? (
|
|
2146
|
+
const streamFunctionCallArguments = isStreaming && isVertexProvider ? (_a2 = googleOptions == null ? void 0 : googleOptions.streamFunctionCallArguments) != null ? _a2 : false : void 0;
|
|
2019
2147
|
const safetyThreshold = googleOptions == null ? void 0 : googleOptions.threshold;
|
|
2020
2148
|
const safetySettings = (_b = googleOptions == null ? void 0 : googleOptions.safetySettings) != null ? _b : safetyThreshold != null ? configurableSafetySettingCategories.map((category) => ({
|
|
2021
2149
|
category,
|
|
@@ -2077,7 +2205,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2077
2205
|
};
|
|
2078
2206
|
}
|
|
2079
2207
|
async doGenerate(options) {
|
|
2080
|
-
var
|
|
2208
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u;
|
|
2081
2209
|
const { args, warnings, providerOptionsName, extraHeaders } = await this.getArgs(options);
|
|
2082
2210
|
const mergedHeaders = combineHeaders3(
|
|
2083
2211
|
await resolve3(this.config.headers),
|
|
@@ -2099,7 +2227,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2099
2227
|
abortSignal: options.abortSignal,
|
|
2100
2228
|
fetch: this.config.fetch
|
|
2101
2229
|
});
|
|
2102
|
-
const candidate = (
|
|
2230
|
+
const candidate = (_a2 = response.candidates) == null ? void 0 : _a2[0];
|
|
2103
2231
|
const promptBlockReason = (_b = response.promptFeedback) == null ? void 0 : _b.blockReason;
|
|
2104
2232
|
const confirmedPromptBlockReason = isConfirmedPromptBlockReason(
|
|
2105
2233
|
promptBlockReason
|
|
@@ -2338,7 +2466,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2338
2466
|
controller.enqueue({ type: "stream-start", warnings });
|
|
2339
2467
|
},
|
|
2340
2468
|
transform(chunk, controller) {
|
|
2341
|
-
var
|
|
2469
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
2342
2470
|
if (options.includeRawChunks) {
|
|
2343
2471
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
2344
2472
|
}
|
|
@@ -2368,7 +2496,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2368
2496
|
};
|
|
2369
2497
|
}
|
|
2370
2498
|
}
|
|
2371
|
-
const candidate = (
|
|
2499
|
+
const candidate = (_a2 = value.candidates) == null ? void 0 : _a2[0];
|
|
2372
2500
|
if (candidate != null) {
|
|
2373
2501
|
if (candidate.groundingMetadata != null) {
|
|
2374
2502
|
lastGroundingMetadata = candidate.groundingMetadata;
|
|
@@ -2677,7 +2805,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2677
2805
|
}
|
|
2678
2806
|
},
|
|
2679
2807
|
flush(controller) {
|
|
2680
|
-
var
|
|
2808
|
+
var _a2;
|
|
2681
2809
|
if (currentTextBlockId !== null) {
|
|
2682
2810
|
controller.enqueue({
|
|
2683
2811
|
type: "text-end",
|
|
@@ -2702,7 +2830,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2702
2830
|
safetyRatings: lastSafetyRatings,
|
|
2703
2831
|
usageMetadata: usage != null ? usage : null,
|
|
2704
2832
|
finishMessage: lastFinishMessage,
|
|
2705
|
-
serviceTier: (
|
|
2833
|
+
serviceTier: (_a2 = usage == null ? void 0 : usage.serviceTier) != null ? _a2 : null
|
|
2706
2834
|
}
|
|
2707
2835
|
}
|
|
2708
2836
|
});
|
|
@@ -2718,7 +2846,7 @@ function extractSources({
|
|
|
2718
2846
|
groundingMetadata,
|
|
2719
2847
|
generateId: generateId3
|
|
2720
2848
|
}) {
|
|
2721
|
-
var
|
|
2849
|
+
var _a2, _b, _c, _d, _e, _f;
|
|
2722
2850
|
if (!(groundingMetadata == null ? void 0 : groundingMetadata.groundingChunks)) {
|
|
2723
2851
|
return void 0;
|
|
2724
2852
|
}
|
|
@@ -2730,7 +2858,7 @@ function extractSources({
|
|
|
2730
2858
|
sourceType: "url",
|
|
2731
2859
|
id: generateId3(),
|
|
2732
2860
|
url: chunk.web.uri,
|
|
2733
|
-
title: (
|
|
2861
|
+
title: (_a2 = chunk.web.title) != null ? _a2 : void 0
|
|
2734
2862
|
});
|
|
2735
2863
|
} else if (chunk.image != null) {
|
|
2736
2864
|
sources.push({
|
|
@@ -3224,7 +3352,7 @@ var GoogleGenerativeAIImageModel = class {
|
|
|
3224
3352
|
return this.doGenerateImagen(options);
|
|
3225
3353
|
}
|
|
3226
3354
|
async doGenerateImagen(options) {
|
|
3227
|
-
var
|
|
3355
|
+
var _a2, _b, _c;
|
|
3228
3356
|
const {
|
|
3229
3357
|
prompt,
|
|
3230
3358
|
n = 1,
|
|
@@ -3267,7 +3395,7 @@ var GoogleGenerativeAIImageModel = class {
|
|
|
3267
3395
|
providerOptions,
|
|
3268
3396
|
schema: googleImageModelOptionsSchema
|
|
3269
3397
|
});
|
|
3270
|
-
const currentDate = (_c = (_b = (
|
|
3398
|
+
const currentDate = (_c = (_b = (_a2 = this.config._internal) == null ? void 0 : _a2.currentDate) == null ? void 0 : _b.call(_a2)) != null ? _c : /* @__PURE__ */ new Date();
|
|
3271
3399
|
const parameters = {
|
|
3272
3400
|
sampleCount: n
|
|
3273
3401
|
};
|
|
@@ -3326,7 +3454,7 @@ var GoogleGenerativeAIImageModel = class {
|
|
|
3326
3454
|
};
|
|
3327
3455
|
}
|
|
3328
3456
|
async doGenerateGemini(options) {
|
|
3329
|
-
var
|
|
3457
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
3330
3458
|
const {
|
|
3331
3459
|
prompt,
|
|
3332
3460
|
n,
|
|
@@ -3386,7 +3514,7 @@ var GoogleGenerativeAIImageModel = class {
|
|
|
3386
3514
|
providerOptions,
|
|
3387
3515
|
schema: googleImageModelOptionsSchema
|
|
3388
3516
|
});
|
|
3389
|
-
const { googleSearch: _strippedGoogleSearch, ...passthroughGoogleOptions } = (
|
|
3517
|
+
const { googleSearch: _strippedGoogleSearch, ...passthroughGoogleOptions } = (_a2 = providerOptions == null ? void 0 : providerOptions.google) != null ? _a2 : {};
|
|
3390
3518
|
const languageModel = new GoogleGenerativeAILanguageModel(this.modelId, {
|
|
3391
3519
|
provider: this.config.provider,
|
|
3392
3520
|
baseURL: this.config.baseURL,
|
|
@@ -3488,7 +3616,7 @@ import {
|
|
|
3488
3616
|
} from "@ai-sdk/provider";
|
|
3489
3617
|
import {
|
|
3490
3618
|
combineHeaders as combineHeaders5,
|
|
3491
|
-
convertUint8ArrayToBase64,
|
|
3619
|
+
convertUint8ArrayToBase64 as convertUint8ArrayToBase642,
|
|
3492
3620
|
createJsonResponseHandler as createJsonResponseHandler5,
|
|
3493
3621
|
delay,
|
|
3494
3622
|
getFromApi,
|
|
@@ -3501,16 +3629,16 @@ import {
|
|
|
3501
3629
|
} from "@ai-sdk/provider-utils";
|
|
3502
3630
|
import { z as z16 } from "zod/v4";
|
|
3503
3631
|
function getFirstFrameImage(options) {
|
|
3504
|
-
var
|
|
3505
|
-
return (_b = (
|
|
3632
|
+
var _a2, _b;
|
|
3633
|
+
return (_b = (_a2 = options.frameImages) == null ? void 0 : _a2.find((frame) => frame.frameType === "first_frame")) == null ? void 0 : _b.image;
|
|
3506
3634
|
}
|
|
3507
3635
|
function resolveStartImage(options) {
|
|
3508
|
-
var
|
|
3509
|
-
return (
|
|
3636
|
+
var _a2;
|
|
3637
|
+
return (_a2 = getFirstFrameImage(options)) != null ? _a2 : options.image;
|
|
3510
3638
|
}
|
|
3511
3639
|
function getLastFrameImage(options) {
|
|
3512
|
-
var
|
|
3513
|
-
return (_b = (
|
|
3640
|
+
var _a2, _b;
|
|
3641
|
+
return (_b = (_a2 = options.frameImages) == null ? void 0 : _a2.find((frame) => frame.frameType === "last_frame")) == null ? void 0 : _b.image;
|
|
3514
3642
|
}
|
|
3515
3643
|
function getInputReferences(options) {
|
|
3516
3644
|
if (options.frameImages != null && options.frameImages.length > 0) {
|
|
@@ -3533,7 +3661,7 @@ function convertFileToGoogleImage(file, warnings) {
|
|
|
3533
3661
|
});
|
|
3534
3662
|
return void 0;
|
|
3535
3663
|
}
|
|
3536
|
-
const base64Data = typeof file.data === "string" ? file.data :
|
|
3664
|
+
const base64Data = typeof file.data === "string" ? file.data : convertUint8ArrayToBase642(file.data);
|
|
3537
3665
|
return {
|
|
3538
3666
|
bytesBase64Encoded: base64Data,
|
|
3539
3667
|
mimeType: file.mediaType || "image/png"
|
|
@@ -3575,8 +3703,8 @@ var GoogleGenerativeAIVideoModel = class {
|
|
|
3575
3703
|
return 4;
|
|
3576
3704
|
}
|
|
3577
3705
|
async doGenerate(options) {
|
|
3578
|
-
var
|
|
3579
|
-
const currentDate = (_c = (_b = (
|
|
3706
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h;
|
|
3707
|
+
const currentDate = (_c = (_b = (_a2 = this.config._internal) == null ? void 0 : _a2.currentDate) == null ? void 0 : _b.call(_a2)) != null ? _c : /* @__PURE__ */ new Date();
|
|
3580
3708
|
const warnings = [];
|
|
3581
3709
|
const googleOptions = await parseProviderOptions5({
|
|
3582
3710
|
provider: "google",
|
|
@@ -3814,7 +3942,7 @@ import {
|
|
|
3814
3942
|
|
|
3815
3943
|
// src/interactions/convert-google-interactions-usage.ts
|
|
3816
3944
|
function convertGoogleInteractionsUsage(usage) {
|
|
3817
|
-
var
|
|
3945
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h;
|
|
3818
3946
|
if (usage == null) {
|
|
3819
3947
|
return {
|
|
3820
3948
|
inputTokens: {
|
|
@@ -3831,7 +3959,7 @@ function convertGoogleInteractionsUsage(usage) {
|
|
|
3831
3959
|
raw: void 0
|
|
3832
3960
|
};
|
|
3833
3961
|
}
|
|
3834
|
-
const totalInput = (
|
|
3962
|
+
const totalInput = (_a2 = usage.total_input_tokens) != null ? _a2 : 0;
|
|
3835
3963
|
const totalOutput = (_b = usage.total_output_tokens) != null ? _b : 0;
|
|
3836
3964
|
const totalThought = (_c = usage.total_thought_tokens) != null ? _c : 0;
|
|
3837
3965
|
const totalCached = (_d = usage.total_cached_tokens) != null ? _d : 0;
|
|
@@ -3889,7 +4017,7 @@ function annotationToSource({
|
|
|
3889
4017
|
annotation,
|
|
3890
4018
|
generateId: generateId3
|
|
3891
4019
|
}) {
|
|
3892
|
-
var
|
|
4020
|
+
var _a2, _b, _c, _d, _e;
|
|
3893
4021
|
switch (annotation.type) {
|
|
3894
4022
|
case "url_citation": {
|
|
3895
4023
|
const a = annotation;
|
|
@@ -3904,7 +4032,7 @@ function annotationToSource({
|
|
|
3904
4032
|
}
|
|
3905
4033
|
case "file_citation": {
|
|
3906
4034
|
const a = annotation;
|
|
3907
|
-
const uri = (_b = (
|
|
4035
|
+
const uri = (_b = (_a2 = a.url) != null ? _a2 : a.document_uri) != null ? _b : a.file_name;
|
|
3908
4036
|
if (uri == null || uri.length === 0) return void 0;
|
|
3909
4037
|
if (uri.startsWith("http://") || uri.startsWith("https://")) {
|
|
3910
4038
|
return {
|
|
@@ -3945,11 +4073,11 @@ function builtinToolResultToSources({
|
|
|
3945
4073
|
block,
|
|
3946
4074
|
generateId: generateId3
|
|
3947
4075
|
}) {
|
|
3948
|
-
var
|
|
4076
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
3949
4077
|
const sources = [];
|
|
3950
4078
|
switch (block.type) {
|
|
3951
4079
|
case "url_context_result": {
|
|
3952
|
-
const result = (
|
|
4080
|
+
const result = (_a2 = block.result) != null ? _a2 : [];
|
|
3953
4081
|
for (const entry of result) {
|
|
3954
4082
|
if ((entry == null ? void 0 : entry.url) == null || entry.url.length === 0) continue;
|
|
3955
4083
|
if (entry.status != null && entry.status !== "success") continue;
|
|
@@ -4032,14 +4160,14 @@ function annotationsToSources({
|
|
|
4032
4160
|
annotations,
|
|
4033
4161
|
generateId: generateId3
|
|
4034
4162
|
}) {
|
|
4035
|
-
var
|
|
4163
|
+
var _a2;
|
|
4036
4164
|
if (annotations == null) return [];
|
|
4037
4165
|
const seen = /* @__PURE__ */ new Set();
|
|
4038
4166
|
const sources = [];
|
|
4039
4167
|
for (const annotation of annotations) {
|
|
4040
4168
|
const source = annotationToSource({ annotation, generateId: generateId3 });
|
|
4041
4169
|
if (source == null) continue;
|
|
4042
|
-
const key = source.sourceType === "url" ? `url:${source.url}` : `doc:${(
|
|
4170
|
+
const key = source.sourceType === "url" ? `url:${source.url}` : `doc:${(_a2 = source.filename) != null ? _a2 : source.title}`;
|
|
4043
4171
|
if (seen.has(key)) continue;
|
|
4044
4172
|
seen.add(key);
|
|
4045
4173
|
sources.push(source);
|
|
@@ -4106,15 +4234,15 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
4106
4234
|
const openBlocks = /* @__PURE__ */ new Map();
|
|
4107
4235
|
const emittedSourceKeys = /* @__PURE__ */ new Set();
|
|
4108
4236
|
function sourceKey(source) {
|
|
4109
|
-
var
|
|
4110
|
-
return source.sourceType === "url" ? `url:${source.url}` : `doc:${(
|
|
4237
|
+
var _a2;
|
|
4238
|
+
return source.sourceType === "url" ? `url:${source.url}` : `doc:${(_a2 = source.filename) != null ? _a2 : source.title}`;
|
|
4111
4239
|
}
|
|
4112
4240
|
return new TransformStream({
|
|
4113
4241
|
start(controller) {
|
|
4114
4242
|
controller.enqueue({ type: "stream-start", warnings });
|
|
4115
4243
|
},
|
|
4116
4244
|
transform(chunk, controller) {
|
|
4117
|
-
var
|
|
4245
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t;
|
|
4118
4246
|
if (includeRawChunks) {
|
|
4119
4247
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
4120
4248
|
}
|
|
@@ -4153,7 +4281,7 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
4153
4281
|
const blockId = `${interactionId != null ? interactionId : "interaction"}:${index}`;
|
|
4154
4282
|
const stepType = step == null ? void 0 : step.type;
|
|
4155
4283
|
if (stepType === "model_output") {
|
|
4156
|
-
const initial = (
|
|
4284
|
+
const initial = (_a2 = step == null ? void 0 : step.content) == null ? void 0 : _a2[0];
|
|
4157
4285
|
if ((initial == null ? void 0 : initial.type) === "text") {
|
|
4158
4286
|
openBlocks.set(index, {
|
|
4159
4287
|
kind: "text",
|
|
@@ -4595,7 +4723,7 @@ function convertToGoogleInteractionsInput({
|
|
|
4595
4723
|
store,
|
|
4596
4724
|
mediaResolution
|
|
4597
4725
|
}) {
|
|
4598
|
-
var
|
|
4726
|
+
var _a2, _b, _c, _d, _e, _f, _g;
|
|
4599
4727
|
const warnings = [];
|
|
4600
4728
|
const incoherentCombo = previousInteractionId != null && store === false;
|
|
4601
4729
|
const shouldCompact = previousInteractionId != null && store !== false;
|
|
@@ -4652,7 +4780,7 @@ function convertToGoogleInteractionsInput({
|
|
|
4652
4780
|
pendingModelOutput.push({ type: "text", text: part.text });
|
|
4653
4781
|
} else if (part.type === "reasoning") {
|
|
4654
4782
|
flushModelOutput();
|
|
4655
|
-
const signature = (_b = (
|
|
4783
|
+
const signature = (_b = (_a2 = part.providerOptions) == null ? void 0 : _a2.google) == null ? void 0 : _b.signature;
|
|
4656
4784
|
steps.push({
|
|
4657
4785
|
type: "thought",
|
|
4658
4786
|
...signature != null ? { signature } : {},
|
|
@@ -4779,8 +4907,8 @@ function compactPromptForPreviousInteraction({
|
|
|
4779
4907
|
for (const message of prompt) {
|
|
4780
4908
|
if (message.role === "assistant") {
|
|
4781
4909
|
const matchesLinkedInteraction = message.content.some((part) => {
|
|
4782
|
-
var
|
|
4783
|
-
const partInteractionId = (_b = (
|
|
4910
|
+
var _a2, _b;
|
|
4911
|
+
const partInteractionId = (_b = (_a2 = part.providerOptions) == null ? void 0 : _a2.google) == null ? void 0 : _b.interactionId;
|
|
4784
4912
|
return partInteractionId === previousInteractionId;
|
|
4785
4913
|
});
|
|
4786
4914
|
if (matchesLinkedInteraction) {
|
|
@@ -4832,7 +4960,7 @@ function convertToolResultPart({
|
|
|
4832
4960
|
signature,
|
|
4833
4961
|
warnings
|
|
4834
4962
|
}) {
|
|
4835
|
-
var
|
|
4963
|
+
var _a2;
|
|
4836
4964
|
const base = {
|
|
4837
4965
|
type: "function_result",
|
|
4838
4966
|
call_id: toolCallId,
|
|
@@ -4852,7 +4980,7 @@ function convertToolResultPart({
|
|
|
4852
4980
|
return {
|
|
4853
4981
|
...base,
|
|
4854
4982
|
is_error: true,
|
|
4855
|
-
result: (
|
|
4983
|
+
result: (_a2 = output.reason) != null ? _a2 : "Tool execution denied by user."
|
|
4856
4984
|
};
|
|
4857
4985
|
case "content": {
|
|
4858
4986
|
const blocks = [];
|
|
@@ -5538,7 +5666,7 @@ function parseGoogleInteractionsOutputs({
|
|
|
5538
5666
|
generateId: generateId3,
|
|
5539
5667
|
interactionId
|
|
5540
5668
|
}) {
|
|
5541
|
-
var
|
|
5669
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
5542
5670
|
const content = [];
|
|
5543
5671
|
let hasFunctionCall = false;
|
|
5544
5672
|
if (steps == null) {
|
|
@@ -5553,7 +5681,7 @@ function parseGoogleInteractionsOutputs({
|
|
|
5553
5681
|
break;
|
|
5554
5682
|
}
|
|
5555
5683
|
case "model_output": {
|
|
5556
|
-
const blocks = (
|
|
5684
|
+
const blocks = (_a2 = step.content) != null ? _a2 : [];
|
|
5557
5685
|
for (const block of blocks) {
|
|
5558
5686
|
if (block == null || typeof block !== "object") continue;
|
|
5559
5687
|
const blockType = block.type;
|
|
@@ -5797,7 +5925,7 @@ function prepareGoogleInteractionsTools({
|
|
|
5797
5925
|
tools,
|
|
5798
5926
|
toolChoice
|
|
5799
5927
|
}) {
|
|
5800
|
-
var
|
|
5928
|
+
var _a2, _b, _c, _d;
|
|
5801
5929
|
const toolWarnings = [];
|
|
5802
5930
|
const normalized = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
|
5803
5931
|
if (normalized == null) {
|
|
@@ -5809,7 +5937,7 @@ function prepareGoogleInteractionsTools({
|
|
|
5809
5937
|
interactionsTools.push({
|
|
5810
5938
|
type: "function",
|
|
5811
5939
|
name: tool.name,
|
|
5812
|
-
description: (
|
|
5940
|
+
description: (_a2 = tool.description) != null ? _a2 : "",
|
|
5813
5941
|
parameters: tool.inputSchema
|
|
5814
5942
|
});
|
|
5815
5943
|
continue;
|
|
@@ -6118,7 +6246,7 @@ function synthesizeGoogleInteractionsAgentStream({
|
|
|
6118
6246
|
}) {
|
|
6119
6247
|
return new ReadableStream({
|
|
6120
6248
|
start(controller) {
|
|
6121
|
-
var
|
|
6249
|
+
var _a2, _b, _c;
|
|
6122
6250
|
controller.enqueue({ type: "stream-start", warnings });
|
|
6123
6251
|
const interactionId = typeof response.id === "string" && response.id.length > 0 ? response.id : void 0;
|
|
6124
6252
|
let timestamp;
|
|
@@ -6132,7 +6260,7 @@ function synthesizeGoogleInteractionsAgentStream({
|
|
|
6132
6260
|
controller.enqueue({
|
|
6133
6261
|
type: "response-metadata",
|
|
6134
6262
|
...interactionId != null ? { id: interactionId } : {},
|
|
6135
|
-
modelId: (
|
|
6263
|
+
modelId: (_a2 = response.model) != null ? _a2 : void 0,
|
|
6136
6264
|
...timestamp ? { timestamp } : {}
|
|
6137
6265
|
});
|
|
6138
6266
|
if (includeRawChunks) {
|
|
@@ -6284,7 +6412,7 @@ var GoogleInteractionsLanguageModel = class {
|
|
|
6284
6412
|
};
|
|
6285
6413
|
}
|
|
6286
6414
|
async getArgs(options) {
|
|
6287
|
-
var
|
|
6415
|
+
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;
|
|
6288
6416
|
const warnings = [];
|
|
6289
6417
|
const opts = await parseProviderOptions6({
|
|
6290
6418
|
provider: "google",
|
|
@@ -6319,7 +6447,7 @@ var GoogleInteractionsLanguageModel = class {
|
|
|
6319
6447
|
warnings.push(...prepared.toolWarnings);
|
|
6320
6448
|
}
|
|
6321
6449
|
const responseFormatEntries = [];
|
|
6322
|
-
if (((
|
|
6450
|
+
if (((_a2 = options.responseFormat) == null ? void 0 : _a2.type) === "json") {
|
|
6323
6451
|
if (isAgent) {
|
|
6324
6452
|
warnings.push({
|
|
6325
6453
|
type: "other",
|
|
@@ -6479,7 +6607,7 @@ var GoogleInteractionsLanguageModel = class {
|
|
|
6479
6607
|
} else {
|
|
6480
6608
|
const env = opts.environment;
|
|
6481
6609
|
const sources = (_A = env.sources) == null ? void 0 : _A.map((s) => {
|
|
6482
|
-
var
|
|
6610
|
+
var _a3;
|
|
6483
6611
|
if (s.type === "inline") {
|
|
6484
6612
|
return {
|
|
6485
6613
|
type: "inline",
|
|
@@ -6490,7 +6618,7 @@ var GoogleInteractionsLanguageModel = class {
|
|
|
6490
6618
|
return pruneUndefined({
|
|
6491
6619
|
type: s.type,
|
|
6492
6620
|
source: s.source,
|
|
6493
|
-
target: (
|
|
6621
|
+
target: (_a3 = s.target) != null ? _a3 : void 0
|
|
6494
6622
|
});
|
|
6495
6623
|
});
|
|
6496
6624
|
let network;
|
|
@@ -6500,10 +6628,10 @@ var GoogleInteractionsLanguageModel = class {
|
|
|
6500
6628
|
network = {
|
|
6501
6629
|
allowlist: env.network.allowlist.map(
|
|
6502
6630
|
(entry) => {
|
|
6503
|
-
var
|
|
6631
|
+
var _a3;
|
|
6504
6632
|
return pruneUndefined({
|
|
6505
6633
|
domain: entry.domain,
|
|
6506
|
-
transform: (
|
|
6634
|
+
transform: (_a3 = entry.transform) != null ? _a3 : void 0
|
|
6507
6635
|
});
|
|
6508
6636
|
}
|
|
6509
6637
|
)
|
|
@@ -6540,7 +6668,7 @@ var GoogleInteractionsLanguageModel = class {
|
|
|
6540
6668
|
};
|
|
6541
6669
|
}
|
|
6542
6670
|
async doGenerate(options) {
|
|
6543
|
-
var
|
|
6671
|
+
var _a2, _b, _c, _d, _e, _f;
|
|
6544
6672
|
const { args, warnings, isAgent, pollingTimeoutMs } = await this.getArgs(options);
|
|
6545
6673
|
const url = `${this.config.baseURL}/interactions`;
|
|
6546
6674
|
const mergedHeaders = combineHeaders7(
|
|
@@ -6575,7 +6703,7 @@ var GoogleInteractionsLanguageModel = class {
|
|
|
6575
6703
|
});
|
|
6576
6704
|
response = polled.response;
|
|
6577
6705
|
rawResponse = polled.rawResponse;
|
|
6578
|
-
responseHeaders = (
|
|
6706
|
+
responseHeaders = (_a2 = polled.responseHeaders) != null ? _a2 : responseHeaders;
|
|
6579
6707
|
}
|
|
6580
6708
|
const interactionId = typeof response.id === "string" && response.id.length > 0 ? response.id : void 0;
|
|
6581
6709
|
const { content, hasFunctionCall } = parseGoogleInteractionsOutputs({
|
|
@@ -6625,7 +6753,7 @@ var GoogleInteractionsLanguageModel = class {
|
|
|
6625
6753
|
};
|
|
6626
6754
|
}
|
|
6627
6755
|
async doStream(options) {
|
|
6628
|
-
var
|
|
6756
|
+
var _a2;
|
|
6629
6757
|
const { args, warnings, isBackground, pollingTimeoutMs } = await this.getArgs(options);
|
|
6630
6758
|
const url = `${this.config.baseURL}/interactions`;
|
|
6631
6759
|
const mergedHeaders = combineHeaders7(
|
|
@@ -6658,7 +6786,7 @@ var GoogleInteractionsLanguageModel = class {
|
|
|
6658
6786
|
const headerServiceTier = responseHeaders == null ? void 0 : responseHeaders["x-gemini-service-tier"];
|
|
6659
6787
|
const transform = buildGoogleInteractionsStreamTransform({
|
|
6660
6788
|
warnings,
|
|
6661
|
-
generateId: (
|
|
6789
|
+
generateId: (_a2 = this.config.generateId) != null ? _a2 : defaultGenerateId2,
|
|
6662
6790
|
includeRawChunks: options.includeRawChunks,
|
|
6663
6791
|
serviceTier: headerServiceTier
|
|
6664
6792
|
});
|
|
@@ -6694,7 +6822,7 @@ var GoogleInteractionsLanguageModel = class {
|
|
|
6694
6822
|
options,
|
|
6695
6823
|
pollingTimeoutMs
|
|
6696
6824
|
}) {
|
|
6697
|
-
var
|
|
6825
|
+
var _a2, _b;
|
|
6698
6826
|
const postResult = await postJsonToApi6({
|
|
6699
6827
|
url,
|
|
6700
6828
|
headers: mergedHeaders,
|
|
@@ -6718,7 +6846,7 @@ var GoogleInteractionsLanguageModel = class {
|
|
|
6718
6846
|
const synthesized = synthesizeGoogleInteractionsAgentStream({
|
|
6719
6847
|
response: postResponse,
|
|
6720
6848
|
warnings,
|
|
6721
|
-
generateId: (
|
|
6849
|
+
generateId: (_a2 = this.config.generateId) != null ? _a2 : defaultGenerateId2,
|
|
6722
6850
|
includeRawChunks: options.includeRawChunks,
|
|
6723
6851
|
headerServiceTier
|
|
6724
6852
|
});
|
|
@@ -6791,8 +6919,8 @@ function supportsExternalFileUrls(modelId) {
|
|
|
6791
6919
|
return /(^|\/)gemini-/.test(modelId) && !/(^|\/)gemini-2\.0/.test(modelId);
|
|
6792
6920
|
}
|
|
6793
6921
|
function createGoogleGenerativeAI(options = {}) {
|
|
6794
|
-
var
|
|
6795
|
-
const baseURL = (
|
|
6922
|
+
var _a2, _b;
|
|
6923
|
+
const baseURL = (_a2 = withoutTrailingSlash(options.baseURL)) != null ? _a2 : "https://generativelanguage.googleapis.com/v1beta";
|
|
6796
6924
|
const providerName = (_b = options.name) != null ? _b : "google.generative-ai";
|
|
6797
6925
|
const getHeaders = () => withUserAgentSuffix2(
|
|
6798
6926
|
{
|
|
@@ -6806,12 +6934,12 @@ function createGoogleGenerativeAI(options = {}) {
|
|
|
6806
6934
|
`ai-sdk/google/${VERSION}`
|
|
6807
6935
|
);
|
|
6808
6936
|
const createChatModel = (modelId) => {
|
|
6809
|
-
var
|
|
6937
|
+
var _a3;
|
|
6810
6938
|
return new GoogleGenerativeAILanguageModel(modelId, {
|
|
6811
6939
|
provider: providerName,
|
|
6812
6940
|
baseURL,
|
|
6813
6941
|
headers: getHeaders,
|
|
6814
|
-
generateId: (
|
|
6942
|
+
generateId: (_a3 = options.generateId) != null ? _a3 : generateId2,
|
|
6815
6943
|
supportedUrls: () => ({
|
|
6816
6944
|
"*": [
|
|
6817
6945
|
// Google Generative Language "files" endpoint
|
|
@@ -6852,24 +6980,24 @@ function createGoogleGenerativeAI(options = {}) {
|
|
|
6852
6980
|
fetch: options.fetch
|
|
6853
6981
|
});
|
|
6854
6982
|
const createVideoModel = (modelId) => {
|
|
6855
|
-
var
|
|
6983
|
+
var _a3;
|
|
6856
6984
|
return new GoogleGenerativeAIVideoModel(modelId, {
|
|
6857
6985
|
provider: providerName,
|
|
6858
6986
|
baseURL,
|
|
6859
6987
|
headers: getHeaders,
|
|
6860
6988
|
fetch: options.fetch,
|
|
6861
|
-
generateId: (
|
|
6989
|
+
generateId: (_a3 = options.generateId) != null ? _a3 : generateId2
|
|
6862
6990
|
});
|
|
6863
6991
|
};
|
|
6864
6992
|
const createInteractionsModel = (modelIdOrAgent) => {
|
|
6865
|
-
var
|
|
6993
|
+
var _a3;
|
|
6866
6994
|
return new GoogleInteractionsLanguageModel(
|
|
6867
6995
|
modelIdOrAgent,
|
|
6868
6996
|
{
|
|
6869
6997
|
provider: `${providerName}.interactions`,
|
|
6870
6998
|
baseURL,
|
|
6871
6999
|
headers: getHeaders,
|
|
6872
|
-
generateId: (
|
|
7000
|
+
generateId: (_a3 = options.generateId) != null ? _a3 : generateId2,
|
|
6873
7001
|
fetch: options.fetch
|
|
6874
7002
|
}
|
|
6875
7003
|
);
|