@ai-sdk/google 2.0.33 → 2.0.35
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 +9 -3
- package/dist/index.d.ts +9 -3
- package/dist/index.js +130 -39
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +116 -25
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +11 -7
- package/dist/internal/index.d.ts +11 -7
- package/dist/internal/index.js +109 -18
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +109 -18
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -3,7 +3,7 @@ import { Resolvable, FetchFunction, InferValidator } from '@ai-sdk/provider-util
|
|
|
3
3
|
import { LanguageModelV2 } from '@ai-sdk/provider';
|
|
4
4
|
import { z } from 'zod/v4';
|
|
5
5
|
|
|
6
|
-
type GoogleGenerativeAIModelId = 'gemini-1.5-flash' | 'gemini-1.5-flash-latest' | 'gemini-1.5-flash-001' | 'gemini-1.5-flash-002' | 'gemini-1.5-flash-8b' | 'gemini-1.5-flash-8b-latest' | 'gemini-1.5-flash-8b-001' | 'gemini-1.5-pro' | 'gemini-1.5-pro-latest' | 'gemini-1.5-pro-001' | 'gemini-1.5-pro-002' | 'gemini-2.0-flash' | 'gemini-2.0-flash-001' | 'gemini-2.0-flash-live-001' | 'gemini-2.0-flash-lite' | 'gemini-2.0-pro-exp-02-05' | 'gemini-2.0-flash-thinking-exp-01-21' | 'gemini-2.0-flash-exp' | 'gemini-2.5-pro' | 'gemini-2.5-flash' | 'gemini-2.5-flash-image-preview' | 'gemini-2.5-flash-lite' | 'gemini-2.5-flash-lite-preview-09-2025' | 'gemini-2.5-flash-preview-04-17' | 'gemini-2.5-flash-preview-09-2025' | 'gemini-2.5-pro-exp-03-25' | 'gemini-exp-1206' | 'gemma-3-12b-it' | 'gemma-3-27b-it' | (string & {});
|
|
6
|
+
type GoogleGenerativeAIModelId = 'gemini-1.5-flash' | 'gemini-1.5-flash-latest' | 'gemini-1.5-flash-001' | 'gemini-1.5-flash-002' | 'gemini-1.5-flash-8b' | 'gemini-1.5-flash-8b-latest' | 'gemini-1.5-flash-8b-001' | 'gemini-1.5-pro' | 'gemini-1.5-pro-latest' | 'gemini-1.5-pro-001' | 'gemini-1.5-pro-002' | 'gemini-2.0-flash' | 'gemini-2.0-flash-001' | 'gemini-2.0-flash-live-001' | 'gemini-2.0-flash-lite' | 'gemini-2.0-pro-exp-02-05' | 'gemini-2.0-flash-thinking-exp-01-21' | 'gemini-2.0-flash-exp' | 'gemini-2.5-pro' | 'gemini-2.5-flash' | 'gemini-2.5-flash-image-preview' | 'gemini-2.5-flash-lite' | 'gemini-2.5-flash-lite-preview-09-2025' | 'gemini-2.5-flash-preview-04-17' | 'gemini-2.5-flash-preview-09-2025' | 'gemini-3-pro-preview' | 'gemini-pro-latest' | 'gemini-flash-latest' | 'gemini-flash-lite-latest' | 'gemini-2.5-pro-exp-03-25' | 'gemini-exp-1206' | 'gemma-3-12b-it' | 'gemma-3-27b-it' | (string & {});
|
|
7
7
|
|
|
8
8
|
type GoogleGenerativeAIConfig = {
|
|
9
9
|
provider: string;
|
|
@@ -39,13 +39,11 @@ declare const getGroundingMetadataSchema: () => z.ZodObject<{
|
|
|
39
39
|
uri: z.ZodString;
|
|
40
40
|
title: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
41
41
|
}, z.core.$strip>>>;
|
|
42
|
-
retrievedContext: z.
|
|
42
|
+
retrievedContext: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
43
43
|
uri: z.ZodString;
|
|
44
44
|
title: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
45
|
-
}, z.core.$strip>>>, z.ZodObject<{
|
|
46
|
-
title: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
47
45
|
text: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
48
|
-
}, z.core.$strip
|
|
46
|
+
}, z.core.$strip>>>;
|
|
49
47
|
}, z.core.$strip>>>>;
|
|
50
48
|
groundingSupports: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodObject<{
|
|
51
49
|
segment: z.ZodObject<{
|
|
@@ -120,8 +118,6 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
120
118
|
retrievedContext?: {
|
|
121
119
|
uri: string;
|
|
122
120
|
title?: string | null | undefined;
|
|
123
|
-
} | {
|
|
124
|
-
title?: string | null | undefined;
|
|
125
121
|
text?: string | null | undefined;
|
|
126
122
|
} | null | undefined;
|
|
127
123
|
}[] | null | undefined;
|
|
@@ -219,6 +215,14 @@ declare const googleTools: {
|
|
|
219
215
|
outcome: string;
|
|
220
216
|
output: string;
|
|
221
217
|
}, {}>;
|
|
218
|
+
/**
|
|
219
|
+
* Creates a Vertex RAG Store tool that enables the model to perform RAG searches against a Vertex RAG Store.
|
|
220
|
+
* Must have name "vertex_rag_store".
|
|
221
|
+
*/
|
|
222
|
+
vertexRagStore: _ai_sdk_provider_utils.ProviderDefinedToolFactory<{}, {
|
|
223
|
+
ragCorpus: string;
|
|
224
|
+
topK?: number;
|
|
225
|
+
}>;
|
|
222
226
|
};
|
|
223
227
|
|
|
224
228
|
export { GoogleGenerativeAILanguageModel, type GoogleGenerativeAIModelId, type GroundingMetadataSchema, type SafetyRatingSchema, type UrlContextMetadataSchema, getGroundingMetadataSchema, getUrlContextMetadataSchema, googleTools };
|
package/dist/internal/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { Resolvable, FetchFunction, InferValidator } from '@ai-sdk/provider-util
|
|
|
3
3
|
import { LanguageModelV2 } from '@ai-sdk/provider';
|
|
4
4
|
import { z } from 'zod/v4';
|
|
5
5
|
|
|
6
|
-
type GoogleGenerativeAIModelId = 'gemini-1.5-flash' | 'gemini-1.5-flash-latest' | 'gemini-1.5-flash-001' | 'gemini-1.5-flash-002' | 'gemini-1.5-flash-8b' | 'gemini-1.5-flash-8b-latest' | 'gemini-1.5-flash-8b-001' | 'gemini-1.5-pro' | 'gemini-1.5-pro-latest' | 'gemini-1.5-pro-001' | 'gemini-1.5-pro-002' | 'gemini-2.0-flash' | 'gemini-2.0-flash-001' | 'gemini-2.0-flash-live-001' | 'gemini-2.0-flash-lite' | 'gemini-2.0-pro-exp-02-05' | 'gemini-2.0-flash-thinking-exp-01-21' | 'gemini-2.0-flash-exp' | 'gemini-2.5-pro' | 'gemini-2.5-flash' | 'gemini-2.5-flash-image-preview' | 'gemini-2.5-flash-lite' | 'gemini-2.5-flash-lite-preview-09-2025' | 'gemini-2.5-flash-preview-04-17' | 'gemini-2.5-flash-preview-09-2025' | 'gemini-2.5-pro-exp-03-25' | 'gemini-exp-1206' | 'gemma-3-12b-it' | 'gemma-3-27b-it' | (string & {});
|
|
6
|
+
type GoogleGenerativeAIModelId = 'gemini-1.5-flash' | 'gemini-1.5-flash-latest' | 'gemini-1.5-flash-001' | 'gemini-1.5-flash-002' | 'gemini-1.5-flash-8b' | 'gemini-1.5-flash-8b-latest' | 'gemini-1.5-flash-8b-001' | 'gemini-1.5-pro' | 'gemini-1.5-pro-latest' | 'gemini-1.5-pro-001' | 'gemini-1.5-pro-002' | 'gemini-2.0-flash' | 'gemini-2.0-flash-001' | 'gemini-2.0-flash-live-001' | 'gemini-2.0-flash-lite' | 'gemini-2.0-pro-exp-02-05' | 'gemini-2.0-flash-thinking-exp-01-21' | 'gemini-2.0-flash-exp' | 'gemini-2.5-pro' | 'gemini-2.5-flash' | 'gemini-2.5-flash-image-preview' | 'gemini-2.5-flash-lite' | 'gemini-2.5-flash-lite-preview-09-2025' | 'gemini-2.5-flash-preview-04-17' | 'gemini-2.5-flash-preview-09-2025' | 'gemini-3-pro-preview' | 'gemini-pro-latest' | 'gemini-flash-latest' | 'gemini-flash-lite-latest' | 'gemini-2.5-pro-exp-03-25' | 'gemini-exp-1206' | 'gemma-3-12b-it' | 'gemma-3-27b-it' | (string & {});
|
|
7
7
|
|
|
8
8
|
type GoogleGenerativeAIConfig = {
|
|
9
9
|
provider: string;
|
|
@@ -39,13 +39,11 @@ declare const getGroundingMetadataSchema: () => z.ZodObject<{
|
|
|
39
39
|
uri: z.ZodString;
|
|
40
40
|
title: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
41
41
|
}, z.core.$strip>>>;
|
|
42
|
-
retrievedContext: z.
|
|
42
|
+
retrievedContext: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
43
43
|
uri: z.ZodString;
|
|
44
44
|
title: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
45
|
-
}, z.core.$strip>>>, z.ZodObject<{
|
|
46
|
-
title: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
47
45
|
text: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
48
|
-
}, z.core.$strip
|
|
46
|
+
}, z.core.$strip>>>;
|
|
49
47
|
}, z.core.$strip>>>>;
|
|
50
48
|
groundingSupports: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodObject<{
|
|
51
49
|
segment: z.ZodObject<{
|
|
@@ -120,8 +118,6 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
120
118
|
retrievedContext?: {
|
|
121
119
|
uri: string;
|
|
122
120
|
title?: string | null | undefined;
|
|
123
|
-
} | {
|
|
124
|
-
title?: string | null | undefined;
|
|
125
121
|
text?: string | null | undefined;
|
|
126
122
|
} | null | undefined;
|
|
127
123
|
}[] | null | undefined;
|
|
@@ -219,6 +215,14 @@ declare const googleTools: {
|
|
|
219
215
|
outcome: string;
|
|
220
216
|
output: string;
|
|
221
217
|
}, {}>;
|
|
218
|
+
/**
|
|
219
|
+
* Creates a Vertex RAG Store tool that enables the model to perform RAG searches against a Vertex RAG Store.
|
|
220
|
+
* Must have name "vertex_rag_store".
|
|
221
|
+
*/
|
|
222
|
+
vertexRagStore: _ai_sdk_provider_utils.ProviderDefinedToolFactory<{}, {
|
|
223
|
+
ragCorpus: string;
|
|
224
|
+
topK?: number;
|
|
225
|
+
}>;
|
|
222
226
|
};
|
|
223
227
|
|
|
224
228
|
export { GoogleGenerativeAILanguageModel, type GoogleGenerativeAIModelId, type GroundingMetadataSchema, type SafetyRatingSchema, type UrlContextMetadataSchema, getGroundingMetadataSchema, getUrlContextMetadataSchema, googleTools };
|
package/dist/internal/index.js
CHANGED
|
@@ -506,6 +506,26 @@ function prepareTools({
|
|
|
506
506
|
});
|
|
507
507
|
}
|
|
508
508
|
break;
|
|
509
|
+
case "google.vertex_rag_store":
|
|
510
|
+
if (isGemini2) {
|
|
511
|
+
googleTools2.push({
|
|
512
|
+
retrieval: {
|
|
513
|
+
vertex_rag_store: {
|
|
514
|
+
rag_resources: {
|
|
515
|
+
rag_corpus: tool.args.ragCorpus
|
|
516
|
+
},
|
|
517
|
+
similarity_top_k: tool.args.topK
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
});
|
|
521
|
+
} else {
|
|
522
|
+
toolWarnings.push({
|
|
523
|
+
type: "unsupported-tool",
|
|
524
|
+
tool,
|
|
525
|
+
details: "The RAG store tool is not supported with other Gemini models than Gemini 2."
|
|
526
|
+
});
|
|
527
|
+
}
|
|
528
|
+
break;
|
|
509
529
|
default:
|
|
510
530
|
toolWarnings.push({ type: "unsupported-tool", tool });
|
|
511
531
|
break;
|
|
@@ -650,6 +670,14 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
650
670
|
message: `The 'includeThoughts' option is only supported with the Google Vertex provider and might not be supported or could behave unexpectedly with the current Google provider (${this.config.provider}).`
|
|
651
671
|
});
|
|
652
672
|
}
|
|
673
|
+
if ((tools == null ? void 0 : tools.some(
|
|
674
|
+
(tool) => tool.type === "provider-defined" && tool.id === "google.vertex_rag_store"
|
|
675
|
+
)) && !this.config.provider.startsWith("google.vertex.")) {
|
|
676
|
+
warnings.push({
|
|
677
|
+
type: "other",
|
|
678
|
+
message: `The 'vertex_rag_store' tool is only supported with the Google Vertex provider and might not be supported or could behave unexpectedly with the current Google provider (${this.config.provider}).`
|
|
679
|
+
});
|
|
680
|
+
}
|
|
653
681
|
const isGemmaModel = this.modelId.toLowerCase().startsWith("gemma-");
|
|
654
682
|
const { contents, systemInstruction } = convertToGoogleGenerativeAIMessages(
|
|
655
683
|
prompt,
|
|
@@ -1093,16 +1121,64 @@ function extractSources({
|
|
|
1093
1121
|
groundingMetadata,
|
|
1094
1122
|
generateId: generateId2
|
|
1095
1123
|
}) {
|
|
1096
|
-
var _a;
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1124
|
+
var _a, _b, _c;
|
|
1125
|
+
if (!(groundingMetadata == null ? void 0 : groundingMetadata.groundingChunks)) {
|
|
1126
|
+
return void 0;
|
|
1127
|
+
}
|
|
1128
|
+
const sources = [];
|
|
1129
|
+
for (const chunk of groundingMetadata.groundingChunks) {
|
|
1130
|
+
if (chunk.web != null) {
|
|
1131
|
+
sources.push({
|
|
1132
|
+
type: "source",
|
|
1133
|
+
sourceType: "url",
|
|
1134
|
+
id: generateId2(),
|
|
1135
|
+
url: chunk.web.uri,
|
|
1136
|
+
title: (_a = chunk.web.title) != null ? _a : void 0
|
|
1137
|
+
});
|
|
1138
|
+
} else if (chunk.retrievedContext != null) {
|
|
1139
|
+
const uri = chunk.retrievedContext.uri;
|
|
1140
|
+
if (uri.startsWith("http://") || uri.startsWith("https://")) {
|
|
1141
|
+
sources.push({
|
|
1142
|
+
type: "source",
|
|
1143
|
+
sourceType: "url",
|
|
1144
|
+
id: generateId2(),
|
|
1145
|
+
url: uri,
|
|
1146
|
+
title: (_b = chunk.retrievedContext.title) != null ? _b : void 0
|
|
1147
|
+
});
|
|
1148
|
+
} else {
|
|
1149
|
+
const title = (_c = chunk.retrievedContext.title) != null ? _c : "Unknown Document";
|
|
1150
|
+
let mediaType = "application/octet-stream";
|
|
1151
|
+
let filename = void 0;
|
|
1152
|
+
if (uri.endsWith(".pdf")) {
|
|
1153
|
+
mediaType = "application/pdf";
|
|
1154
|
+
filename = uri.split("/").pop();
|
|
1155
|
+
} else if (uri.endsWith(".txt")) {
|
|
1156
|
+
mediaType = "text/plain";
|
|
1157
|
+
filename = uri.split("/").pop();
|
|
1158
|
+
} else if (uri.endsWith(".docx")) {
|
|
1159
|
+
mediaType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
|
|
1160
|
+
filename = uri.split("/").pop();
|
|
1161
|
+
} else if (uri.endsWith(".doc")) {
|
|
1162
|
+
mediaType = "application/msword";
|
|
1163
|
+
filename = uri.split("/").pop();
|
|
1164
|
+
} else if (uri.match(/\.(md|markdown)$/)) {
|
|
1165
|
+
mediaType = "text/markdown";
|
|
1166
|
+
filename = uri.split("/").pop();
|
|
1167
|
+
} else {
|
|
1168
|
+
filename = uri.split("/").pop();
|
|
1169
|
+
}
|
|
1170
|
+
sources.push({
|
|
1171
|
+
type: "source",
|
|
1172
|
+
sourceType: "document",
|
|
1173
|
+
id: generateId2(),
|
|
1174
|
+
mediaType,
|
|
1175
|
+
title,
|
|
1176
|
+
filename
|
|
1177
|
+
});
|
|
1178
|
+
}
|
|
1179
|
+
}
|
|
1180
|
+
}
|
|
1181
|
+
return sources.length > 0 ? sources : void 0;
|
|
1106
1182
|
}
|
|
1107
1183
|
var getGroundingMetadataSchema = () => import_v43.z.object({
|
|
1108
1184
|
webSearchQueries: import_v43.z.array(import_v43.z.string()).nullish(),
|
|
@@ -1111,13 +1187,11 @@ var getGroundingMetadataSchema = () => import_v43.z.object({
|
|
|
1111
1187
|
groundingChunks: import_v43.z.array(
|
|
1112
1188
|
import_v43.z.object({
|
|
1113
1189
|
web: import_v43.z.object({ uri: import_v43.z.string(), title: import_v43.z.string().nullish() }).nullish(),
|
|
1114
|
-
retrievedContext: import_v43.z.
|
|
1115
|
-
|
|
1116
|
-
import_v43.z.
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
})
|
|
1120
|
-
])
|
|
1190
|
+
retrievedContext: import_v43.z.object({
|
|
1191
|
+
uri: import_v43.z.string(),
|
|
1192
|
+
title: import_v43.z.string().nullish(),
|
|
1193
|
+
text: import_v43.z.string().nullish()
|
|
1194
|
+
}).nullish()
|
|
1121
1195
|
})
|
|
1122
1196
|
).nullish(),
|
|
1123
1197
|
groundingSupports: import_v43.z.array(
|
|
@@ -1309,6 +1383,18 @@ var urlContext = (0, import_provider_utils8.createProviderDefinedToolFactory)({
|
|
|
1309
1383
|
inputSchema: (0, import_provider_utils8.lazySchema)(() => (0, import_provider_utils8.zodSchema)(import_v47.z.object({})))
|
|
1310
1384
|
});
|
|
1311
1385
|
|
|
1386
|
+
// src/tool/vertex-rag-store.ts
|
|
1387
|
+
var import_provider_utils9 = require("@ai-sdk/provider-utils");
|
|
1388
|
+
var import_v48 = require("zod/v4");
|
|
1389
|
+
var vertexRagStore = (0, import_provider_utils9.createProviderDefinedToolFactory)({
|
|
1390
|
+
id: "google.vertex_rag_store",
|
|
1391
|
+
name: "vertex_rag_store",
|
|
1392
|
+
inputSchema: import_v48.z.object({
|
|
1393
|
+
ragCorpus: import_v48.z.string(),
|
|
1394
|
+
topK: import_v48.z.number().optional()
|
|
1395
|
+
})
|
|
1396
|
+
});
|
|
1397
|
+
|
|
1312
1398
|
// src/google-tools.ts
|
|
1313
1399
|
var googleTools = {
|
|
1314
1400
|
/**
|
|
@@ -1342,7 +1428,12 @@ var googleTools = {
|
|
|
1342
1428
|
* @see https://ai.google.dev/gemini-api/docs/code-execution (Google AI)
|
|
1343
1429
|
* @see https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/code-execution-api (Vertex AI)
|
|
1344
1430
|
*/
|
|
1345
|
-
codeExecution
|
|
1431
|
+
codeExecution,
|
|
1432
|
+
/**
|
|
1433
|
+
* Creates a Vertex RAG Store tool that enables the model to perform RAG searches against a Vertex RAG Store.
|
|
1434
|
+
* Must have name "vertex_rag_store".
|
|
1435
|
+
*/
|
|
1436
|
+
vertexRagStore
|
|
1346
1437
|
};
|
|
1347
1438
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1348
1439
|
0 && (module.exports = {
|