@google/genai 1.3.0 → 1.5.0

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.
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var zod = require('zod');
4
+ var types_js = require('@modelcontextprotocol/sdk/types.js');
4
5
  var googleAuthLibrary = require('google-auth-library');
5
6
  var fs = require('fs');
6
7
  var node_stream = require('node:stream');
@@ -1980,16 +1981,16 @@ function flattenTypeArrayToAnyOf(typeList, resultingSchema) {
1980
1981
  }
1981
1982
  const listWithoutNull = typeList.filter((type) => type !== 'null');
1982
1983
  if (listWithoutNull.length === 1) {
1983
- resultingSchema['type'] = Object.keys(exports.Type).includes(listWithoutNull[0].toUpperCase())
1984
- ? exports.Type[listWithoutNull[0].toUpperCase()]
1984
+ resultingSchema['type'] = Object.values(exports.Type).includes(listWithoutNull[0].toUpperCase())
1985
+ ? listWithoutNull[0].toUpperCase()
1985
1986
  : exports.Type.TYPE_UNSPECIFIED;
1986
1987
  }
1987
1988
  else {
1988
1989
  resultingSchema['anyOf'] = [];
1989
1990
  for (const i of listWithoutNull) {
1990
1991
  resultingSchema['anyOf'].push({
1991
- 'type': Object.keys(exports.Type).includes(i.toUpperCase())
1992
- ? exports.Type[i.toUpperCase()]
1992
+ 'type': Object.values(exports.Type).includes(i.toUpperCase())
1993
+ ? i.toUpperCase()
1993
1994
  : exports.Type.TYPE_UNSPECIFIED,
1994
1995
  });
1995
1996
  }
@@ -2073,7 +2074,7 @@ function processJsonSchema(_jsonSchema) {
2073
2074
  // beginning of this function.
2074
2075
  continue;
2075
2076
  }
2076
- genAISchema['type'] = Object.keys(exports.Type).includes(fieldValue.toUpperCase())
2077
+ genAISchema['type'] = Object.values(exports.Type).includes(fieldValue.toUpperCase())
2077
2078
  ? fieldValue.toUpperCase()
2078
2079
  : exports.Type.TYPE_UNSPECIFIED;
2079
2080
  }
@@ -2432,7 +2433,7 @@ function filterToJsonSchema(schema) {
2432
2433
  }
2433
2434
  else if (fieldName === 'type') {
2434
2435
  const typeValue = fieldValue.toUpperCase();
2435
- filteredSchema[fieldName] = Object.keys(exports.Type).includes(typeValue)
2436
+ filteredSchema[fieldName] = Object.values(exports.Type).includes(typeValue)
2436
2437
  ? typeValue
2437
2438
  : exports.Type.TYPE_UNSPECIFIED;
2438
2439
  }
@@ -3109,6 +3110,10 @@ function googleMapsToVertex$2(apiClient, fromObject) {
3109
3110
  }
3110
3111
  return toObject;
3111
3112
  }
3113
+ function urlContextToVertex$2() {
3114
+ const toObject = {};
3115
+ return toObject;
3116
+ }
3112
3117
  function toolToVertex$2(apiClient, fromObject) {
3113
3118
  const toObject = {};
3114
3119
  const fromFunctionDeclarations = getValueByPath(fromObject, [
@@ -3147,8 +3152,9 @@ function toolToVertex$2(apiClient, fromObject) {
3147
3152
  if (fromGoogleMaps != null) {
3148
3153
  setValueByPath(toObject, ['googleMaps'], googleMapsToVertex$2(apiClient, fromGoogleMaps));
3149
3154
  }
3150
- if (getValueByPath(fromObject, ['urlContext']) !== undefined) {
3151
- throw new Error('urlContext parameter is not supported in Vertex AI.');
3155
+ const fromUrlContext = getValueByPath(fromObject, ['urlContext']);
3156
+ if (fromUrlContext != null) {
3157
+ setValueByPath(toObject, ['urlContext'], urlContextToVertex$2());
3152
3158
  }
3153
3159
  const fromCodeExecution = getValueByPath(fromObject, [
3154
3160
  'codeExecution',
@@ -3658,7 +3664,7 @@ class Caches extends BaseModule {
3658
3664
  * @example
3659
3665
  * ```ts
3660
3666
  * const cachedContents = await ai.caches.list({config: {'pageSize': 2}});
3661
- * for (const cachedContent of cachedContents) {
3667
+ * for await (const cachedContent of cachedContents) {
3662
3668
  * console.log(cachedContent);
3663
3669
  * }
3664
3670
  * ```
@@ -5450,6 +5456,10 @@ function urlContextToMldev$2() {
5450
5456
  const toObject = {};
5451
5457
  return toObject;
5452
5458
  }
5459
+ function urlContextToVertex$1() {
5460
+ const toObject = {};
5461
+ return toObject;
5462
+ }
5453
5463
  function toolToMldev$2(apiClient, fromObject) {
5454
5464
  const toObject = {};
5455
5465
  const fromFunctionDeclarations = getValueByPath(fromObject, [
@@ -5533,8 +5543,9 @@ function toolToVertex$1(apiClient, fromObject) {
5533
5543
  if (fromGoogleMaps != null) {
5534
5544
  setValueByPath(toObject, ['googleMaps'], googleMapsToVertex$1(apiClient, fromGoogleMaps));
5535
5545
  }
5536
- if (getValueByPath(fromObject, ['urlContext']) !== undefined) {
5537
- throw new Error('urlContext parameter is not supported in Vertex AI.');
5546
+ const fromUrlContext = getValueByPath(fromObject, ['urlContext']);
5547
+ if (fromUrlContext != null) {
5548
+ setValueByPath(toObject, ['urlContext'], urlContextToVertex$1());
5538
5549
  }
5539
5550
  const fromCodeExecution = getValueByPath(fromObject, [
5540
5551
  'codeExecution',
@@ -8130,12 +8141,18 @@ function generateVideosConfigToMldev(apiClient, fromObject, parentObject) {
8130
8141
  if (parentObject !== undefined && fromNegativePrompt != null) {
8131
8142
  setValueByPath(parentObject, ['parameters', 'negativePrompt'], fromNegativePrompt);
8132
8143
  }
8133
- if (getValueByPath(fromObject, ['enhancePrompt']) !== undefined) {
8134
- throw new Error('enhancePrompt parameter is not supported in Gemini API.');
8144
+ const fromEnhancePrompt = getValueByPath(fromObject, [
8145
+ 'enhancePrompt',
8146
+ ]);
8147
+ if (parentObject !== undefined && fromEnhancePrompt != null) {
8148
+ setValueByPath(parentObject, ['parameters', 'enhancePrompt'], fromEnhancePrompt);
8135
8149
  }
8136
8150
  if (getValueByPath(fromObject, ['generateAudio']) !== undefined) {
8137
8151
  throw new Error('generateAudio parameter is not supported in Gemini API.');
8138
8152
  }
8153
+ if (getValueByPath(fromObject, ['lastFrame']) !== undefined) {
8154
+ throw new Error('lastFrame parameter is not supported in Gemini API.');
8155
+ }
8139
8156
  return toObject;
8140
8157
  }
8141
8158
  function generateVideosParametersToMldev(apiClient, fromObject) {
@@ -8152,6 +8169,9 @@ function generateVideosParametersToMldev(apiClient, fromObject) {
8152
8169
  if (fromImage != null) {
8153
8170
  setValueByPath(toObject, ['instances[0]', 'image'], imageToMldev(apiClient, fromImage));
8154
8171
  }
8172
+ if (getValueByPath(fromObject, ['video']) !== undefined) {
8173
+ throw new Error('video parameter is not supported in Gemini API.');
8174
+ }
8155
8175
  const fromConfig = getValueByPath(fromObject, ['config']);
8156
8176
  if (fromConfig != null) {
8157
8177
  setValueByPath(toObject, ['config'], generateVideosConfigToMldev(apiClient, fromConfig, toObject));
@@ -8523,6 +8543,10 @@ function googleMapsToVertex(apiClient, fromObject) {
8523
8543
  }
8524
8544
  return toObject;
8525
8545
  }
8546
+ function urlContextToVertex() {
8547
+ const toObject = {};
8548
+ return toObject;
8549
+ }
8526
8550
  function toolToVertex(apiClient, fromObject) {
8527
8551
  const toObject = {};
8528
8552
  const fromFunctionDeclarations = getValueByPath(fromObject, [
@@ -8561,8 +8585,9 @@ function toolToVertex(apiClient, fromObject) {
8561
8585
  if (fromGoogleMaps != null) {
8562
8586
  setValueByPath(toObject, ['googleMaps'], googleMapsToVertex(apiClient, fromGoogleMaps));
8563
8587
  }
8564
- if (getValueByPath(fromObject, ['urlContext']) !== undefined) {
8565
- throw new Error('urlContext parameter is not supported in Vertex AI.');
8588
+ const fromUrlContext = getValueByPath(fromObject, ['urlContext']);
8589
+ if (fromUrlContext != null) {
8590
+ setValueByPath(toObject, ['urlContext'], urlContextToVertex());
8566
8591
  }
8567
8592
  const fromCodeExecution = getValueByPath(fromObject, [
8568
8593
  'codeExecution',
@@ -9425,6 +9450,22 @@ function computeTokensParametersToVertex(apiClient, fromObject) {
9425
9450
  }
9426
9451
  return toObject;
9427
9452
  }
9453
+ function videoToVertex(apiClient, fromObject) {
9454
+ const toObject = {};
9455
+ const fromUri = getValueByPath(fromObject, ['uri']);
9456
+ if (fromUri != null) {
9457
+ setValueByPath(toObject, ['gcsUri'], fromUri);
9458
+ }
9459
+ const fromVideoBytes = getValueByPath(fromObject, ['videoBytes']);
9460
+ if (fromVideoBytes != null) {
9461
+ setValueByPath(toObject, ['bytesBase64Encoded'], tBytes(apiClient, fromVideoBytes));
9462
+ }
9463
+ const fromMimeType = getValueByPath(fromObject, ['mimeType']);
9464
+ if (fromMimeType != null) {
9465
+ setValueByPath(toObject, ['mimeType'], fromMimeType);
9466
+ }
9467
+ return toObject;
9468
+ }
9428
9469
  function generateVideosConfigToVertex(apiClient, fromObject, parentObject) {
9429
9470
  const toObject = {};
9430
9471
  const fromNumberOfVideos = getValueByPath(fromObject, [
@@ -9487,6 +9528,10 @@ function generateVideosConfigToVertex(apiClient, fromObject, parentObject) {
9487
9528
  if (parentObject !== undefined && fromGenerateAudio != null) {
9488
9529
  setValueByPath(parentObject, ['parameters', 'generateAudio'], fromGenerateAudio);
9489
9530
  }
9531
+ const fromLastFrame = getValueByPath(fromObject, ['lastFrame']);
9532
+ if (parentObject !== undefined && fromLastFrame != null) {
9533
+ setValueByPath(parentObject, ['instances[0]', 'lastFrame'], imageToVertex(apiClient, fromLastFrame));
9534
+ }
9490
9535
  return toObject;
9491
9536
  }
9492
9537
  function generateVideosParametersToVertex(apiClient, fromObject) {
@@ -9503,6 +9548,10 @@ function generateVideosParametersToVertex(apiClient, fromObject) {
9503
9548
  if (fromImage != null) {
9504
9549
  setValueByPath(toObject, ['instances[0]', 'image'], imageToVertex(apiClient, fromImage));
9505
9550
  }
9551
+ const fromVideo = getValueByPath(fromObject, ['video']);
9552
+ if (fromVideo != null) {
9553
+ setValueByPath(toObject, ['instances[0]', 'video'], videoToVertex(apiClient, fromVideo));
9554
+ }
9506
9555
  const fromConfig = getValueByPath(fromObject, ['config']);
9507
9556
  if (fromConfig != null) {
9508
9557
  setValueByPath(toObject, ['config'], generateVideosConfigToVertex(apiClient, fromConfig, toObject));
@@ -10153,6 +10202,34 @@ function citationMetadataFromVertex(apiClient, fromObject) {
10153
10202
  }
10154
10203
  return toObject;
10155
10204
  }
10205
+ function urlMetadataFromVertex(apiClient, fromObject) {
10206
+ const toObject = {};
10207
+ const fromRetrievedUrl = getValueByPath(fromObject, ['retrievedUrl']);
10208
+ if (fromRetrievedUrl != null) {
10209
+ setValueByPath(toObject, ['retrievedUrl'], fromRetrievedUrl);
10210
+ }
10211
+ const fromUrlRetrievalStatus = getValueByPath(fromObject, [
10212
+ 'urlRetrievalStatus',
10213
+ ]);
10214
+ if (fromUrlRetrievalStatus != null) {
10215
+ setValueByPath(toObject, ['urlRetrievalStatus'], fromUrlRetrievalStatus);
10216
+ }
10217
+ return toObject;
10218
+ }
10219
+ function urlContextMetadataFromVertex(apiClient, fromObject) {
10220
+ const toObject = {};
10221
+ const fromUrlMetadata = getValueByPath(fromObject, ['urlMetadata']);
10222
+ if (fromUrlMetadata != null) {
10223
+ let transformedList = fromUrlMetadata;
10224
+ if (Array.isArray(transformedList)) {
10225
+ transformedList = transformedList.map((item) => {
10226
+ return urlMetadataFromVertex(apiClient, item);
10227
+ });
10228
+ }
10229
+ setValueByPath(toObject, ['urlMetadata'], transformedList);
10230
+ }
10231
+ return toObject;
10232
+ }
10156
10233
  function candidateFromVertex(apiClient, fromObject) {
10157
10234
  const toObject = {};
10158
10235
  const fromContent = getValueByPath(fromObject, ['content']);
@@ -10175,6 +10252,12 @@ function candidateFromVertex(apiClient, fromObject) {
10175
10252
  if (fromFinishReason != null) {
10176
10253
  setValueByPath(toObject, ['finishReason'], fromFinishReason);
10177
10254
  }
10255
+ const fromUrlContextMetadata = getValueByPath(fromObject, [
10256
+ 'urlContextMetadata',
10257
+ ]);
10258
+ if (fromUrlContextMetadata != null) {
10259
+ setValueByPath(toObject, ['urlContextMetadata'], urlContextMetadataFromVertex(apiClient, fromUrlContextMetadata));
10260
+ }
10178
10261
  const fromAvgLogprobs = getValueByPath(fromObject, ['avgLogprobs']);
10179
10262
  if (fromAvgLogprobs != null) {
10180
10263
  setValueByPath(toObject, ['avgLogprobs'], fromAvgLogprobs);
@@ -10641,7 +10724,7 @@ const CONTENT_TYPE_HEADER = 'Content-Type';
10641
10724
  const SERVER_TIMEOUT_HEADER = 'X-Server-Timeout';
10642
10725
  const USER_AGENT_HEADER = 'User-Agent';
10643
10726
  const GOOGLE_API_CLIENT_HEADER = 'x-goog-api-client';
10644
- const SDK_VERSION = '1.3.0'; // x-release-please-version
10727
+ const SDK_VERSION = '1.5.0'; // x-release-please-version
10645
10728
  const LIBRARY_LABEL = `google-genai-sdk/${SDK_VERSION}`;
10646
10729
  const VERTEX_AI_API_DEFAULT_VERSION = 'v1beta1';
10647
10730
  const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
@@ -11284,9 +11367,18 @@ class McpCallableTool {
11284
11367
  for (const functionCall of functionCalls) {
11285
11368
  if (functionCall.name in this.functionNameToMcpClient) {
11286
11369
  const mcpClient = this.functionNameToMcpClient[functionCall.name];
11370
+ let requestOptions = undefined;
11371
+ // TODO: b/424238654 - Add support for finer grained timeout control.
11372
+ if (this.config.timeout) {
11373
+ requestOptions = {
11374
+ timeout: this.config.timeout,
11375
+ };
11376
+ }
11287
11377
  const callToolResponse = await mcpClient.callTool({
11288
11378
  name: functionCall.name,
11289
11379
  arguments: functionCall.args,
11380
+ CallToolResultSchema: types_js.CallToolResultSchema,
11381
+ requestOptions,
11290
11382
  });
11291
11383
  functionCallResponseParts.push({
11292
11384
  functionResponse: {
@@ -15731,14 +15823,14 @@ const LANGUAGE_LABEL_PREFIX = 'gl-node/';
15731
15823
  */
15732
15824
  class GoogleGenAI {
15733
15825
  constructor(options) {
15734
- var _a, _b, _c, _d, _e;
15826
+ var _a, _b, _c, _d, _e, _f;
15735
15827
  // Validate explicitly set initializer values.
15736
15828
  if ((options.project || options.location) && options.apiKey) {
15737
15829
  throw new Error('Project/location and API key are mutually exclusive in the client initializer.');
15738
15830
  }
15739
15831
  this.vertexai =
15740
15832
  (_b = (_a = options.vertexai) !== null && _a !== void 0 ? _a : getBooleanEnv('GOOGLE_GENAI_USE_VERTEXAI')) !== null && _b !== void 0 ? _b : false;
15741
- const envApiKey = getEnv('GOOGLE_API_KEY');
15833
+ const envApiKey = getApiKeyFromEnv();
15742
15834
  const envProject = getEnv('GOOGLE_CLOUD_PROJECT');
15743
15835
  const envLocation = getEnv('GOOGLE_CLOUD_LOCATION');
15744
15836
  this.apiKey = (_c = options.apiKey) !== null && _c !== void 0 ? _c : envApiKey;
@@ -15746,6 +15838,12 @@ class GoogleGenAI {
15746
15838
  this.location = (_e = options.location) !== null && _e !== void 0 ? _e : envLocation;
15747
15839
  // Handle when to use Vertex AI in express mode (api key)
15748
15840
  if (options.vertexai) {
15841
+ if ((_f = options.googleAuthOptions) === null || _f === void 0 ? void 0 : _f.credentials) {
15842
+ // Explicit credentials take precedence over implicit api_key.
15843
+ console.debug('The user provided Google Cloud credentials will take precedence' +
15844
+ ' over the API key from the environment variable.');
15845
+ this.apiKey = undefined;
15846
+ }
15749
15847
  // Explicit api_key and explicit project/location already handled above.
15750
15848
  if ((envProject || envLocation) && options.apiKey) {
15751
15849
  // Explicit api_key takes precedence over implicit project/location.
@@ -15816,6 +15914,14 @@ function stringToBoolean(str) {
15816
15914
  }
15817
15915
  return str.toLowerCase() === 'true';
15818
15916
  }
15917
+ function getApiKeyFromEnv() {
15918
+ const envGoogleApiKey = getEnv('GOOGLE_API_KEY');
15919
+ const envGeminiApiKey = getEnv('GEMINI_API_KEY');
15920
+ if (envGoogleApiKey && envGeminiApiKey) {
15921
+ console.warn('Both GOOGLE_API_KEY and GEMINI_API_KEY are set. Using GOOGLE_API_KEY.');
15922
+ }
15923
+ return envGoogleApiKey || envGeminiApiKey;
15924
+ }
15819
15925
 
15820
15926
  exports.Caches = Caches;
15821
15927
  exports.Chat = Chat;
@@ -1,4 +1,5 @@
1
1
  import { z } from 'zod';
2
+ import { CallToolResultSchema } from '@modelcontextprotocol/sdk/types.js';
2
3
  import { GoogleAuth } from 'google-auth-library';
3
4
  import { createWriteStream, writeFile } from 'fs';
4
5
  import { Readable } from 'node:stream';
@@ -1958,16 +1959,16 @@ function flattenTypeArrayToAnyOf(typeList, resultingSchema) {
1958
1959
  }
1959
1960
  const listWithoutNull = typeList.filter((type) => type !== 'null');
1960
1961
  if (listWithoutNull.length === 1) {
1961
- resultingSchema['type'] = Object.keys(Type).includes(listWithoutNull[0].toUpperCase())
1962
- ? Type[listWithoutNull[0].toUpperCase()]
1962
+ resultingSchema['type'] = Object.values(Type).includes(listWithoutNull[0].toUpperCase())
1963
+ ? listWithoutNull[0].toUpperCase()
1963
1964
  : Type.TYPE_UNSPECIFIED;
1964
1965
  }
1965
1966
  else {
1966
1967
  resultingSchema['anyOf'] = [];
1967
1968
  for (const i of listWithoutNull) {
1968
1969
  resultingSchema['anyOf'].push({
1969
- 'type': Object.keys(Type).includes(i.toUpperCase())
1970
- ? Type[i.toUpperCase()]
1970
+ 'type': Object.values(Type).includes(i.toUpperCase())
1971
+ ? i.toUpperCase()
1971
1972
  : Type.TYPE_UNSPECIFIED,
1972
1973
  });
1973
1974
  }
@@ -2051,7 +2052,7 @@ function processJsonSchema(_jsonSchema) {
2051
2052
  // beginning of this function.
2052
2053
  continue;
2053
2054
  }
2054
- genAISchema['type'] = Object.keys(Type).includes(fieldValue.toUpperCase())
2055
+ genAISchema['type'] = Object.values(Type).includes(fieldValue.toUpperCase())
2055
2056
  ? fieldValue.toUpperCase()
2056
2057
  : Type.TYPE_UNSPECIFIED;
2057
2058
  }
@@ -2410,7 +2411,7 @@ function filterToJsonSchema(schema) {
2410
2411
  }
2411
2412
  else if (fieldName === 'type') {
2412
2413
  const typeValue = fieldValue.toUpperCase();
2413
- filteredSchema[fieldName] = Object.keys(Type).includes(typeValue)
2414
+ filteredSchema[fieldName] = Object.values(Type).includes(typeValue)
2414
2415
  ? typeValue
2415
2416
  : Type.TYPE_UNSPECIFIED;
2416
2417
  }
@@ -3087,6 +3088,10 @@ function googleMapsToVertex$2(apiClient, fromObject) {
3087
3088
  }
3088
3089
  return toObject;
3089
3090
  }
3091
+ function urlContextToVertex$2() {
3092
+ const toObject = {};
3093
+ return toObject;
3094
+ }
3090
3095
  function toolToVertex$2(apiClient, fromObject) {
3091
3096
  const toObject = {};
3092
3097
  const fromFunctionDeclarations = getValueByPath(fromObject, [
@@ -3125,8 +3130,9 @@ function toolToVertex$2(apiClient, fromObject) {
3125
3130
  if (fromGoogleMaps != null) {
3126
3131
  setValueByPath(toObject, ['googleMaps'], googleMapsToVertex$2(apiClient, fromGoogleMaps));
3127
3132
  }
3128
- if (getValueByPath(fromObject, ['urlContext']) !== undefined) {
3129
- throw new Error('urlContext parameter is not supported in Vertex AI.');
3133
+ const fromUrlContext = getValueByPath(fromObject, ['urlContext']);
3134
+ if (fromUrlContext != null) {
3135
+ setValueByPath(toObject, ['urlContext'], urlContextToVertex$2());
3130
3136
  }
3131
3137
  const fromCodeExecution = getValueByPath(fromObject, [
3132
3138
  'codeExecution',
@@ -3636,7 +3642,7 @@ class Caches extends BaseModule {
3636
3642
  * @example
3637
3643
  * ```ts
3638
3644
  * const cachedContents = await ai.caches.list({config: {'pageSize': 2}});
3639
- * for (const cachedContent of cachedContents) {
3645
+ * for await (const cachedContent of cachedContents) {
3640
3646
  * console.log(cachedContent);
3641
3647
  * }
3642
3648
  * ```
@@ -5428,6 +5434,10 @@ function urlContextToMldev$2() {
5428
5434
  const toObject = {};
5429
5435
  return toObject;
5430
5436
  }
5437
+ function urlContextToVertex$1() {
5438
+ const toObject = {};
5439
+ return toObject;
5440
+ }
5431
5441
  function toolToMldev$2(apiClient, fromObject) {
5432
5442
  const toObject = {};
5433
5443
  const fromFunctionDeclarations = getValueByPath(fromObject, [
@@ -5511,8 +5521,9 @@ function toolToVertex$1(apiClient, fromObject) {
5511
5521
  if (fromGoogleMaps != null) {
5512
5522
  setValueByPath(toObject, ['googleMaps'], googleMapsToVertex$1(apiClient, fromGoogleMaps));
5513
5523
  }
5514
- if (getValueByPath(fromObject, ['urlContext']) !== undefined) {
5515
- throw new Error('urlContext parameter is not supported in Vertex AI.');
5524
+ const fromUrlContext = getValueByPath(fromObject, ['urlContext']);
5525
+ if (fromUrlContext != null) {
5526
+ setValueByPath(toObject, ['urlContext'], urlContextToVertex$1());
5516
5527
  }
5517
5528
  const fromCodeExecution = getValueByPath(fromObject, [
5518
5529
  'codeExecution',
@@ -8108,12 +8119,18 @@ function generateVideosConfigToMldev(apiClient, fromObject, parentObject) {
8108
8119
  if (parentObject !== undefined && fromNegativePrompt != null) {
8109
8120
  setValueByPath(parentObject, ['parameters', 'negativePrompt'], fromNegativePrompt);
8110
8121
  }
8111
- if (getValueByPath(fromObject, ['enhancePrompt']) !== undefined) {
8112
- throw new Error('enhancePrompt parameter is not supported in Gemini API.');
8122
+ const fromEnhancePrompt = getValueByPath(fromObject, [
8123
+ 'enhancePrompt',
8124
+ ]);
8125
+ if (parentObject !== undefined && fromEnhancePrompt != null) {
8126
+ setValueByPath(parentObject, ['parameters', 'enhancePrompt'], fromEnhancePrompt);
8113
8127
  }
8114
8128
  if (getValueByPath(fromObject, ['generateAudio']) !== undefined) {
8115
8129
  throw new Error('generateAudio parameter is not supported in Gemini API.');
8116
8130
  }
8131
+ if (getValueByPath(fromObject, ['lastFrame']) !== undefined) {
8132
+ throw new Error('lastFrame parameter is not supported in Gemini API.');
8133
+ }
8117
8134
  return toObject;
8118
8135
  }
8119
8136
  function generateVideosParametersToMldev(apiClient, fromObject) {
@@ -8130,6 +8147,9 @@ function generateVideosParametersToMldev(apiClient, fromObject) {
8130
8147
  if (fromImage != null) {
8131
8148
  setValueByPath(toObject, ['instances[0]', 'image'], imageToMldev(apiClient, fromImage));
8132
8149
  }
8150
+ if (getValueByPath(fromObject, ['video']) !== undefined) {
8151
+ throw new Error('video parameter is not supported in Gemini API.');
8152
+ }
8133
8153
  const fromConfig = getValueByPath(fromObject, ['config']);
8134
8154
  if (fromConfig != null) {
8135
8155
  setValueByPath(toObject, ['config'], generateVideosConfigToMldev(apiClient, fromConfig, toObject));
@@ -8501,6 +8521,10 @@ function googleMapsToVertex(apiClient, fromObject) {
8501
8521
  }
8502
8522
  return toObject;
8503
8523
  }
8524
+ function urlContextToVertex() {
8525
+ const toObject = {};
8526
+ return toObject;
8527
+ }
8504
8528
  function toolToVertex(apiClient, fromObject) {
8505
8529
  const toObject = {};
8506
8530
  const fromFunctionDeclarations = getValueByPath(fromObject, [
@@ -8539,8 +8563,9 @@ function toolToVertex(apiClient, fromObject) {
8539
8563
  if (fromGoogleMaps != null) {
8540
8564
  setValueByPath(toObject, ['googleMaps'], googleMapsToVertex(apiClient, fromGoogleMaps));
8541
8565
  }
8542
- if (getValueByPath(fromObject, ['urlContext']) !== undefined) {
8543
- throw new Error('urlContext parameter is not supported in Vertex AI.');
8566
+ const fromUrlContext = getValueByPath(fromObject, ['urlContext']);
8567
+ if (fromUrlContext != null) {
8568
+ setValueByPath(toObject, ['urlContext'], urlContextToVertex());
8544
8569
  }
8545
8570
  const fromCodeExecution = getValueByPath(fromObject, [
8546
8571
  'codeExecution',
@@ -9403,6 +9428,22 @@ function computeTokensParametersToVertex(apiClient, fromObject) {
9403
9428
  }
9404
9429
  return toObject;
9405
9430
  }
9431
+ function videoToVertex(apiClient, fromObject) {
9432
+ const toObject = {};
9433
+ const fromUri = getValueByPath(fromObject, ['uri']);
9434
+ if (fromUri != null) {
9435
+ setValueByPath(toObject, ['gcsUri'], fromUri);
9436
+ }
9437
+ const fromVideoBytes = getValueByPath(fromObject, ['videoBytes']);
9438
+ if (fromVideoBytes != null) {
9439
+ setValueByPath(toObject, ['bytesBase64Encoded'], tBytes(apiClient, fromVideoBytes));
9440
+ }
9441
+ const fromMimeType = getValueByPath(fromObject, ['mimeType']);
9442
+ if (fromMimeType != null) {
9443
+ setValueByPath(toObject, ['mimeType'], fromMimeType);
9444
+ }
9445
+ return toObject;
9446
+ }
9406
9447
  function generateVideosConfigToVertex(apiClient, fromObject, parentObject) {
9407
9448
  const toObject = {};
9408
9449
  const fromNumberOfVideos = getValueByPath(fromObject, [
@@ -9465,6 +9506,10 @@ function generateVideosConfigToVertex(apiClient, fromObject, parentObject) {
9465
9506
  if (parentObject !== undefined && fromGenerateAudio != null) {
9466
9507
  setValueByPath(parentObject, ['parameters', 'generateAudio'], fromGenerateAudio);
9467
9508
  }
9509
+ const fromLastFrame = getValueByPath(fromObject, ['lastFrame']);
9510
+ if (parentObject !== undefined && fromLastFrame != null) {
9511
+ setValueByPath(parentObject, ['instances[0]', 'lastFrame'], imageToVertex(apiClient, fromLastFrame));
9512
+ }
9468
9513
  return toObject;
9469
9514
  }
9470
9515
  function generateVideosParametersToVertex(apiClient, fromObject) {
@@ -9481,6 +9526,10 @@ function generateVideosParametersToVertex(apiClient, fromObject) {
9481
9526
  if (fromImage != null) {
9482
9527
  setValueByPath(toObject, ['instances[0]', 'image'], imageToVertex(apiClient, fromImage));
9483
9528
  }
9529
+ const fromVideo = getValueByPath(fromObject, ['video']);
9530
+ if (fromVideo != null) {
9531
+ setValueByPath(toObject, ['instances[0]', 'video'], videoToVertex(apiClient, fromVideo));
9532
+ }
9484
9533
  const fromConfig = getValueByPath(fromObject, ['config']);
9485
9534
  if (fromConfig != null) {
9486
9535
  setValueByPath(toObject, ['config'], generateVideosConfigToVertex(apiClient, fromConfig, toObject));
@@ -10131,6 +10180,34 @@ function citationMetadataFromVertex(apiClient, fromObject) {
10131
10180
  }
10132
10181
  return toObject;
10133
10182
  }
10183
+ function urlMetadataFromVertex(apiClient, fromObject) {
10184
+ const toObject = {};
10185
+ const fromRetrievedUrl = getValueByPath(fromObject, ['retrievedUrl']);
10186
+ if (fromRetrievedUrl != null) {
10187
+ setValueByPath(toObject, ['retrievedUrl'], fromRetrievedUrl);
10188
+ }
10189
+ const fromUrlRetrievalStatus = getValueByPath(fromObject, [
10190
+ 'urlRetrievalStatus',
10191
+ ]);
10192
+ if (fromUrlRetrievalStatus != null) {
10193
+ setValueByPath(toObject, ['urlRetrievalStatus'], fromUrlRetrievalStatus);
10194
+ }
10195
+ return toObject;
10196
+ }
10197
+ function urlContextMetadataFromVertex(apiClient, fromObject) {
10198
+ const toObject = {};
10199
+ const fromUrlMetadata = getValueByPath(fromObject, ['urlMetadata']);
10200
+ if (fromUrlMetadata != null) {
10201
+ let transformedList = fromUrlMetadata;
10202
+ if (Array.isArray(transformedList)) {
10203
+ transformedList = transformedList.map((item) => {
10204
+ return urlMetadataFromVertex(apiClient, item);
10205
+ });
10206
+ }
10207
+ setValueByPath(toObject, ['urlMetadata'], transformedList);
10208
+ }
10209
+ return toObject;
10210
+ }
10134
10211
  function candidateFromVertex(apiClient, fromObject) {
10135
10212
  const toObject = {};
10136
10213
  const fromContent = getValueByPath(fromObject, ['content']);
@@ -10153,6 +10230,12 @@ function candidateFromVertex(apiClient, fromObject) {
10153
10230
  if (fromFinishReason != null) {
10154
10231
  setValueByPath(toObject, ['finishReason'], fromFinishReason);
10155
10232
  }
10233
+ const fromUrlContextMetadata = getValueByPath(fromObject, [
10234
+ 'urlContextMetadata',
10235
+ ]);
10236
+ if (fromUrlContextMetadata != null) {
10237
+ setValueByPath(toObject, ['urlContextMetadata'], urlContextMetadataFromVertex(apiClient, fromUrlContextMetadata));
10238
+ }
10156
10239
  const fromAvgLogprobs = getValueByPath(fromObject, ['avgLogprobs']);
10157
10240
  if (fromAvgLogprobs != null) {
10158
10241
  setValueByPath(toObject, ['avgLogprobs'], fromAvgLogprobs);
@@ -10619,7 +10702,7 @@ const CONTENT_TYPE_HEADER = 'Content-Type';
10619
10702
  const SERVER_TIMEOUT_HEADER = 'X-Server-Timeout';
10620
10703
  const USER_AGENT_HEADER = 'User-Agent';
10621
10704
  const GOOGLE_API_CLIENT_HEADER = 'x-goog-api-client';
10622
- const SDK_VERSION = '1.3.0'; // x-release-please-version
10705
+ const SDK_VERSION = '1.5.0'; // x-release-please-version
10623
10706
  const LIBRARY_LABEL = `google-genai-sdk/${SDK_VERSION}`;
10624
10707
  const VERTEX_AI_API_DEFAULT_VERSION = 'v1beta1';
10625
10708
  const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
@@ -11262,9 +11345,18 @@ class McpCallableTool {
11262
11345
  for (const functionCall of functionCalls) {
11263
11346
  if (functionCall.name in this.functionNameToMcpClient) {
11264
11347
  const mcpClient = this.functionNameToMcpClient[functionCall.name];
11348
+ let requestOptions = undefined;
11349
+ // TODO: b/424238654 - Add support for finer grained timeout control.
11350
+ if (this.config.timeout) {
11351
+ requestOptions = {
11352
+ timeout: this.config.timeout,
11353
+ };
11354
+ }
11265
11355
  const callToolResponse = await mcpClient.callTool({
11266
11356
  name: functionCall.name,
11267
11357
  arguments: functionCall.args,
11358
+ CallToolResultSchema,
11359
+ requestOptions,
11268
11360
  });
11269
11361
  functionCallResponseParts.push({
11270
11362
  functionResponse: {
@@ -15709,14 +15801,14 @@ const LANGUAGE_LABEL_PREFIX = 'gl-node/';
15709
15801
  */
15710
15802
  class GoogleGenAI {
15711
15803
  constructor(options) {
15712
- var _a, _b, _c, _d, _e;
15804
+ var _a, _b, _c, _d, _e, _f;
15713
15805
  // Validate explicitly set initializer values.
15714
15806
  if ((options.project || options.location) && options.apiKey) {
15715
15807
  throw new Error('Project/location and API key are mutually exclusive in the client initializer.');
15716
15808
  }
15717
15809
  this.vertexai =
15718
15810
  (_b = (_a = options.vertexai) !== null && _a !== void 0 ? _a : getBooleanEnv('GOOGLE_GENAI_USE_VERTEXAI')) !== null && _b !== void 0 ? _b : false;
15719
- const envApiKey = getEnv('GOOGLE_API_KEY');
15811
+ const envApiKey = getApiKeyFromEnv();
15720
15812
  const envProject = getEnv('GOOGLE_CLOUD_PROJECT');
15721
15813
  const envLocation = getEnv('GOOGLE_CLOUD_LOCATION');
15722
15814
  this.apiKey = (_c = options.apiKey) !== null && _c !== void 0 ? _c : envApiKey;
@@ -15724,6 +15816,12 @@ class GoogleGenAI {
15724
15816
  this.location = (_e = options.location) !== null && _e !== void 0 ? _e : envLocation;
15725
15817
  // Handle when to use Vertex AI in express mode (api key)
15726
15818
  if (options.vertexai) {
15819
+ if ((_f = options.googleAuthOptions) === null || _f === void 0 ? void 0 : _f.credentials) {
15820
+ // Explicit credentials take precedence over implicit api_key.
15821
+ console.debug('The user provided Google Cloud credentials will take precedence' +
15822
+ ' over the API key from the environment variable.');
15823
+ this.apiKey = undefined;
15824
+ }
15727
15825
  // Explicit api_key and explicit project/location already handled above.
15728
15826
  if ((envProject || envLocation) && options.apiKey) {
15729
15827
  // Explicit api_key takes precedence over implicit project/location.
@@ -15794,6 +15892,14 @@ function stringToBoolean(str) {
15794
15892
  }
15795
15893
  return str.toLowerCase() === 'true';
15796
15894
  }
15895
+ function getApiKeyFromEnv() {
15896
+ const envGoogleApiKey = getEnv('GOOGLE_API_KEY');
15897
+ const envGeminiApiKey = getEnv('GEMINI_API_KEY');
15898
+ if (envGoogleApiKey && envGeminiApiKey) {
15899
+ console.warn('Both GOOGLE_API_KEY and GEMINI_API_KEY are set. Using GOOGLE_API_KEY.');
15900
+ }
15901
+ return envGoogleApiKey || envGeminiApiKey;
15902
+ }
15797
15903
 
15798
15904
  export { ActivityHandling, AdapterSize, AuthType, Behavior, BlockedReason, Caches, Chat, Chats, ComputeTokensResponse, ControlReferenceImage, ControlReferenceType, CountTokensResponse, CreateFileResponse, DeleteCachedContentResponse, DeleteFileResponse, DeleteModelResponse, DynamicRetrievalConfigMode, EditImageResponse, EditMode, EmbedContentResponse, EndSensitivity, FeatureSelectionPreference, FileSource, FileState, Files, FinishReason, FunctionCallingConfigMode, FunctionResponse, FunctionResponseScheduling, GenerateContentResponse, GenerateContentResponsePromptFeedback, GenerateContentResponseUsageMetadata, GenerateImagesResponse, GenerateVideosResponse, GoogleGenAI, HarmBlockMethod, HarmBlockThreshold, HarmCategory, HarmProbability, HarmSeverity, HttpResponse, ImagePromptLanguage, JobState, Language, ListCachedContentsResponse, ListFilesResponse, ListModelsResponse, ListTuningJobsResponse, Live, LiveClientToolResponse, LiveMusicPlaybackControl, LiveMusicServerMessage, LiveSendToolResponseParameters, LiveServerMessage, MaskReferenceImage, MaskReferenceMode, MediaModality, MediaResolution, Modality, Mode, Models, Operations, Outcome, PagedItem, Pager, PersonGeneration, RawReferenceImage, ReplayResponse, SafetyFilterLevel, Scale, Session, StartSensitivity, StyleReferenceImage, SubjectReferenceImage, SubjectReferenceType, Tokens, TrafficType, TurnCoverage, Type, UpscaleImageResponse, UrlRetrievalStatus, createModelContent, createPartFromBase64, createPartFromCodeExecutionResult, createPartFromExecutableCode, createPartFromFunctionCall, createPartFromFunctionResponse, createPartFromText, createPartFromUri, createUserContent, mcpToTool, setDefaultBaseUrls };
15799
15905
  //# sourceMappingURL=index.mjs.map