@ai-sdk/google 2.0.32 → 2.0.34
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 +8 -2
- package/dist/index.d.ts +8 -2
- package/dist/index.js +132 -40
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +118 -26
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +10 -6
- package/dist/internal/index.d.ts +10 -6
- package/dist/internal/index.js +111 -19
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +111 -19
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/internal/index.d.ts
CHANGED
|
@@ -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
|
@@ -443,10 +443,11 @@ function prepareTools({
|
|
|
443
443
|
(tool) => tool.type === "provider-defined"
|
|
444
444
|
);
|
|
445
445
|
if (hasFunctionTools && hasProviderDefinedTools) {
|
|
446
|
+
const functionTools = tools.filter((tool) => tool.type === "function");
|
|
446
447
|
toolWarnings.push({
|
|
447
448
|
type: "unsupported-tool",
|
|
448
449
|
tool: tools.find((tool) => tool.type === "function"),
|
|
449
|
-
details:
|
|
450
|
+
details: `Cannot mix function tools with provider-defined tools in the same request. Falling back to provider-defined tools only. The following function tools will be ignored: ${functionTools.map((t) => t.name).join(", ")}. Please use either function tools or provider-defined tools, but not both.`
|
|
450
451
|
});
|
|
451
452
|
}
|
|
452
453
|
if (hasProviderDefinedTools) {
|
|
@@ -505,6 +506,26 @@ function prepareTools({
|
|
|
505
506
|
});
|
|
506
507
|
}
|
|
507
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;
|
|
508
529
|
default:
|
|
509
530
|
toolWarnings.push({ type: "unsupported-tool", tool });
|
|
510
531
|
break;
|
|
@@ -649,6 +670,14 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
649
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}).`
|
|
650
671
|
});
|
|
651
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
|
+
}
|
|
652
681
|
const isGemmaModel = this.modelId.toLowerCase().startsWith("gemma-");
|
|
653
682
|
const { contents, systemInstruction } = convertToGoogleGenerativeAIMessages(
|
|
654
683
|
prompt,
|
|
@@ -1092,16 +1121,64 @@ function extractSources({
|
|
|
1092
1121
|
groundingMetadata,
|
|
1093
1122
|
generateId: generateId2
|
|
1094
1123
|
}) {
|
|
1095
|
-
var _a;
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
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;
|
|
1105
1182
|
}
|
|
1106
1183
|
var getGroundingMetadataSchema = () => import_v43.z.object({
|
|
1107
1184
|
webSearchQueries: import_v43.z.array(import_v43.z.string()).nullish(),
|
|
@@ -1110,13 +1187,11 @@ var getGroundingMetadataSchema = () => import_v43.z.object({
|
|
|
1110
1187
|
groundingChunks: import_v43.z.array(
|
|
1111
1188
|
import_v43.z.object({
|
|
1112
1189
|
web: import_v43.z.object({ uri: import_v43.z.string(), title: import_v43.z.string().nullish() }).nullish(),
|
|
1113
|
-
retrievedContext: import_v43.z.
|
|
1114
|
-
|
|
1115
|
-
import_v43.z.
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
})
|
|
1119
|
-
])
|
|
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()
|
|
1120
1195
|
})
|
|
1121
1196
|
).nullish(),
|
|
1122
1197
|
groundingSupports: import_v43.z.array(
|
|
@@ -1308,6 +1383,18 @@ var urlContext = (0, import_provider_utils8.createProviderDefinedToolFactory)({
|
|
|
1308
1383
|
inputSchema: (0, import_provider_utils8.lazySchema)(() => (0, import_provider_utils8.zodSchema)(import_v47.z.object({})))
|
|
1309
1384
|
});
|
|
1310
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
|
+
|
|
1311
1398
|
// src/google-tools.ts
|
|
1312
1399
|
var googleTools = {
|
|
1313
1400
|
/**
|
|
@@ -1341,7 +1428,12 @@ var googleTools = {
|
|
|
1341
1428
|
* @see https://ai.google.dev/gemini-api/docs/code-execution (Google AI)
|
|
1342
1429
|
* @see https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/code-execution-api (Vertex AI)
|
|
1343
1430
|
*/
|
|
1344
|
-
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
|
|
1345
1437
|
};
|
|
1346
1438
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1347
1439
|
0 && (module.exports = {
|