@ai-sdk/google 3.0.38 → 3.0.40
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 +18 -4
- package/dist/index.d.ts +18 -4
- package/dist/index.js +50 -31
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +50 -31
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +27 -6
- package/dist/internal/index.d.ts +27 -6
- package/dist/internal/index.js +49 -30
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +49 -30
- package/dist/internal/index.mjs.map +1 -1
- package/docs/15-google-generative-ai.mdx +22 -10
- package/package.json +3 -3
- package/src/google-generative-ai-language-model.ts +28 -6
- 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":
|
|
@@ -1257,7 +1251,7 @@ function extractSources({
|
|
|
1257
1251
|
groundingMetadata,
|
|
1258
1252
|
generateId: generateId2
|
|
1259
1253
|
}) {
|
|
1260
|
-
var _a, _b, _c, _d, _e;
|
|
1254
|
+
var _a, _b, _c, _d, _e, _f;
|
|
1261
1255
|
if (!(groundingMetadata == null ? void 0 : groundingMetadata.groundingChunks)) {
|
|
1262
1256
|
return void 0;
|
|
1263
1257
|
}
|
|
@@ -1271,6 +1265,16 @@ function extractSources({
|
|
|
1271
1265
|
url: chunk.web.uri,
|
|
1272
1266
|
title: (_a = chunk.web.title) != null ? _a : void 0
|
|
1273
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
|
+
});
|
|
1274
1278
|
} else if (chunk.retrievedContext != null) {
|
|
1275
1279
|
const uri = chunk.retrievedContext.uri;
|
|
1276
1280
|
const fileSearchStore = chunk.retrievedContext.fileSearchStore;
|
|
@@ -1280,10 +1284,10 @@ function extractSources({
|
|
|
1280
1284
|
sourceType: "url",
|
|
1281
1285
|
id: generateId2(),
|
|
1282
1286
|
url: uri,
|
|
1283
|
-
title: (
|
|
1287
|
+
title: (_c = chunk.retrievedContext.title) != null ? _c : void 0
|
|
1284
1288
|
});
|
|
1285
1289
|
} else if (uri) {
|
|
1286
|
-
const title = (
|
|
1290
|
+
const title = (_d = chunk.retrievedContext.title) != null ? _d : "Unknown Document";
|
|
1287
1291
|
let mediaType = "application/octet-stream";
|
|
1288
1292
|
let filename = void 0;
|
|
1289
1293
|
if (uri.endsWith(".pdf")) {
|
|
@@ -1313,7 +1317,7 @@ function extractSources({
|
|
|
1313
1317
|
filename
|
|
1314
1318
|
});
|
|
1315
1319
|
} else if (fileSearchStore) {
|
|
1316
|
-
const title = (
|
|
1320
|
+
const title = (_e = chunk.retrievedContext.title) != null ? _e : "Unknown Document";
|
|
1317
1321
|
sources.push({
|
|
1318
1322
|
type: "source",
|
|
1319
1323
|
sourceType: "document",
|
|
@@ -1330,7 +1334,7 @@ function extractSources({
|
|
|
1330
1334
|
sourceType: "url",
|
|
1331
1335
|
id: generateId2(),
|
|
1332
1336
|
url: chunk.maps.uri,
|
|
1333
|
-
title: (
|
|
1337
|
+
title: (_f = chunk.maps.title) != null ? _f : void 0
|
|
1334
1338
|
});
|
|
1335
1339
|
}
|
|
1336
1340
|
}
|
|
@@ -1339,11 +1343,18 @@ function extractSources({
|
|
|
1339
1343
|
}
|
|
1340
1344
|
var getGroundingMetadataSchema = () => z3.object({
|
|
1341
1345
|
webSearchQueries: z3.array(z3.string()).nullish(),
|
|
1346
|
+
imageSearchQueries: z3.array(z3.string()).nullish(),
|
|
1342
1347
|
retrievalQueries: z3.array(z3.string()).nullish(),
|
|
1343
1348
|
searchEntryPoint: z3.object({ renderedContent: z3.string() }).nullish(),
|
|
1344
1349
|
groundingChunks: z3.array(
|
|
1345
1350
|
z3.object({
|
|
1346
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(),
|
|
1347
1358
|
retrievedContext: z3.object({
|
|
1348
1359
|
uri: z3.string().nullish(),
|
|
1349
1360
|
title: z3.string().nullish(),
|
|
@@ -1436,7 +1447,7 @@ var getUrlContextMetadataSchema = () => z3.object({
|
|
|
1436
1447
|
retrievedUrl: z3.string(),
|
|
1437
1448
|
urlRetrievalStatus: z3.string()
|
|
1438
1449
|
})
|
|
1439
|
-
)
|
|
1450
|
+
).nullish()
|
|
1440
1451
|
});
|
|
1441
1452
|
var responseSchema = lazySchema3(
|
|
1442
1453
|
() => zodSchema3(
|
|
@@ -1556,17 +1567,25 @@ import {
|
|
|
1556
1567
|
zodSchema as zodSchema7
|
|
1557
1568
|
} from "@ai-sdk/provider-utils";
|
|
1558
1569
|
import { z as z8 } from "zod/v4";
|
|
1559
|
-
var
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
()
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
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
|
+
);
|
|
1570
1589
|
|
|
1571
1590
|
// src/tool/url-context.ts
|
|
1572
1591
|
import {
|