@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/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.32" : "0.0.0-test";
10
+ var VERSION = true ? "2.0.34" : "0.0.0-test";
11
11
 
12
12
  // src/google-generative-ai-embedding-model.ts
13
13
  import {
@@ -609,10 +609,11 @@ function prepareTools({
609
609
  (tool) => tool.type === "provider-defined"
610
610
  );
611
611
  if (hasFunctionTools && hasProviderDefinedTools) {
612
+ const functionTools = tools.filter((tool) => tool.type === "function");
612
613
  toolWarnings.push({
613
614
  type: "unsupported-tool",
614
615
  tool: tools.find((tool) => tool.type === "function"),
615
- 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."
616
+ 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.`
616
617
  });
617
618
  }
618
619
  if (hasProviderDefinedTools) {
@@ -671,6 +672,26 @@ function prepareTools({
671
672
  });
672
673
  }
673
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;
674
695
  default:
675
696
  toolWarnings.push({ type: "unsupported-tool", tool });
676
697
  break;
@@ -815,6 +836,14 @@ var GoogleGenerativeAILanguageModel = class {
815
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}).`
816
837
  });
817
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
+ }
818
847
  const isGemmaModel = this.modelId.toLowerCase().startsWith("gemma-");
819
848
  const { contents, systemInstruction } = convertToGoogleGenerativeAIMessages(
820
849
  prompt,
@@ -1258,16 +1287,64 @@ function extractSources({
1258
1287
  groundingMetadata,
1259
1288
  generateId: generateId3
1260
1289
  }) {
1261
- var _a;
1262
- return (_a = groundingMetadata == null ? void 0 : groundingMetadata.groundingChunks) == null ? void 0 : _a.filter(
1263
- (chunk) => chunk.web != null
1264
- ).map((chunk) => ({
1265
- type: "source",
1266
- sourceType: "url",
1267
- id: generateId3(),
1268
- url: chunk.web.uri,
1269
- title: chunk.web.title
1270
- }));
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;
1271
1348
  }
1272
1349
  var getGroundingMetadataSchema = () => z5.object({
1273
1350
  webSearchQueries: z5.array(z5.string()).nullish(),
@@ -1276,13 +1353,11 @@ var getGroundingMetadataSchema = () => z5.object({
1276
1353
  groundingChunks: z5.array(
1277
1354
  z5.object({
1278
1355
  web: z5.object({ uri: z5.string(), title: z5.string().nullish() }).nullish(),
1279
- retrievedContext: z5.union([
1280
- z5.object({ uri: z5.string(), title: z5.string().nullish() }).nullish(),
1281
- z5.object({
1282
- title: z5.string().nullish(),
1283
- text: z5.string().nullish()
1284
- })
1285
- ])
1356
+ retrievedContext: z5.object({
1357
+ uri: z5.string(),
1358
+ title: z5.string().nullish(),
1359
+ text: z5.string().nullish()
1360
+ }).nullish()
1286
1361
  })
1287
1362
  ).nullish(),
1288
1363
  groundingSupports: z5.array(
@@ -1486,6 +1561,18 @@ var urlContext = createProviderDefinedToolFactory3({
1486
1561
  inputSchema: lazySchema8(() => zodSchema8(z9.object({})))
1487
1562
  });
1488
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
+
1489
1576
  // src/google-tools.ts
1490
1577
  var googleTools = {
1491
1578
  /**
@@ -1519,7 +1606,12 @@ var googleTools = {
1519
1606
  * @see https://ai.google.dev/gemini-api/docs/code-execution (Google AI)
1520
1607
  * @see https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/code-execution-api (Vertex AI)
1521
1608
  */
1522
- 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
1523
1615
  };
1524
1616
 
1525
1617
  // src/google-generative-ai-image-model.ts
@@ -1532,7 +1624,7 @@ import {
1532
1624
  resolve as resolve3,
1533
1625
  zodSchema as zodSchema9
1534
1626
  } from "@ai-sdk/provider-utils";
1535
- import { z as z10 } from "zod/v4";
1627
+ import { z as z11 } from "zod/v4";
1536
1628
  var GoogleGenerativeAIImageModel = class {
1537
1629
  constructor(modelId, settings, config) {
1538
1630
  this.modelId = modelId;
@@ -1626,16 +1718,16 @@ var GoogleGenerativeAIImageModel = class {
1626
1718
  };
1627
1719
  var googleImageResponseSchema = lazySchema9(
1628
1720
  () => zodSchema9(
1629
- z10.object({
1630
- predictions: z10.array(z10.object({ bytesBase64Encoded: z10.string() })).default([])
1721
+ z11.object({
1722
+ predictions: z11.array(z11.object({ bytesBase64Encoded: z11.string() })).default([])
1631
1723
  })
1632
1724
  )
1633
1725
  );
1634
1726
  var googleImageProviderOptionsSchema = lazySchema9(
1635
1727
  () => zodSchema9(
1636
- z10.object({
1637
- personGeneration: z10.enum(["dont_allow", "allow_adult", "allow_all"]).nullish(),
1638
- 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()
1639
1731
  })
1640
1732
  )
1641
1733
  );