@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.
package/dist/genai.d.ts CHANGED
@@ -456,7 +456,7 @@ export declare class Caches extends BaseModule {
456
456
  * @example
457
457
  * ```ts
458
458
  * const cachedContents = await ai.caches.list({config: {'pageSize': 2}});
459
- * for (const cachedContent of cachedContents) {
459
+ * for await (const cachedContent of cachedContents) {
460
460
  * console.log(cachedContent);
461
461
  * }
462
462
  * ```
@@ -556,6 +556,10 @@ export declare interface CallableToolConfig {
556
556
  * Specifies the model's behavior after invoking this tool.
557
557
  */
558
558
  behavior?: Behavior;
559
+ /**
560
+ * Timeout for remote calls in milliseconds. Note this timeout applies only to
561
+ * tool remote calls, and not making HTTP requests to the API. */
562
+ timeout?: number;
559
563
  }
560
564
 
561
565
  /** A response candidate generated from the model. */
@@ -2426,6 +2430,8 @@ export declare interface GenerateVideosConfig {
2426
2430
  enhancePrompt?: boolean;
2427
2431
  /** Whether to generate audio along with the video. */
2428
2432
  generateAudio?: boolean;
2433
+ /** Image to use as the last frame of generated videos. Only supported for image to video use cases. */
2434
+ lastFrame?: Image_2;
2429
2435
  }
2430
2436
 
2431
2437
  /** A video generation operation. */
@@ -2442,7 +2448,7 @@ export declare interface GenerateVideosOperation {
2442
2448
  response?: GenerateVideosResponse;
2443
2449
  }
2444
2450
 
2445
- /** Class that represents the parameters for generating an image. */
2451
+ /** Class that represents the parameters for generating videos. */
2446
2452
  export declare interface GenerateVideosParameters {
2447
2453
  /** ID of the model to use. For a list of models, see `Google models
2448
2454
  <https://cloud.google.com/vertex-ai/generative-ai/docs/learn/models>`_. */
@@ -2450,8 +2456,11 @@ export declare interface GenerateVideosParameters {
2450
2456
  /** The text prompt for generating the videos. Optional for image to video use cases. */
2451
2457
  prompt?: string;
2452
2458
  /** The input image for generating the videos.
2453
- Optional if prompt is provided. */
2459
+ Optional if prompt or video is provided. */
2454
2460
  image?: Image_2;
2461
+ /** The input video for video extension use cases.
2462
+ Optional if prompt or image is provided. */
2463
+ video?: Video;
2455
2464
  /** Configuration for generating videos. */
2456
2465
  config?: GenerateVideosConfig;
2457
2466
  }
@@ -5985,6 +5994,7 @@ declare namespace types {
5985
5994
  AuthConfig,
5986
5995
  GoogleMaps,
5987
5996
  UrlContext,
5997
+ VertexAISearchDataStoreSpec,
5988
5998
  VertexAISearch,
5989
5999
  VertexRagStoreRagResource,
5990
6000
  RagRetrievalConfigFilter,
@@ -6081,9 +6091,9 @@ declare namespace types {
6081
6091
  ComputeTokensParameters,
6082
6092
  TokensInfo,
6083
6093
  ComputeTokensResponse,
6094
+ Video,
6084
6095
  GenerateVideosConfig,
6085
6096
  GenerateVideosParameters,
6086
- Video,
6087
6097
  GeneratedVideo,
6088
6098
  GenerateVideosResponse,
6089
6099
  GenerateVideosOperation,
@@ -6435,6 +6445,8 @@ export declare interface UsageMetadata {
6435
6445
 
6436
6446
  /** Retrieve from Vertex AI Search datastore or engine for grounding. datastore and engine are mutually exclusive. See https://cloud.google.com/products/agent-builder */
6437
6447
  export declare interface VertexAISearch {
6448
+ /** Specifications that define the specific DataStores to be searched, along with configurations for those data stores. This is only considered for Engines with multiple data stores. It should only be set if engine is used. */
6449
+ dataStoreSpecs?: VertexAISearchDataStoreSpec[];
6438
6450
  /** Optional. Fully-qualified Vertex AI Search data store resource ID. Format: `projects/{project}/locations/{location}/collections/{collection}/dataStores/{dataStore}` */
6439
6451
  datastore?: string;
6440
6452
  /** Optional. Fully-qualified Vertex AI Search engine resource ID. Format: `projects/{project}/locations/{location}/collections/{collection}/engines/{engine}` */
@@ -6445,6 +6457,14 @@ export declare interface VertexAISearch {
6445
6457
  maxResults?: number;
6446
6458
  }
6447
6459
 
6460
+ /** Define data stores within engine to filter on in a search call and configurations for those data stores. For more information, see https://cloud.google.com/generative-ai-app-builder/docs/reference/rpc/google.cloud.discoveryengine.v1#datastorespec */
6461
+ export declare interface VertexAISearchDataStoreSpec {
6462
+ /** Full resource name of DataStore, such as Format: `projects/{project}/locations/{location}/collections/{collection}/dataStores/{dataStore}` */
6463
+ dataStore?: string;
6464
+ /** Optional. Filter specification to filter documents in the data store specified by data_store field. For more information on filtering, see [Filtering](https://cloud.google.com/generative-ai-app-builder/docs/filter-search-metadata) */
6465
+ filter?: string;
6466
+ }
6467
+
6448
6468
  /** Retrieve from Vertex RAG Store for grounding. */
6449
6469
  export declare interface VertexRagStore {
6450
6470
  /** Optional. Deprecated. Please use rag_resources instead. */
@@ -6455,6 +6475,8 @@ export declare interface VertexRagStore {
6455
6475
  ragRetrievalConfig?: RagRetrievalConfig;
6456
6476
  /** Optional. Number of top k results to return from the selected corpora. */
6457
6477
  similarityTopK?: number;
6478
+ /** Optional. Currently only supported for Gemini Multimodal Live API. In Gemini Multimodal Live API, if `store_context` bool is specified, Gemini will leverage it to automatically memorize the interactions between the client and Gemini, and retrieve context when needed to augment the response generation for users' ongoing and future interactions. */
6479
+ storeContext?: boolean;
6458
6480
  /** Optional. Only return results with vector distance smaller than the threshold. */
6459
6481
  vectorDistanceThreshold?: number;
6460
6482
  }
package/dist/index.cjs CHANGED
@@ -3608,7 +3608,7 @@ class Caches extends BaseModule {
3608
3608
  * @example
3609
3609
  * ```ts
3610
3610
  * const cachedContents = await ai.caches.list({config: {'pageSize': 2}});
3611
- * for (const cachedContent of cachedContents) {
3611
+ * for await (const cachedContent of cachedContents) {
3612
3612
  * console.log(cachedContent);
3613
3613
  * }
3614
3614
  * ```
@@ -4353,7 +4353,7 @@ const CONTENT_TYPE_HEADER = 'Content-Type';
4353
4353
  const SERVER_TIMEOUT_HEADER = 'X-Server-Timeout';
4354
4354
  const USER_AGENT_HEADER = 'User-Agent';
4355
4355
  const GOOGLE_API_CLIENT_HEADER = 'x-goog-api-client';
4356
- const SDK_VERSION = '1.4.0'; // x-release-please-version
4356
+ const SDK_VERSION = '1.5.1'; // x-release-please-version
4357
4357
  const LIBRARY_LABEL = `google-genai-sdk/${SDK_VERSION}`;
4358
4358
  const VERTEX_AI_API_DEFAULT_VERSION = 'v1beta1';
4359
4359
  const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
@@ -4983,10 +4983,8 @@ function sleep(ms) {
4983
4983
  * Copyright 2025 Google LLC
4984
4984
  * SPDX-License-Identifier: Apache-2.0
4985
4985
  */
4986
- // TODO((b/401271082): re-enable lint once CrossWebSocketFactory is implemented.
4987
- /* eslint-disable @typescript-eslint/no-unused-vars */
4988
4986
  class CrossWebSocketFactory {
4989
- create(url, headers, callbacks) {
4987
+ create(_url, _headers, _callbacks) {
4990
4988
  throw crossError();
4991
4989
  }
4992
4990
  }
@@ -8741,6 +8739,9 @@ function generateVideosConfigToMldev(apiClient, fromObject, parentObject) {
8741
8739
  if (getValueByPath(fromObject, ['generateAudio']) !== undefined) {
8742
8740
  throw new Error('generateAudio parameter is not supported in Gemini API.');
8743
8741
  }
8742
+ if (getValueByPath(fromObject, ['lastFrame']) !== undefined) {
8743
+ throw new Error('lastFrame parameter is not supported in Gemini API.');
8744
+ }
8744
8745
  return toObject;
8745
8746
  }
8746
8747
  function generateVideosParametersToMldev(apiClient, fromObject) {
@@ -8757,6 +8758,9 @@ function generateVideosParametersToMldev(apiClient, fromObject) {
8757
8758
  if (fromImage != null) {
8758
8759
  setValueByPath(toObject, ['instances[0]', 'image'], imageToMldev(apiClient, fromImage));
8759
8760
  }
8761
+ if (getValueByPath(fromObject, ['video']) !== undefined) {
8762
+ throw new Error('video parameter is not supported in Gemini API.');
8763
+ }
8760
8764
  const fromConfig = getValueByPath(fromObject, ['config']);
8761
8765
  if (fromConfig != null) {
8762
8766
  setValueByPath(toObject, ['config'], generateVideosConfigToMldev(apiClient, fromConfig, toObject));
@@ -10035,6 +10039,22 @@ function computeTokensParametersToVertex(apiClient, fromObject) {
10035
10039
  }
10036
10040
  return toObject;
10037
10041
  }
10042
+ function videoToVertex(apiClient, fromObject) {
10043
+ const toObject = {};
10044
+ const fromUri = getValueByPath(fromObject, ['uri']);
10045
+ if (fromUri != null) {
10046
+ setValueByPath(toObject, ['gcsUri'], fromUri);
10047
+ }
10048
+ const fromVideoBytes = getValueByPath(fromObject, ['videoBytes']);
10049
+ if (fromVideoBytes != null) {
10050
+ setValueByPath(toObject, ['bytesBase64Encoded'], tBytes(apiClient, fromVideoBytes));
10051
+ }
10052
+ const fromMimeType = getValueByPath(fromObject, ['mimeType']);
10053
+ if (fromMimeType != null) {
10054
+ setValueByPath(toObject, ['mimeType'], fromMimeType);
10055
+ }
10056
+ return toObject;
10057
+ }
10038
10058
  function generateVideosConfigToVertex(apiClient, fromObject, parentObject) {
10039
10059
  const toObject = {};
10040
10060
  const fromNumberOfVideos = getValueByPath(fromObject, [
@@ -10097,6 +10117,10 @@ function generateVideosConfigToVertex(apiClient, fromObject, parentObject) {
10097
10117
  if (parentObject !== undefined && fromGenerateAudio != null) {
10098
10118
  setValueByPath(parentObject, ['parameters', 'generateAudio'], fromGenerateAudio);
10099
10119
  }
10120
+ const fromLastFrame = getValueByPath(fromObject, ['lastFrame']);
10121
+ if (parentObject !== undefined && fromLastFrame != null) {
10122
+ setValueByPath(parentObject, ['instances[0]', 'lastFrame'], imageToVertex(apiClient, fromLastFrame));
10123
+ }
10100
10124
  return toObject;
10101
10125
  }
10102
10126
  function generateVideosParametersToVertex(apiClient, fromObject) {
@@ -10113,6 +10137,10 @@ function generateVideosParametersToVertex(apiClient, fromObject) {
10113
10137
  if (fromImage != null) {
10114
10138
  setValueByPath(toObject, ['instances[0]', 'image'], imageToVertex(apiClient, fromImage));
10115
10139
  }
10140
+ const fromVideo = getValueByPath(fromObject, ['video']);
10141
+ if (fromVideo != null) {
10142
+ setValueByPath(toObject, ['instances[0]', 'video'], videoToVertex(apiClient, fromVideo));
10143
+ }
10116
10144
  const fromConfig = getValueByPath(fromObject, ['config']);
10117
10145
  if (fromConfig != null) {
10118
10146
  setValueByPath(toObject, ['config'], generateVideosConfigToVertex(apiClient, fromConfig, toObject));
@@ -11406,10 +11434,20 @@ class McpCallableTool {
11406
11434
  for (const functionCall of functionCalls) {
11407
11435
  if (functionCall.name in this.functionNameToMcpClient) {
11408
11436
  const mcpClient = this.functionNameToMcpClient[functionCall.name];
11437
+ let requestOptions = undefined;
11438
+ // TODO: b/424238654 - Add support for finer grained timeout control.
11439
+ if (this.config.timeout) {
11440
+ requestOptions = {
11441
+ timeout: this.config.timeout,
11442
+ };
11443
+ }
11409
11444
  const callToolResponse = await mcpClient.callTool({
11410
11445
  name: functionCall.name,
11411
11446
  arguments: functionCall.args,
11412
- });
11447
+ },
11448
+ // Set the result schema to undefined to allow MCP to rely on the
11449
+ // default schema.
11450
+ undefined, requestOptions);
11413
11451
  functionCallResponseParts.push({
11414
11452
  functionResponse: {
11415
11453
  name: functionCall.name,
package/dist/index.mjs CHANGED
@@ -3606,7 +3606,7 @@ class Caches extends BaseModule {
3606
3606
  * @example
3607
3607
  * ```ts
3608
3608
  * const cachedContents = await ai.caches.list({config: {'pageSize': 2}});
3609
- * for (const cachedContent of cachedContents) {
3609
+ * for await (const cachedContent of cachedContents) {
3610
3610
  * console.log(cachedContent);
3611
3611
  * }
3612
3612
  * ```
@@ -4351,7 +4351,7 @@ const CONTENT_TYPE_HEADER = 'Content-Type';
4351
4351
  const SERVER_TIMEOUT_HEADER = 'X-Server-Timeout';
4352
4352
  const USER_AGENT_HEADER = 'User-Agent';
4353
4353
  const GOOGLE_API_CLIENT_HEADER = 'x-goog-api-client';
4354
- const SDK_VERSION = '1.4.0'; // x-release-please-version
4354
+ const SDK_VERSION = '1.5.1'; // x-release-please-version
4355
4355
  const LIBRARY_LABEL = `google-genai-sdk/${SDK_VERSION}`;
4356
4356
  const VERTEX_AI_API_DEFAULT_VERSION = 'v1beta1';
4357
4357
  const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
@@ -4981,10 +4981,8 @@ function sleep(ms) {
4981
4981
  * Copyright 2025 Google LLC
4982
4982
  * SPDX-License-Identifier: Apache-2.0
4983
4983
  */
4984
- // TODO((b/401271082): re-enable lint once CrossWebSocketFactory is implemented.
4985
- /* eslint-disable @typescript-eslint/no-unused-vars */
4986
4984
  class CrossWebSocketFactory {
4987
- create(url, headers, callbacks) {
4985
+ create(_url, _headers, _callbacks) {
4988
4986
  throw crossError();
4989
4987
  }
4990
4988
  }
@@ -8739,6 +8737,9 @@ function generateVideosConfigToMldev(apiClient, fromObject, parentObject) {
8739
8737
  if (getValueByPath(fromObject, ['generateAudio']) !== undefined) {
8740
8738
  throw new Error('generateAudio parameter is not supported in Gemini API.');
8741
8739
  }
8740
+ if (getValueByPath(fromObject, ['lastFrame']) !== undefined) {
8741
+ throw new Error('lastFrame parameter is not supported in Gemini API.');
8742
+ }
8742
8743
  return toObject;
8743
8744
  }
8744
8745
  function generateVideosParametersToMldev(apiClient, fromObject) {
@@ -8755,6 +8756,9 @@ function generateVideosParametersToMldev(apiClient, fromObject) {
8755
8756
  if (fromImage != null) {
8756
8757
  setValueByPath(toObject, ['instances[0]', 'image'], imageToMldev(apiClient, fromImage));
8757
8758
  }
8759
+ if (getValueByPath(fromObject, ['video']) !== undefined) {
8760
+ throw new Error('video parameter is not supported in Gemini API.');
8761
+ }
8758
8762
  const fromConfig = getValueByPath(fromObject, ['config']);
8759
8763
  if (fromConfig != null) {
8760
8764
  setValueByPath(toObject, ['config'], generateVideosConfigToMldev(apiClient, fromConfig, toObject));
@@ -10033,6 +10037,22 @@ function computeTokensParametersToVertex(apiClient, fromObject) {
10033
10037
  }
10034
10038
  return toObject;
10035
10039
  }
10040
+ function videoToVertex(apiClient, fromObject) {
10041
+ const toObject = {};
10042
+ const fromUri = getValueByPath(fromObject, ['uri']);
10043
+ if (fromUri != null) {
10044
+ setValueByPath(toObject, ['gcsUri'], fromUri);
10045
+ }
10046
+ const fromVideoBytes = getValueByPath(fromObject, ['videoBytes']);
10047
+ if (fromVideoBytes != null) {
10048
+ setValueByPath(toObject, ['bytesBase64Encoded'], tBytes(apiClient, fromVideoBytes));
10049
+ }
10050
+ const fromMimeType = getValueByPath(fromObject, ['mimeType']);
10051
+ if (fromMimeType != null) {
10052
+ setValueByPath(toObject, ['mimeType'], fromMimeType);
10053
+ }
10054
+ return toObject;
10055
+ }
10036
10056
  function generateVideosConfigToVertex(apiClient, fromObject, parentObject) {
10037
10057
  const toObject = {};
10038
10058
  const fromNumberOfVideos = getValueByPath(fromObject, [
@@ -10095,6 +10115,10 @@ function generateVideosConfigToVertex(apiClient, fromObject, parentObject) {
10095
10115
  if (parentObject !== undefined && fromGenerateAudio != null) {
10096
10116
  setValueByPath(parentObject, ['parameters', 'generateAudio'], fromGenerateAudio);
10097
10117
  }
10118
+ const fromLastFrame = getValueByPath(fromObject, ['lastFrame']);
10119
+ if (parentObject !== undefined && fromLastFrame != null) {
10120
+ setValueByPath(parentObject, ['instances[0]', 'lastFrame'], imageToVertex(apiClient, fromLastFrame));
10121
+ }
10098
10122
  return toObject;
10099
10123
  }
10100
10124
  function generateVideosParametersToVertex(apiClient, fromObject) {
@@ -10111,6 +10135,10 @@ function generateVideosParametersToVertex(apiClient, fromObject) {
10111
10135
  if (fromImage != null) {
10112
10136
  setValueByPath(toObject, ['instances[0]', 'image'], imageToVertex(apiClient, fromImage));
10113
10137
  }
10138
+ const fromVideo = getValueByPath(fromObject, ['video']);
10139
+ if (fromVideo != null) {
10140
+ setValueByPath(toObject, ['instances[0]', 'video'], videoToVertex(apiClient, fromVideo));
10141
+ }
10114
10142
  const fromConfig = getValueByPath(fromObject, ['config']);
10115
10143
  if (fromConfig != null) {
10116
10144
  setValueByPath(toObject, ['config'], generateVideosConfigToVertex(apiClient, fromConfig, toObject));
@@ -11404,10 +11432,20 @@ class McpCallableTool {
11404
11432
  for (const functionCall of functionCalls) {
11405
11433
  if (functionCall.name in this.functionNameToMcpClient) {
11406
11434
  const mcpClient = this.functionNameToMcpClient[functionCall.name];
11435
+ let requestOptions = undefined;
11436
+ // TODO: b/424238654 - Add support for finer grained timeout control.
11437
+ if (this.config.timeout) {
11438
+ requestOptions = {
11439
+ timeout: this.config.timeout,
11440
+ };
11441
+ }
11407
11442
  const callToolResponse = await mcpClient.callTool({
11408
11443
  name: functionCall.name,
11409
11444
  arguments: functionCall.args,
11410
- });
11445
+ },
11446
+ // Set the result schema to undefined to allow MCP to rely on the
11447
+ // default schema.
11448
+ undefined, requestOptions);
11411
11449
  functionCallResponseParts.push({
11412
11450
  functionResponse: {
11413
11451
  name: functionCall.name,