@google/genai 1.4.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.
@@ -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
  }
@@ -5997,6 +6006,7 @@ declare namespace types {
5997
6006
  AuthConfig,
5998
6007
  GoogleMaps,
5999
6008
  UrlContext,
6009
+ VertexAISearchDataStoreSpec,
6000
6010
  VertexAISearch,
6001
6011
  VertexRagStoreRagResource,
6002
6012
  RagRetrievalConfigFilter,
@@ -6093,9 +6103,9 @@ declare namespace types {
6093
6103
  ComputeTokensParameters,
6094
6104
  TokensInfo,
6095
6105
  ComputeTokensResponse,
6106
+ Video,
6096
6107
  GenerateVideosConfig,
6097
6108
  GenerateVideosParameters,
6098
- Video,
6099
6109
  GeneratedVideo,
6100
6110
  GenerateVideosResponse,
6101
6111
  GenerateVideosOperation,
@@ -6447,6 +6457,8 @@ export declare interface UsageMetadata {
6447
6457
 
6448
6458
  /** Retrieve from Vertex AI Search datastore or engine for grounding. datastore and engine are mutually exclusive. See https://cloud.google.com/products/agent-builder */
6449
6459
  export declare interface VertexAISearch {
6460
+ /** 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. */
6461
+ dataStoreSpecs?: VertexAISearchDataStoreSpec[];
6450
6462
  /** Optional. Fully-qualified Vertex AI Search data store resource ID. Format: `projects/{project}/locations/{location}/collections/{collection}/dataStores/{dataStore}` */
6451
6463
  datastore?: string;
6452
6464
  /** Optional. Fully-qualified Vertex AI Search engine resource ID. Format: `projects/{project}/locations/{location}/collections/{collection}/engines/{engine}` */
@@ -6457,6 +6469,14 @@ export declare interface VertexAISearch {
6457
6469
  maxResults?: number;
6458
6470
  }
6459
6471
 
6472
+ /** 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 */
6473
+ export declare interface VertexAISearchDataStoreSpec {
6474
+ /** Full resource name of DataStore, such as Format: `projects/{project}/locations/{location}/collections/{collection}/dataStores/{dataStore}` */
6475
+ dataStore?: string;
6476
+ /** 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) */
6477
+ filter?: string;
6478
+ }
6479
+
6460
6480
  /** Retrieve from Vertex RAG Store for grounding. */
6461
6481
  export declare interface VertexRagStore {
6462
6482
  /** Optional. Deprecated. Please use rag_resources instead. */
@@ -6467,6 +6487,8 @@ export declare interface VertexRagStore {
6467
6487
  ragRetrievalConfig?: RagRetrievalConfig;
6468
6488
  /** Optional. Number of top k results to return from the selected corpora. */
6469
6489
  similarityTopK?: number;
6490
+ /** 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. */
6491
+ storeContext?: boolean;
6470
6492
  /** Optional. Only return results with vector distance smaller than the threshold. */
6471
6493
  vectorDistanceThreshold?: number;
6472
6494
  }
@@ -1,4 +1,5 @@
1
1
  import { z } from 'zod';
2
+ import { CallToolResultSchema } from '@modelcontextprotocol/sdk/types.js';
2
3
 
3
4
  /**
4
5
  * @license
@@ -3636,7 +3637,7 @@ class Caches extends BaseModule {
3636
3637
  * @example
3637
3638
  * ```ts
3638
3639
  * const cachedContents = await ai.caches.list({config: {'pageSize': 2}});
3639
- * for (const cachedContent of cachedContents) {
3640
+ * for await (const cachedContent of cachedContents) {
3640
3641
  * console.log(cachedContent);
3641
3642
  * }
3642
3643
  * ```
@@ -8122,6 +8123,9 @@ function generateVideosConfigToMldev(apiClient, fromObject, parentObject) {
8122
8123
  if (getValueByPath(fromObject, ['generateAudio']) !== undefined) {
8123
8124
  throw new Error('generateAudio parameter is not supported in Gemini API.');
8124
8125
  }
8126
+ if (getValueByPath(fromObject, ['lastFrame']) !== undefined) {
8127
+ throw new Error('lastFrame parameter is not supported in Gemini API.');
8128
+ }
8125
8129
  return toObject;
8126
8130
  }
8127
8131
  function generateVideosParametersToMldev(apiClient, fromObject) {
@@ -8138,6 +8142,9 @@ function generateVideosParametersToMldev(apiClient, fromObject) {
8138
8142
  if (fromImage != null) {
8139
8143
  setValueByPath(toObject, ['instances[0]', 'image'], imageToMldev(apiClient, fromImage));
8140
8144
  }
8145
+ if (getValueByPath(fromObject, ['video']) !== undefined) {
8146
+ throw new Error('video parameter is not supported in Gemini API.');
8147
+ }
8141
8148
  const fromConfig = getValueByPath(fromObject, ['config']);
8142
8149
  if (fromConfig != null) {
8143
8150
  setValueByPath(toObject, ['config'], generateVideosConfigToMldev(apiClient, fromConfig, toObject));
@@ -9416,6 +9423,22 @@ function computeTokensParametersToVertex(apiClient, fromObject) {
9416
9423
  }
9417
9424
  return toObject;
9418
9425
  }
9426
+ function videoToVertex(apiClient, fromObject) {
9427
+ const toObject = {};
9428
+ const fromUri = getValueByPath(fromObject, ['uri']);
9429
+ if (fromUri != null) {
9430
+ setValueByPath(toObject, ['gcsUri'], fromUri);
9431
+ }
9432
+ const fromVideoBytes = getValueByPath(fromObject, ['videoBytes']);
9433
+ if (fromVideoBytes != null) {
9434
+ setValueByPath(toObject, ['bytesBase64Encoded'], tBytes(apiClient, fromVideoBytes));
9435
+ }
9436
+ const fromMimeType = getValueByPath(fromObject, ['mimeType']);
9437
+ if (fromMimeType != null) {
9438
+ setValueByPath(toObject, ['mimeType'], fromMimeType);
9439
+ }
9440
+ return toObject;
9441
+ }
9419
9442
  function generateVideosConfigToVertex(apiClient, fromObject, parentObject) {
9420
9443
  const toObject = {};
9421
9444
  const fromNumberOfVideos = getValueByPath(fromObject, [
@@ -9478,6 +9501,10 @@ function generateVideosConfigToVertex(apiClient, fromObject, parentObject) {
9478
9501
  if (parentObject !== undefined && fromGenerateAudio != null) {
9479
9502
  setValueByPath(parentObject, ['parameters', 'generateAudio'], fromGenerateAudio);
9480
9503
  }
9504
+ const fromLastFrame = getValueByPath(fromObject, ['lastFrame']);
9505
+ if (parentObject !== undefined && fromLastFrame != null) {
9506
+ setValueByPath(parentObject, ['instances[0]', 'lastFrame'], imageToVertex(apiClient, fromLastFrame));
9507
+ }
9481
9508
  return toObject;
9482
9509
  }
9483
9510
  function generateVideosParametersToVertex(apiClient, fromObject) {
@@ -9494,6 +9521,10 @@ function generateVideosParametersToVertex(apiClient, fromObject) {
9494
9521
  if (fromImage != null) {
9495
9522
  setValueByPath(toObject, ['instances[0]', 'image'], imageToVertex(apiClient, fromImage));
9496
9523
  }
9524
+ const fromVideo = getValueByPath(fromObject, ['video']);
9525
+ if (fromVideo != null) {
9526
+ setValueByPath(toObject, ['instances[0]', 'video'], videoToVertex(apiClient, fromVideo));
9527
+ }
9497
9528
  const fromConfig = getValueByPath(fromObject, ['config']);
9498
9529
  if (fromConfig != null) {
9499
9530
  setValueByPath(toObject, ['config'], generateVideosConfigToVertex(apiClient, fromConfig, toObject));
@@ -10666,7 +10697,7 @@ const CONTENT_TYPE_HEADER = 'Content-Type';
10666
10697
  const SERVER_TIMEOUT_HEADER = 'X-Server-Timeout';
10667
10698
  const USER_AGENT_HEADER = 'User-Agent';
10668
10699
  const GOOGLE_API_CLIENT_HEADER = 'x-goog-api-client';
10669
- const SDK_VERSION = '1.4.0'; // x-release-please-version
10700
+ const SDK_VERSION = '1.5.0'; // x-release-please-version
10670
10701
  const LIBRARY_LABEL = `google-genai-sdk/${SDK_VERSION}`;
10671
10702
  const VERTEX_AI_API_DEFAULT_VERSION = 'v1beta1';
10672
10703
  const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
@@ -11309,9 +11340,18 @@ class McpCallableTool {
11309
11340
  for (const functionCall of functionCalls) {
11310
11341
  if (functionCall.name in this.functionNameToMcpClient) {
11311
11342
  const mcpClient = this.functionNameToMcpClient[functionCall.name];
11343
+ let requestOptions = undefined;
11344
+ // TODO: b/424238654 - Add support for finer grained timeout control.
11345
+ if (this.config.timeout) {
11346
+ requestOptions = {
11347
+ timeout: this.config.timeout,
11348
+ };
11349
+ }
11312
11350
  const callToolResponse = await mcpClient.callTool({
11313
11351
  name: functionCall.name,
11314
11352
  arguments: functionCall.args,
11353
+ CallToolResultSchema,
11354
+ requestOptions,
11315
11355
  });
11316
11356
  functionCallResponseParts.push({
11317
11357
  functionResponse: {