@google/genai 1.4.0 → 1.5.1

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.
@@ -3663,7 +3663,7 @@ class Caches extends BaseModule {
3663
3663
  * @example
3664
3664
  * ```ts
3665
3665
  * const cachedContents = await ai.caches.list({config: {'pageSize': 2}});
3666
- * for (const cachedContent of cachedContents) {
3666
+ * for await (const cachedContent of cachedContents) {
3667
3667
  * console.log(cachedContent);
3668
3668
  * }
3669
3669
  * ```
@@ -8149,6 +8149,9 @@ function generateVideosConfigToMldev(apiClient, fromObject, parentObject) {
8149
8149
  if (getValueByPath(fromObject, ['generateAudio']) !== undefined) {
8150
8150
  throw new Error('generateAudio parameter is not supported in Gemini API.');
8151
8151
  }
8152
+ if (getValueByPath(fromObject, ['lastFrame']) !== undefined) {
8153
+ throw new Error('lastFrame parameter is not supported in Gemini API.');
8154
+ }
8152
8155
  return toObject;
8153
8156
  }
8154
8157
  function generateVideosParametersToMldev(apiClient, fromObject) {
@@ -8165,6 +8168,9 @@ function generateVideosParametersToMldev(apiClient, fromObject) {
8165
8168
  if (fromImage != null) {
8166
8169
  setValueByPath(toObject, ['instances[0]', 'image'], imageToMldev(apiClient, fromImage));
8167
8170
  }
8171
+ if (getValueByPath(fromObject, ['video']) !== undefined) {
8172
+ throw new Error('video parameter is not supported in Gemini API.');
8173
+ }
8168
8174
  const fromConfig = getValueByPath(fromObject, ['config']);
8169
8175
  if (fromConfig != null) {
8170
8176
  setValueByPath(toObject, ['config'], generateVideosConfigToMldev(apiClient, fromConfig, toObject));
@@ -9443,6 +9449,22 @@ function computeTokensParametersToVertex(apiClient, fromObject) {
9443
9449
  }
9444
9450
  return toObject;
9445
9451
  }
9452
+ function videoToVertex(apiClient, fromObject) {
9453
+ const toObject = {};
9454
+ const fromUri = getValueByPath(fromObject, ['uri']);
9455
+ if (fromUri != null) {
9456
+ setValueByPath(toObject, ['gcsUri'], fromUri);
9457
+ }
9458
+ const fromVideoBytes = getValueByPath(fromObject, ['videoBytes']);
9459
+ if (fromVideoBytes != null) {
9460
+ setValueByPath(toObject, ['bytesBase64Encoded'], tBytes(apiClient, fromVideoBytes));
9461
+ }
9462
+ const fromMimeType = getValueByPath(fromObject, ['mimeType']);
9463
+ if (fromMimeType != null) {
9464
+ setValueByPath(toObject, ['mimeType'], fromMimeType);
9465
+ }
9466
+ return toObject;
9467
+ }
9446
9468
  function generateVideosConfigToVertex(apiClient, fromObject, parentObject) {
9447
9469
  const toObject = {};
9448
9470
  const fromNumberOfVideos = getValueByPath(fromObject, [
@@ -9505,6 +9527,10 @@ function generateVideosConfigToVertex(apiClient, fromObject, parentObject) {
9505
9527
  if (parentObject !== undefined && fromGenerateAudio != null) {
9506
9528
  setValueByPath(parentObject, ['parameters', 'generateAudio'], fromGenerateAudio);
9507
9529
  }
9530
+ const fromLastFrame = getValueByPath(fromObject, ['lastFrame']);
9531
+ if (parentObject !== undefined && fromLastFrame != null) {
9532
+ setValueByPath(parentObject, ['instances[0]', 'lastFrame'], imageToVertex(apiClient, fromLastFrame));
9533
+ }
9508
9534
  return toObject;
9509
9535
  }
9510
9536
  function generateVideosParametersToVertex(apiClient, fromObject) {
@@ -9521,6 +9547,10 @@ function generateVideosParametersToVertex(apiClient, fromObject) {
9521
9547
  if (fromImage != null) {
9522
9548
  setValueByPath(toObject, ['instances[0]', 'image'], imageToVertex(apiClient, fromImage));
9523
9549
  }
9550
+ const fromVideo = getValueByPath(fromObject, ['video']);
9551
+ if (fromVideo != null) {
9552
+ setValueByPath(toObject, ['instances[0]', 'video'], videoToVertex(apiClient, fromVideo));
9553
+ }
9524
9554
  const fromConfig = getValueByPath(fromObject, ['config']);
9525
9555
  if (fromConfig != null) {
9526
9556
  setValueByPath(toObject, ['config'], generateVideosConfigToVertex(apiClient, fromConfig, toObject));
@@ -10693,7 +10723,7 @@ const CONTENT_TYPE_HEADER = 'Content-Type';
10693
10723
  const SERVER_TIMEOUT_HEADER = 'X-Server-Timeout';
10694
10724
  const USER_AGENT_HEADER = 'User-Agent';
10695
10725
  const GOOGLE_API_CLIENT_HEADER = 'x-goog-api-client';
10696
- const SDK_VERSION = '1.4.0'; // x-release-please-version
10726
+ const SDK_VERSION = '1.5.1'; // x-release-please-version
10697
10727
  const LIBRARY_LABEL = `google-genai-sdk/${SDK_VERSION}`;
10698
10728
  const VERTEX_AI_API_DEFAULT_VERSION = 'v1beta1';
10699
10729
  const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
@@ -11336,10 +11366,20 @@ class McpCallableTool {
11336
11366
  for (const functionCall of functionCalls) {
11337
11367
  if (functionCall.name in this.functionNameToMcpClient) {
11338
11368
  const mcpClient = this.functionNameToMcpClient[functionCall.name];
11369
+ let requestOptions = undefined;
11370
+ // TODO: b/424238654 - Add support for finer grained timeout control.
11371
+ if (this.config.timeout) {
11372
+ requestOptions = {
11373
+ timeout: this.config.timeout,
11374
+ };
11375
+ }
11339
11376
  const callToolResponse = await mcpClient.callTool({
11340
11377
  name: functionCall.name,
11341
11378
  arguments: functionCall.args,
11342
- });
11379
+ },
11380
+ // Set the result schema to undefined to allow MCP to rely on the
11381
+ // default schema.
11382
+ undefined, requestOptions);
11343
11383
  functionCallResponseParts.push({
11344
11384
  functionResponse: {
11345
11385
  name: functionCall.name,
@@ -15783,7 +15823,7 @@ const LANGUAGE_LABEL_PREFIX = 'gl-node/';
15783
15823
  */
15784
15824
  class GoogleGenAI {
15785
15825
  constructor(options) {
15786
- var _a, _b, _c, _d, _e;
15826
+ var _a, _b, _c, _d, _e, _f;
15787
15827
  // Validate explicitly set initializer values.
15788
15828
  if ((options.project || options.location) && options.apiKey) {
15789
15829
  throw new Error('Project/location and API key are mutually exclusive in the client initializer.');
@@ -15798,6 +15838,12 @@ class GoogleGenAI {
15798
15838
  this.location = (_e = options.location) !== null && _e !== void 0 ? _e : envLocation;
15799
15839
  // Handle when to use Vertex AI in express mode (api key)
15800
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
+ }
15801
15847
  // Explicit api_key and explicit project/location already handled above.
15802
15848
  if ((envProject || envLocation) && options.apiKey) {
15803
15849
  // Explicit api_key takes precedence over implicit project/location.
@@ -3641,7 +3641,7 @@ class Caches extends BaseModule {
3641
3641
  * @example
3642
3642
  * ```ts
3643
3643
  * const cachedContents = await ai.caches.list({config: {'pageSize': 2}});
3644
- * for (const cachedContent of cachedContents) {
3644
+ * for await (const cachedContent of cachedContents) {
3645
3645
  * console.log(cachedContent);
3646
3646
  * }
3647
3647
  * ```
@@ -8127,6 +8127,9 @@ function generateVideosConfigToMldev(apiClient, fromObject, parentObject) {
8127
8127
  if (getValueByPath(fromObject, ['generateAudio']) !== undefined) {
8128
8128
  throw new Error('generateAudio parameter is not supported in Gemini API.');
8129
8129
  }
8130
+ if (getValueByPath(fromObject, ['lastFrame']) !== undefined) {
8131
+ throw new Error('lastFrame parameter is not supported in Gemini API.');
8132
+ }
8130
8133
  return toObject;
8131
8134
  }
8132
8135
  function generateVideosParametersToMldev(apiClient, fromObject) {
@@ -8143,6 +8146,9 @@ function generateVideosParametersToMldev(apiClient, fromObject) {
8143
8146
  if (fromImage != null) {
8144
8147
  setValueByPath(toObject, ['instances[0]', 'image'], imageToMldev(apiClient, fromImage));
8145
8148
  }
8149
+ if (getValueByPath(fromObject, ['video']) !== undefined) {
8150
+ throw new Error('video parameter is not supported in Gemini API.');
8151
+ }
8146
8152
  const fromConfig = getValueByPath(fromObject, ['config']);
8147
8153
  if (fromConfig != null) {
8148
8154
  setValueByPath(toObject, ['config'], generateVideosConfigToMldev(apiClient, fromConfig, toObject));
@@ -9421,6 +9427,22 @@ function computeTokensParametersToVertex(apiClient, fromObject) {
9421
9427
  }
9422
9428
  return toObject;
9423
9429
  }
9430
+ function videoToVertex(apiClient, fromObject) {
9431
+ const toObject = {};
9432
+ const fromUri = getValueByPath(fromObject, ['uri']);
9433
+ if (fromUri != null) {
9434
+ setValueByPath(toObject, ['gcsUri'], fromUri);
9435
+ }
9436
+ const fromVideoBytes = getValueByPath(fromObject, ['videoBytes']);
9437
+ if (fromVideoBytes != null) {
9438
+ setValueByPath(toObject, ['bytesBase64Encoded'], tBytes(apiClient, fromVideoBytes));
9439
+ }
9440
+ const fromMimeType = getValueByPath(fromObject, ['mimeType']);
9441
+ if (fromMimeType != null) {
9442
+ setValueByPath(toObject, ['mimeType'], fromMimeType);
9443
+ }
9444
+ return toObject;
9445
+ }
9424
9446
  function generateVideosConfigToVertex(apiClient, fromObject, parentObject) {
9425
9447
  const toObject = {};
9426
9448
  const fromNumberOfVideos = getValueByPath(fromObject, [
@@ -9483,6 +9505,10 @@ function generateVideosConfigToVertex(apiClient, fromObject, parentObject) {
9483
9505
  if (parentObject !== undefined && fromGenerateAudio != null) {
9484
9506
  setValueByPath(parentObject, ['parameters', 'generateAudio'], fromGenerateAudio);
9485
9507
  }
9508
+ const fromLastFrame = getValueByPath(fromObject, ['lastFrame']);
9509
+ if (parentObject !== undefined && fromLastFrame != null) {
9510
+ setValueByPath(parentObject, ['instances[0]', 'lastFrame'], imageToVertex(apiClient, fromLastFrame));
9511
+ }
9486
9512
  return toObject;
9487
9513
  }
9488
9514
  function generateVideosParametersToVertex(apiClient, fromObject) {
@@ -9499,6 +9525,10 @@ function generateVideosParametersToVertex(apiClient, fromObject) {
9499
9525
  if (fromImage != null) {
9500
9526
  setValueByPath(toObject, ['instances[0]', 'image'], imageToVertex(apiClient, fromImage));
9501
9527
  }
9528
+ const fromVideo = getValueByPath(fromObject, ['video']);
9529
+ if (fromVideo != null) {
9530
+ setValueByPath(toObject, ['instances[0]', 'video'], videoToVertex(apiClient, fromVideo));
9531
+ }
9502
9532
  const fromConfig = getValueByPath(fromObject, ['config']);
9503
9533
  if (fromConfig != null) {
9504
9534
  setValueByPath(toObject, ['config'], generateVideosConfigToVertex(apiClient, fromConfig, toObject));
@@ -10671,7 +10701,7 @@ const CONTENT_TYPE_HEADER = 'Content-Type';
10671
10701
  const SERVER_TIMEOUT_HEADER = 'X-Server-Timeout';
10672
10702
  const USER_AGENT_HEADER = 'User-Agent';
10673
10703
  const GOOGLE_API_CLIENT_HEADER = 'x-goog-api-client';
10674
- const SDK_VERSION = '1.4.0'; // x-release-please-version
10704
+ const SDK_VERSION = '1.5.1'; // x-release-please-version
10675
10705
  const LIBRARY_LABEL = `google-genai-sdk/${SDK_VERSION}`;
10676
10706
  const VERTEX_AI_API_DEFAULT_VERSION = 'v1beta1';
10677
10707
  const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
@@ -11314,10 +11344,20 @@ class McpCallableTool {
11314
11344
  for (const functionCall of functionCalls) {
11315
11345
  if (functionCall.name in this.functionNameToMcpClient) {
11316
11346
  const mcpClient = this.functionNameToMcpClient[functionCall.name];
11347
+ let requestOptions = undefined;
11348
+ // TODO: b/424238654 - Add support for finer grained timeout control.
11349
+ if (this.config.timeout) {
11350
+ requestOptions = {
11351
+ timeout: this.config.timeout,
11352
+ };
11353
+ }
11317
11354
  const callToolResponse = await mcpClient.callTool({
11318
11355
  name: functionCall.name,
11319
11356
  arguments: functionCall.args,
11320
- });
11357
+ },
11358
+ // Set the result schema to undefined to allow MCP to rely on the
11359
+ // default schema.
11360
+ undefined, requestOptions);
11321
11361
  functionCallResponseParts.push({
11322
11362
  functionResponse: {
11323
11363
  name: functionCall.name,
@@ -15761,7 +15801,7 @@ const LANGUAGE_LABEL_PREFIX = 'gl-node/';
15761
15801
  */
15762
15802
  class GoogleGenAI {
15763
15803
  constructor(options) {
15764
- var _a, _b, _c, _d, _e;
15804
+ var _a, _b, _c, _d, _e, _f;
15765
15805
  // Validate explicitly set initializer values.
15766
15806
  if ((options.project || options.location) && options.apiKey) {
15767
15807
  throw new Error('Project/location and API key are mutually exclusive in the client initializer.');
@@ -15776,6 +15816,12 @@ class GoogleGenAI {
15776
15816
  this.location = (_e = options.location) !== null && _e !== void 0 ? _e : envLocation;
15777
15817
  // Handle when to use Vertex AI in express mode (api key)
15778
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
+ }
15779
15825
  // Explicit api_key and explicit project/location already handled above.
15780
15826
  if ((envProject || envLocation) && options.apiKey) {
15781
15827
  // Explicit api_key takes precedence over implicit project/location.