@ai-sdk/google 3.0.38 → 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 +6 -0
- package/dist/index.d.mts +16 -2
- package/dist/index.d.ts +16 -2
- package/dist/index.js +49 -30
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +49 -30
- 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 +48 -29
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +48 -29
- 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 +20 -0
- package/src/google-prepare-tools.ts +10 -20
- package/src/tool/google-search.ts +31 -28
|
@@ -30,6 +30,7 @@ declare class GoogleGenerativeAILanguageModel implements LanguageModelV3 {
|
|
|
30
30
|
}
|
|
31
31
|
declare const getGroundingMetadataSchema: () => z.ZodObject<{
|
|
32
32
|
webSearchQueries: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString>>>;
|
|
33
|
+
imageSearchQueries: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString>>>;
|
|
33
34
|
retrievalQueries: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString>>>;
|
|
34
35
|
searchEntryPoint: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
35
36
|
renderedContent: z.ZodString;
|
|
@@ -39,6 +40,12 @@ declare const getGroundingMetadataSchema: () => z.ZodObject<{
|
|
|
39
40
|
uri: z.ZodString;
|
|
40
41
|
title: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
41
42
|
}, z.core.$strip>>>;
|
|
43
|
+
image: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
44
|
+
sourceUri: z.ZodString;
|
|
45
|
+
imageUri: z.ZodString;
|
|
46
|
+
title: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
47
|
+
domain: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
48
|
+
}, z.core.$strip>>>;
|
|
42
49
|
retrievedContext: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
43
50
|
uri: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
44
51
|
title: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
@@ -114,6 +121,7 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
114
121
|
}[] | null | undefined;
|
|
115
122
|
groundingMetadata?: {
|
|
116
123
|
webSearchQueries?: string[] | null | undefined;
|
|
124
|
+
imageSearchQueries?: string[] | null | undefined;
|
|
117
125
|
retrievalQueries?: string[] | null | undefined;
|
|
118
126
|
searchEntryPoint?: {
|
|
119
127
|
renderedContent: string;
|
|
@@ -123,6 +131,12 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
123
131
|
uri: string;
|
|
124
132
|
title?: string | null | undefined;
|
|
125
133
|
} | null | undefined;
|
|
134
|
+
image?: {
|
|
135
|
+
sourceUri: string;
|
|
136
|
+
imageUri: string;
|
|
137
|
+
title?: string | null | undefined;
|
|
138
|
+
domain?: string | null | undefined;
|
|
139
|
+
} | null | undefined;
|
|
126
140
|
retrievedContext?: {
|
|
127
141
|
uri?: string | null | undefined;
|
|
128
142
|
title?: string | null | undefined;
|
|
@@ -189,8 +203,15 @@ declare const googleTools: {
|
|
|
189
203
|
* Must have name "google_search".
|
|
190
204
|
*/
|
|
191
205
|
googleSearch: _ai_sdk_provider_utils.ProviderToolFactory<{}, {
|
|
192
|
-
|
|
193
|
-
|
|
206
|
+
[x: string]: unknown;
|
|
207
|
+
searchTypes?: {
|
|
208
|
+
webSearch?: Record<string, never> | undefined;
|
|
209
|
+
imageSearch?: Record<string, never> | undefined;
|
|
210
|
+
} | undefined;
|
|
211
|
+
timeRangeFilter?: {
|
|
212
|
+
startTime: string;
|
|
213
|
+
endTime: string;
|
|
214
|
+
} | undefined;
|
|
194
215
|
}>;
|
|
195
216
|
/**
|
|
196
217
|
* Creates an Enterprise Web Search tool for grounding responses using a compliance-focused web index.
|
package/dist/internal/index.d.ts
CHANGED
|
@@ -30,6 +30,7 @@ declare class GoogleGenerativeAILanguageModel implements LanguageModelV3 {
|
|
|
30
30
|
}
|
|
31
31
|
declare const getGroundingMetadataSchema: () => z.ZodObject<{
|
|
32
32
|
webSearchQueries: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString>>>;
|
|
33
|
+
imageSearchQueries: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString>>>;
|
|
33
34
|
retrievalQueries: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString>>>;
|
|
34
35
|
searchEntryPoint: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
35
36
|
renderedContent: z.ZodString;
|
|
@@ -39,6 +40,12 @@ declare const getGroundingMetadataSchema: () => z.ZodObject<{
|
|
|
39
40
|
uri: z.ZodString;
|
|
40
41
|
title: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
41
42
|
}, z.core.$strip>>>;
|
|
43
|
+
image: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
44
|
+
sourceUri: z.ZodString;
|
|
45
|
+
imageUri: z.ZodString;
|
|
46
|
+
title: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
47
|
+
domain: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
48
|
+
}, z.core.$strip>>>;
|
|
42
49
|
retrievedContext: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
43
50
|
uri: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
44
51
|
title: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
@@ -114,6 +121,7 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
114
121
|
}[] | null | undefined;
|
|
115
122
|
groundingMetadata?: {
|
|
116
123
|
webSearchQueries?: string[] | null | undefined;
|
|
124
|
+
imageSearchQueries?: string[] | null | undefined;
|
|
117
125
|
retrievalQueries?: string[] | null | undefined;
|
|
118
126
|
searchEntryPoint?: {
|
|
119
127
|
renderedContent: string;
|
|
@@ -123,6 +131,12 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
123
131
|
uri: string;
|
|
124
132
|
title?: string | null | undefined;
|
|
125
133
|
} | null | undefined;
|
|
134
|
+
image?: {
|
|
135
|
+
sourceUri: string;
|
|
136
|
+
imageUri: string;
|
|
137
|
+
title?: string | null | undefined;
|
|
138
|
+
domain?: string | null | undefined;
|
|
139
|
+
} | null | undefined;
|
|
126
140
|
retrievedContext?: {
|
|
127
141
|
uri?: string | null | undefined;
|
|
128
142
|
title?: string | null | undefined;
|
|
@@ -189,8 +203,15 @@ declare const googleTools: {
|
|
|
189
203
|
* Must have name "google_search".
|
|
190
204
|
*/
|
|
191
205
|
googleSearch: _ai_sdk_provider_utils.ProviderToolFactory<{}, {
|
|
192
|
-
|
|
193
|
-
|
|
206
|
+
[x: string]: unknown;
|
|
207
|
+
searchTypes?: {
|
|
208
|
+
webSearch?: Record<string, never> | undefined;
|
|
209
|
+
imageSearch?: Record<string, never> | undefined;
|
|
210
|
+
} | undefined;
|
|
211
|
+
timeRangeFilter?: {
|
|
212
|
+
startTime: string;
|
|
213
|
+
endTime: string;
|
|
214
|
+
} | undefined;
|
|
194
215
|
}>;
|
|
195
216
|
/**
|
|
196
217
|
* Creates an Enterprise Web Search tool for grounding responses using a compliance-focused web index.
|
package/dist/internal/index.js
CHANGED
|
@@ -519,8 +519,7 @@ function prepareTools({
|
|
|
519
519
|
"gemini-flash-lite-latest",
|
|
520
520
|
"gemini-pro-latest"
|
|
521
521
|
].some((id) => id === modelId);
|
|
522
|
-
const isGemini2orNewer = modelId.includes("gemini-2") || modelId.includes("gemini-3") || isLatest;
|
|
523
|
-
const supportsDynamicRetrieval = modelId.includes("gemini-1.5-flash") && !modelId.includes("-8b");
|
|
522
|
+
const isGemini2orNewer = modelId.includes("gemini-2") || modelId.includes("gemini-3") || modelId.includes("nano-banana") || isLatest;
|
|
524
523
|
const supportsFileSearch = modelId.includes("gemini-2.5") || modelId.includes("gemini-3");
|
|
525
524
|
if (tools == null) {
|
|
526
525
|
return { tools: void 0, toolConfig: void 0, toolWarnings };
|
|
@@ -540,18 +539,13 @@ function prepareTools({
|
|
|
540
539
|
switch (tool.id) {
|
|
541
540
|
case "google.google_search":
|
|
542
541
|
if (isGemini2orNewer) {
|
|
543
|
-
googleTools2.push({ googleSearch: {} });
|
|
544
|
-
} else if (supportsDynamicRetrieval) {
|
|
545
|
-
googleTools2.push({
|
|
546
|
-
googleSearchRetrieval: {
|
|
547
|
-
dynamicRetrievalConfig: {
|
|
548
|
-
mode: tool.args.mode,
|
|
549
|
-
dynamicThreshold: tool.args.dynamicThreshold
|
|
550
|
-
}
|
|
551
|
-
}
|
|
552
|
-
});
|
|
542
|
+
googleTools2.push({ googleSearch: { ...tool.args } });
|
|
553
543
|
} else {
|
|
554
|
-
|
|
544
|
+
toolWarnings.push({
|
|
545
|
+
type: "unsupported",
|
|
546
|
+
feature: `provider-defined tool ${tool.id}`,
|
|
547
|
+
details: "Google Search requires Gemini 2.0 or newer."
|
|
548
|
+
});
|
|
555
549
|
}
|
|
556
550
|
break;
|
|
557
551
|
case "google.enterprise_web_search":
|
|
@@ -1268,7 +1262,7 @@ function extractSources({
|
|
|
1268
1262
|
groundingMetadata,
|
|
1269
1263
|
generateId: generateId2
|
|
1270
1264
|
}) {
|
|
1271
|
-
var _a, _b, _c, _d, _e;
|
|
1265
|
+
var _a, _b, _c, _d, _e, _f;
|
|
1272
1266
|
if (!(groundingMetadata == null ? void 0 : groundingMetadata.groundingChunks)) {
|
|
1273
1267
|
return void 0;
|
|
1274
1268
|
}
|
|
@@ -1282,6 +1276,16 @@ function extractSources({
|
|
|
1282
1276
|
url: chunk.web.uri,
|
|
1283
1277
|
title: (_a = chunk.web.title) != null ? _a : void 0
|
|
1284
1278
|
});
|
|
1279
|
+
} else if (chunk.image != null) {
|
|
1280
|
+
sources.push({
|
|
1281
|
+
type: "source",
|
|
1282
|
+
sourceType: "url",
|
|
1283
|
+
id: generateId2(),
|
|
1284
|
+
// Google requires attribution to the source URI, not the actual image URI.
|
|
1285
|
+
// TODO: add another type in v7 to allow both the image and source URL to be included separately
|
|
1286
|
+
url: chunk.image.sourceUri,
|
|
1287
|
+
title: (_b = chunk.image.title) != null ? _b : void 0
|
|
1288
|
+
});
|
|
1285
1289
|
} else if (chunk.retrievedContext != null) {
|
|
1286
1290
|
const uri = chunk.retrievedContext.uri;
|
|
1287
1291
|
const fileSearchStore = chunk.retrievedContext.fileSearchStore;
|
|
@@ -1291,10 +1295,10 @@ function extractSources({
|
|
|
1291
1295
|
sourceType: "url",
|
|
1292
1296
|
id: generateId2(),
|
|
1293
1297
|
url: uri,
|
|
1294
|
-
title: (
|
|
1298
|
+
title: (_c = chunk.retrievedContext.title) != null ? _c : void 0
|
|
1295
1299
|
});
|
|
1296
1300
|
} else if (uri) {
|
|
1297
|
-
const title = (
|
|
1301
|
+
const title = (_d = chunk.retrievedContext.title) != null ? _d : "Unknown Document";
|
|
1298
1302
|
let mediaType = "application/octet-stream";
|
|
1299
1303
|
let filename = void 0;
|
|
1300
1304
|
if (uri.endsWith(".pdf")) {
|
|
@@ -1324,7 +1328,7 @@ function extractSources({
|
|
|
1324
1328
|
filename
|
|
1325
1329
|
});
|
|
1326
1330
|
} else if (fileSearchStore) {
|
|
1327
|
-
const title = (
|
|
1331
|
+
const title = (_e = chunk.retrievedContext.title) != null ? _e : "Unknown Document";
|
|
1328
1332
|
sources.push({
|
|
1329
1333
|
type: "source",
|
|
1330
1334
|
sourceType: "document",
|
|
@@ -1341,7 +1345,7 @@ function extractSources({
|
|
|
1341
1345
|
sourceType: "url",
|
|
1342
1346
|
id: generateId2(),
|
|
1343
1347
|
url: chunk.maps.uri,
|
|
1344
|
-
title: (
|
|
1348
|
+
title: (_f = chunk.maps.title) != null ? _f : void 0
|
|
1345
1349
|
});
|
|
1346
1350
|
}
|
|
1347
1351
|
}
|
|
@@ -1350,11 +1354,18 @@ function extractSources({
|
|
|
1350
1354
|
}
|
|
1351
1355
|
var getGroundingMetadataSchema = () => import_v43.z.object({
|
|
1352
1356
|
webSearchQueries: import_v43.z.array(import_v43.z.string()).nullish(),
|
|
1357
|
+
imageSearchQueries: import_v43.z.array(import_v43.z.string()).nullish(),
|
|
1353
1358
|
retrievalQueries: import_v43.z.array(import_v43.z.string()).nullish(),
|
|
1354
1359
|
searchEntryPoint: import_v43.z.object({ renderedContent: import_v43.z.string() }).nullish(),
|
|
1355
1360
|
groundingChunks: import_v43.z.array(
|
|
1356
1361
|
import_v43.z.object({
|
|
1357
1362
|
web: import_v43.z.object({ uri: import_v43.z.string(), title: import_v43.z.string().nullish() }).nullish(),
|
|
1363
|
+
image: import_v43.z.object({
|
|
1364
|
+
sourceUri: import_v43.z.string(),
|
|
1365
|
+
imageUri: import_v43.z.string(),
|
|
1366
|
+
title: import_v43.z.string().nullish(),
|
|
1367
|
+
domain: import_v43.z.string().nullish()
|
|
1368
|
+
}).nullish(),
|
|
1358
1369
|
retrievedContext: import_v43.z.object({
|
|
1359
1370
|
uri: import_v43.z.string().nullish(),
|
|
1360
1371
|
title: import_v43.z.string().nullish(),
|
|
@@ -1551,17 +1562,25 @@ var googleMaps = (0, import_provider_utils8.createProviderToolFactory)({
|
|
|
1551
1562
|
// src/tool/google-search.ts
|
|
1552
1563
|
var import_provider_utils9 = require("@ai-sdk/provider-utils");
|
|
1553
1564
|
var import_v48 = require("zod/v4");
|
|
1554
|
-
var
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
()
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
+
var googleSearchToolArgsBaseSchema = import_v48.z.object({
|
|
1566
|
+
searchTypes: import_v48.z.object({
|
|
1567
|
+
webSearch: import_v48.z.object({}).optional(),
|
|
1568
|
+
imageSearch: import_v48.z.object({}).optional()
|
|
1569
|
+
}).optional(),
|
|
1570
|
+
timeRangeFilter: import_v48.z.object({
|
|
1571
|
+
startTime: import_v48.z.string(),
|
|
1572
|
+
endTime: import_v48.z.string()
|
|
1573
|
+
}).optional()
|
|
1574
|
+
}).passthrough();
|
|
1575
|
+
var googleSearchToolArgsSchema = (0, import_provider_utils9.lazySchema)(
|
|
1576
|
+
() => (0, import_provider_utils9.zodSchema)(googleSearchToolArgsBaseSchema)
|
|
1577
|
+
);
|
|
1578
|
+
var googleSearch = (0, import_provider_utils9.createProviderToolFactory)(
|
|
1579
|
+
{
|
|
1580
|
+
id: "google.google_search",
|
|
1581
|
+
inputSchema: googleSearchToolArgsSchema
|
|
1582
|
+
}
|
|
1583
|
+
);
|
|
1565
1584
|
|
|
1566
1585
|
// src/tool/url-context.ts
|
|
1567
1586
|
var import_provider_utils10 = require("@ai-sdk/provider-utils");
|