@ai-sdk/google 2.0.28 → 2.0.30

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.30
4
+
5
+ ### Patch Changes
6
+
7
+ - e2dac8b: Support for custom provider name in google and anthropic providers
8
+
9
+ ## 2.0.29
10
+
11
+ ### Patch Changes
12
+
13
+ - a929a32: Add Google File search tool
14
+
3
15
  ## 2.0.28
4
16
 
5
17
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -85,6 +85,9 @@ 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
+ text?: string | null | undefined;
88
91
  } | null | undefined;
89
92
  }[] | null | undefined;
90
93
  groundingSupports?: {
@@ -177,6 +180,22 @@ declare const googleTools: {
177
180
  * Must have name "url_context".
178
181
  */
179
182
  urlContext: _ai_sdk_provider_utils.ProviderDefinedToolFactory<{}, {}>;
183
+ /**
184
+ * Enables Retrieval Augmented Generation (RAG) via the Gemini File Search tool.
185
+ * Must have name "file_search".
186
+ *
187
+ * @param fileSearchStoreNames - Fully-qualified File Search store resource names.
188
+ * @param metadataFilter - Optional filter expression to restrict the files that can be retrieved.
189
+ * @param topK - Optional result limit for the number of chunks returned from File Search.
190
+ *
191
+ * @see https://ai.google.dev/gemini-api/docs/file-search
192
+ */
193
+ fileSearch: _ai_sdk_provider_utils.ProviderDefinedToolFactory<{}, {
194
+ [x: string]: unknown;
195
+ fileSearchStoreNames: string[];
196
+ topK?: number | undefined;
197
+ metadataFilter?: string | undefined;
198
+ }>;
180
199
  /**
181
200
  * A tool that enables the model to generate and run Python code.
182
201
  * Must have name "code_execution".
@@ -240,6 +259,11 @@ interface GoogleGenerativeAIProviderSettings {
240
259
  Optional function to generate a unique ID for each request.
241
260
  */
242
261
  generateId?: () => string;
262
+ /**
263
+ * Custom provider name
264
+ * Defaults to 'google.generative-ai'.
265
+ */
266
+ name?: string;
243
267
  }
244
268
  /**
245
269
  Create a Google Generative AI provider instance.
package/dist/index.d.ts CHANGED
@@ -85,6 +85,9 @@ 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
+ text?: string | null | undefined;
88
91
  } | null | undefined;
89
92
  }[] | null | undefined;
90
93
  groundingSupports?: {
@@ -177,6 +180,22 @@ declare const googleTools: {
177
180
  * Must have name "url_context".
178
181
  */
179
182
  urlContext: _ai_sdk_provider_utils.ProviderDefinedToolFactory<{}, {}>;
183
+ /**
184
+ * Enables Retrieval Augmented Generation (RAG) via the Gemini File Search tool.
185
+ * Must have name "file_search".
186
+ *
187
+ * @param fileSearchStoreNames - Fully-qualified File Search store resource names.
188
+ * @param metadataFilter - Optional filter expression to restrict the files that can be retrieved.
189
+ * @param topK - Optional result limit for the number of chunks returned from File Search.
190
+ *
191
+ * @see https://ai.google.dev/gemini-api/docs/file-search
192
+ */
193
+ fileSearch: _ai_sdk_provider_utils.ProviderDefinedToolFactory<{}, {
194
+ [x: string]: unknown;
195
+ fileSearchStoreNames: string[];
196
+ topK?: number | undefined;
197
+ metadataFilter?: string | undefined;
198
+ }>;
180
199
  /**
181
200
  * A tool that enables the model to generate and run Python code.
182
201
  * Must have name "code_execution".
@@ -240,6 +259,11 @@ interface GoogleGenerativeAIProviderSettings {
240
259
  Optional function to generate a unique ID for each request.
241
260
  */
242
261
  generateId?: () => string;
262
+ /**
263
+ * Custom provider name
264
+ * Defaults to 'google.generative-ai'.
265
+ */
266
+ name?: string;
243
267
  }
244
268
  /**
245
269
  Create a Google Generative AI provider instance.
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_utils11 = require("@ai-sdk/provider-utils");
30
+ var import_provider_utils12 = require("@ai-sdk/provider-utils");
31
31
 
32
32
  // src/version.ts
33
- var VERSION = true ? "2.0.28" : "0.0.0-test";
33
+ var VERSION = true ? "2.0.30" : "0.0.0-test";
34
34
 
35
35
  // src/google-generative-ai-embedding-model.ts
36
36
  var import_provider = require("@ai-sdk/provider");
@@ -589,6 +589,7 @@ function prepareTools({
589
589
  const toolWarnings = [];
590
590
  const isGemini2 = modelId.includes("gemini-2");
591
591
  const supportsDynamicRetrieval = modelId.includes("gemini-1.5-flash") && !modelId.includes("-8b");
592
+ const supportsFileSearch = modelId.includes("gemini-2.5");
592
593
  if (tools == null) {
593
594
  return { tools: void 0, toolConfig: void 0, toolWarnings };
594
595
  }
@@ -648,6 +649,17 @@ function prepareTools({
648
649
  });
649
650
  }
650
651
  break;
652
+ case "google.file_search":
653
+ if (supportsFileSearch) {
654
+ googleTools2.push({ fileSearch: { ...tool.args } });
655
+ } else {
656
+ toolWarnings.push({
657
+ type: "unsupported-tool",
658
+ tool,
659
+ details: "The file search tool is only supported with Gemini 2.5 models."
660
+ });
661
+ }
662
+ break;
651
663
  default:
652
664
  toolWarnings.push({ type: "unsupported-tool", tool });
653
665
  break;
@@ -1253,7 +1265,13 @@ var getGroundingMetadataSchema = () => import_v45.z.object({
1253
1265
  groundingChunks: import_v45.z.array(
1254
1266
  import_v45.z.object({
1255
1267
  web: import_v45.z.object({ uri: import_v45.z.string(), title: import_v45.z.string().nullish() }).nullish(),
1256
- retrievedContext: 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
+ ])
1257
1275
  })
1258
1276
  ).nullish(),
1259
1277
  groundingSupports: import_v45.z.array(
@@ -1390,29 +1408,57 @@ var codeExecution = (0, import_provider_utils7.createProviderDefinedToolFactoryW
1390
1408
  })
1391
1409
  });
1392
1410
 
1393
- // src/tool/google-search.ts
1411
+ // src/tool/file-search.ts
1394
1412
  var import_provider_utils8 = require("@ai-sdk/provider-utils");
1395
1413
  var import_v47 = require("zod/v4");
1396
- var googleSearch = (0, import_provider_utils8.createProviderDefinedToolFactory)({
1414
+ var fileSearchArgsBaseSchema = import_v47.z.object({
1415
+ /** The names of the file_search_stores to retrieve from.
1416
+ * Example: `fileSearchStores/my-file-search-store-123`
1417
+ */
1418
+ fileSearchStoreNames: import_v47.z.array(import_v47.z.string()).describe(
1419
+ "The names of the file_search_stores to retrieve from. Example: `fileSearchStores/my-file-search-store-123`"
1420
+ ),
1421
+ /** The number of file search retrieval chunks to retrieve. */
1422
+ topK: import_v47.z.number().int().positive().describe("The number of file search retrieval chunks to retrieve.").optional(),
1423
+ /** Metadata filter to apply to the file search retrieval documents.
1424
+ * See https://google.aip.dev/160 for the syntax of the filter expression.
1425
+ */
1426
+ metadataFilter: import_v47.z.string().describe(
1427
+ "Metadata filter to apply to the file search retrieval documents. See https://google.aip.dev/160 for the syntax of the filter expression."
1428
+ ).optional()
1429
+ }).passthrough();
1430
+ var fileSearchArgsSchema = (0, import_provider_utils8.lazySchema)(
1431
+ () => (0, import_provider_utils8.zodSchema)(fileSearchArgsBaseSchema)
1432
+ );
1433
+ var fileSearch = (0, import_provider_utils8.createProviderDefinedToolFactory)({
1434
+ id: "google.file_search",
1435
+ name: "file_search",
1436
+ inputSchema: fileSearchArgsSchema
1437
+ });
1438
+
1439
+ // src/tool/google-search.ts
1440
+ var import_provider_utils9 = require("@ai-sdk/provider-utils");
1441
+ var import_v48 = require("zod/v4");
1442
+ var googleSearch = (0, import_provider_utils9.createProviderDefinedToolFactory)({
1397
1443
  id: "google.google_search",
1398
1444
  name: "google_search",
1399
- inputSchema: (0, import_provider_utils8.lazySchema)(
1400
- () => (0, import_provider_utils8.zodSchema)(
1401
- import_v47.z.object({
1402
- mode: import_v47.z.enum(["MODE_DYNAMIC", "MODE_UNSPECIFIED"]).default("MODE_UNSPECIFIED"),
1403
- dynamicThreshold: import_v47.z.number().default(1)
1445
+ inputSchema: (0, import_provider_utils9.lazySchema)(
1446
+ () => (0, import_provider_utils9.zodSchema)(
1447
+ import_v48.z.object({
1448
+ mode: import_v48.z.enum(["MODE_DYNAMIC", "MODE_UNSPECIFIED"]).default("MODE_UNSPECIFIED"),
1449
+ dynamicThreshold: import_v48.z.number().default(1)
1404
1450
  })
1405
1451
  )
1406
1452
  )
1407
1453
  });
1408
1454
 
1409
1455
  // src/tool/url-context.ts
1410
- var import_provider_utils9 = require("@ai-sdk/provider-utils");
1411
- var import_v48 = require("zod/v4");
1412
- var urlContext = (0, import_provider_utils9.createProviderDefinedToolFactory)({
1456
+ var import_provider_utils10 = require("@ai-sdk/provider-utils");
1457
+ var import_v49 = require("zod/v4");
1458
+ var urlContext = (0, import_provider_utils10.createProviderDefinedToolFactory)({
1413
1459
  id: "google.url_context",
1414
1460
  name: "url_context",
1415
- inputSchema: (0, import_provider_utils9.lazySchema)(() => (0, import_provider_utils9.zodSchema)(import_v48.z.object({})))
1461
+ inputSchema: (0, import_provider_utils10.lazySchema)(() => (0, import_provider_utils10.zodSchema)(import_v49.z.object({})))
1416
1462
  });
1417
1463
 
1418
1464
  // src/google-tools.ts
@@ -1427,6 +1473,17 @@ var googleTools = {
1427
1473
  * Must have name "url_context".
1428
1474
  */
1429
1475
  urlContext,
1476
+ /**
1477
+ * Enables Retrieval Augmented Generation (RAG) via the Gemini File Search tool.
1478
+ * Must have name "file_search".
1479
+ *
1480
+ * @param fileSearchStoreNames - Fully-qualified File Search store resource names.
1481
+ * @param metadataFilter - Optional filter expression to restrict the files that can be retrieved.
1482
+ * @param topK - Optional result limit for the number of chunks returned from File Search.
1483
+ *
1484
+ * @see https://ai.google.dev/gemini-api/docs/file-search
1485
+ */
1486
+ fileSearch,
1430
1487
  /**
1431
1488
  * A tool that enables the model to generate and run Python code.
1432
1489
  * Must have name "code_execution".
@@ -1441,8 +1498,8 @@ var googleTools = {
1441
1498
  };
1442
1499
 
1443
1500
  // src/google-generative-ai-image-model.ts
1444
- var import_provider_utils10 = require("@ai-sdk/provider-utils");
1445
- var import_v49 = require("zod/v4");
1501
+ var import_provider_utils11 = require("@ai-sdk/provider-utils");
1502
+ var import_v410 = require("zod/v4");
1446
1503
  var GoogleGenerativeAIImageModel = class {
1447
1504
  constructor(modelId, settings, config) {
1448
1505
  this.modelId = modelId;
@@ -1484,7 +1541,7 @@ var GoogleGenerativeAIImageModel = class {
1484
1541
  details: "This model does not support the `seed` option through this provider."
1485
1542
  });
1486
1543
  }
1487
- const googleOptions = await (0, import_provider_utils10.parseProviderOptions)({
1544
+ const googleOptions = await (0, import_provider_utils11.parseProviderOptions)({
1488
1545
  provider: "google",
1489
1546
  providerOptions,
1490
1547
  schema: googleImageProviderOptionsSchema
@@ -1503,12 +1560,12 @@ var GoogleGenerativeAIImageModel = class {
1503
1560
  instances: [{ prompt }],
1504
1561
  parameters
1505
1562
  };
1506
- const { responseHeaders, value: response } = await (0, import_provider_utils10.postJsonToApi)({
1563
+ const { responseHeaders, value: response } = await (0, import_provider_utils11.postJsonToApi)({
1507
1564
  url: `${this.config.baseURL}/models/${this.modelId}:predict`,
1508
- headers: (0, import_provider_utils10.combineHeaders)(await (0, import_provider_utils10.resolve)(this.config.headers), headers),
1565
+ headers: (0, import_provider_utils11.combineHeaders)(await (0, import_provider_utils11.resolve)(this.config.headers), headers),
1509
1566
  body,
1510
1567
  failedResponseHandler: googleFailedResponseHandler,
1511
- successfulResponseHandler: (0, import_provider_utils10.createJsonResponseHandler)(
1568
+ successfulResponseHandler: (0, import_provider_utils11.createJsonResponseHandler)(
1512
1569
  googleImageResponseSchema
1513
1570
  ),
1514
1571
  abortSignal,
@@ -1534,29 +1591,30 @@ var GoogleGenerativeAIImageModel = class {
1534
1591
  };
1535
1592
  }
1536
1593
  };
1537
- var googleImageResponseSchema = (0, import_provider_utils10.lazySchema)(
1538
- () => (0, import_provider_utils10.zodSchema)(
1539
- import_v49.z.object({
1540
- predictions: import_v49.z.array(import_v49.z.object({ bytesBase64Encoded: import_v49.z.string() })).default([])
1594
+ var googleImageResponseSchema = (0, import_provider_utils11.lazySchema)(
1595
+ () => (0, import_provider_utils11.zodSchema)(
1596
+ import_v410.z.object({
1597
+ predictions: import_v410.z.array(import_v410.z.object({ bytesBase64Encoded: import_v410.z.string() })).default([])
1541
1598
  })
1542
1599
  )
1543
1600
  );
1544
- var googleImageProviderOptionsSchema = (0, import_provider_utils10.lazySchema)(
1545
- () => (0, import_provider_utils10.zodSchema)(
1546
- import_v49.z.object({
1547
- personGeneration: import_v49.z.enum(["dont_allow", "allow_adult", "allow_all"]).nullish(),
1548
- aspectRatio: import_v49.z.enum(["1:1", "3:4", "4:3", "9:16", "16:9"]).nullish()
1601
+ var googleImageProviderOptionsSchema = (0, import_provider_utils11.lazySchema)(
1602
+ () => (0, import_provider_utils11.zodSchema)(
1603
+ import_v410.z.object({
1604
+ personGeneration: import_v410.z.enum(["dont_allow", "allow_adult", "allow_all"]).nullish(),
1605
+ aspectRatio: import_v410.z.enum(["1:1", "3:4", "4:3", "9:16", "16:9"]).nullish()
1549
1606
  })
1550
1607
  )
1551
1608
  );
1552
1609
 
1553
1610
  // src/google-provider.ts
1554
1611
  function createGoogleGenerativeAI(options = {}) {
1555
- var _a;
1556
- const baseURL = (_a = (0, import_provider_utils11.withoutTrailingSlash)(options.baseURL)) != null ? _a : "https://generativelanguage.googleapis.com/v1beta";
1557
- const getHeaders = () => (0, import_provider_utils11.withUserAgentSuffix)(
1612
+ var _a, _b;
1613
+ const baseURL = (_a = (0, import_provider_utils12.withoutTrailingSlash)(options.baseURL)) != null ? _a : "https://generativelanguage.googleapis.com/v1beta";
1614
+ const providerName = (_b = options.name) != null ? _b : "google.generative-ai";
1615
+ const getHeaders = () => (0, import_provider_utils12.withUserAgentSuffix)(
1558
1616
  {
1559
- "x-goog-api-key": (0, import_provider_utils11.loadApiKey)({
1617
+ "x-goog-api-key": (0, import_provider_utils12.loadApiKey)({
1560
1618
  apiKey: options.apiKey,
1561
1619
  environmentVariableName: "GOOGLE_GENERATIVE_AI_API_KEY",
1562
1620
  description: "Google Generative AI"
@@ -1568,10 +1626,10 @@ function createGoogleGenerativeAI(options = {}) {
1568
1626
  const createChatModel = (modelId) => {
1569
1627
  var _a2;
1570
1628
  return new GoogleGenerativeAILanguageModel(modelId, {
1571
- provider: "google.generative-ai",
1629
+ provider: providerName,
1572
1630
  baseURL,
1573
1631
  headers: getHeaders,
1574
- generateId: (_a2 = options.generateId) != null ? _a2 : import_provider_utils11.generateId,
1632
+ generateId: (_a2 = options.generateId) != null ? _a2 : import_provider_utils12.generateId,
1575
1633
  supportedUrls: () => ({
1576
1634
  "*": [
1577
1635
  // Google Generative Language "files" endpoint
@@ -1588,13 +1646,13 @@ function createGoogleGenerativeAI(options = {}) {
1588
1646
  });
1589
1647
  };
1590
1648
  const createEmbeddingModel = (modelId) => new GoogleGenerativeAIEmbeddingModel(modelId, {
1591
- provider: "google.generative-ai",
1649
+ provider: providerName,
1592
1650
  baseURL,
1593
1651
  headers: getHeaders,
1594
1652
  fetch: options.fetch
1595
1653
  });
1596
1654
  const createImageModel = (modelId, settings = {}) => new GoogleGenerativeAIImageModel(modelId, settings, {
1597
- provider: "google.generative-ai",
1655
+ provider: providerName,
1598
1656
  baseURL,
1599
1657
  headers: getHeaders,
1600
1658
  fetch: options.fetch