@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/dist/index.mjs CHANGED
@@ -7,7 +7,7 @@ import {
7
7
  } from "@ai-sdk/provider-utils";
8
8
 
9
9
  // src/version.ts
10
- var VERSION = true ? "2.0.33" : "0.0.0-test";
10
+ var VERSION = true ? "2.0.35" : "0.0.0-test";
11
11
 
12
12
  // src/google-generative-ai-embedding-model.ts
13
13
  import {
@@ -672,6 +672,26 @@ function prepareTools({
672
672
  });
673
673
  }
674
674
  break;
675
+ case "google.vertex_rag_store":
676
+ if (isGemini2) {
677
+ googleTools2.push({
678
+ retrieval: {
679
+ vertex_rag_store: {
680
+ rag_resources: {
681
+ rag_corpus: tool.args.ragCorpus
682
+ },
683
+ similarity_top_k: tool.args.topK
684
+ }
685
+ }
686
+ });
687
+ } else {
688
+ toolWarnings.push({
689
+ type: "unsupported-tool",
690
+ tool,
691
+ details: "The RAG store tool is not supported with other Gemini models than Gemini 2."
692
+ });
693
+ }
694
+ break;
675
695
  default:
676
696
  toolWarnings.push({ type: "unsupported-tool", tool });
677
697
  break;
@@ -816,6 +836,14 @@ var GoogleGenerativeAILanguageModel = class {
816
836
  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}).`
817
837
  });
818
838
  }
839
+ if ((tools == null ? void 0 : tools.some(
840
+ (tool) => tool.type === "provider-defined" && tool.id === "google.vertex_rag_store"
841
+ )) && !this.config.provider.startsWith("google.vertex.")) {
842
+ warnings.push({
843
+ type: "other",
844
+ 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}).`
845
+ });
846
+ }
819
847
  const isGemmaModel = this.modelId.toLowerCase().startsWith("gemma-");
820
848
  const { contents, systemInstruction } = convertToGoogleGenerativeAIMessages(
821
849
  prompt,
@@ -1259,16 +1287,64 @@ function extractSources({
1259
1287
  groundingMetadata,
1260
1288
  generateId: generateId3
1261
1289
  }) {
1262
- var _a;
1263
- return (_a = groundingMetadata == null ? void 0 : groundingMetadata.groundingChunks) == null ? void 0 : _a.filter(
1264
- (chunk) => chunk.web != null
1265
- ).map((chunk) => ({
1266
- type: "source",
1267
- sourceType: "url",
1268
- id: generateId3(),
1269
- url: chunk.web.uri,
1270
- title: chunk.web.title
1271
- }));
1290
+ var _a, _b, _c;
1291
+ if (!(groundingMetadata == null ? void 0 : groundingMetadata.groundingChunks)) {
1292
+ return void 0;
1293
+ }
1294
+ const sources = [];
1295
+ for (const chunk of groundingMetadata.groundingChunks) {
1296
+ if (chunk.web != null) {
1297
+ sources.push({
1298
+ type: "source",
1299
+ sourceType: "url",
1300
+ id: generateId3(),
1301
+ url: chunk.web.uri,
1302
+ title: (_a = chunk.web.title) != null ? _a : void 0
1303
+ });
1304
+ } else if (chunk.retrievedContext != null) {
1305
+ const uri = chunk.retrievedContext.uri;
1306
+ if (uri.startsWith("http://") || uri.startsWith("https://")) {
1307
+ sources.push({
1308
+ type: "source",
1309
+ sourceType: "url",
1310
+ id: generateId3(),
1311
+ url: uri,
1312
+ title: (_b = chunk.retrievedContext.title) != null ? _b : void 0
1313
+ });
1314
+ } else {
1315
+ const title = (_c = chunk.retrievedContext.title) != null ? _c : "Unknown Document";
1316
+ let mediaType = "application/octet-stream";
1317
+ let filename = void 0;
1318
+ if (uri.endsWith(".pdf")) {
1319
+ mediaType = "application/pdf";
1320
+ filename = uri.split("/").pop();
1321
+ } else if (uri.endsWith(".txt")) {
1322
+ mediaType = "text/plain";
1323
+ filename = uri.split("/").pop();
1324
+ } else if (uri.endsWith(".docx")) {
1325
+ mediaType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
1326
+ filename = uri.split("/").pop();
1327
+ } else if (uri.endsWith(".doc")) {
1328
+ mediaType = "application/msword";
1329
+ filename = uri.split("/").pop();
1330
+ } else if (uri.match(/\.(md|markdown)$/)) {
1331
+ mediaType = "text/markdown";
1332
+ filename = uri.split("/").pop();
1333
+ } else {
1334
+ filename = uri.split("/").pop();
1335
+ }
1336
+ sources.push({
1337
+ type: "source",
1338
+ sourceType: "document",
1339
+ id: generateId3(),
1340
+ mediaType,
1341
+ title,
1342
+ filename
1343
+ });
1344
+ }
1345
+ }
1346
+ }
1347
+ return sources.length > 0 ? sources : void 0;
1272
1348
  }
1273
1349
  var getGroundingMetadataSchema = () => z5.object({
1274
1350
  webSearchQueries: z5.array(z5.string()).nullish(),
@@ -1277,13 +1353,11 @@ var getGroundingMetadataSchema = () => z5.object({
1277
1353
  groundingChunks: z5.array(
1278
1354
  z5.object({
1279
1355
  web: z5.object({ uri: z5.string(), title: z5.string().nullish() }).nullish(),
1280
- retrievedContext: z5.union([
1281
- z5.object({ uri: z5.string(), title: z5.string().nullish() }).nullish(),
1282
- z5.object({
1283
- title: z5.string().nullish(),
1284
- text: z5.string().nullish()
1285
- })
1286
- ])
1356
+ retrievedContext: z5.object({
1357
+ uri: z5.string(),
1358
+ title: z5.string().nullish(),
1359
+ text: z5.string().nullish()
1360
+ }).nullish()
1287
1361
  })
1288
1362
  ).nullish(),
1289
1363
  groundingSupports: z5.array(
@@ -1487,6 +1561,18 @@ var urlContext = createProviderDefinedToolFactory3({
1487
1561
  inputSchema: lazySchema8(() => zodSchema8(z9.object({})))
1488
1562
  });
1489
1563
 
1564
+ // src/tool/vertex-rag-store.ts
1565
+ import { createProviderDefinedToolFactory as createProviderDefinedToolFactory4 } from "@ai-sdk/provider-utils";
1566
+ import { z as z10 } from "zod/v4";
1567
+ var vertexRagStore = createProviderDefinedToolFactory4({
1568
+ id: "google.vertex_rag_store",
1569
+ name: "vertex_rag_store",
1570
+ inputSchema: z10.object({
1571
+ ragCorpus: z10.string(),
1572
+ topK: z10.number().optional()
1573
+ })
1574
+ });
1575
+
1490
1576
  // src/google-tools.ts
1491
1577
  var googleTools = {
1492
1578
  /**
@@ -1520,7 +1606,12 @@ var googleTools = {
1520
1606
  * @see https://ai.google.dev/gemini-api/docs/code-execution (Google AI)
1521
1607
  * @see https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/code-execution-api (Vertex AI)
1522
1608
  */
1523
- codeExecution
1609
+ codeExecution,
1610
+ /**
1611
+ * Creates a Vertex RAG Store tool that enables the model to perform RAG searches against a Vertex RAG Store.
1612
+ * Must have name "vertex_rag_store".
1613
+ */
1614
+ vertexRagStore
1524
1615
  };
1525
1616
 
1526
1617
  // src/google-generative-ai-image-model.ts
@@ -1533,7 +1624,7 @@ import {
1533
1624
  resolve as resolve3,
1534
1625
  zodSchema as zodSchema9
1535
1626
  } from "@ai-sdk/provider-utils";
1536
- import { z as z10 } from "zod/v4";
1627
+ import { z as z11 } from "zod/v4";
1537
1628
  var GoogleGenerativeAIImageModel = class {
1538
1629
  constructor(modelId, settings, config) {
1539
1630
  this.modelId = modelId;
@@ -1627,16 +1718,16 @@ var GoogleGenerativeAIImageModel = class {
1627
1718
  };
1628
1719
  var googleImageResponseSchema = lazySchema9(
1629
1720
  () => zodSchema9(
1630
- z10.object({
1631
- predictions: z10.array(z10.object({ bytesBase64Encoded: z10.string() })).default([])
1721
+ z11.object({
1722
+ predictions: z11.array(z11.object({ bytesBase64Encoded: z11.string() })).default([])
1632
1723
  })
1633
1724
  )
1634
1725
  );
1635
1726
  var googleImageProviderOptionsSchema = lazySchema9(
1636
1727
  () => zodSchema9(
1637
- z10.object({
1638
- personGeneration: z10.enum(["dont_allow", "allow_adult", "allow_all"]).nullish(),
1639
- aspectRatio: z10.enum(["1:1", "3:4", "4:3", "9:16", "16:9"]).nullish()
1728
+ z11.object({
1729
+ personGeneration: z11.enum(["dont_allow", "allow_adult", "allow_all"]).nullish(),
1730
+ aspectRatio: z11.enum(["1:1", "3:4", "4:3", "9:16", "16:9"]).nullish()
1640
1731
  })
1641
1732
  )
1642
1733
  );