@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
|
@@ -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":
|
|
@@ -1134,10 +1128,30 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1134
1128
|
});
|
|
1135
1129
|
}
|
|
1136
1130
|
} else if ("inlineData" in part) {
|
|
1131
|
+
if (currentTextBlockId !== null) {
|
|
1132
|
+
controller.enqueue({
|
|
1133
|
+
type: "text-end",
|
|
1134
|
+
id: currentTextBlockId
|
|
1135
|
+
});
|
|
1136
|
+
currentTextBlockId = null;
|
|
1137
|
+
}
|
|
1138
|
+
if (currentReasoningBlockId !== null) {
|
|
1139
|
+
controller.enqueue({
|
|
1140
|
+
type: "reasoning-end",
|
|
1141
|
+
id: currentReasoningBlockId
|
|
1142
|
+
});
|
|
1143
|
+
currentReasoningBlockId = null;
|
|
1144
|
+
}
|
|
1145
|
+
const thoughtSignatureMetadata = part.thoughtSignature ? {
|
|
1146
|
+
[providerOptionsName]: {
|
|
1147
|
+
thoughtSignature: part.thoughtSignature
|
|
1148
|
+
}
|
|
1149
|
+
} : void 0;
|
|
1137
1150
|
controller.enqueue({
|
|
1138
1151
|
type: "file",
|
|
1139
1152
|
mediaType: part.inlineData.mimeType,
|
|
1140
|
-
data: part.inlineData.data
|
|
1153
|
+
data: part.inlineData.data,
|
|
1154
|
+
providerMetadata: thoughtSignatureMetadata
|
|
1141
1155
|
});
|
|
1142
1156
|
}
|
|
1143
1157
|
}
|
|
@@ -1248,7 +1262,7 @@ function extractSources({
|
|
|
1248
1262
|
groundingMetadata,
|
|
1249
1263
|
generateId: generateId2
|
|
1250
1264
|
}) {
|
|
1251
|
-
var _a, _b, _c, _d, _e;
|
|
1265
|
+
var _a, _b, _c, _d, _e, _f;
|
|
1252
1266
|
if (!(groundingMetadata == null ? void 0 : groundingMetadata.groundingChunks)) {
|
|
1253
1267
|
return void 0;
|
|
1254
1268
|
}
|
|
@@ -1262,6 +1276,16 @@ function extractSources({
|
|
|
1262
1276
|
url: chunk.web.uri,
|
|
1263
1277
|
title: (_a = chunk.web.title) != null ? _a : void 0
|
|
1264
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
|
+
});
|
|
1265
1289
|
} else if (chunk.retrievedContext != null) {
|
|
1266
1290
|
const uri = chunk.retrievedContext.uri;
|
|
1267
1291
|
const fileSearchStore = chunk.retrievedContext.fileSearchStore;
|
|
@@ -1271,10 +1295,10 @@ function extractSources({
|
|
|
1271
1295
|
sourceType: "url",
|
|
1272
1296
|
id: generateId2(),
|
|
1273
1297
|
url: uri,
|
|
1274
|
-
title: (
|
|
1298
|
+
title: (_c = chunk.retrievedContext.title) != null ? _c : void 0
|
|
1275
1299
|
});
|
|
1276
1300
|
} else if (uri) {
|
|
1277
|
-
const title = (
|
|
1301
|
+
const title = (_d = chunk.retrievedContext.title) != null ? _d : "Unknown Document";
|
|
1278
1302
|
let mediaType = "application/octet-stream";
|
|
1279
1303
|
let filename = void 0;
|
|
1280
1304
|
if (uri.endsWith(".pdf")) {
|
|
@@ -1304,7 +1328,7 @@ function extractSources({
|
|
|
1304
1328
|
filename
|
|
1305
1329
|
});
|
|
1306
1330
|
} else if (fileSearchStore) {
|
|
1307
|
-
const title = (
|
|
1331
|
+
const title = (_e = chunk.retrievedContext.title) != null ? _e : "Unknown Document";
|
|
1308
1332
|
sources.push({
|
|
1309
1333
|
type: "source",
|
|
1310
1334
|
sourceType: "document",
|
|
@@ -1321,7 +1345,7 @@ function extractSources({
|
|
|
1321
1345
|
sourceType: "url",
|
|
1322
1346
|
id: generateId2(),
|
|
1323
1347
|
url: chunk.maps.uri,
|
|
1324
|
-
title: (
|
|
1348
|
+
title: (_f = chunk.maps.title) != null ? _f : void 0
|
|
1325
1349
|
});
|
|
1326
1350
|
}
|
|
1327
1351
|
}
|
|
@@ -1330,11 +1354,18 @@ function extractSources({
|
|
|
1330
1354
|
}
|
|
1331
1355
|
var getGroundingMetadataSchema = () => import_v43.z.object({
|
|
1332
1356
|
webSearchQueries: import_v43.z.array(import_v43.z.string()).nullish(),
|
|
1357
|
+
imageSearchQueries: import_v43.z.array(import_v43.z.string()).nullish(),
|
|
1333
1358
|
retrievalQueries: import_v43.z.array(import_v43.z.string()).nullish(),
|
|
1334
1359
|
searchEntryPoint: import_v43.z.object({ renderedContent: import_v43.z.string() }).nullish(),
|
|
1335
1360
|
groundingChunks: import_v43.z.array(
|
|
1336
1361
|
import_v43.z.object({
|
|
1337
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(),
|
|
1338
1369
|
retrievedContext: import_v43.z.object({
|
|
1339
1370
|
uri: import_v43.z.string().nullish(),
|
|
1340
1371
|
title: import_v43.z.string().nullish(),
|
|
@@ -1531,17 +1562,25 @@ var googleMaps = (0, import_provider_utils8.createProviderToolFactory)({
|
|
|
1531
1562
|
// src/tool/google-search.ts
|
|
1532
1563
|
var import_provider_utils9 = require("@ai-sdk/provider-utils");
|
|
1533
1564
|
var import_v48 = require("zod/v4");
|
|
1534
|
-
var
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
()
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
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
|
+
);
|
|
1545
1584
|
|
|
1546
1585
|
// src/tool/url-context.ts
|
|
1547
1586
|
var import_provider_utils10 = require("@ai-sdk/provider-utils");
|