@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 CHANGED
@@ -1,5 +1,17 @@
1
1
  # @ai-sdk/google
2
2
 
3
+ ## 2.0.34
4
+
5
+ ### Patch Changes
6
+
7
+ - 9a66892: Add Google Vertex RAG Engine grounding provider tool
8
+
9
+ ## 2.0.33
10
+
11
+ ### Patch Changes
12
+
13
+ - 30a7d54: Improve error message when mixing function tools with provider-defined tools to clarify fallback behavior and list ignored function tools
14
+
3
15
  ## 2.0.32
4
16
 
5
17
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -85,8 +85,6 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
85
85
  retrievedContext?: {
86
86
  uri: string;
87
87
  title?: string | null | undefined;
88
- } | {
89
- title?: string | null | undefined;
90
88
  text?: string | null | undefined;
91
89
  } | null | undefined;
92
90
  }[] | null | undefined;
@@ -214,6 +212,14 @@ declare const googleTools: {
214
212
  outcome: string;
215
213
  output: string;
216
214
  }, {}>;
215
+ /**
216
+ * Creates a Vertex RAG Store tool that enables the model to perform RAG searches against a Vertex RAG Store.
217
+ * Must have name "vertex_rag_store".
218
+ */
219
+ vertexRagStore: _ai_sdk_provider_utils.ProviderDefinedToolFactory<{}, {
220
+ ragCorpus: string;
221
+ topK?: number;
222
+ }>;
217
223
  };
218
224
 
219
225
  interface GoogleGenerativeAIProvider extends ProviderV2 {
package/dist/index.d.ts CHANGED
@@ -85,8 +85,6 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
85
85
  retrievedContext?: {
86
86
  uri: string;
87
87
  title?: string | null | undefined;
88
- } | {
89
- title?: string | null | undefined;
90
88
  text?: string | null | undefined;
91
89
  } | null | undefined;
92
90
  }[] | null | undefined;
@@ -214,6 +212,14 @@ declare const googleTools: {
214
212
  outcome: string;
215
213
  output: string;
216
214
  }, {}>;
215
+ /**
216
+ * Creates a Vertex RAG Store tool that enables the model to perform RAG searches against a Vertex RAG Store.
217
+ * Must have name "vertex_rag_store".
218
+ */
219
+ vertexRagStore: _ai_sdk_provider_utils.ProviderDefinedToolFactory<{}, {
220
+ ragCorpus: string;
221
+ topK?: number;
222
+ }>;
217
223
  };
218
224
 
219
225
  interface GoogleGenerativeAIProvider extends ProviderV2 {
package/dist/index.js CHANGED
@@ -27,10 +27,10 @@ __export(src_exports, {
27
27
  module.exports = __toCommonJS(src_exports);
28
28
 
29
29
  // src/google-provider.ts
30
- var import_provider_utils12 = require("@ai-sdk/provider-utils");
30
+ var import_provider_utils13 = require("@ai-sdk/provider-utils");
31
31
 
32
32
  // src/version.ts
33
- var VERSION = true ? "2.0.32" : "0.0.0-test";
33
+ var VERSION = true ? "2.0.34" : "0.0.0-test";
34
34
 
35
35
  // src/google-generative-ai-embedding-model.ts
36
36
  var import_provider = require("@ai-sdk/provider");
@@ -598,10 +598,11 @@ function prepareTools({
598
598
  (tool) => tool.type === "provider-defined"
599
599
  );
600
600
  if (hasFunctionTools && hasProviderDefinedTools) {
601
+ const functionTools = tools.filter((tool) => tool.type === "function");
601
602
  toolWarnings.push({
602
603
  type: "unsupported-tool",
603
604
  tool: tools.find((tool) => tool.type === "function"),
604
- details: "Cannot mix function tools with provider-defined tools in the same request. Please use either function tools or provider-defined tools, but not both."
605
+ 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.`
605
606
  });
606
607
  }
607
608
  if (hasProviderDefinedTools) {
@@ -660,6 +661,26 @@ function prepareTools({
660
661
  });
661
662
  }
662
663
  break;
664
+ case "google.vertex_rag_store":
665
+ if (isGemini2) {
666
+ googleTools2.push({
667
+ retrieval: {
668
+ vertex_rag_store: {
669
+ rag_resources: {
670
+ rag_corpus: tool.args.ragCorpus
671
+ },
672
+ similarity_top_k: tool.args.topK
673
+ }
674
+ }
675
+ });
676
+ } else {
677
+ toolWarnings.push({
678
+ type: "unsupported-tool",
679
+ tool,
680
+ details: "The RAG store tool is not supported with other Gemini models than Gemini 2."
681
+ });
682
+ }
683
+ break;
663
684
  default:
664
685
  toolWarnings.push({ type: "unsupported-tool", tool });
665
686
  break;
@@ -804,6 +825,14 @@ var GoogleGenerativeAILanguageModel = class {
804
825
  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}).`
805
826
  });
806
827
  }
828
+ if ((tools == null ? void 0 : tools.some(
829
+ (tool) => tool.type === "provider-defined" && tool.id === "google.vertex_rag_store"
830
+ )) && !this.config.provider.startsWith("google.vertex.")) {
831
+ warnings.push({
832
+ type: "other",
833
+ 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}).`
834
+ });
835
+ }
807
836
  const isGemmaModel = this.modelId.toLowerCase().startsWith("gemma-");
808
837
  const { contents, systemInstruction } = convertToGoogleGenerativeAIMessages(
809
838
  prompt,
@@ -1247,16 +1276,64 @@ function extractSources({
1247
1276
  groundingMetadata,
1248
1277
  generateId: generateId3
1249
1278
  }) {
1250
- var _a;
1251
- return (_a = groundingMetadata == null ? void 0 : groundingMetadata.groundingChunks) == null ? void 0 : _a.filter(
1252
- (chunk) => chunk.web != null
1253
- ).map((chunk) => ({
1254
- type: "source",
1255
- sourceType: "url",
1256
- id: generateId3(),
1257
- url: chunk.web.uri,
1258
- title: chunk.web.title
1259
- }));
1279
+ var _a, _b, _c;
1280
+ if (!(groundingMetadata == null ? void 0 : groundingMetadata.groundingChunks)) {
1281
+ return void 0;
1282
+ }
1283
+ const sources = [];
1284
+ for (const chunk of groundingMetadata.groundingChunks) {
1285
+ if (chunk.web != null) {
1286
+ sources.push({
1287
+ type: "source",
1288
+ sourceType: "url",
1289
+ id: generateId3(),
1290
+ url: chunk.web.uri,
1291
+ title: (_a = chunk.web.title) != null ? _a : void 0
1292
+ });
1293
+ } else if (chunk.retrievedContext != null) {
1294
+ const uri = chunk.retrievedContext.uri;
1295
+ if (uri.startsWith("http://") || uri.startsWith("https://")) {
1296
+ sources.push({
1297
+ type: "source",
1298
+ sourceType: "url",
1299
+ id: generateId3(),
1300
+ url: uri,
1301
+ title: (_b = chunk.retrievedContext.title) != null ? _b : void 0
1302
+ });
1303
+ } else {
1304
+ const title = (_c = chunk.retrievedContext.title) != null ? _c : "Unknown Document";
1305
+ let mediaType = "application/octet-stream";
1306
+ let filename = void 0;
1307
+ if (uri.endsWith(".pdf")) {
1308
+ mediaType = "application/pdf";
1309
+ filename = uri.split("/").pop();
1310
+ } else if (uri.endsWith(".txt")) {
1311
+ mediaType = "text/plain";
1312
+ filename = uri.split("/").pop();
1313
+ } else if (uri.endsWith(".docx")) {
1314
+ mediaType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
1315
+ filename = uri.split("/").pop();
1316
+ } else if (uri.endsWith(".doc")) {
1317
+ mediaType = "application/msword";
1318
+ filename = uri.split("/").pop();
1319
+ } else if (uri.match(/\.(md|markdown)$/)) {
1320
+ mediaType = "text/markdown";
1321
+ filename = uri.split("/").pop();
1322
+ } else {
1323
+ filename = uri.split("/").pop();
1324
+ }
1325
+ sources.push({
1326
+ type: "source",
1327
+ sourceType: "document",
1328
+ id: generateId3(),
1329
+ mediaType,
1330
+ title,
1331
+ filename
1332
+ });
1333
+ }
1334
+ }
1335
+ }
1336
+ return sources.length > 0 ? sources : void 0;
1260
1337
  }
1261
1338
  var getGroundingMetadataSchema = () => import_v45.z.object({
1262
1339
  webSearchQueries: import_v45.z.array(import_v45.z.string()).nullish(),
@@ -1265,13 +1342,11 @@ var getGroundingMetadataSchema = () => import_v45.z.object({
1265
1342
  groundingChunks: import_v45.z.array(
1266
1343
  import_v45.z.object({
1267
1344
  web: import_v45.z.object({ uri: import_v45.z.string(), title: import_v45.z.string().nullish() }).nullish(),
1268
- retrievedContext: import_v45.z.union([
1269
- import_v45.z.object({ uri: import_v45.z.string(), title: import_v45.z.string().nullish() }).nullish(),
1270
- import_v45.z.object({
1271
- title: import_v45.z.string().nullish(),
1272
- text: import_v45.z.string().nullish()
1273
- })
1274
- ])
1345
+ retrievedContext: import_v45.z.object({
1346
+ uri: import_v45.z.string(),
1347
+ title: import_v45.z.string().nullish(),
1348
+ text: import_v45.z.string().nullish()
1349
+ }).nullish()
1275
1350
  })
1276
1351
  ).nullish(),
1277
1352
  groundingSupports: import_v45.z.array(
@@ -1463,6 +1538,18 @@ var urlContext = (0, import_provider_utils10.createProviderDefinedToolFactory)({
1463
1538
  inputSchema: (0, import_provider_utils10.lazySchema)(() => (0, import_provider_utils10.zodSchema)(import_v49.z.object({})))
1464
1539
  });
1465
1540
 
1541
+ // src/tool/vertex-rag-store.ts
1542
+ var import_provider_utils11 = require("@ai-sdk/provider-utils");
1543
+ var import_v410 = require("zod/v4");
1544
+ var vertexRagStore = (0, import_provider_utils11.createProviderDefinedToolFactory)({
1545
+ id: "google.vertex_rag_store",
1546
+ name: "vertex_rag_store",
1547
+ inputSchema: import_v410.z.object({
1548
+ ragCorpus: import_v410.z.string(),
1549
+ topK: import_v410.z.number().optional()
1550
+ })
1551
+ });
1552
+
1466
1553
  // src/google-tools.ts
1467
1554
  var googleTools = {
1468
1555
  /**
@@ -1496,12 +1583,17 @@ var googleTools = {
1496
1583
  * @see https://ai.google.dev/gemini-api/docs/code-execution (Google AI)
1497
1584
  * @see https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/code-execution-api (Vertex AI)
1498
1585
  */
1499
- codeExecution
1586
+ codeExecution,
1587
+ /**
1588
+ * Creates a Vertex RAG Store tool that enables the model to perform RAG searches against a Vertex RAG Store.
1589
+ * Must have name "vertex_rag_store".
1590
+ */
1591
+ vertexRagStore
1500
1592
  };
1501
1593
 
1502
1594
  // src/google-generative-ai-image-model.ts
1503
- var import_provider_utils11 = require("@ai-sdk/provider-utils");
1504
- var import_v410 = require("zod/v4");
1595
+ var import_provider_utils12 = require("@ai-sdk/provider-utils");
1596
+ var import_v411 = require("zod/v4");
1505
1597
  var GoogleGenerativeAIImageModel = class {
1506
1598
  constructor(modelId, settings, config) {
1507
1599
  this.modelId = modelId;
@@ -1543,7 +1635,7 @@ var GoogleGenerativeAIImageModel = class {
1543
1635
  details: "This model does not support the `seed` option through this provider."
1544
1636
  });
1545
1637
  }
1546
- const googleOptions = await (0, import_provider_utils11.parseProviderOptions)({
1638
+ const googleOptions = await (0, import_provider_utils12.parseProviderOptions)({
1547
1639
  provider: "google",
1548
1640
  providerOptions,
1549
1641
  schema: googleImageProviderOptionsSchema
@@ -1562,12 +1654,12 @@ var GoogleGenerativeAIImageModel = class {
1562
1654
  instances: [{ prompt }],
1563
1655
  parameters
1564
1656
  };
1565
- const { responseHeaders, value: response } = await (0, import_provider_utils11.postJsonToApi)({
1657
+ const { responseHeaders, value: response } = await (0, import_provider_utils12.postJsonToApi)({
1566
1658
  url: `${this.config.baseURL}/models/${this.modelId}:predict`,
1567
- headers: (0, import_provider_utils11.combineHeaders)(await (0, import_provider_utils11.resolve)(this.config.headers), headers),
1659
+ headers: (0, import_provider_utils12.combineHeaders)(await (0, import_provider_utils12.resolve)(this.config.headers), headers),
1568
1660
  body,
1569
1661
  failedResponseHandler: googleFailedResponseHandler,
1570
- successfulResponseHandler: (0, import_provider_utils11.createJsonResponseHandler)(
1662
+ successfulResponseHandler: (0, import_provider_utils12.createJsonResponseHandler)(
1571
1663
  googleImageResponseSchema
1572
1664
  ),
1573
1665
  abortSignal,
@@ -1593,18 +1685,18 @@ var GoogleGenerativeAIImageModel = class {
1593
1685
  };
1594
1686
  }
1595
1687
  };
1596
- var googleImageResponseSchema = (0, import_provider_utils11.lazySchema)(
1597
- () => (0, import_provider_utils11.zodSchema)(
1598
- import_v410.z.object({
1599
- predictions: import_v410.z.array(import_v410.z.object({ bytesBase64Encoded: import_v410.z.string() })).default([])
1688
+ var googleImageResponseSchema = (0, import_provider_utils12.lazySchema)(
1689
+ () => (0, import_provider_utils12.zodSchema)(
1690
+ import_v411.z.object({
1691
+ predictions: import_v411.z.array(import_v411.z.object({ bytesBase64Encoded: import_v411.z.string() })).default([])
1600
1692
  })
1601
1693
  )
1602
1694
  );
1603
- var googleImageProviderOptionsSchema = (0, import_provider_utils11.lazySchema)(
1604
- () => (0, import_provider_utils11.zodSchema)(
1605
- import_v410.z.object({
1606
- personGeneration: import_v410.z.enum(["dont_allow", "allow_adult", "allow_all"]).nullish(),
1607
- aspectRatio: import_v410.z.enum(["1:1", "3:4", "4:3", "9:16", "16:9"]).nullish()
1695
+ var googleImageProviderOptionsSchema = (0, import_provider_utils12.lazySchema)(
1696
+ () => (0, import_provider_utils12.zodSchema)(
1697
+ import_v411.z.object({
1698
+ personGeneration: import_v411.z.enum(["dont_allow", "allow_adult", "allow_all"]).nullish(),
1699
+ aspectRatio: import_v411.z.enum(["1:1", "3:4", "4:3", "9:16", "16:9"]).nullish()
1608
1700
  })
1609
1701
  )
1610
1702
  );
@@ -1612,11 +1704,11 @@ var googleImageProviderOptionsSchema = (0, import_provider_utils11.lazySchema)(
1612
1704
  // src/google-provider.ts
1613
1705
  function createGoogleGenerativeAI(options = {}) {
1614
1706
  var _a, _b;
1615
- const baseURL = (_a = (0, import_provider_utils12.withoutTrailingSlash)(options.baseURL)) != null ? _a : "https://generativelanguage.googleapis.com/v1beta";
1707
+ const baseURL = (_a = (0, import_provider_utils13.withoutTrailingSlash)(options.baseURL)) != null ? _a : "https://generativelanguage.googleapis.com/v1beta";
1616
1708
  const providerName = (_b = options.name) != null ? _b : "google.generative-ai";
1617
- const getHeaders = () => (0, import_provider_utils12.withUserAgentSuffix)(
1709
+ const getHeaders = () => (0, import_provider_utils13.withUserAgentSuffix)(
1618
1710
  {
1619
- "x-goog-api-key": (0, import_provider_utils12.loadApiKey)({
1711
+ "x-goog-api-key": (0, import_provider_utils13.loadApiKey)({
1620
1712
  apiKey: options.apiKey,
1621
1713
  environmentVariableName: "GOOGLE_GENERATIVE_AI_API_KEY",
1622
1714
  description: "Google Generative AI"
@@ -1631,7 +1723,7 @@ function createGoogleGenerativeAI(options = {}) {
1631
1723
  provider: providerName,
1632
1724
  baseURL,
1633
1725
  headers: getHeaders,
1634
- generateId: (_a2 = options.generateId) != null ? _a2 : import_provider_utils12.generateId,
1726
+ generateId: (_a2 = options.generateId) != null ? _a2 : import_provider_utils13.generateId,
1635
1727
  supportedUrls: () => ({
1636
1728
  "*": [
1637
1729
  // Google Generative Language "files" endpoint