@ai-sdk/google 3.0.37 → 3.0.39
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 +12 -0
- package/dist/index.d.mts +16 -2
- package/dist/index.d.ts +16 -2
- package/dist/index.js +70 -31
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +70 -31
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +23 -2
- package/dist/internal/index.d.ts +23 -2
- package/dist/internal/index.js +69 -30
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +69 -30
- package/dist/internal/index.mjs.map +1 -1
- package/docs/15-google-generative-ai.mdx +22 -10
- package/package.json +1 -1
- package/src/google-generative-ai-language-model.ts +45 -0
- package/src/google-prepare-tools.ts +10 -20
- package/src/tool/google-search.ts +31 -28
package/dist/internal/index.mjs
CHANGED
|
@@ -508,8 +508,7 @@ function prepareTools({
|
|
|
508
508
|
"gemini-flash-lite-latest",
|
|
509
509
|
"gemini-pro-latest"
|
|
510
510
|
].some((id) => id === modelId);
|
|
511
|
-
const isGemini2orNewer = modelId.includes("gemini-2") || modelId.includes("gemini-3") || isLatest;
|
|
512
|
-
const supportsDynamicRetrieval = modelId.includes("gemini-1.5-flash") && !modelId.includes("-8b");
|
|
511
|
+
const isGemini2orNewer = modelId.includes("gemini-2") || modelId.includes("gemini-3") || modelId.includes("nano-banana") || isLatest;
|
|
513
512
|
const supportsFileSearch = modelId.includes("gemini-2.5") || modelId.includes("gemini-3");
|
|
514
513
|
if (tools == null) {
|
|
515
514
|
return { tools: void 0, toolConfig: void 0, toolWarnings };
|
|
@@ -529,18 +528,13 @@ function prepareTools({
|
|
|
529
528
|
switch (tool.id) {
|
|
530
529
|
case "google.google_search":
|
|
531
530
|
if (isGemini2orNewer) {
|
|
532
|
-
googleTools2.push({ googleSearch: {} });
|
|
533
|
-
} else if (supportsDynamicRetrieval) {
|
|
534
|
-
googleTools2.push({
|
|
535
|
-
googleSearchRetrieval: {
|
|
536
|
-
dynamicRetrievalConfig: {
|
|
537
|
-
mode: tool.args.mode,
|
|
538
|
-
dynamicThreshold: tool.args.dynamicThreshold
|
|
539
|
-
}
|
|
540
|
-
}
|
|
541
|
-
});
|
|
531
|
+
googleTools2.push({ googleSearch: { ...tool.args } });
|
|
542
532
|
} else {
|
|
543
|
-
|
|
533
|
+
toolWarnings.push({
|
|
534
|
+
type: "unsupported",
|
|
535
|
+
feature: `provider-defined tool ${tool.id}`,
|
|
536
|
+
details: "Google Search requires Gemini 2.0 or newer."
|
|
537
|
+
});
|
|
544
538
|
}
|
|
545
539
|
break;
|
|
546
540
|
case "google.enterprise_web_search":
|
|
@@ -1123,10 +1117,30 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1123
1117
|
});
|
|
1124
1118
|
}
|
|
1125
1119
|
} else if ("inlineData" in part) {
|
|
1120
|
+
if (currentTextBlockId !== null) {
|
|
1121
|
+
controller.enqueue({
|
|
1122
|
+
type: "text-end",
|
|
1123
|
+
id: currentTextBlockId
|
|
1124
|
+
});
|
|
1125
|
+
currentTextBlockId = null;
|
|
1126
|
+
}
|
|
1127
|
+
if (currentReasoningBlockId !== null) {
|
|
1128
|
+
controller.enqueue({
|
|
1129
|
+
type: "reasoning-end",
|
|
1130
|
+
id: currentReasoningBlockId
|
|
1131
|
+
});
|
|
1132
|
+
currentReasoningBlockId = null;
|
|
1133
|
+
}
|
|
1134
|
+
const thoughtSignatureMetadata = part.thoughtSignature ? {
|
|
1135
|
+
[providerOptionsName]: {
|
|
1136
|
+
thoughtSignature: part.thoughtSignature
|
|
1137
|
+
}
|
|
1138
|
+
} : void 0;
|
|
1126
1139
|
controller.enqueue({
|
|
1127
1140
|
type: "file",
|
|
1128
1141
|
mediaType: part.inlineData.mimeType,
|
|
1129
|
-
data: part.inlineData.data
|
|
1142
|
+
data: part.inlineData.data,
|
|
1143
|
+
providerMetadata: thoughtSignatureMetadata
|
|
1130
1144
|
});
|
|
1131
1145
|
}
|
|
1132
1146
|
}
|
|
@@ -1237,7 +1251,7 @@ function extractSources({
|
|
|
1237
1251
|
groundingMetadata,
|
|
1238
1252
|
generateId: generateId2
|
|
1239
1253
|
}) {
|
|
1240
|
-
var _a, _b, _c, _d, _e;
|
|
1254
|
+
var _a, _b, _c, _d, _e, _f;
|
|
1241
1255
|
if (!(groundingMetadata == null ? void 0 : groundingMetadata.groundingChunks)) {
|
|
1242
1256
|
return void 0;
|
|
1243
1257
|
}
|
|
@@ -1251,6 +1265,16 @@ function extractSources({
|
|
|
1251
1265
|
url: chunk.web.uri,
|
|
1252
1266
|
title: (_a = chunk.web.title) != null ? _a : void 0
|
|
1253
1267
|
});
|
|
1268
|
+
} else if (chunk.image != null) {
|
|
1269
|
+
sources.push({
|
|
1270
|
+
type: "source",
|
|
1271
|
+
sourceType: "url",
|
|
1272
|
+
id: generateId2(),
|
|
1273
|
+
// Google requires attribution to the source URI, not the actual image URI.
|
|
1274
|
+
// TODO: add another type in v7 to allow both the image and source URL to be included separately
|
|
1275
|
+
url: chunk.image.sourceUri,
|
|
1276
|
+
title: (_b = chunk.image.title) != null ? _b : void 0
|
|
1277
|
+
});
|
|
1254
1278
|
} else if (chunk.retrievedContext != null) {
|
|
1255
1279
|
const uri = chunk.retrievedContext.uri;
|
|
1256
1280
|
const fileSearchStore = chunk.retrievedContext.fileSearchStore;
|
|
@@ -1260,10 +1284,10 @@ function extractSources({
|
|
|
1260
1284
|
sourceType: "url",
|
|
1261
1285
|
id: generateId2(),
|
|
1262
1286
|
url: uri,
|
|
1263
|
-
title: (
|
|
1287
|
+
title: (_c = chunk.retrievedContext.title) != null ? _c : void 0
|
|
1264
1288
|
});
|
|
1265
1289
|
} else if (uri) {
|
|
1266
|
-
const title = (
|
|
1290
|
+
const title = (_d = chunk.retrievedContext.title) != null ? _d : "Unknown Document";
|
|
1267
1291
|
let mediaType = "application/octet-stream";
|
|
1268
1292
|
let filename = void 0;
|
|
1269
1293
|
if (uri.endsWith(".pdf")) {
|
|
@@ -1293,7 +1317,7 @@ function extractSources({
|
|
|
1293
1317
|
filename
|
|
1294
1318
|
});
|
|
1295
1319
|
} else if (fileSearchStore) {
|
|
1296
|
-
const title = (
|
|
1320
|
+
const title = (_e = chunk.retrievedContext.title) != null ? _e : "Unknown Document";
|
|
1297
1321
|
sources.push({
|
|
1298
1322
|
type: "source",
|
|
1299
1323
|
sourceType: "document",
|
|
@@ -1310,7 +1334,7 @@ function extractSources({
|
|
|
1310
1334
|
sourceType: "url",
|
|
1311
1335
|
id: generateId2(),
|
|
1312
1336
|
url: chunk.maps.uri,
|
|
1313
|
-
title: (
|
|
1337
|
+
title: (_f = chunk.maps.title) != null ? _f : void 0
|
|
1314
1338
|
});
|
|
1315
1339
|
}
|
|
1316
1340
|
}
|
|
@@ -1319,11 +1343,18 @@ function extractSources({
|
|
|
1319
1343
|
}
|
|
1320
1344
|
var getGroundingMetadataSchema = () => z3.object({
|
|
1321
1345
|
webSearchQueries: z3.array(z3.string()).nullish(),
|
|
1346
|
+
imageSearchQueries: z3.array(z3.string()).nullish(),
|
|
1322
1347
|
retrievalQueries: z3.array(z3.string()).nullish(),
|
|
1323
1348
|
searchEntryPoint: z3.object({ renderedContent: z3.string() }).nullish(),
|
|
1324
1349
|
groundingChunks: z3.array(
|
|
1325
1350
|
z3.object({
|
|
1326
1351
|
web: z3.object({ uri: z3.string(), title: z3.string().nullish() }).nullish(),
|
|
1352
|
+
image: z3.object({
|
|
1353
|
+
sourceUri: z3.string(),
|
|
1354
|
+
imageUri: z3.string(),
|
|
1355
|
+
title: z3.string().nullish(),
|
|
1356
|
+
domain: z3.string().nullish()
|
|
1357
|
+
}).nullish(),
|
|
1327
1358
|
retrievedContext: z3.object({
|
|
1328
1359
|
uri: z3.string().nullish(),
|
|
1329
1360
|
title: z3.string().nullish(),
|
|
@@ -1536,17 +1567,25 @@ import {
|
|
|
1536
1567
|
zodSchema as zodSchema7
|
|
1537
1568
|
} from "@ai-sdk/provider-utils";
|
|
1538
1569
|
import { z as z8 } from "zod/v4";
|
|
1539
|
-
var
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
()
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1570
|
+
var googleSearchToolArgsBaseSchema = z8.object({
|
|
1571
|
+
searchTypes: z8.object({
|
|
1572
|
+
webSearch: z8.object({}).optional(),
|
|
1573
|
+
imageSearch: z8.object({}).optional()
|
|
1574
|
+
}).optional(),
|
|
1575
|
+
timeRangeFilter: z8.object({
|
|
1576
|
+
startTime: z8.string(),
|
|
1577
|
+
endTime: z8.string()
|
|
1578
|
+
}).optional()
|
|
1579
|
+
}).passthrough();
|
|
1580
|
+
var googleSearchToolArgsSchema = lazySchema7(
|
|
1581
|
+
() => zodSchema7(googleSearchToolArgsBaseSchema)
|
|
1582
|
+
);
|
|
1583
|
+
var googleSearch = createProviderToolFactory4(
|
|
1584
|
+
{
|
|
1585
|
+
id: "google.google_search",
|
|
1586
|
+
inputSchema: googleSearchToolArgsSchema
|
|
1587
|
+
}
|
|
1588
|
+
);
|
|
1550
1589
|
|
|
1551
1590
|
// src/tool/url-context.ts
|
|
1552
1591
|
import {
|