@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.js
CHANGED
|
@@ -106,14 +106,14 @@ var GoogleTranscriptionModel = class {
|
|
|
106
106
|
});
|
|
107
107
|
}
|
|
108
108
|
async doGenerate(options) {
|
|
109
|
-
var
|
|
109
|
+
var _a2, _b, _c, _d, _e, _f;
|
|
110
110
|
if (isLiveTranscriptionModelId(this.modelId)) {
|
|
111
111
|
throw new import_provider.InvalidArgumentError({
|
|
112
112
|
argument: "modelId",
|
|
113
113
|
message: `Model '${this.modelId}' only supports streaming transcription, which requires AI SDK v7. Use a unary model such as 'gemini-3.5-transcribe'.`
|
|
114
114
|
});
|
|
115
115
|
}
|
|
116
|
-
const currentDate = (_c = (_b = (
|
|
116
|
+
const currentDate = (_c = (_b = (_a2 = this.config._internal) == null ? void 0 : _a2.currentDate) == null ? void 0 : _b.call(_a2)) != null ? _c : /* @__PURE__ */ new Date();
|
|
117
117
|
const warnings = [];
|
|
118
118
|
const googleOptions = await this.parseOptions(options.providerOptions);
|
|
119
119
|
const transcriptionConfig = buildTranscriptionConfig(googleOptions);
|
|
@@ -184,7 +184,7 @@ var GoogleTranscriptionModel = class {
|
|
|
184
184
|
}
|
|
185
185
|
};
|
|
186
186
|
function buildTranscriptionConfig(options) {
|
|
187
|
-
var
|
|
187
|
+
var _a2;
|
|
188
188
|
if (options == null) return void 0;
|
|
189
189
|
const config = {};
|
|
190
190
|
if (options.languageCodes != null) {
|
|
@@ -195,7 +195,7 @@ function buildTranscriptionConfig(options) {
|
|
|
195
195
|
}
|
|
196
196
|
if (options.mode != null || options.diarization === true || options.wordTimestamp === true) {
|
|
197
197
|
config.mode = {
|
|
198
|
-
type: ((
|
|
198
|
+
type: ((_a2 = options.mode) != null ? _a2 : "VERBATIM").toLowerCase(),
|
|
199
199
|
...options.diarization === true ? { diarization_mode: "speaker" } : {},
|
|
200
200
|
...options.wordTimestamp === true ? { timestamp_granularities: ["word"] } : {}
|
|
201
201
|
};
|
|
@@ -232,10 +232,10 @@ var googleInteractionsTranscriptionResponseSchema = import_v43.z.object({
|
|
|
232
232
|
});
|
|
233
233
|
|
|
234
234
|
// src/google-provider.ts
|
|
235
|
-
var
|
|
235
|
+
var import_provider_utils25 = require("@ai-sdk/provider-utils");
|
|
236
236
|
|
|
237
237
|
// src/version.ts
|
|
238
|
-
var VERSION = true ? "3.0.
|
|
238
|
+
var VERSION = true ? "3.0.128" : "0.0.0-test";
|
|
239
239
|
|
|
240
240
|
// src/google-generative-ai-embedding-model.ts
|
|
241
241
|
var import_provider2 = require("@ai-sdk/provider");
|
|
@@ -305,11 +305,31 @@ var googleEmbeddingModelOptions = (0, import_provider_utils3.lazySchema)(
|
|
|
305
305
|
);
|
|
306
306
|
|
|
307
307
|
// src/google-generative-ai-embedding-model.ts
|
|
308
|
+
var _a;
|
|
309
|
+
_a = import_provider_utils4.EXPERIMENTAL_EMBEDDING_MODEL_PROVIDER_OPTIONS_TRANSFORMER;
|
|
308
310
|
var GoogleGenerativeAIEmbeddingModel = class {
|
|
309
311
|
constructor(modelId, config) {
|
|
310
312
|
this.specificationVersion = "v3";
|
|
311
313
|
this.maxEmbeddingsPerCall = 100;
|
|
312
314
|
this.supportsParallelCalls = true;
|
|
315
|
+
this[_a] = ({ providerOptions, values, startIndex, endIndex }) => {
|
|
316
|
+
var _a2;
|
|
317
|
+
const multimodalContent = (_a2 = providerOptions == null ? void 0 : providerOptions.google) == null ? void 0 : _a2.content;
|
|
318
|
+
if (!Array.isArray(multimodalContent)) {
|
|
319
|
+
return providerOptions;
|
|
320
|
+
}
|
|
321
|
+
validateMultimodalContentLength({
|
|
322
|
+
multimodalContent,
|
|
323
|
+
values
|
|
324
|
+
});
|
|
325
|
+
return {
|
|
326
|
+
...providerOptions,
|
|
327
|
+
google: {
|
|
328
|
+
...providerOptions == null ? void 0 : providerOptions.google,
|
|
329
|
+
content: multimodalContent.slice(startIndex, endIndex)
|
|
330
|
+
}
|
|
331
|
+
};
|
|
332
|
+
};
|
|
313
333
|
this.modelId = modelId;
|
|
314
334
|
this.config = config;
|
|
315
335
|
}
|
|
@@ -340,11 +360,7 @@ var GoogleGenerativeAIEmbeddingModel = class {
|
|
|
340
360
|
headers
|
|
341
361
|
);
|
|
342
362
|
const multimodalContent = googleOptions == null ? void 0 : googleOptions.content;
|
|
343
|
-
|
|
344
|
-
throw new Error(
|
|
345
|
-
`The number of multimodal content entries (${multimodalContent.length}) must match the number of values (${values.length}).`
|
|
346
|
-
);
|
|
347
|
-
}
|
|
363
|
+
validateMultimodalContentLength({ multimodalContent, values });
|
|
348
364
|
if (values.length === 1) {
|
|
349
365
|
const valueParts = multimodalContent == null ? void 0 : multimodalContent[0];
|
|
350
366
|
const textPart = values[0] ? [{ text: values[0] }] : [];
|
|
@@ -429,14 +445,24 @@ var googleGenerativeAISingleEmbeddingResponseSchema = (0, import_provider_utils4
|
|
|
429
445
|
})
|
|
430
446
|
)
|
|
431
447
|
);
|
|
448
|
+
function validateMultimodalContentLength({
|
|
449
|
+
multimodalContent,
|
|
450
|
+
values
|
|
451
|
+
}) {
|
|
452
|
+
if (multimodalContent != null && multimodalContent.length !== values.length) {
|
|
453
|
+
throw new Error(
|
|
454
|
+
`The number of multimodal content entries (${multimodalContent.length}) must match the number of values (${values.length}).`
|
|
455
|
+
);
|
|
456
|
+
}
|
|
457
|
+
}
|
|
432
458
|
|
|
433
459
|
// src/google-generative-ai-language-model.ts
|
|
434
|
-
var
|
|
460
|
+
var import_provider_utils8 = require("@ai-sdk/provider-utils");
|
|
435
461
|
var import_v47 = require("zod/v4");
|
|
436
462
|
|
|
437
463
|
// src/convert-google-generative-ai-usage.ts
|
|
438
464
|
function convertGoogleGenerativeAIUsage(usage) {
|
|
439
|
-
var
|
|
465
|
+
var _a2, _b, _c, _d;
|
|
440
466
|
if (usage == null) {
|
|
441
467
|
return {
|
|
442
468
|
inputTokens: {
|
|
@@ -453,7 +479,7 @@ function convertGoogleGenerativeAIUsage(usage) {
|
|
|
453
479
|
raw: void 0
|
|
454
480
|
};
|
|
455
481
|
}
|
|
456
|
-
const promptTokens = (
|
|
482
|
+
const promptTokens = (_a2 = usage.promptTokenCount) != null ? _a2 : 0;
|
|
457
483
|
const candidatesTokens = (_b = usage.candidatesTokenCount) != null ? _b : 0;
|
|
458
484
|
const cachedContentTokens = (_c = usage.cachedContentTokenCount) != null ? _c : 0;
|
|
459
485
|
const thoughtsTokens = (_d = usage.thoughtsTokenCount) != null ? _d : 0;
|
|
@@ -774,19 +800,28 @@ function parseBase64DataUrl(value) {
|
|
|
774
800
|
data: match[2]
|
|
775
801
|
};
|
|
776
802
|
}
|
|
777
|
-
function convertUrlToolResultPart(url) {
|
|
803
|
+
function convertUrlToolResultPart(url, mediaType, supportedFunctionResponseUrls) {
|
|
778
804
|
const parsedDataUrl = parseBase64DataUrl(url);
|
|
779
|
-
if (parsedDataUrl
|
|
780
|
-
return
|
|
805
|
+
if (parsedDataUrl != null) {
|
|
806
|
+
return {
|
|
807
|
+
inlineData: {
|
|
808
|
+
mimeType: parsedDataUrl.mediaType,
|
|
809
|
+
data: parsedDataUrl.data
|
|
810
|
+
}
|
|
811
|
+
};
|
|
781
812
|
}
|
|
782
|
-
return {
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
813
|
+
return mediaType != null && (0, import_provider_utils5.isUrlSupported)({
|
|
814
|
+
url,
|
|
815
|
+
mediaType,
|
|
816
|
+
supportedUrls: supportedFunctionResponseUrls
|
|
817
|
+
}) ? {
|
|
818
|
+
fileData: {
|
|
819
|
+
mimeType: mediaType,
|
|
820
|
+
fileUri: url
|
|
786
821
|
}
|
|
787
|
-
};
|
|
822
|
+
} : void 0;
|
|
788
823
|
}
|
|
789
|
-
function appendToolResultParts(parts, toolName, outputValue, toolCallId, includeFunctionCallIds = true) {
|
|
824
|
+
function appendToolResultParts(parts, toolName, outputValue, toolCallId, includeFunctionCallIds = true, supportedFunctionResponseUrls = {}) {
|
|
790
825
|
const functionResponseParts = [];
|
|
791
826
|
const responseTextParts = [];
|
|
792
827
|
for (const contentPart of outputValue) {
|
|
@@ -808,7 +843,9 @@ function appendToolResultParts(parts, toolName, outputValue, toolCallId, include
|
|
|
808
843
|
case "image-url":
|
|
809
844
|
case "file-url": {
|
|
810
845
|
const functionResponsePart = convertUrlToolResultPart(
|
|
811
|
-
contentPart.url
|
|
846
|
+
contentPart.url,
|
|
847
|
+
contentPart.mediaType,
|
|
848
|
+
supportedFunctionResponseUrls
|
|
812
849
|
);
|
|
813
850
|
if (functionResponsePart != null) {
|
|
814
851
|
functionResponseParts.push(functionResponsePart);
|
|
@@ -873,16 +910,17 @@ function appendLegacyToolResultParts(parts, toolName, outputValue, toolCallId, i
|
|
|
873
910
|
}
|
|
874
911
|
}
|
|
875
912
|
function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
876
|
-
var
|
|
913
|
+
var _a2, _b, _c, _d, _e, _f, _g;
|
|
877
914
|
const systemInstructionParts = [];
|
|
878
915
|
const contents = [];
|
|
879
916
|
let systemMessagesAllowed = true;
|
|
880
|
-
const isGemmaModel = (
|
|
917
|
+
const isGemmaModel = (_a2 = options == null ? void 0 : options.isGemmaModel) != null ? _a2 : false;
|
|
881
918
|
const isGemini3Model = (_b = options == null ? void 0 : options.isGemini3Model) != null ? _b : false;
|
|
882
919
|
const providerOptionsName = (_c = options == null ? void 0 : options.providerOptionsName) != null ? _c : "google";
|
|
883
920
|
const supportsFunctionResponseParts = (_d = options == null ? void 0 : options.supportsFunctionResponseParts) != null ? _d : true;
|
|
884
921
|
const onWarning = options == null ? void 0 : options.onWarning;
|
|
885
922
|
const includeFunctionCallIds = (_e = options == null ? void 0 : options.includeFunctionCallIds) != null ? _e : true;
|
|
923
|
+
const supportedFunctionResponseUrls = (_f = options == null ? void 0 : options.supportedFunctionResponseUrls) != null ? _f : {};
|
|
886
924
|
let sentinelInjected = false;
|
|
887
925
|
const missingSignatureToolNames = [];
|
|
888
926
|
const injectSkipSignature = (toolName) => {
|
|
@@ -1064,7 +1102,8 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
1064
1102
|
part.toolName,
|
|
1065
1103
|
output.value,
|
|
1066
1104
|
part.toolCallId,
|
|
1067
|
-
includeFunctionCallIds
|
|
1105
|
+
includeFunctionCallIds,
|
|
1106
|
+
supportedFunctionResponseUrls
|
|
1068
1107
|
);
|
|
1069
1108
|
} else {
|
|
1070
1109
|
appendLegacyToolResultParts(
|
|
@@ -1082,7 +1121,7 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
1082
1121
|
name: part.toolName,
|
|
1083
1122
|
response: {
|
|
1084
1123
|
name: part.toolName,
|
|
1085
|
-
content: output.type === "execution-denied" ? (
|
|
1124
|
+
content: output.type === "execution-denied" ? (_g = output.reason) != null ? _g : "Tool call execution denied." : output.value
|
|
1086
1125
|
}
|
|
1087
1126
|
}
|
|
1088
1127
|
});
|
|
@@ -1113,16 +1152,82 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
1113
1152
|
};
|
|
1114
1153
|
}
|
|
1115
1154
|
|
|
1155
|
+
// src/download-tool-result-files.ts
|
|
1156
|
+
var import_provider_utils6 = require("@ai-sdk/provider-utils");
|
|
1157
|
+
async function downloadToolResultFiles(prompt, {
|
|
1158
|
+
abortSignal,
|
|
1159
|
+
supportedUrls = {}
|
|
1160
|
+
}) {
|
|
1161
|
+
async function downloadOutput(output) {
|
|
1162
|
+
if (output.type !== "content") {
|
|
1163
|
+
return output;
|
|
1164
|
+
}
|
|
1165
|
+
return {
|
|
1166
|
+
...output,
|
|
1167
|
+
value: await Promise.all(
|
|
1168
|
+
output.value.map(async (part) => {
|
|
1169
|
+
var _a2;
|
|
1170
|
+
if (part.type !== "file-url" && part.type !== "image-url") {
|
|
1171
|
+
return part;
|
|
1172
|
+
}
|
|
1173
|
+
if (part.type === "file-url" && part.mediaType != null && (0, import_provider_utils6.isUrlSupported)({
|
|
1174
|
+
url: part.url,
|
|
1175
|
+
mediaType: part.mediaType,
|
|
1176
|
+
supportedUrls
|
|
1177
|
+
})) {
|
|
1178
|
+
return part;
|
|
1179
|
+
}
|
|
1180
|
+
const blob = await (0, import_provider_utils6.downloadBlob)(part.url, { abortSignal });
|
|
1181
|
+
return {
|
|
1182
|
+
type: part.type === "file-url" ? "file-data" : "image-data",
|
|
1183
|
+
data: (0, import_provider_utils6.convertUint8ArrayToBase64)(
|
|
1184
|
+
new Uint8Array(await blob.arrayBuffer())
|
|
1185
|
+
),
|
|
1186
|
+
mediaType: blob.type || (part.type === "file-url" ? (_a2 = part.mediaType) != null ? _a2 : "application/octet-stream" : "image/*"),
|
|
1187
|
+
providerOptions: part.providerOptions
|
|
1188
|
+
};
|
|
1189
|
+
})
|
|
1190
|
+
)
|
|
1191
|
+
};
|
|
1192
|
+
}
|
|
1193
|
+
return Promise.all(
|
|
1194
|
+
prompt.map(async (message) => {
|
|
1195
|
+
switch (message.role) {
|
|
1196
|
+
case "assistant":
|
|
1197
|
+
return {
|
|
1198
|
+
...message,
|
|
1199
|
+
content: await Promise.all(
|
|
1200
|
+
message.content.map(
|
|
1201
|
+
async (part) => part.type === "tool-result" ? { ...part, output: await downloadOutput(part.output) } : part
|
|
1202
|
+
)
|
|
1203
|
+
)
|
|
1204
|
+
};
|
|
1205
|
+
case "tool":
|
|
1206
|
+
return {
|
|
1207
|
+
...message,
|
|
1208
|
+
content: await Promise.all(
|
|
1209
|
+
message.content.map(
|
|
1210
|
+
async (part) => part.type === "tool-result" ? { ...part, output: await downloadOutput(part.output) } : part
|
|
1211
|
+
)
|
|
1212
|
+
)
|
|
1213
|
+
};
|
|
1214
|
+
default:
|
|
1215
|
+
return message;
|
|
1216
|
+
}
|
|
1217
|
+
})
|
|
1218
|
+
);
|
|
1219
|
+
}
|
|
1220
|
+
|
|
1116
1221
|
// src/get-model-path.ts
|
|
1117
1222
|
function getModelPath(modelId) {
|
|
1118
1223
|
return modelId.includes("/") ? modelId : `models/${modelId}`;
|
|
1119
1224
|
}
|
|
1120
1225
|
|
|
1121
1226
|
// src/google-generative-ai-options.ts
|
|
1122
|
-
var
|
|
1227
|
+
var import_provider_utils7 = require("@ai-sdk/provider-utils");
|
|
1123
1228
|
var import_v46 = require("zod/v4");
|
|
1124
|
-
var googleLanguageModelOptions = (0,
|
|
1125
|
-
() => (0,
|
|
1229
|
+
var googleLanguageModelOptions = (0, import_provider_utils7.lazySchema)(
|
|
1230
|
+
() => (0, import_provider_utils7.zodSchema)(
|
|
1126
1231
|
import_v46.z.object({
|
|
1127
1232
|
responseModalities: import_v46.z.array(import_v46.z.enum(["TEXT", "IMAGE"])).optional(),
|
|
1128
1233
|
thinkingConfig: import_v46.z.object({
|
|
@@ -1564,10 +1669,10 @@ function prepareTools({
|
|
|
1564
1669
|
}
|
|
1565
1670
|
}
|
|
1566
1671
|
function prepareFunctionDeclaration(tool) {
|
|
1567
|
-
var
|
|
1672
|
+
var _a2;
|
|
1568
1673
|
const declaration = {
|
|
1569
1674
|
name: tool.name,
|
|
1570
|
-
description: (
|
|
1675
|
+
description: (_a2 = tool.description) != null ? _a2 : ""
|
|
1571
1676
|
};
|
|
1572
1677
|
try {
|
|
1573
1678
|
return {
|
|
@@ -1815,8 +1920,8 @@ function setNestedValue(obj, segments, value) {
|
|
|
1815
1920
|
defineOwnProperty(current, segments[segments.length - 1], value);
|
|
1816
1921
|
}
|
|
1817
1922
|
function resolvePartialArgValue(arg) {
|
|
1818
|
-
var
|
|
1819
|
-
const value = (_b = (
|
|
1923
|
+
var _a2, _b;
|
|
1924
|
+
const value = (_b = (_a2 = arg.stringValue) != null ? _a2 : arg.numberValue) != null ? _b : arg.boolValue;
|
|
1820
1925
|
if (value != null) return { value, json: JSON.stringify(value) };
|
|
1821
1926
|
if ("nullValue" in arg) return { value: null, json: "null" };
|
|
1822
1927
|
return void 0;
|
|
@@ -1856,20 +1961,27 @@ var configurableSafetySettingCategories = [
|
|
|
1856
1961
|
"HARM_CATEGORY_SEXUALLY_EXPLICIT"
|
|
1857
1962
|
];
|
|
1858
1963
|
var gemini25ModelPattern2 = /(^|\/)gemini-2\.5(?:[.-]|$)/i;
|
|
1964
|
+
var googleCloudStorageFunctionResponseUrls = {
|
|
1965
|
+
"image/png": [/^gs:\/\/.*$/],
|
|
1966
|
+
"image/jpeg": [/^gs:\/\/.*$/],
|
|
1967
|
+
"image/webp": [/^gs:\/\/.*$/],
|
|
1968
|
+
"application/pdf": [/^gs:\/\/.*$/],
|
|
1969
|
+
"text/plain": [/^gs:\/\/.*$/]
|
|
1970
|
+
};
|
|
1859
1971
|
var GoogleGenerativeAILanguageModel = class {
|
|
1860
1972
|
constructor(modelId, config) {
|
|
1861
1973
|
this.specificationVersion = "v3";
|
|
1862
|
-
var
|
|
1974
|
+
var _a2;
|
|
1863
1975
|
this.modelId = modelId;
|
|
1864
1976
|
this.config = config;
|
|
1865
|
-
this.generateId = (
|
|
1977
|
+
this.generateId = (_a2 = config.generateId) != null ? _a2 : import_provider_utils8.generateId;
|
|
1866
1978
|
}
|
|
1867
1979
|
get provider() {
|
|
1868
1980
|
return this.config.provider;
|
|
1869
1981
|
}
|
|
1870
1982
|
get supportedUrls() {
|
|
1871
|
-
var
|
|
1872
|
-
return (_c = (_b = (
|
|
1983
|
+
var _a2, _b, _c;
|
|
1984
|
+
return (_c = (_b = (_a2 = this.config).supportedUrls) == null ? void 0 : _b.call(_a2)) != null ? _c : {};
|
|
1873
1985
|
}
|
|
1874
1986
|
async getArgs({
|
|
1875
1987
|
prompt,
|
|
@@ -1884,18 +1996,19 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1884
1996
|
seed,
|
|
1885
1997
|
tools,
|
|
1886
1998
|
toolChoice,
|
|
1887
|
-
providerOptions
|
|
1999
|
+
providerOptions,
|
|
2000
|
+
abortSignal
|
|
1888
2001
|
}, { isStreaming = false } = {}) {
|
|
1889
|
-
var
|
|
2002
|
+
var _a2, _b, _c;
|
|
1890
2003
|
const warnings = [];
|
|
1891
2004
|
const providerOptionsName = this.config.provider.includes("vertex") ? "vertex" : "google";
|
|
1892
|
-
let googleOptions = await (0,
|
|
2005
|
+
let googleOptions = await (0, import_provider_utils8.parseProviderOptions)({
|
|
1893
2006
|
provider: providerOptionsName,
|
|
1894
2007
|
providerOptions,
|
|
1895
2008
|
schema: googleLanguageModelOptions
|
|
1896
2009
|
});
|
|
1897
2010
|
if (googleOptions == null && providerOptionsName !== "google") {
|
|
1898
|
-
googleOptions = await (0,
|
|
2011
|
+
googleOptions = await (0, import_provider_utils8.parseProviderOptions)({
|
|
1899
2012
|
provider: "google",
|
|
1900
2013
|
providerOptions,
|
|
1901
2014
|
schema: googleLanguageModelOptions
|
|
@@ -1973,15 +2086,21 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1973
2086
|
});
|
|
1974
2087
|
}
|
|
1975
2088
|
const { usesGemini3Features } = getGoogleModelCapabilities(this.modelId);
|
|
2089
|
+
const supportedFunctionResponseUrls = usesGemini3Features && isVertexProvider ? googleCloudStorageFunctionResponseUrls : void 0;
|
|
2090
|
+
const promptWithDownloadedToolResultFiles = isVertexProvider ? await downloadToolResultFiles(prompt, {
|
|
2091
|
+
abortSignal,
|
|
2092
|
+
supportedUrls: supportedFunctionResponseUrls
|
|
2093
|
+
}) : prompt;
|
|
1976
2094
|
const { contents, systemInstruction } = convertToGoogleGenerativeAIMessages(
|
|
1977
|
-
|
|
2095
|
+
promptWithDownloadedToolResultFiles,
|
|
1978
2096
|
{
|
|
1979
2097
|
isGemmaModel,
|
|
1980
2098
|
isGemini3Model: usesGemini3Features,
|
|
1981
2099
|
providerOptionsName,
|
|
1982
2100
|
supportsFunctionResponseParts: usesGemini3Features,
|
|
1983
2101
|
onWarning: (warning) => warnings.push(warning),
|
|
1984
|
-
includeFunctionCallIds: !isVertexProvider
|
|
2102
|
+
includeFunctionCallIds: !isVertexProvider,
|
|
2103
|
+
supportedFunctionResponseUrls
|
|
1985
2104
|
}
|
|
1986
2105
|
);
|
|
1987
2106
|
const {
|
|
@@ -1994,7 +2113,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1994
2113
|
modelId: this.modelId,
|
|
1995
2114
|
isVertexProvider
|
|
1996
2115
|
});
|
|
1997
|
-
const streamFunctionCallArguments = isStreaming && isVertexProvider ? (
|
|
2116
|
+
const streamFunctionCallArguments = isStreaming && isVertexProvider ? (_a2 = googleOptions == null ? void 0 : googleOptions.streamFunctionCallArguments) != null ? _a2 : false : void 0;
|
|
1998
2117
|
const safetyThreshold = googleOptions == null ? void 0 : googleOptions.threshold;
|
|
1999
2118
|
const safetySettings = (_b = googleOptions == null ? void 0 : googleOptions.safetySettings) != null ? _b : safetyThreshold != null ? configurableSafetySettingCategories.map((category) => ({
|
|
2000
2119
|
category,
|
|
@@ -2056,10 +2175,10 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2056
2175
|
};
|
|
2057
2176
|
}
|
|
2058
2177
|
async doGenerate(options) {
|
|
2059
|
-
var
|
|
2178
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u;
|
|
2060
2179
|
const { args, warnings, providerOptionsName, extraHeaders } = await this.getArgs(options);
|
|
2061
|
-
const mergedHeaders = (0,
|
|
2062
|
-
await (0,
|
|
2180
|
+
const mergedHeaders = (0, import_provider_utils8.combineHeaders)(
|
|
2181
|
+
await (0, import_provider_utils8.resolve)(this.config.headers),
|
|
2063
2182
|
options.headers,
|
|
2064
2183
|
extraHeaders
|
|
2065
2184
|
);
|
|
@@ -2067,18 +2186,18 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2067
2186
|
responseHeaders,
|
|
2068
2187
|
value: response,
|
|
2069
2188
|
rawValue: rawResponse
|
|
2070
|
-
} = await (0,
|
|
2189
|
+
} = await (0, import_provider_utils8.postJsonToApi)({
|
|
2071
2190
|
url: `${this.config.baseURL}/${getModelPath(
|
|
2072
2191
|
this.modelId
|
|
2073
2192
|
)}:generateContent`,
|
|
2074
2193
|
headers: mergedHeaders,
|
|
2075
2194
|
body: args,
|
|
2076
2195
|
failedResponseHandler: googleFailedResponseHandler,
|
|
2077
|
-
successfulResponseHandler: (0,
|
|
2196
|
+
successfulResponseHandler: (0, import_provider_utils8.createJsonResponseHandler)(responseSchema),
|
|
2078
2197
|
abortSignal: options.abortSignal,
|
|
2079
2198
|
fetch: this.config.fetch
|
|
2080
2199
|
});
|
|
2081
|
-
const candidate = (
|
|
2200
|
+
const candidate = (_a2 = response.candidates) == null ? void 0 : _a2[0];
|
|
2082
2201
|
const promptBlockReason = (_b = response.promptFeedback) == null ? void 0 : _b.blockReason;
|
|
2083
2202
|
const confirmedPromptBlockReason = isConfirmedPromptBlockReason(
|
|
2084
2203
|
promptBlockReason
|
|
@@ -2245,19 +2364,19 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2245
2364
|
}
|
|
2246
2365
|
async doStream(options) {
|
|
2247
2366
|
const { args, warnings, providerOptionsName, extraHeaders } = await this.getArgs(options, { isStreaming: true });
|
|
2248
|
-
const headers = (0,
|
|
2249
|
-
await (0,
|
|
2367
|
+
const headers = (0, import_provider_utils8.combineHeaders)(
|
|
2368
|
+
await (0, import_provider_utils8.resolve)(this.config.headers),
|
|
2250
2369
|
options.headers,
|
|
2251
2370
|
extraHeaders
|
|
2252
2371
|
);
|
|
2253
|
-
const { responseHeaders, value: response } = await (0,
|
|
2372
|
+
const { responseHeaders, value: response } = await (0, import_provider_utils8.postJsonToApi)({
|
|
2254
2373
|
url: `${this.config.baseURL}/${getModelPath(
|
|
2255
2374
|
this.modelId
|
|
2256
2375
|
)}:streamGenerateContent?alt=sse`,
|
|
2257
2376
|
headers,
|
|
2258
2377
|
body: args,
|
|
2259
2378
|
failedResponseHandler: googleFailedResponseHandler,
|
|
2260
|
-
successfulResponseHandler: (0,
|
|
2379
|
+
successfulResponseHandler: (0, import_provider_utils8.createEventSourceResponseHandler)(chunkSchema),
|
|
2261
2380
|
abortSignal: options.abortSignal,
|
|
2262
2381
|
fetch: this.config.fetch
|
|
2263
2382
|
});
|
|
@@ -2317,7 +2436,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2317
2436
|
controller.enqueue({ type: "stream-start", warnings });
|
|
2318
2437
|
},
|
|
2319
2438
|
transform(chunk, controller) {
|
|
2320
|
-
var
|
|
2439
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
2321
2440
|
if (options.includeRawChunks) {
|
|
2322
2441
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
2323
2442
|
}
|
|
@@ -2347,7 +2466,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2347
2466
|
};
|
|
2348
2467
|
}
|
|
2349
2468
|
}
|
|
2350
|
-
const candidate = (
|
|
2469
|
+
const candidate = (_a2 = value.candidates) == null ? void 0 : _a2[0];
|
|
2351
2470
|
if (candidate != null) {
|
|
2352
2471
|
if (candidate.groundingMetadata != null) {
|
|
2353
2472
|
lastGroundingMetadata = candidate.groundingMetadata;
|
|
@@ -2656,7 +2775,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2656
2775
|
}
|
|
2657
2776
|
},
|
|
2658
2777
|
flush(controller) {
|
|
2659
|
-
var
|
|
2778
|
+
var _a2;
|
|
2660
2779
|
if (currentTextBlockId !== null) {
|
|
2661
2780
|
controller.enqueue({
|
|
2662
2781
|
type: "text-end",
|
|
@@ -2681,7 +2800,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
2681
2800
|
safetyRatings: lastSafetyRatings,
|
|
2682
2801
|
usageMetadata: usage != null ? usage : null,
|
|
2683
2802
|
finishMessage: lastFinishMessage,
|
|
2684
|
-
serviceTier: (
|
|
2803
|
+
serviceTier: (_a2 = usage == null ? void 0 : usage.serviceTier) != null ? _a2 : null
|
|
2685
2804
|
}
|
|
2686
2805
|
}
|
|
2687
2806
|
});
|
|
@@ -2697,7 +2816,7 @@ function extractSources({
|
|
|
2697
2816
|
groundingMetadata,
|
|
2698
2817
|
generateId: generateId3
|
|
2699
2818
|
}) {
|
|
2700
|
-
var
|
|
2819
|
+
var _a2, _b, _c, _d, _e, _f;
|
|
2701
2820
|
if (!(groundingMetadata == null ? void 0 : groundingMetadata.groundingChunks)) {
|
|
2702
2821
|
return void 0;
|
|
2703
2822
|
}
|
|
@@ -2709,7 +2828,7 @@ function extractSources({
|
|
|
2709
2828
|
sourceType: "url",
|
|
2710
2829
|
id: generateId3(),
|
|
2711
2830
|
url: chunk.web.uri,
|
|
2712
|
-
title: (
|
|
2831
|
+
title: (_a2 = chunk.web.title) != null ? _a2 : void 0
|
|
2713
2832
|
});
|
|
2714
2833
|
} else if (chunk.image != null) {
|
|
2715
2834
|
sources.push({
|
|
@@ -2936,8 +3055,8 @@ var getUrlContextMetadataSchema = () => import_v47.z.object({
|
|
|
2936
3055
|
})
|
|
2937
3056
|
).nullish()
|
|
2938
3057
|
});
|
|
2939
|
-
var responseSchema = (0,
|
|
2940
|
-
() => (0,
|
|
3058
|
+
var responseSchema = (0, import_provider_utils8.lazySchema)(
|
|
3059
|
+
() => (0, import_provider_utils8.zodSchema)(
|
|
2941
3060
|
import_v47.z.object({
|
|
2942
3061
|
responseId: import_v47.z.string().nullish(),
|
|
2943
3062
|
candidates: import_v47.z.array(
|
|
@@ -2958,8 +3077,8 @@ var responseSchema = (0, import_provider_utils7.lazySchema)(
|
|
|
2958
3077
|
})
|
|
2959
3078
|
)
|
|
2960
3079
|
);
|
|
2961
|
-
var chunkSchema = (0,
|
|
2962
|
-
() => (0,
|
|
3080
|
+
var chunkSchema = (0, import_provider_utils8.lazySchema)(
|
|
3081
|
+
() => (0, import_provider_utils8.zodSchema)(
|
|
2963
3082
|
import_v47.z.object({
|
|
2964
3083
|
responseId: import_v47.z.string().nullish(),
|
|
2965
3084
|
candidates: import_v47.z.array(
|
|
@@ -2985,9 +3104,9 @@ function isConfirmedPromptBlockReason(blockReason) {
|
|
|
2985
3104
|
}
|
|
2986
3105
|
|
|
2987
3106
|
// src/tool/code-execution.ts
|
|
2988
|
-
var
|
|
3107
|
+
var import_provider_utils9 = require("@ai-sdk/provider-utils");
|
|
2989
3108
|
var import_v48 = require("zod/v4");
|
|
2990
|
-
var codeExecution = (0,
|
|
3109
|
+
var codeExecution = (0, import_provider_utils9.createProviderToolFactoryWithOutputSchema)({
|
|
2991
3110
|
id: "google.code_execution",
|
|
2992
3111
|
inputSchema: import_v48.z.object({
|
|
2993
3112
|
language: import_v48.z.string().describe("The programming language of the code."),
|
|
@@ -3000,15 +3119,15 @@ var codeExecution = (0, import_provider_utils8.createProviderToolFactoryWithOutp
|
|
|
3000
3119
|
});
|
|
3001
3120
|
|
|
3002
3121
|
// src/tool/enterprise-web-search.ts
|
|
3003
|
-
var
|
|
3122
|
+
var import_provider_utils10 = require("@ai-sdk/provider-utils");
|
|
3004
3123
|
var import_v49 = require("zod/v4");
|
|
3005
|
-
var enterpriseWebSearch = (0,
|
|
3124
|
+
var enterpriseWebSearch = (0, import_provider_utils10.createProviderToolFactory)({
|
|
3006
3125
|
id: "google.enterprise_web_search",
|
|
3007
|
-
inputSchema: (0,
|
|
3126
|
+
inputSchema: (0, import_provider_utils10.lazySchema)(() => (0, import_provider_utils10.zodSchema)(import_v49.z.object({})))
|
|
3008
3127
|
});
|
|
3009
3128
|
|
|
3010
3129
|
// src/tool/file-search.ts
|
|
3011
|
-
var
|
|
3130
|
+
var import_provider_utils11 = require("@ai-sdk/provider-utils");
|
|
3012
3131
|
var import_v410 = require("zod/v4");
|
|
3013
3132
|
var fileSearchArgsBaseSchema = import_v410.z.object({
|
|
3014
3133
|
/** The names of the file_search_stores to retrieve from.
|
|
@@ -3026,24 +3145,24 @@ var fileSearchArgsBaseSchema = import_v410.z.object({
|
|
|
3026
3145
|
"Metadata filter to apply to the file search retrieval documents. See https://google.aip.dev/160 for the syntax of the filter expression."
|
|
3027
3146
|
).optional()
|
|
3028
3147
|
}).passthrough();
|
|
3029
|
-
var fileSearchArgsSchema = (0,
|
|
3030
|
-
() => (0,
|
|
3148
|
+
var fileSearchArgsSchema = (0, import_provider_utils11.lazySchema)(
|
|
3149
|
+
() => (0, import_provider_utils11.zodSchema)(fileSearchArgsBaseSchema)
|
|
3031
3150
|
);
|
|
3032
|
-
var fileSearch = (0,
|
|
3151
|
+
var fileSearch = (0, import_provider_utils11.createProviderToolFactory)({
|
|
3033
3152
|
id: "google.file_search",
|
|
3034
3153
|
inputSchema: fileSearchArgsSchema
|
|
3035
3154
|
});
|
|
3036
3155
|
|
|
3037
3156
|
// src/tool/google-maps.ts
|
|
3038
|
-
var
|
|
3157
|
+
var import_provider_utils12 = require("@ai-sdk/provider-utils");
|
|
3039
3158
|
var import_v411 = require("zod/v4");
|
|
3040
|
-
var googleMaps = (0,
|
|
3159
|
+
var googleMaps = (0, import_provider_utils12.createProviderToolFactory)({
|
|
3041
3160
|
id: "google.google_maps",
|
|
3042
|
-
inputSchema: (0,
|
|
3161
|
+
inputSchema: (0, import_provider_utils12.lazySchema)(() => (0, import_provider_utils12.zodSchema)(import_v411.z.object({})))
|
|
3043
3162
|
});
|
|
3044
3163
|
|
|
3045
3164
|
// src/tool/google-search.ts
|
|
3046
|
-
var
|
|
3165
|
+
var import_provider_utils13 = require("@ai-sdk/provider-utils");
|
|
3047
3166
|
var import_v412 = require("zod/v4");
|
|
3048
3167
|
var googleSearchToolArgsBaseSchema = import_v412.z.object({
|
|
3049
3168
|
searchTypes: import_v412.z.object({
|
|
@@ -3055,10 +3174,10 @@ var googleSearchToolArgsBaseSchema = import_v412.z.object({
|
|
|
3055
3174
|
endTime: import_v412.z.string()
|
|
3056
3175
|
}).optional()
|
|
3057
3176
|
}).passthrough();
|
|
3058
|
-
var googleSearchToolArgsSchema = (0,
|
|
3059
|
-
() => (0,
|
|
3177
|
+
var googleSearchToolArgsSchema = (0, import_provider_utils13.lazySchema)(
|
|
3178
|
+
() => (0, import_provider_utils13.zodSchema)(googleSearchToolArgsBaseSchema)
|
|
3060
3179
|
);
|
|
3061
|
-
var googleSearch = (0,
|
|
3180
|
+
var googleSearch = (0, import_provider_utils13.createProviderToolFactory)(
|
|
3062
3181
|
{
|
|
3063
3182
|
id: "google.google_search",
|
|
3064
3183
|
inputSchema: googleSearchToolArgsSchema
|
|
@@ -3066,17 +3185,17 @@ var googleSearch = (0, import_provider_utils12.createProviderToolFactory)(
|
|
|
3066
3185
|
);
|
|
3067
3186
|
|
|
3068
3187
|
// src/tool/url-context.ts
|
|
3069
|
-
var
|
|
3188
|
+
var import_provider_utils14 = require("@ai-sdk/provider-utils");
|
|
3070
3189
|
var import_v413 = require("zod/v4");
|
|
3071
|
-
var urlContext = (0,
|
|
3190
|
+
var urlContext = (0, import_provider_utils14.createProviderToolFactory)({
|
|
3072
3191
|
id: "google.url_context",
|
|
3073
|
-
inputSchema: (0,
|
|
3192
|
+
inputSchema: (0, import_provider_utils14.lazySchema)(() => (0, import_provider_utils14.zodSchema)(import_v413.z.object({})))
|
|
3074
3193
|
});
|
|
3075
3194
|
|
|
3076
3195
|
// src/tool/vertex-rag-store.ts
|
|
3077
|
-
var
|
|
3196
|
+
var import_provider_utils15 = require("@ai-sdk/provider-utils");
|
|
3078
3197
|
var import_v414 = require("zod/v4");
|
|
3079
|
-
var vertexRagStore = (0,
|
|
3198
|
+
var vertexRagStore = (0, import_provider_utils15.createProviderToolFactory)({
|
|
3080
3199
|
id: "google.vertex_rag_store",
|
|
3081
3200
|
inputSchema: import_v414.z.object({
|
|
3082
3201
|
ragCorpus: import_v414.z.string(),
|
|
@@ -3145,7 +3264,7 @@ var googleTools = {
|
|
|
3145
3264
|
};
|
|
3146
3265
|
|
|
3147
3266
|
// src/google-generative-ai-image-model.ts
|
|
3148
|
-
var
|
|
3267
|
+
var import_provider_utils16 = require("@ai-sdk/provider-utils");
|
|
3149
3268
|
var import_v415 = require("zod/v4");
|
|
3150
3269
|
var GoogleGenerativeAIImageModel = class {
|
|
3151
3270
|
constructor(modelId, settings, config) {
|
|
@@ -3173,7 +3292,7 @@ var GoogleGenerativeAIImageModel = class {
|
|
|
3173
3292
|
return this.doGenerateImagen(options);
|
|
3174
3293
|
}
|
|
3175
3294
|
async doGenerateImagen(options) {
|
|
3176
|
-
var
|
|
3295
|
+
var _a2, _b, _c;
|
|
3177
3296
|
const {
|
|
3178
3297
|
prompt,
|
|
3179
3298
|
n = 1,
|
|
@@ -3211,12 +3330,12 @@ var GoogleGenerativeAIImageModel = class {
|
|
|
3211
3330
|
details: "This model does not support the `seed` option through this provider."
|
|
3212
3331
|
});
|
|
3213
3332
|
}
|
|
3214
|
-
const googleOptions = await (0,
|
|
3333
|
+
const googleOptions = await (0, import_provider_utils16.parseProviderOptions)({
|
|
3215
3334
|
provider: "google",
|
|
3216
3335
|
providerOptions,
|
|
3217
3336
|
schema: googleImageModelOptionsSchema
|
|
3218
3337
|
});
|
|
3219
|
-
const currentDate = (_c = (_b = (
|
|
3338
|
+
const currentDate = (_c = (_b = (_a2 = this.config._internal) == null ? void 0 : _a2.currentDate) == null ? void 0 : _b.call(_a2)) != null ? _c : /* @__PURE__ */ new Date();
|
|
3220
3339
|
const parameters = {
|
|
3221
3340
|
sampleCount: n
|
|
3222
3341
|
};
|
|
@@ -3238,12 +3357,12 @@ var GoogleGenerativeAIImageModel = class {
|
|
|
3238
3357
|
instances: [{ prompt }],
|
|
3239
3358
|
parameters
|
|
3240
3359
|
};
|
|
3241
|
-
const { responseHeaders, value: response } = await (0,
|
|
3360
|
+
const { responseHeaders, value: response } = await (0, import_provider_utils16.postJsonToApi)({
|
|
3242
3361
|
url: `${this.config.baseURL}/models/${this.modelId}:predict`,
|
|
3243
|
-
headers: (0,
|
|
3362
|
+
headers: (0, import_provider_utils16.combineHeaders)(await (0, import_provider_utils16.resolve)(this.config.headers), headers),
|
|
3244
3363
|
body,
|
|
3245
3364
|
failedResponseHandler: googleFailedResponseHandler,
|
|
3246
|
-
successfulResponseHandler: (0,
|
|
3365
|
+
successfulResponseHandler: (0, import_provider_utils16.createJsonResponseHandler)(
|
|
3247
3366
|
googleImageResponseSchema
|
|
3248
3367
|
),
|
|
3249
3368
|
abortSignal,
|
|
@@ -3275,7 +3394,7 @@ var GoogleGenerativeAIImageModel = class {
|
|
|
3275
3394
|
};
|
|
3276
3395
|
}
|
|
3277
3396
|
async doGenerateGemini(options) {
|
|
3278
|
-
var
|
|
3397
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
3279
3398
|
const {
|
|
3280
3399
|
prompt,
|
|
3281
3400
|
n,
|
|
@@ -3330,18 +3449,18 @@ var GoogleGenerativeAIImageModel = class {
|
|
|
3330
3449
|
const languageModelPrompt = [
|
|
3331
3450
|
{ role: "user", content: userContent }
|
|
3332
3451
|
];
|
|
3333
|
-
const googleImageOptions = await (0,
|
|
3452
|
+
const googleImageOptions = await (0, import_provider_utils16.parseProviderOptions)({
|
|
3334
3453
|
provider: "google",
|
|
3335
3454
|
providerOptions,
|
|
3336
3455
|
schema: googleImageModelOptionsSchema
|
|
3337
3456
|
});
|
|
3338
|
-
const { googleSearch: _strippedGoogleSearch, ...passthroughGoogleOptions } = (
|
|
3457
|
+
const { googleSearch: _strippedGoogleSearch, ...passthroughGoogleOptions } = (_a2 = providerOptions == null ? void 0 : providerOptions.google) != null ? _a2 : {};
|
|
3339
3458
|
const languageModel = new GoogleGenerativeAILanguageModel(this.modelId, {
|
|
3340
3459
|
provider: this.config.provider,
|
|
3341
3460
|
baseURL: this.config.baseURL,
|
|
3342
3461
|
headers: (_b = this.config.headers) != null ? _b : {},
|
|
3343
3462
|
fetch: this.config.fetch,
|
|
3344
|
-
generateId: (_c = this.config.generateId) != null ? _c :
|
|
3463
|
+
generateId: (_c = this.config.generateId) != null ? _c : import_provider_utils16.generateId
|
|
3345
3464
|
});
|
|
3346
3465
|
const result = await languageModel.doGenerate({
|
|
3347
3466
|
prompt: languageModelPrompt,
|
|
@@ -3370,7 +3489,7 @@ var GoogleGenerativeAIImageModel = class {
|
|
|
3370
3489
|
const images = [];
|
|
3371
3490
|
for (const part of result.content) {
|
|
3372
3491
|
if (part.type === "file" && part.mediaType.startsWith("image/")) {
|
|
3373
|
-
images.push((0,
|
|
3492
|
+
images.push((0, import_provider_utils16.convertToBase64)(part.data));
|
|
3374
3493
|
}
|
|
3375
3494
|
}
|
|
3376
3495
|
const languageModelGoogleMetadata = (_h = (_g = result.providerMetadata) == null ? void 0 : _g.google) != null ? _h : {};
|
|
@@ -3400,8 +3519,8 @@ var GoogleGenerativeAIImageModel = class {
|
|
|
3400
3519
|
function isGeminiModel(modelId) {
|
|
3401
3520
|
return modelId.startsWith("gemini-");
|
|
3402
3521
|
}
|
|
3403
|
-
var googleImageResponseSchema = (0,
|
|
3404
|
-
() => (0,
|
|
3522
|
+
var googleImageResponseSchema = (0, import_provider_utils16.lazySchema)(
|
|
3523
|
+
() => (0, import_provider_utils16.zodSchema)(
|
|
3405
3524
|
import_v415.z.object({
|
|
3406
3525
|
predictions: import_v415.z.array(
|
|
3407
3526
|
import_v415.z.union([
|
|
@@ -3412,8 +3531,8 @@ var googleImageResponseSchema = (0, import_provider_utils15.lazySchema)(
|
|
|
3412
3531
|
})
|
|
3413
3532
|
)
|
|
3414
3533
|
);
|
|
3415
|
-
var googleImageModelOptionsSchema = (0,
|
|
3416
|
-
() => (0,
|
|
3534
|
+
var googleImageModelOptionsSchema = (0, import_provider_utils16.lazySchema)(
|
|
3535
|
+
() => (0, import_provider_utils16.zodSchema)(
|
|
3417
3536
|
import_v415.z.object({
|
|
3418
3537
|
personGeneration: import_v415.z.enum(["dont_allow", "allow_adult", "allow_all"]).nullish(),
|
|
3419
3538
|
aspectRatio: import_v415.z.enum(["1:1", "3:4", "4:3", "9:16", "16:9"]).nullish(),
|
|
@@ -3433,19 +3552,19 @@ var googleImageModelOptionsSchema = (0, import_provider_utils15.lazySchema)(
|
|
|
3433
3552
|
|
|
3434
3553
|
// src/google-generative-ai-video-model.ts
|
|
3435
3554
|
var import_provider6 = require("@ai-sdk/provider");
|
|
3436
|
-
var
|
|
3555
|
+
var import_provider_utils17 = require("@ai-sdk/provider-utils");
|
|
3437
3556
|
var import_v416 = require("zod/v4");
|
|
3438
3557
|
function getFirstFrameImage(options) {
|
|
3439
|
-
var
|
|
3440
|
-
return (_b = (
|
|
3558
|
+
var _a2, _b;
|
|
3559
|
+
return (_b = (_a2 = options.frameImages) == null ? void 0 : _a2.find((frame) => frame.frameType === "first_frame")) == null ? void 0 : _b.image;
|
|
3441
3560
|
}
|
|
3442
3561
|
function resolveStartImage(options) {
|
|
3443
|
-
var
|
|
3444
|
-
return (
|
|
3562
|
+
var _a2;
|
|
3563
|
+
return (_a2 = getFirstFrameImage(options)) != null ? _a2 : options.image;
|
|
3445
3564
|
}
|
|
3446
3565
|
function getLastFrameImage(options) {
|
|
3447
|
-
var
|
|
3448
|
-
return (_b = (
|
|
3566
|
+
var _a2, _b;
|
|
3567
|
+
return (_b = (_a2 = options.frameImages) == null ? void 0 : _a2.find((frame) => frame.frameType === "last_frame")) == null ? void 0 : _b.image;
|
|
3449
3568
|
}
|
|
3450
3569
|
function getInputReferences(options) {
|
|
3451
3570
|
if (options.frameImages != null && options.frameImages.length > 0) {
|
|
@@ -3468,7 +3587,7 @@ function convertFileToGoogleImage(file, warnings) {
|
|
|
3468
3587
|
});
|
|
3469
3588
|
return void 0;
|
|
3470
3589
|
}
|
|
3471
|
-
const base64Data = typeof file.data === "string" ? file.data : (0,
|
|
3590
|
+
const base64Data = typeof file.data === "string" ? file.data : (0, import_provider_utils17.convertUint8ArrayToBase64)(file.data);
|
|
3472
3591
|
return {
|
|
3473
3592
|
bytesBase64Encoded: base64Data,
|
|
3474
3593
|
mimeType: file.mediaType || "image/png"
|
|
@@ -3510,10 +3629,10 @@ var GoogleGenerativeAIVideoModel = class {
|
|
|
3510
3629
|
return 4;
|
|
3511
3630
|
}
|
|
3512
3631
|
async doGenerate(options) {
|
|
3513
|
-
var
|
|
3514
|
-
const currentDate = (_c = (_b = (
|
|
3632
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h;
|
|
3633
|
+
const currentDate = (_c = (_b = (_a2 = this.config._internal) == null ? void 0 : _a2.currentDate) == null ? void 0 : _b.call(_a2)) != null ? _c : /* @__PURE__ */ new Date();
|
|
3515
3634
|
const warnings = [];
|
|
3516
|
-
const googleOptions = await (0,
|
|
3635
|
+
const googleOptions = await (0, import_provider_utils17.parseProviderOptions)({
|
|
3517
3636
|
provider: "google",
|
|
3518
3637
|
providerOptions: options.providerOptions,
|
|
3519
3638
|
schema: googleVideoModelOptionsSchema
|
|
@@ -3588,17 +3707,17 @@ var GoogleGenerativeAIVideoModel = class {
|
|
|
3588
3707
|
}
|
|
3589
3708
|
}
|
|
3590
3709
|
}
|
|
3591
|
-
const { value: operation } = await (0,
|
|
3710
|
+
const { value: operation } = await (0, import_provider_utils17.postJsonToApi)({
|
|
3592
3711
|
url: `${this.config.baseURL}/models/${this.modelId}:predictLongRunning`,
|
|
3593
|
-
headers: (0,
|
|
3594
|
-
await (0,
|
|
3712
|
+
headers: (0, import_provider_utils17.combineHeaders)(
|
|
3713
|
+
await (0, import_provider_utils17.resolve)(this.config.headers),
|
|
3595
3714
|
options.headers
|
|
3596
3715
|
),
|
|
3597
3716
|
body: {
|
|
3598
3717
|
instances,
|
|
3599
3718
|
parameters
|
|
3600
3719
|
},
|
|
3601
|
-
successfulResponseHandler: (0,
|
|
3720
|
+
successfulResponseHandler: (0, import_provider_utils17.createJsonResponseHandler)(
|
|
3602
3721
|
googleOperationSchema
|
|
3603
3722
|
),
|
|
3604
3723
|
failedResponseHandler: googleFailedResponseHandler,
|
|
@@ -3624,20 +3743,20 @@ var GoogleGenerativeAIVideoModel = class {
|
|
|
3624
3743
|
message: `Video generation timed out after ${pollTimeoutMs}ms`
|
|
3625
3744
|
});
|
|
3626
3745
|
}
|
|
3627
|
-
await (0,
|
|
3746
|
+
await (0, import_provider_utils17.delay)(pollIntervalMs);
|
|
3628
3747
|
if ((_f = options.abortSignal) == null ? void 0 : _f.aborted) {
|
|
3629
3748
|
throw new import_provider6.AISDKError({
|
|
3630
3749
|
name: "GOOGLE_VIDEO_GENERATION_ABORTED",
|
|
3631
3750
|
message: "Video generation request was aborted"
|
|
3632
3751
|
});
|
|
3633
3752
|
}
|
|
3634
|
-
const { value: statusOperation, responseHeaders: pollHeaders } = await (0,
|
|
3753
|
+
const { value: statusOperation, responseHeaders: pollHeaders } = await (0, import_provider_utils17.getFromApi)({
|
|
3635
3754
|
url: `${this.config.baseURL}/${operationName}`,
|
|
3636
|
-
headers: (0,
|
|
3637
|
-
await (0,
|
|
3755
|
+
headers: (0, import_provider_utils17.combineHeaders)(
|
|
3756
|
+
await (0, import_provider_utils17.resolve)(this.config.headers),
|
|
3638
3757
|
options.headers
|
|
3639
3758
|
),
|
|
3640
|
-
successfulResponseHandler: (0,
|
|
3759
|
+
successfulResponseHandler: (0, import_provider_utils17.createJsonResponseHandler)(
|
|
3641
3760
|
googleOperationSchema
|
|
3642
3761
|
),
|
|
3643
3762
|
failedResponseHandler: googleFailedResponseHandler,
|
|
@@ -3662,11 +3781,11 @@ var GoogleGenerativeAIVideoModel = class {
|
|
|
3662
3781
|
}
|
|
3663
3782
|
const videos = [];
|
|
3664
3783
|
const videoMetadata = [];
|
|
3665
|
-
const resolvedHeaders = await (0,
|
|
3784
|
+
const resolvedHeaders = await (0, import_provider_utils17.resolve)(this.config.headers);
|
|
3666
3785
|
const apiKey = resolvedHeaders == null ? void 0 : resolvedHeaders["x-goog-api-key"];
|
|
3667
3786
|
for (const generatedSample of response.generateVideoResponse.generatedSamples) {
|
|
3668
3787
|
if ((_h = generatedSample.video) == null ? void 0 : _h.uri) {
|
|
3669
|
-
const urlWithAuth = apiKey && (0,
|
|
3788
|
+
const urlWithAuth = apiKey && (0, import_provider_utils17.isSameOrigin)(generatedSample.video.uri, this.config.baseURL) ? `${generatedSample.video.uri}${generatedSample.video.uri.includes("?") ? "&" : "?"}key=${apiKey}` : generatedSample.video.uri;
|
|
3670
3789
|
videos.push({
|
|
3671
3790
|
type: "url",
|
|
3672
3791
|
url: urlWithAuth,
|
|
@@ -3719,8 +3838,8 @@ var googleOperationSchema = import_v416.z.object({
|
|
|
3719
3838
|
}).nullish()
|
|
3720
3839
|
}).nullish()
|
|
3721
3840
|
});
|
|
3722
|
-
var googleVideoModelOptionsSchema = (0,
|
|
3723
|
-
() => (0,
|
|
3841
|
+
var googleVideoModelOptionsSchema = (0, import_provider_utils17.lazySchema)(
|
|
3842
|
+
() => (0, import_provider_utils17.zodSchema)(
|
|
3724
3843
|
import_v416.z.object({
|
|
3725
3844
|
pollIntervalMs: import_v416.z.number().positive().nullish(),
|
|
3726
3845
|
pollTimeoutMs: import_v416.z.number().positive().nullish(),
|
|
@@ -3737,11 +3856,11 @@ var googleVideoModelOptionsSchema = (0, import_provider_utils16.lazySchema)(
|
|
|
3737
3856
|
);
|
|
3738
3857
|
|
|
3739
3858
|
// src/interactions/google-interactions-language-model.ts
|
|
3740
|
-
var
|
|
3859
|
+
var import_provider_utils24 = require("@ai-sdk/provider-utils");
|
|
3741
3860
|
|
|
3742
3861
|
// src/interactions/convert-google-interactions-usage.ts
|
|
3743
3862
|
function convertGoogleInteractionsUsage(usage) {
|
|
3744
|
-
var
|
|
3863
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h;
|
|
3745
3864
|
if (usage == null) {
|
|
3746
3865
|
return {
|
|
3747
3866
|
inputTokens: {
|
|
@@ -3758,7 +3877,7 @@ function convertGoogleInteractionsUsage(usage) {
|
|
|
3758
3877
|
raw: void 0
|
|
3759
3878
|
};
|
|
3760
3879
|
}
|
|
3761
|
-
const totalInput = (
|
|
3880
|
+
const totalInput = (_a2 = usage.total_input_tokens) != null ? _a2 : 0;
|
|
3762
3881
|
const totalOutput = (_b = usage.total_output_tokens) != null ? _b : 0;
|
|
3763
3882
|
const totalThought = (_c = usage.total_thought_tokens) != null ? _c : 0;
|
|
3764
3883
|
const totalCached = (_d = usage.total_cached_tokens) != null ? _d : 0;
|
|
@@ -3816,7 +3935,7 @@ function annotationToSource({
|
|
|
3816
3935
|
annotation,
|
|
3817
3936
|
generateId: generateId3
|
|
3818
3937
|
}) {
|
|
3819
|
-
var
|
|
3938
|
+
var _a2, _b, _c, _d, _e;
|
|
3820
3939
|
switch (annotation.type) {
|
|
3821
3940
|
case "url_citation": {
|
|
3822
3941
|
const a = annotation;
|
|
@@ -3831,7 +3950,7 @@ function annotationToSource({
|
|
|
3831
3950
|
}
|
|
3832
3951
|
case "file_citation": {
|
|
3833
3952
|
const a = annotation;
|
|
3834
|
-
const uri = (_b = (
|
|
3953
|
+
const uri = (_b = (_a2 = a.url) != null ? _a2 : a.document_uri) != null ? _b : a.file_name;
|
|
3835
3954
|
if (uri == null || uri.length === 0) return void 0;
|
|
3836
3955
|
if (uri.startsWith("http://") || uri.startsWith("https://")) {
|
|
3837
3956
|
return {
|
|
@@ -3872,11 +3991,11 @@ function builtinToolResultToSources({
|
|
|
3872
3991
|
block,
|
|
3873
3992
|
generateId: generateId3
|
|
3874
3993
|
}) {
|
|
3875
|
-
var
|
|
3994
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
3876
3995
|
const sources = [];
|
|
3877
3996
|
switch (block.type) {
|
|
3878
3997
|
case "url_context_result": {
|
|
3879
|
-
const result = (
|
|
3998
|
+
const result = (_a2 = block.result) != null ? _a2 : [];
|
|
3880
3999
|
for (const entry of result) {
|
|
3881
4000
|
if ((entry == null ? void 0 : entry.url) == null || entry.url.length === 0) continue;
|
|
3882
4001
|
if (entry.status != null && entry.status !== "success") continue;
|
|
@@ -3959,14 +4078,14 @@ function annotationsToSources({
|
|
|
3959
4078
|
annotations,
|
|
3960
4079
|
generateId: generateId3
|
|
3961
4080
|
}) {
|
|
3962
|
-
var
|
|
4081
|
+
var _a2;
|
|
3963
4082
|
if (annotations == null) return [];
|
|
3964
4083
|
const seen = /* @__PURE__ */ new Set();
|
|
3965
4084
|
const sources = [];
|
|
3966
4085
|
for (const annotation of annotations) {
|
|
3967
4086
|
const source = annotationToSource({ annotation, generateId: generateId3 });
|
|
3968
4087
|
if (source == null) continue;
|
|
3969
|
-
const key = source.sourceType === "url" ? `url:${source.url}` : `doc:${(
|
|
4088
|
+
const key = source.sourceType === "url" ? `url:${source.url}` : `doc:${(_a2 = source.filename) != null ? _a2 : source.title}`;
|
|
3970
4089
|
if (seen.has(key)) continue;
|
|
3971
4090
|
seen.add(key);
|
|
3972
4091
|
sources.push(source);
|
|
@@ -4033,15 +4152,15 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
4033
4152
|
const openBlocks = /* @__PURE__ */ new Map();
|
|
4034
4153
|
const emittedSourceKeys = /* @__PURE__ */ new Set();
|
|
4035
4154
|
function sourceKey(source) {
|
|
4036
|
-
var
|
|
4037
|
-
return source.sourceType === "url" ? `url:${source.url}` : `doc:${(
|
|
4155
|
+
var _a2;
|
|
4156
|
+
return source.sourceType === "url" ? `url:${source.url}` : `doc:${(_a2 = source.filename) != null ? _a2 : source.title}`;
|
|
4038
4157
|
}
|
|
4039
4158
|
return new TransformStream({
|
|
4040
4159
|
start(controller) {
|
|
4041
4160
|
controller.enqueue({ type: "stream-start", warnings });
|
|
4042
4161
|
},
|
|
4043
4162
|
transform(chunk, controller) {
|
|
4044
|
-
var
|
|
4163
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t;
|
|
4045
4164
|
if (includeRawChunks) {
|
|
4046
4165
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
4047
4166
|
}
|
|
@@ -4080,7 +4199,7 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
4080
4199
|
const blockId = `${interactionId != null ? interactionId : "interaction"}:${index}`;
|
|
4081
4200
|
const stepType = step == null ? void 0 : step.type;
|
|
4082
4201
|
if (stepType === "model_output") {
|
|
4083
|
-
const initial = (
|
|
4202
|
+
const initial = (_a2 = step == null ? void 0 : step.content) == null ? void 0 : _a2[0];
|
|
4084
4203
|
if ((initial == null ? void 0 : initial.type) === "text") {
|
|
4085
4204
|
openBlocks.set(index, {
|
|
4086
4205
|
kind: "text",
|
|
@@ -4503,7 +4622,7 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
4503
4622
|
}
|
|
4504
4623
|
|
|
4505
4624
|
// src/interactions/convert-to-google-interactions-input.ts
|
|
4506
|
-
var
|
|
4625
|
+
var import_provider_utils18 = require("@ai-sdk/provider-utils");
|
|
4507
4626
|
function getTopLevelMediaType(mediaType) {
|
|
4508
4627
|
const slashIndex = mediaType.indexOf("/");
|
|
4509
4628
|
return slashIndex === -1 ? mediaType : mediaType.substring(0, slashIndex);
|
|
@@ -4522,7 +4641,7 @@ function convertToGoogleInteractionsInput({
|
|
|
4522
4641
|
store,
|
|
4523
4642
|
mediaResolution
|
|
4524
4643
|
}) {
|
|
4525
|
-
var
|
|
4644
|
+
var _a2, _b, _c, _d, _e, _f, _g;
|
|
4526
4645
|
const warnings = [];
|
|
4527
4646
|
const incoherentCombo = previousInteractionId != null && store === false;
|
|
4528
4647
|
const shouldCompact = previousInteractionId != null && store !== false;
|
|
@@ -4579,7 +4698,7 @@ function convertToGoogleInteractionsInput({
|
|
|
4579
4698
|
pendingModelOutput.push({ type: "text", text: part.text });
|
|
4580
4699
|
} else if (part.type === "reasoning") {
|
|
4581
4700
|
flushModelOutput();
|
|
4582
|
-
const signature = (_b = (
|
|
4701
|
+
const signature = (_b = (_a2 = part.providerOptions) == null ? void 0 : _a2.google) == null ? void 0 : _b.signature;
|
|
4583
4702
|
steps.push({
|
|
4584
4703
|
type: "thought",
|
|
4585
4704
|
...signature != null ? { signature } : {},
|
|
@@ -4692,7 +4811,7 @@ function convertFilePartToContent({
|
|
|
4692
4811
|
}
|
|
4693
4812
|
return {
|
|
4694
4813
|
type: kind,
|
|
4695
|
-
data: (0,
|
|
4814
|
+
data: (0, import_provider_utils18.convertToBase64)(part.data),
|
|
4696
4815
|
mime_type: part.mediaType,
|
|
4697
4816
|
...resolutionField
|
|
4698
4817
|
};
|
|
@@ -4706,8 +4825,8 @@ function compactPromptForPreviousInteraction({
|
|
|
4706
4825
|
for (const message of prompt) {
|
|
4707
4826
|
if (message.role === "assistant") {
|
|
4708
4827
|
const matchesLinkedInteraction = message.content.some((part) => {
|
|
4709
|
-
var
|
|
4710
|
-
const partInteractionId = (_b = (
|
|
4828
|
+
var _a2, _b;
|
|
4829
|
+
const partInteractionId = (_b = (_a2 = part.providerOptions) == null ? void 0 : _a2.google) == null ? void 0 : _b.interactionId;
|
|
4711
4830
|
return partInteractionId === previousInteractionId;
|
|
4712
4831
|
});
|
|
4713
4832
|
if (matchesLinkedInteraction) {
|
|
@@ -4743,7 +4862,7 @@ function compactPromptForPreviousInteraction({
|
|
|
4743
4862
|
}
|
|
4744
4863
|
function safeParseToolArgs(input) {
|
|
4745
4864
|
try {
|
|
4746
|
-
const parsed = (0,
|
|
4865
|
+
const parsed = (0, import_provider_utils18.secureJsonParse)(input);
|
|
4747
4866
|
if (parsed != null && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
4748
4867
|
return parsed;
|
|
4749
4868
|
}
|
|
@@ -4759,7 +4878,7 @@ function convertToolResultPart({
|
|
|
4759
4878
|
signature,
|
|
4760
4879
|
warnings
|
|
4761
4880
|
}) {
|
|
4762
|
-
var
|
|
4881
|
+
var _a2;
|
|
4763
4882
|
const base = {
|
|
4764
4883
|
type: "function_result",
|
|
4765
4884
|
call_id: toolCallId,
|
|
@@ -4779,7 +4898,7 @@ function convertToolResultPart({
|
|
|
4779
4898
|
return {
|
|
4780
4899
|
...base,
|
|
4781
4900
|
is_error: true,
|
|
4782
|
-
result: (
|
|
4901
|
+
result: (_a2 = output.reason) != null ? _a2 : "Tool execution denied by user."
|
|
4783
4902
|
};
|
|
4784
4903
|
case "content": {
|
|
4785
4904
|
const blocks = [];
|
|
@@ -4866,7 +4985,7 @@ function filePartToImageBlock({
|
|
|
4866
4985
|
}
|
|
4867
4986
|
return {
|
|
4868
4987
|
type: "image",
|
|
4869
|
-
data: (0,
|
|
4988
|
+
data: (0, import_provider_utils18.convertToBase64)(part.data),
|
|
4870
4989
|
mime_type: part.mediaType
|
|
4871
4990
|
};
|
|
4872
4991
|
}
|
|
@@ -4893,7 +5012,7 @@ ${block.text}`
|
|
|
4893
5012
|
}
|
|
4894
5013
|
|
|
4895
5014
|
// src/interactions/google-interactions-api.ts
|
|
4896
|
-
var
|
|
5015
|
+
var import_provider_utils19 = require("@ai-sdk/provider-utils");
|
|
4897
5016
|
var import_v417 = require("zod/v4");
|
|
4898
5017
|
var tokenByModalitySchema = () => import_v417.z.object({
|
|
4899
5018
|
modality: import_v417.z.string().nullish(),
|
|
@@ -5056,8 +5175,8 @@ var stepSchema = () => {
|
|
|
5056
5175
|
import_v417.z.object({ type: import_v417.z.string() }).loose()
|
|
5057
5176
|
]);
|
|
5058
5177
|
};
|
|
5059
|
-
var googleInteractionsResponseSchema = (0,
|
|
5060
|
-
() => (0,
|
|
5178
|
+
var googleInteractionsResponseSchema = (0, import_provider_utils19.lazySchema)(
|
|
5179
|
+
() => (0, import_provider_utils19.zodSchema)(
|
|
5061
5180
|
import_v417.z.object({
|
|
5062
5181
|
/*
|
|
5063
5182
|
* `id` is omitted from the response body when `store: false` (fully
|
|
@@ -5078,8 +5197,8 @@ var googleInteractionsResponseSchema = (0, import_provider_utils18.lazySchema)(
|
|
|
5078
5197
|
}).loose()
|
|
5079
5198
|
)
|
|
5080
5199
|
);
|
|
5081
|
-
var googleInteractionsEventSchema = (0,
|
|
5082
|
-
() => (0,
|
|
5200
|
+
var googleInteractionsEventSchema = (0, import_provider_utils19.lazySchema)(
|
|
5201
|
+
() => (0, import_provider_utils19.zodSchema)(
|
|
5083
5202
|
(() => {
|
|
5084
5203
|
const status = interactionStatusSchema();
|
|
5085
5204
|
const annotation = annotationSchema();
|
|
@@ -5236,10 +5355,10 @@ var googleInteractionsEventSchema = (0, import_provider_utils18.lazySchema)(
|
|
|
5236
5355
|
);
|
|
5237
5356
|
|
|
5238
5357
|
// src/interactions/google-interactions-language-model-options.ts
|
|
5239
|
-
var
|
|
5358
|
+
var import_provider_utils20 = require("@ai-sdk/provider-utils");
|
|
5240
5359
|
var import_v418 = require("zod/v4");
|
|
5241
|
-
var googleInteractionsLanguageModelOptions = (0,
|
|
5242
|
-
() => (0,
|
|
5360
|
+
var googleInteractionsLanguageModelOptions = (0, import_provider_utils20.lazySchema)(
|
|
5361
|
+
() => (0, import_provider_utils20.zodSchema)(
|
|
5243
5362
|
import_v418.z.object({
|
|
5244
5363
|
previousInteractionId: import_v418.z.string().nullish(),
|
|
5245
5364
|
store: import_v418.z.boolean().nullish(),
|
|
@@ -5459,7 +5578,7 @@ function parseGoogleInteractionsOutputs({
|
|
|
5459
5578
|
generateId: generateId3,
|
|
5460
5579
|
interactionId
|
|
5461
5580
|
}) {
|
|
5462
|
-
var
|
|
5581
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
5463
5582
|
const content = [];
|
|
5464
5583
|
let hasFunctionCall = false;
|
|
5465
5584
|
if (steps == null) {
|
|
@@ -5474,7 +5593,7 @@ function parseGoogleInteractionsOutputs({
|
|
|
5474
5593
|
break;
|
|
5475
5594
|
}
|
|
5476
5595
|
case "model_output": {
|
|
5477
|
-
const blocks = (
|
|
5596
|
+
const blocks = (_a2 = step.content) != null ? _a2 : [];
|
|
5478
5597
|
for (const block of blocks) {
|
|
5479
5598
|
if (block == null || typeof block !== "object") continue;
|
|
5480
5599
|
const blockType = block.type;
|
|
@@ -5606,10 +5725,10 @@ function parseGoogleInteractionsOutputs({
|
|
|
5606
5725
|
}
|
|
5607
5726
|
|
|
5608
5727
|
// src/interactions/poll-google-interactions.ts
|
|
5609
|
-
var
|
|
5728
|
+
var import_provider_utils22 = require("@ai-sdk/provider-utils");
|
|
5610
5729
|
|
|
5611
5730
|
// src/interactions/cancel-google-interaction.ts
|
|
5612
|
-
var
|
|
5731
|
+
var import_provider_utils21 = require("@ai-sdk/provider-utils");
|
|
5613
5732
|
var getOriginalFetch = () => globalThis.fetch;
|
|
5614
5733
|
async function cancelGoogleInteraction({
|
|
5615
5734
|
baseURL,
|
|
@@ -5624,9 +5743,9 @@ async function cancelGoogleInteraction({
|
|
|
5624
5743
|
try {
|
|
5625
5744
|
const response = await fetch(url, {
|
|
5626
5745
|
method: "POST",
|
|
5627
|
-
headers: (0,
|
|
5628
|
-
(0,
|
|
5629
|
-
(0,
|
|
5746
|
+
headers: (0, import_provider_utils21.withUserAgentSuffix)(
|
|
5747
|
+
(0, import_provider_utils21.combineHeaders)({ "Content-Type": "application/json" }, headers),
|
|
5748
|
+
(0, import_provider_utils21.getRuntimeEnvironmentUserAgent)()
|
|
5630
5749
|
),
|
|
5631
5750
|
body: "{}"
|
|
5632
5751
|
});
|
|
@@ -5676,16 +5795,16 @@ async function pollGoogleInteractionUntilTerminal({
|
|
|
5676
5795
|
`google.interactions: timed out polling interaction ${interactionId} after ${timeoutMs}ms.`
|
|
5677
5796
|
);
|
|
5678
5797
|
}
|
|
5679
|
-
await (0,
|
|
5798
|
+
await (0, import_provider_utils22.delay)(nextDelayMs, { abortSignal });
|
|
5680
5799
|
const {
|
|
5681
5800
|
value: response,
|
|
5682
5801
|
rawValue: rawResponse,
|
|
5683
5802
|
responseHeaders
|
|
5684
|
-
} = await (0,
|
|
5803
|
+
} = await (0, import_provider_utils22.getFromApi)({
|
|
5685
5804
|
url,
|
|
5686
5805
|
headers,
|
|
5687
5806
|
failedResponseHandler: googleFailedResponseHandler,
|
|
5688
|
-
successfulResponseHandler: (0,
|
|
5807
|
+
successfulResponseHandler: (0, import_provider_utils22.createJsonResponseHandler)(
|
|
5689
5808
|
googleInteractionsResponseSchema
|
|
5690
5809
|
),
|
|
5691
5810
|
abortSignal,
|
|
@@ -5697,7 +5816,7 @@ async function pollGoogleInteractionUntilTerminal({
|
|
|
5697
5816
|
nextDelayMs = Math.min(nextDelayMs * 2, maxDelayMs);
|
|
5698
5817
|
}
|
|
5699
5818
|
} catch (error) {
|
|
5700
|
-
if ((0,
|
|
5819
|
+
if ((0, import_provider_utils22.isAbortError)(error)) {
|
|
5701
5820
|
await cancelOnServer();
|
|
5702
5821
|
}
|
|
5703
5822
|
throw error;
|
|
@@ -5709,7 +5828,7 @@ function prepareGoogleInteractionsTools({
|
|
|
5709
5828
|
tools,
|
|
5710
5829
|
toolChoice
|
|
5711
5830
|
}) {
|
|
5712
|
-
var
|
|
5831
|
+
var _a2, _b, _c, _d;
|
|
5713
5832
|
const toolWarnings = [];
|
|
5714
5833
|
const normalized = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
|
5715
5834
|
if (normalized == null) {
|
|
@@ -5721,7 +5840,7 @@ function prepareGoogleInteractionsTools({
|
|
|
5721
5840
|
interactionsTools.push({
|
|
5722
5841
|
type: "function",
|
|
5723
5842
|
name: tool.name,
|
|
5724
|
-
description: (
|
|
5843
|
+
description: (_a2 = tool.description) != null ? _a2 : "",
|
|
5725
5844
|
parameters: tool.inputSchema
|
|
5726
5845
|
});
|
|
5727
5846
|
continue;
|
|
@@ -5853,7 +5972,7 @@ function prepareGoogleInteractionsTools({
|
|
|
5853
5972
|
}
|
|
5854
5973
|
|
|
5855
5974
|
// src/interactions/stream-google-interactions.ts
|
|
5856
|
-
var
|
|
5975
|
+
var import_provider_utils23 = require("@ai-sdk/provider-utils");
|
|
5857
5976
|
var DEFAULT_MAX_RETRIES = 3;
|
|
5858
5977
|
var DEFAULT_RETRY_DELAY_MS = 500;
|
|
5859
5978
|
function streamGoogleInteractionEvents({
|
|
@@ -5900,11 +6019,11 @@ function streamGoogleInteractionEvents({
|
|
|
5900
6019
|
return `${base}?${params.toString()}`;
|
|
5901
6020
|
}
|
|
5902
6021
|
async function openReader() {
|
|
5903
|
-
const { value: stream } = await (0,
|
|
6022
|
+
const { value: stream } = await (0, import_provider_utils23.getFromApi)({
|
|
5904
6023
|
url: buildUrl(),
|
|
5905
6024
|
headers: eventSourceHeaders,
|
|
5906
6025
|
failedResponseHandler: googleFailedResponseHandler,
|
|
5907
|
-
successfulResponseHandler: (0,
|
|
6026
|
+
successfulResponseHandler: (0, import_provider_utils23.createEventSourceResponseHandler)(
|
|
5908
6027
|
googleInteractionsEventSchema
|
|
5909
6028
|
),
|
|
5910
6029
|
abortSignal: effectiveSignal,
|
|
@@ -5921,7 +6040,7 @@ function streamGoogleInteractionEvents({
|
|
|
5921
6040
|
currentReader = await openReader();
|
|
5922
6041
|
receivedAnyEventThisAttempt = false;
|
|
5923
6042
|
} catch (error) {
|
|
5924
|
-
if ((0,
|
|
6043
|
+
if ((0, import_provider_utils23.isAbortError)(error) || effectiveSignal.aborted) {
|
|
5925
6044
|
controller.error(error);
|
|
5926
6045
|
return;
|
|
5927
6046
|
}
|
|
@@ -5930,7 +6049,7 @@ function streamGoogleInteractionEvents({
|
|
|
5930
6049
|
controller.error(error);
|
|
5931
6050
|
return;
|
|
5932
6051
|
}
|
|
5933
|
-
await (0,
|
|
6052
|
+
await (0, import_provider_utils23.delay)(retryDelayMs * attempt, {
|
|
5934
6053
|
abortSignal: effectiveSignal
|
|
5935
6054
|
});
|
|
5936
6055
|
continue;
|
|
@@ -5951,7 +6070,7 @@ function streamGoogleInteractionEvents({
|
|
|
5951
6070
|
);
|
|
5952
6071
|
return;
|
|
5953
6072
|
}
|
|
5954
|
-
await (0,
|
|
6073
|
+
await (0, import_provider_utils23.delay)(retryDelayMs * attempt, {
|
|
5955
6074
|
abortSignal: effectiveSignal
|
|
5956
6075
|
});
|
|
5957
6076
|
} else {
|
|
@@ -5971,7 +6090,7 @@ function streamGoogleInteractionEvents({
|
|
|
5971
6090
|
}
|
|
5972
6091
|
controller.enqueue(value);
|
|
5973
6092
|
} catch (error) {
|
|
5974
|
-
if ((0,
|
|
6093
|
+
if ((0, import_provider_utils23.isAbortError)(error) || effectiveSignal.aborted) {
|
|
5975
6094
|
controller.error(error);
|
|
5976
6095
|
return;
|
|
5977
6096
|
}
|
|
@@ -5981,7 +6100,7 @@ function streamGoogleInteractionEvents({
|
|
|
5981
6100
|
controller.error(error);
|
|
5982
6101
|
return;
|
|
5983
6102
|
}
|
|
5984
|
-
await (0,
|
|
6103
|
+
await (0, import_provider_utils23.delay)(retryDelayMs * attempt, {
|
|
5985
6104
|
abortSignal: effectiveSignal
|
|
5986
6105
|
});
|
|
5987
6106
|
}
|
|
@@ -6025,7 +6144,7 @@ function synthesizeGoogleInteractionsAgentStream({
|
|
|
6025
6144
|
}) {
|
|
6026
6145
|
return new ReadableStream({
|
|
6027
6146
|
start(controller) {
|
|
6028
|
-
var
|
|
6147
|
+
var _a2, _b, _c;
|
|
6029
6148
|
controller.enqueue({ type: "stream-start", warnings });
|
|
6030
6149
|
const interactionId = typeof response.id === "string" && response.id.length > 0 ? response.id : void 0;
|
|
6031
6150
|
let timestamp;
|
|
@@ -6039,7 +6158,7 @@ function synthesizeGoogleInteractionsAgentStream({
|
|
|
6039
6158
|
controller.enqueue({
|
|
6040
6159
|
type: "response-metadata",
|
|
6041
6160
|
...interactionId != null ? { id: interactionId } : {},
|
|
6042
|
-
modelId: (
|
|
6161
|
+
modelId: (_a2 = response.model) != null ? _a2 : void 0,
|
|
6043
6162
|
...timestamp ? { timestamp } : {}
|
|
6044
6163
|
});
|
|
6045
6164
|
if (includeRawChunks) {
|
|
@@ -6191,9 +6310,9 @@ var GoogleInteractionsLanguageModel = class {
|
|
|
6191
6310
|
};
|
|
6192
6311
|
}
|
|
6193
6312
|
async getArgs(options) {
|
|
6194
|
-
var
|
|
6313
|
+
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;
|
|
6195
6314
|
const warnings = [];
|
|
6196
|
-
const opts = await (0,
|
|
6315
|
+
const opts = await (0, import_provider_utils24.parseProviderOptions)({
|
|
6197
6316
|
provider: "google",
|
|
6198
6317
|
providerOptions: options.providerOptions,
|
|
6199
6318
|
schema: googleInteractionsLanguageModelOptions
|
|
@@ -6226,7 +6345,7 @@ var GoogleInteractionsLanguageModel = class {
|
|
|
6226
6345
|
warnings.push(...prepared.toolWarnings);
|
|
6227
6346
|
}
|
|
6228
6347
|
const responseFormatEntries = [];
|
|
6229
|
-
if (((
|
|
6348
|
+
if (((_a2 = options.responseFormat) == null ? void 0 : _a2.type) === "json") {
|
|
6230
6349
|
if (isAgent) {
|
|
6231
6350
|
warnings.push({
|
|
6232
6351
|
type: "other",
|
|
@@ -6386,7 +6505,7 @@ var GoogleInteractionsLanguageModel = class {
|
|
|
6386
6505
|
} else {
|
|
6387
6506
|
const env = opts.environment;
|
|
6388
6507
|
const sources = (_A = env.sources) == null ? void 0 : _A.map((s) => {
|
|
6389
|
-
var
|
|
6508
|
+
var _a3;
|
|
6390
6509
|
if (s.type === "inline") {
|
|
6391
6510
|
return {
|
|
6392
6511
|
type: "inline",
|
|
@@ -6397,7 +6516,7 @@ var GoogleInteractionsLanguageModel = class {
|
|
|
6397
6516
|
return pruneUndefined({
|
|
6398
6517
|
type: s.type,
|
|
6399
6518
|
source: s.source,
|
|
6400
|
-
target: (
|
|
6519
|
+
target: (_a3 = s.target) != null ? _a3 : void 0
|
|
6401
6520
|
});
|
|
6402
6521
|
});
|
|
6403
6522
|
let network;
|
|
@@ -6407,10 +6526,10 @@ var GoogleInteractionsLanguageModel = class {
|
|
|
6407
6526
|
network = {
|
|
6408
6527
|
allowlist: env.network.allowlist.map(
|
|
6409
6528
|
(entry) => {
|
|
6410
|
-
var
|
|
6529
|
+
var _a3;
|
|
6411
6530
|
return pruneUndefined({
|
|
6412
6531
|
domain: entry.domain,
|
|
6413
|
-
transform: (
|
|
6532
|
+
transform: (_a3 = entry.transform) != null ? _a3 : void 0
|
|
6414
6533
|
});
|
|
6415
6534
|
}
|
|
6416
6535
|
)
|
|
@@ -6447,20 +6566,20 @@ var GoogleInteractionsLanguageModel = class {
|
|
|
6447
6566
|
};
|
|
6448
6567
|
}
|
|
6449
6568
|
async doGenerate(options) {
|
|
6450
|
-
var
|
|
6569
|
+
var _a2, _b, _c, _d, _e, _f;
|
|
6451
6570
|
const { args, warnings, isAgent, pollingTimeoutMs } = await this.getArgs(options);
|
|
6452
6571
|
const url = `${this.config.baseURL}/interactions`;
|
|
6453
|
-
const mergedHeaders = (0,
|
|
6572
|
+
const mergedHeaders = (0, import_provider_utils24.combineHeaders)(
|
|
6454
6573
|
INTERACTIONS_API_REVISION_HEADER,
|
|
6455
|
-
this.config.headers ? await (0,
|
|
6574
|
+
this.config.headers ? await (0, import_provider_utils24.resolve)(this.config.headers) : void 0,
|
|
6456
6575
|
options.headers
|
|
6457
6576
|
);
|
|
6458
|
-
const postResult = await (0,
|
|
6577
|
+
const postResult = await (0, import_provider_utils24.postJsonToApi)({
|
|
6459
6578
|
url,
|
|
6460
6579
|
headers: mergedHeaders,
|
|
6461
6580
|
body: args,
|
|
6462
6581
|
failedResponseHandler: googleFailedResponseHandler,
|
|
6463
|
-
successfulResponseHandler: (0,
|
|
6582
|
+
successfulResponseHandler: (0, import_provider_utils24.createJsonResponseHandler)(
|
|
6464
6583
|
googleInteractionsResponseSchema
|
|
6465
6584
|
),
|
|
6466
6585
|
abortSignal: options.abortSignal,
|
|
@@ -6482,12 +6601,12 @@ var GoogleInteractionsLanguageModel = class {
|
|
|
6482
6601
|
});
|
|
6483
6602
|
response = polled.response;
|
|
6484
6603
|
rawResponse = polled.rawResponse;
|
|
6485
|
-
responseHeaders = (
|
|
6604
|
+
responseHeaders = (_a2 = polled.responseHeaders) != null ? _a2 : responseHeaders;
|
|
6486
6605
|
}
|
|
6487
6606
|
const interactionId = typeof response.id === "string" && response.id.length > 0 ? response.id : void 0;
|
|
6488
6607
|
const { content, hasFunctionCall } = parseGoogleInteractionsOutputs({
|
|
6489
6608
|
steps: (_b = response.steps) != null ? _b : null,
|
|
6490
|
-
generateId: (_c = this.config.generateId) != null ? _c :
|
|
6609
|
+
generateId: (_c = this.config.generateId) != null ? _c : import_provider_utils24.generateId,
|
|
6491
6610
|
interactionId
|
|
6492
6611
|
});
|
|
6493
6612
|
const finishReason = {
|
|
@@ -6532,12 +6651,12 @@ var GoogleInteractionsLanguageModel = class {
|
|
|
6532
6651
|
};
|
|
6533
6652
|
}
|
|
6534
6653
|
async doStream(options) {
|
|
6535
|
-
var
|
|
6654
|
+
var _a2;
|
|
6536
6655
|
const { args, warnings, isBackground, pollingTimeoutMs } = await this.getArgs(options);
|
|
6537
6656
|
const url = `${this.config.baseURL}/interactions`;
|
|
6538
|
-
const mergedHeaders = (0,
|
|
6657
|
+
const mergedHeaders = (0, import_provider_utils24.combineHeaders)(
|
|
6539
6658
|
INTERACTIONS_API_REVISION_HEADER,
|
|
6540
|
-
this.config.headers ? await (0,
|
|
6659
|
+
this.config.headers ? await (0, import_provider_utils24.resolve)(this.config.headers) : void 0,
|
|
6541
6660
|
options.headers
|
|
6542
6661
|
);
|
|
6543
6662
|
if (isBackground) {
|
|
@@ -6551,12 +6670,12 @@ var GoogleInteractionsLanguageModel = class {
|
|
|
6551
6670
|
});
|
|
6552
6671
|
}
|
|
6553
6672
|
const body = { ...args, stream: true };
|
|
6554
|
-
const { responseHeaders, value: response } = await (0,
|
|
6673
|
+
const { responseHeaders, value: response } = await (0, import_provider_utils24.postJsonToApi)({
|
|
6555
6674
|
url,
|
|
6556
6675
|
headers: mergedHeaders,
|
|
6557
6676
|
body,
|
|
6558
6677
|
failedResponseHandler: googleFailedResponseHandler,
|
|
6559
|
-
successfulResponseHandler: (0,
|
|
6678
|
+
successfulResponseHandler: (0, import_provider_utils24.createEventSourceResponseHandler)(
|
|
6560
6679
|
googleInteractionsEventSchema
|
|
6561
6680
|
),
|
|
6562
6681
|
abortSignal: options.abortSignal,
|
|
@@ -6565,7 +6684,7 @@ var GoogleInteractionsLanguageModel = class {
|
|
|
6565
6684
|
const headerServiceTier = responseHeaders == null ? void 0 : responseHeaders["x-gemini-service-tier"];
|
|
6566
6685
|
const transform = buildGoogleInteractionsStreamTransform({
|
|
6567
6686
|
warnings,
|
|
6568
|
-
generateId: (
|
|
6687
|
+
generateId: (_a2 = this.config.generateId) != null ? _a2 : import_provider_utils24.generateId,
|
|
6569
6688
|
includeRawChunks: options.includeRawChunks,
|
|
6570
6689
|
serviceTier: headerServiceTier
|
|
6571
6690
|
});
|
|
@@ -6601,13 +6720,13 @@ var GoogleInteractionsLanguageModel = class {
|
|
|
6601
6720
|
options,
|
|
6602
6721
|
pollingTimeoutMs
|
|
6603
6722
|
}) {
|
|
6604
|
-
var
|
|
6605
|
-
const postResult = await (0,
|
|
6723
|
+
var _a2, _b;
|
|
6724
|
+
const postResult = await (0, import_provider_utils24.postJsonToApi)({
|
|
6606
6725
|
url,
|
|
6607
6726
|
headers: mergedHeaders,
|
|
6608
6727
|
body: args,
|
|
6609
6728
|
failedResponseHandler: googleFailedResponseHandler,
|
|
6610
|
-
successfulResponseHandler: (0,
|
|
6729
|
+
successfulResponseHandler: (0, import_provider_utils24.createJsonResponseHandler)(
|
|
6611
6730
|
googleInteractionsResponseSchema
|
|
6612
6731
|
),
|
|
6613
6732
|
abortSignal: options.abortSignal,
|
|
@@ -6625,7 +6744,7 @@ var GoogleInteractionsLanguageModel = class {
|
|
|
6625
6744
|
const synthesized = synthesizeGoogleInteractionsAgentStream({
|
|
6626
6745
|
response: postResponse,
|
|
6627
6746
|
warnings,
|
|
6628
|
-
generateId: (
|
|
6747
|
+
generateId: (_a2 = this.config.generateId) != null ? _a2 : import_provider_utils24.generateId,
|
|
6629
6748
|
includeRawChunks: options.includeRawChunks,
|
|
6630
6749
|
headerServiceTier
|
|
6631
6750
|
});
|
|
@@ -6645,7 +6764,7 @@ var GoogleInteractionsLanguageModel = class {
|
|
|
6645
6764
|
});
|
|
6646
6765
|
const transform = buildGoogleInteractionsStreamTransform({
|
|
6647
6766
|
warnings,
|
|
6648
|
-
generateId: (_b = this.config.generateId) != null ? _b :
|
|
6767
|
+
generateId: (_b = this.config.generateId) != null ? _b : import_provider_utils24.generateId,
|
|
6649
6768
|
includeRawChunks: options.includeRawChunks,
|
|
6650
6769
|
serviceTier: headerServiceTier
|
|
6651
6770
|
});
|
|
@@ -6698,12 +6817,12 @@ function supportsExternalFileUrls(modelId) {
|
|
|
6698
6817
|
return /(^|\/)gemini-/.test(modelId) && !/(^|\/)gemini-2\.0/.test(modelId);
|
|
6699
6818
|
}
|
|
6700
6819
|
function createGoogleGenerativeAI(options = {}) {
|
|
6701
|
-
var
|
|
6702
|
-
const baseURL = (
|
|
6820
|
+
var _a2, _b;
|
|
6821
|
+
const baseURL = (_a2 = (0, import_provider_utils25.withoutTrailingSlash)(options.baseURL)) != null ? _a2 : "https://generativelanguage.googleapis.com/v1beta";
|
|
6703
6822
|
const providerName = (_b = options.name) != null ? _b : "google.generative-ai";
|
|
6704
|
-
const getHeaders = () => (0,
|
|
6823
|
+
const getHeaders = () => (0, import_provider_utils25.withUserAgentSuffix)(
|
|
6705
6824
|
{
|
|
6706
|
-
"x-goog-api-key": (0,
|
|
6825
|
+
"x-goog-api-key": (0, import_provider_utils25.loadApiKey)({
|
|
6707
6826
|
apiKey: options.apiKey,
|
|
6708
6827
|
environmentVariableName: "GOOGLE_GENERATIVE_AI_API_KEY",
|
|
6709
6828
|
description: "Google Generative AI"
|
|
@@ -6713,12 +6832,12 @@ function createGoogleGenerativeAI(options = {}) {
|
|
|
6713
6832
|
`ai-sdk/google/${VERSION}`
|
|
6714
6833
|
);
|
|
6715
6834
|
const createChatModel = (modelId) => {
|
|
6716
|
-
var
|
|
6835
|
+
var _a3;
|
|
6717
6836
|
return new GoogleGenerativeAILanguageModel(modelId, {
|
|
6718
6837
|
provider: providerName,
|
|
6719
6838
|
baseURL,
|
|
6720
6839
|
headers: getHeaders,
|
|
6721
|
-
generateId: (
|
|
6840
|
+
generateId: (_a3 = options.generateId) != null ? _a3 : import_provider_utils25.generateId,
|
|
6722
6841
|
supportedUrls: () => ({
|
|
6723
6842
|
"*": [
|
|
6724
6843
|
// Google Generative Language "files" endpoint
|
|
@@ -6759,24 +6878,24 @@ function createGoogleGenerativeAI(options = {}) {
|
|
|
6759
6878
|
fetch: options.fetch
|
|
6760
6879
|
});
|
|
6761
6880
|
const createVideoModel = (modelId) => {
|
|
6762
|
-
var
|
|
6881
|
+
var _a3;
|
|
6763
6882
|
return new GoogleGenerativeAIVideoModel(modelId, {
|
|
6764
6883
|
provider: providerName,
|
|
6765
6884
|
baseURL,
|
|
6766
6885
|
headers: getHeaders,
|
|
6767
6886
|
fetch: options.fetch,
|
|
6768
|
-
generateId: (
|
|
6887
|
+
generateId: (_a3 = options.generateId) != null ? _a3 : import_provider_utils25.generateId
|
|
6769
6888
|
});
|
|
6770
6889
|
};
|
|
6771
6890
|
const createInteractionsModel = (modelIdOrAgent) => {
|
|
6772
|
-
var
|
|
6891
|
+
var _a3;
|
|
6773
6892
|
return new GoogleInteractionsLanguageModel(
|
|
6774
6893
|
modelIdOrAgent,
|
|
6775
6894
|
{
|
|
6776
6895
|
provider: `${providerName}.interactions`,
|
|
6777
6896
|
baseURL,
|
|
6778
6897
|
headers: getHeaders,
|
|
6779
|
-
generateId: (
|
|
6898
|
+
generateId: (_a3 = options.generateId) != null ? _a3 : import_provider_utils25.generateId,
|
|
6780
6899
|
fetch: options.fetch
|
|
6781
6900
|
}
|
|
6782
6901
|
);
|