@google/genai 1.30.0 → 1.31.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.
@@ -2233,6 +2233,9 @@ class GenerateVideosOperation {
2233
2233
  /** Response for the list tuning jobs method. */
2234
2234
  class ListTuningJobsResponse {
2235
2235
  }
2236
+ /** Empty response for tunings.cancel method. */
2237
+ class CancelTuningJobResponse {
2238
+ }
2236
2239
  /** Empty response for caches.delete method. */
2237
2240
  class DeleteCachedContentResponse {
2238
2241
  }
@@ -4700,6 +4703,23 @@ class Batches extends BaseModule {
4700
4703
  constructor(apiClient) {
4701
4704
  super();
4702
4705
  this.apiClient = apiClient;
4706
+ /**
4707
+ * Lists batch jobs.
4708
+ *
4709
+ * @param params - The parameters for the list request.
4710
+ * @return - A pager of batch jobs.
4711
+ *
4712
+ * @example
4713
+ * ```ts
4714
+ * const batchJobs = await ai.batches.list({config: {'pageSize': 2}});
4715
+ * for await (const batchJob of batchJobs) {
4716
+ * console.log(batchJob);
4717
+ * }
4718
+ * ```
4719
+ */
4720
+ this.list = async (params = {}) => {
4721
+ return new Pager(PagedItem.PAGED_ITEM_BATCH_JOBS, (x) => this.listInternal(x), await this.listInternal(params), params);
4722
+ };
4703
4723
  /**
4704
4724
  * Create batch job.
4705
4725
  *
@@ -4748,23 +4768,6 @@ class Batches extends BaseModule {
4748
4768
  }
4749
4769
  return this.createEmbeddingsInternal(params);
4750
4770
  };
4751
- /**
4752
- * Lists batch job configurations.
4753
- *
4754
- * @param params - The parameters for the list request.
4755
- * @return The paginated results of the list of batch jobs.
4756
- *
4757
- * @example
4758
- * ```ts
4759
- * const batchJobs = await ai.batches.list({config: {'pageSize': 2}});
4760
- * for await (const batchJob of batchJobs) {
4761
- * console.log(batchJob);
4762
- * }
4763
- * ```
4764
- */
4765
- this.list = async (params = {}) => {
4766
- return new Pager(PagedItem.PAGED_ITEM_BATCH_JOBS, (x) => this.listInternal(x), await this.listInternal(params), params);
4767
- };
4768
4771
  }
4769
4772
  // Helper function to handle inlined generate content requests
4770
4773
  createInlinedGenerateContentRequest(params) {
@@ -5867,10 +5870,10 @@ class Caches extends BaseModule {
5867
5870
  super();
5868
5871
  this.apiClient = apiClient;
5869
5872
  /**
5870
- * Lists cached content configurations.
5873
+ * Lists cached contents.
5871
5874
  *
5872
5875
  * @param params - The parameters for the list request.
5873
- * @return The paginated results of the list of cached contents.
5876
+ * @return - A pager of cached contents.
5874
5877
  *
5875
5878
  * @example
5876
5879
  * ```ts
@@ -6740,19 +6743,16 @@ class Files extends BaseModule {
6740
6743
  super();
6741
6744
  this.apiClient = apiClient;
6742
6745
  /**
6743
- * Lists all current project files from the service.
6746
+ * Lists files.
6744
6747
  *
6745
- * @param params - The parameters for the list request
6746
- * @return The paginated results of the list of files
6748
+ * @param params - The parameters for the list request.
6749
+ * @return - A pager of files.
6747
6750
  *
6748
6751
  * @example
6749
- * The following code prints the names of all files from the service, the
6750
- * size of each page is 10.
6751
- *
6752
6752
  * ```ts
6753
- * const listResponse = await ai.files.list({config: {'pageSize': 10}});
6754
- * for await (const file of listResponse) {
6755
- * console.log(file.name);
6753
+ * const files = await ai.files.list({config: {'pageSize': 2}});
6754
+ * for await (const file of files) {
6755
+ * console.log(file);
6756
6756
  * }
6757
6757
  * ```
6758
6758
  */
@@ -11191,239 +11191,474 @@ function videoToVertex(fromObject) {
11191
11191
  * Copyright 2025 Google LLC
11192
11192
  * SPDX-License-Identifier: Apache-2.0
11193
11193
  */
11194
- const CONTENT_TYPE_HEADER = 'Content-Type';
11195
- const SERVER_TIMEOUT_HEADER = 'X-Server-Timeout';
11196
- const USER_AGENT_HEADER = 'User-Agent';
11197
- const GOOGLE_API_CLIENT_HEADER = 'x-goog-api-client';
11198
- const SDK_VERSION = '1.30.0'; // x-release-please-version
11199
- const LIBRARY_LABEL = `google-genai-sdk/${SDK_VERSION}`;
11200
- const VERTEX_AI_API_DEFAULT_VERSION = 'v1beta1';
11201
- const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
11202
- const responseLineRE = /^\s*data: (.*)(?:\n\n|\r\r|\r\n\r\n)/;
11203
- /**
11204
- * The ApiClient class is used to send requests to the Gemini API or Vertex AI
11205
- * endpoints.
11206
- */
11207
- class ApiClient {
11208
- constructor(opts) {
11209
- var _a, _b;
11210
- this.clientOptions = Object.assign(Object.assign({}, opts), { project: opts.project, location: opts.location, apiKey: opts.apiKey, vertexai: opts.vertexai });
11211
- const initHttpOptions = {};
11212
- if (this.clientOptions.vertexai) {
11213
- initHttpOptions.apiVersion =
11214
- (_a = this.clientOptions.apiVersion) !== null && _a !== void 0 ? _a : VERTEX_AI_API_DEFAULT_VERSION;
11215
- initHttpOptions.baseUrl = this.baseUrlFromProjectLocation();
11216
- this.normalizeAuthParameters();
11217
- }
11218
- else {
11219
- // Gemini API
11220
- initHttpOptions.apiVersion =
11221
- (_b = this.clientOptions.apiVersion) !== null && _b !== void 0 ? _b : GOOGLE_AI_API_DEFAULT_VERSION;
11222
- initHttpOptions.baseUrl = `https://generativelanguage.googleapis.com/`;
11223
- }
11224
- initHttpOptions.headers = this.getDefaultHeaders();
11225
- this.clientOptions.httpOptions = initHttpOptions;
11226
- if (opts.httpOptions) {
11227
- this.clientOptions.httpOptions = this.patchHttpOptions(initHttpOptions, opts.httpOptions);
11228
- }
11194
+ // Code generated by the Google Gen AI SDK generator DO NOT EDIT.
11195
+ function createFileSearchStoreConfigToMldev(fromObject, parentObject) {
11196
+ const toObject = {};
11197
+ const fromDisplayName = getValueByPath(fromObject, ['displayName']);
11198
+ if (parentObject !== undefined && fromDisplayName != null) {
11199
+ setValueByPath(parentObject, ['displayName'], fromDisplayName);
11229
11200
  }
11230
- /**
11231
- * Determines the base URL for Vertex AI based on project and location.
11232
- * Uses the global endpoint if location is 'global' or if project/location
11233
- * are not specified (implying API key usage).
11234
- * @private
11235
- */
11236
- baseUrlFromProjectLocation() {
11237
- if (this.clientOptions.project &&
11238
- this.clientOptions.location &&
11239
- this.clientOptions.location !== 'global') {
11240
- // Regional endpoint
11241
- return `https://${this.clientOptions.location}-aiplatform.googleapis.com/`;
11242
- }
11243
- // Global endpoint (covers 'global' location and API key usage)
11244
- return `https://aiplatform.googleapis.com/`;
11201
+ return toObject;
11202
+ }
11203
+ function createFileSearchStoreParametersToMldev(fromObject) {
11204
+ const toObject = {};
11205
+ const fromConfig = getValueByPath(fromObject, ['config']);
11206
+ if (fromConfig != null) {
11207
+ createFileSearchStoreConfigToMldev(fromConfig, toObject);
11245
11208
  }
11246
- /**
11247
- * Normalizes authentication parameters for Vertex AI.
11248
- * If project and location are provided, API key is cleared.
11249
- * If project and location are not provided (implying API key usage),
11250
- * project and location are cleared.
11251
- * @private
11252
- */
11253
- normalizeAuthParameters() {
11254
- if (this.clientOptions.project && this.clientOptions.location) {
11255
- // Using project/location for auth, clear potential API key
11256
- this.clientOptions.apiKey = undefined;
11257
- return;
11258
- }
11259
- // Using API key for auth (or no auth provided yet), clear project/location
11260
- this.clientOptions.project = undefined;
11261
- this.clientOptions.location = undefined;
11209
+ return toObject;
11210
+ }
11211
+ function deleteFileSearchStoreConfigToMldev(fromObject, parentObject) {
11212
+ const toObject = {};
11213
+ const fromForce = getValueByPath(fromObject, ['force']);
11214
+ if (parentObject !== undefined && fromForce != null) {
11215
+ setValueByPath(parentObject, ['_query', 'force'], fromForce);
11262
11216
  }
11263
- isVertexAI() {
11264
- var _a;
11265
- return (_a = this.clientOptions.vertexai) !== null && _a !== void 0 ? _a : false;
11217
+ return toObject;
11218
+ }
11219
+ function deleteFileSearchStoreParametersToMldev(fromObject) {
11220
+ const toObject = {};
11221
+ const fromName = getValueByPath(fromObject, ['name']);
11222
+ if (fromName != null) {
11223
+ setValueByPath(toObject, ['_url', 'name'], fromName);
11266
11224
  }
11267
- getProject() {
11268
- return this.clientOptions.project;
11225
+ const fromConfig = getValueByPath(fromObject, ['config']);
11226
+ if (fromConfig != null) {
11227
+ deleteFileSearchStoreConfigToMldev(fromConfig, toObject);
11269
11228
  }
11270
- getLocation() {
11271
- return this.clientOptions.location;
11229
+ return toObject;
11230
+ }
11231
+ function getFileSearchStoreParametersToMldev(fromObject) {
11232
+ const toObject = {};
11233
+ const fromName = getValueByPath(fromObject, ['name']);
11234
+ if (fromName != null) {
11235
+ setValueByPath(toObject, ['_url', 'name'], fromName);
11272
11236
  }
11273
- getApiVersion() {
11274
- if (this.clientOptions.httpOptions &&
11275
- this.clientOptions.httpOptions.apiVersion !== undefined) {
11276
- return this.clientOptions.httpOptions.apiVersion;
11237
+ return toObject;
11238
+ }
11239
+ function importFileConfigToMldev(fromObject, parentObject) {
11240
+ const toObject = {};
11241
+ const fromCustomMetadata = getValueByPath(fromObject, [
11242
+ 'customMetadata',
11243
+ ]);
11244
+ if (parentObject !== undefined && fromCustomMetadata != null) {
11245
+ let transformedList = fromCustomMetadata;
11246
+ if (Array.isArray(transformedList)) {
11247
+ transformedList = transformedList.map((item) => {
11248
+ return item;
11249
+ });
11277
11250
  }
11278
- throw new Error('API version is not set.');
11251
+ setValueByPath(parentObject, ['customMetadata'], transformedList);
11279
11252
  }
11280
- getBaseUrl() {
11281
- if (this.clientOptions.httpOptions &&
11282
- this.clientOptions.httpOptions.baseUrl !== undefined) {
11283
- return this.clientOptions.httpOptions.baseUrl;
11284
- }
11285
- throw new Error('Base URL is not set.');
11253
+ const fromChunkingConfig = getValueByPath(fromObject, [
11254
+ 'chunkingConfig',
11255
+ ]);
11256
+ if (parentObject !== undefined && fromChunkingConfig != null) {
11257
+ setValueByPath(parentObject, ['chunkingConfig'], fromChunkingConfig);
11286
11258
  }
11287
- getRequestUrl() {
11288
- return this.getRequestUrlInternal(this.clientOptions.httpOptions);
11259
+ return toObject;
11260
+ }
11261
+ function importFileOperationFromMldev(fromObject) {
11262
+ const toObject = {};
11263
+ const fromName = getValueByPath(fromObject, ['name']);
11264
+ if (fromName != null) {
11265
+ setValueByPath(toObject, ['name'], fromName);
11289
11266
  }
11290
- getHeaders() {
11291
- if (this.clientOptions.httpOptions &&
11292
- this.clientOptions.httpOptions.headers !== undefined) {
11293
- return this.clientOptions.httpOptions.headers;
11294
- }
11295
- else {
11296
- throw new Error('Headers are not set.');
11297
- }
11267
+ const fromMetadata = getValueByPath(fromObject, ['metadata']);
11268
+ if (fromMetadata != null) {
11269
+ setValueByPath(toObject, ['metadata'], fromMetadata);
11298
11270
  }
11299
- getRequestUrlInternal(httpOptions) {
11300
- if (!httpOptions ||
11301
- httpOptions.baseUrl === undefined ||
11302
- httpOptions.apiVersion === undefined) {
11303
- throw new Error('HTTP options are not correctly set.');
11304
- }
11305
- const baseUrl = httpOptions.baseUrl.endsWith('/')
11306
- ? httpOptions.baseUrl.slice(0, -1)
11307
- : httpOptions.baseUrl;
11308
- const urlElement = [baseUrl];
11309
- if (httpOptions.apiVersion && httpOptions.apiVersion !== '') {
11310
- urlElement.push(httpOptions.apiVersion);
11311
- }
11312
- return urlElement.join('/');
11271
+ const fromDone = getValueByPath(fromObject, ['done']);
11272
+ if (fromDone != null) {
11273
+ setValueByPath(toObject, ['done'], fromDone);
11313
11274
  }
11314
- getBaseResourcePath() {
11315
- return `projects/${this.clientOptions.project}/locations/${this.clientOptions.location}`;
11275
+ const fromError = getValueByPath(fromObject, ['error']);
11276
+ if (fromError != null) {
11277
+ setValueByPath(toObject, ['error'], fromError);
11316
11278
  }
11317
- getApiKey() {
11318
- return this.clientOptions.apiKey;
11279
+ const fromResponse = getValueByPath(fromObject, ['response']);
11280
+ if (fromResponse != null) {
11281
+ setValueByPath(toObject, ['response'], importFileResponseFromMldev(fromResponse));
11319
11282
  }
11320
- getWebsocketBaseUrl() {
11321
- const baseUrl = this.getBaseUrl();
11322
- const urlParts = new URL(baseUrl);
11323
- urlParts.protocol = urlParts.protocol == 'http:' ? 'ws' : 'wss';
11324
- return urlParts.toString();
11283
+ return toObject;
11284
+ }
11285
+ function importFileParametersToMldev(fromObject) {
11286
+ const toObject = {};
11287
+ const fromFileSearchStoreName = getValueByPath(fromObject, [
11288
+ 'fileSearchStoreName',
11289
+ ]);
11290
+ if (fromFileSearchStoreName != null) {
11291
+ setValueByPath(toObject, ['_url', 'file_search_store_name'], fromFileSearchStoreName);
11325
11292
  }
11326
- setBaseUrl(url) {
11327
- if (this.clientOptions.httpOptions) {
11328
- this.clientOptions.httpOptions.baseUrl = url;
11329
- }
11330
- else {
11331
- throw new Error('HTTP options are not correctly set.');
11332
- }
11293
+ const fromFileName = getValueByPath(fromObject, ['fileName']);
11294
+ if (fromFileName != null) {
11295
+ setValueByPath(toObject, ['fileName'], fromFileName);
11333
11296
  }
11334
- constructUrl(path, httpOptions, prependProjectLocation) {
11335
- const urlElement = [this.getRequestUrlInternal(httpOptions)];
11336
- if (prependProjectLocation) {
11337
- urlElement.push(this.getBaseResourcePath());
11338
- }
11339
- if (path !== '') {
11340
- urlElement.push(path);
11341
- }
11342
- const url = new URL(`${urlElement.join('/')}`);
11343
- return url;
11297
+ const fromConfig = getValueByPath(fromObject, ['config']);
11298
+ if (fromConfig != null) {
11299
+ importFileConfigToMldev(fromConfig, toObject);
11344
11300
  }
11345
- shouldPrependVertexProjectPath(request) {
11346
- if (this.clientOptions.apiKey) {
11347
- return false;
11348
- }
11349
- if (!this.clientOptions.vertexai) {
11350
- return false;
11351
- }
11352
- if (request.path.startsWith('projects/')) {
11353
- // Assume the path already starts with
11354
- // `projects/<project>/location/<location>`.
11355
- return false;
11356
- }
11357
- if (request.httpMethod === 'GET' &&
11358
- request.path.startsWith('publishers/google/models')) {
11359
- // These paths are used by Vertex's models.get and models.list
11360
- // calls. For base models Vertex does not accept a project/location
11361
- // prefix (for tuned model the prefix is required).
11362
- return false;
11363
- }
11364
- return true;
11301
+ return toObject;
11302
+ }
11303
+ function importFileResponseFromMldev(fromObject) {
11304
+ const toObject = {};
11305
+ const fromSdkHttpResponse = getValueByPath(fromObject, [
11306
+ 'sdkHttpResponse',
11307
+ ]);
11308
+ if (fromSdkHttpResponse != null) {
11309
+ setValueByPath(toObject, ['sdkHttpResponse'], fromSdkHttpResponse);
11365
11310
  }
11366
- async request(request) {
11367
- let patchedHttpOptions = this.clientOptions.httpOptions;
11368
- if (request.httpOptions) {
11369
- patchedHttpOptions = this.patchHttpOptions(this.clientOptions.httpOptions, request.httpOptions);
11311
+ const fromParent = getValueByPath(fromObject, ['parent']);
11312
+ if (fromParent != null) {
11313
+ setValueByPath(toObject, ['parent'], fromParent);
11314
+ }
11315
+ const fromDocumentName = getValueByPath(fromObject, ['documentName']);
11316
+ if (fromDocumentName != null) {
11317
+ setValueByPath(toObject, ['documentName'], fromDocumentName);
11318
+ }
11319
+ return toObject;
11320
+ }
11321
+ function listFileSearchStoresConfigToMldev(fromObject, parentObject) {
11322
+ const toObject = {};
11323
+ const fromPageSize = getValueByPath(fromObject, ['pageSize']);
11324
+ if (parentObject !== undefined && fromPageSize != null) {
11325
+ setValueByPath(parentObject, ['_query', 'pageSize'], fromPageSize);
11326
+ }
11327
+ const fromPageToken = getValueByPath(fromObject, ['pageToken']);
11328
+ if (parentObject !== undefined && fromPageToken != null) {
11329
+ setValueByPath(parentObject, ['_query', 'pageToken'], fromPageToken);
11330
+ }
11331
+ return toObject;
11332
+ }
11333
+ function listFileSearchStoresParametersToMldev(fromObject) {
11334
+ const toObject = {};
11335
+ const fromConfig = getValueByPath(fromObject, ['config']);
11336
+ if (fromConfig != null) {
11337
+ listFileSearchStoresConfigToMldev(fromConfig, toObject);
11338
+ }
11339
+ return toObject;
11340
+ }
11341
+ function listFileSearchStoresResponseFromMldev(fromObject) {
11342
+ const toObject = {};
11343
+ const fromSdkHttpResponse = getValueByPath(fromObject, [
11344
+ 'sdkHttpResponse',
11345
+ ]);
11346
+ if (fromSdkHttpResponse != null) {
11347
+ setValueByPath(toObject, ['sdkHttpResponse'], fromSdkHttpResponse);
11348
+ }
11349
+ const fromNextPageToken = getValueByPath(fromObject, [
11350
+ 'nextPageToken',
11351
+ ]);
11352
+ if (fromNextPageToken != null) {
11353
+ setValueByPath(toObject, ['nextPageToken'], fromNextPageToken);
11354
+ }
11355
+ const fromFileSearchStores = getValueByPath(fromObject, [
11356
+ 'fileSearchStores',
11357
+ ]);
11358
+ if (fromFileSearchStores != null) {
11359
+ let transformedList = fromFileSearchStores;
11360
+ if (Array.isArray(transformedList)) {
11361
+ transformedList = transformedList.map((item) => {
11362
+ return item;
11363
+ });
11370
11364
  }
11371
- const prependProjectLocation = this.shouldPrependVertexProjectPath(request);
11372
- const url = this.constructUrl(request.path, patchedHttpOptions, prependProjectLocation);
11373
- if (request.queryParams) {
11374
- for (const [key, value] of Object.entries(request.queryParams)) {
11375
- url.searchParams.append(key, String(value));
11376
- }
11365
+ setValueByPath(toObject, ['fileSearchStores'], transformedList);
11366
+ }
11367
+ return toObject;
11368
+ }
11369
+ function uploadToFileSearchStoreConfigToMldev(fromObject, parentObject) {
11370
+ const toObject = {};
11371
+ const fromMimeType = getValueByPath(fromObject, ['mimeType']);
11372
+ if (parentObject !== undefined && fromMimeType != null) {
11373
+ setValueByPath(parentObject, ['mimeType'], fromMimeType);
11374
+ }
11375
+ const fromDisplayName = getValueByPath(fromObject, ['displayName']);
11376
+ if (parentObject !== undefined && fromDisplayName != null) {
11377
+ setValueByPath(parentObject, ['displayName'], fromDisplayName);
11378
+ }
11379
+ const fromCustomMetadata = getValueByPath(fromObject, [
11380
+ 'customMetadata',
11381
+ ]);
11382
+ if (parentObject !== undefined && fromCustomMetadata != null) {
11383
+ let transformedList = fromCustomMetadata;
11384
+ if (Array.isArray(transformedList)) {
11385
+ transformedList = transformedList.map((item) => {
11386
+ return item;
11387
+ });
11377
11388
  }
11378
- let requestInit = {};
11379
- if (request.httpMethod === 'GET') {
11380
- if (request.body && request.body !== '{}') {
11381
- throw new Error('Request body should be empty for GET request, but got non empty request body');
11382
- }
11389
+ setValueByPath(parentObject, ['customMetadata'], transformedList);
11390
+ }
11391
+ const fromChunkingConfig = getValueByPath(fromObject, [
11392
+ 'chunkingConfig',
11393
+ ]);
11394
+ if (parentObject !== undefined && fromChunkingConfig != null) {
11395
+ setValueByPath(parentObject, ['chunkingConfig'], fromChunkingConfig);
11396
+ }
11397
+ return toObject;
11398
+ }
11399
+ function uploadToFileSearchStoreParametersToMldev(fromObject) {
11400
+ const toObject = {};
11401
+ const fromFileSearchStoreName = getValueByPath(fromObject, [
11402
+ 'fileSearchStoreName',
11403
+ ]);
11404
+ if (fromFileSearchStoreName != null) {
11405
+ setValueByPath(toObject, ['_url', 'file_search_store_name'], fromFileSearchStoreName);
11406
+ }
11407
+ const fromConfig = getValueByPath(fromObject, ['config']);
11408
+ if (fromConfig != null) {
11409
+ uploadToFileSearchStoreConfigToMldev(fromConfig, toObject);
11410
+ }
11411
+ return toObject;
11412
+ }
11413
+ function uploadToFileSearchStoreResumableResponseFromMldev(fromObject) {
11414
+ const toObject = {};
11415
+ const fromSdkHttpResponse = getValueByPath(fromObject, [
11416
+ 'sdkHttpResponse',
11417
+ ]);
11418
+ if (fromSdkHttpResponse != null) {
11419
+ setValueByPath(toObject, ['sdkHttpResponse'], fromSdkHttpResponse);
11420
+ }
11421
+ return toObject;
11422
+ }
11423
+
11424
+ /**
11425
+ * @license
11426
+ * Copyright 2025 Google LLC
11427
+ * SPDX-License-Identifier: Apache-2.0
11428
+ */
11429
+ const CONTENT_TYPE_HEADER = 'Content-Type';
11430
+ const SERVER_TIMEOUT_HEADER = 'X-Server-Timeout';
11431
+ const USER_AGENT_HEADER = 'User-Agent';
11432
+ const GOOGLE_API_CLIENT_HEADER = 'x-goog-api-client';
11433
+ const SDK_VERSION = '1.31.0'; // x-release-please-version
11434
+ const LIBRARY_LABEL = `google-genai-sdk/${SDK_VERSION}`;
11435
+ const VERTEX_AI_API_DEFAULT_VERSION = 'v1beta1';
11436
+ const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
11437
+ const responseLineRE = /^\s*data: (.*)(?:\n\n|\r\r|\r\n\r\n)/;
11438
+ /**
11439
+ * The ApiClient class is used to send requests to the Gemini API or Vertex AI
11440
+ * endpoints.
11441
+ */
11442
+ class ApiClient {
11443
+ constructor(opts) {
11444
+ var _a, _b;
11445
+ this.clientOptions = Object.assign(Object.assign({}, opts), { project: opts.project, location: opts.location, apiKey: opts.apiKey, vertexai: opts.vertexai });
11446
+ const initHttpOptions = {};
11447
+ if (this.clientOptions.vertexai) {
11448
+ initHttpOptions.apiVersion =
11449
+ (_a = this.clientOptions.apiVersion) !== null && _a !== void 0 ? _a : VERTEX_AI_API_DEFAULT_VERSION;
11450
+ initHttpOptions.baseUrl = this.baseUrlFromProjectLocation();
11451
+ this.normalizeAuthParameters();
11383
11452
  }
11384
11453
  else {
11385
- requestInit.body = request.body;
11454
+ // Gemini API
11455
+ initHttpOptions.apiVersion =
11456
+ (_b = this.clientOptions.apiVersion) !== null && _b !== void 0 ? _b : GOOGLE_AI_API_DEFAULT_VERSION;
11457
+ initHttpOptions.baseUrl = `https://generativelanguage.googleapis.com/`;
11386
11458
  }
11387
- requestInit = await this.includeExtraHttpOptionsToRequestInit(requestInit, patchedHttpOptions, url.toString(), request.abortSignal);
11388
- return this.unaryApiCall(url, requestInit, request.httpMethod);
11389
- }
11390
- patchHttpOptions(baseHttpOptions, requestHttpOptions) {
11391
- const patchedHttpOptions = JSON.parse(JSON.stringify(baseHttpOptions));
11392
- for (const [key, value] of Object.entries(requestHttpOptions)) {
11393
- // Records compile to objects.
11394
- if (typeof value === 'object') {
11395
- // @ts-expect-error TS2345TS7053: Element implicitly has an 'any' type
11396
- // because expression of type 'string' can't be used to index type
11397
- // 'HttpOptions'.
11398
- patchedHttpOptions[key] = Object.assign(Object.assign({}, patchedHttpOptions[key]), value);
11399
- }
11400
- else if (value !== undefined) {
11401
- // @ts-expect-error TS2345TS7053: Element implicitly has an 'any' type
11402
- // because expression of type 'string' can't be used to index type
11403
- // 'HttpOptions'.
11404
- patchedHttpOptions[key] = value;
11405
- }
11459
+ initHttpOptions.headers = this.getDefaultHeaders();
11460
+ this.clientOptions.httpOptions = initHttpOptions;
11461
+ if (opts.httpOptions) {
11462
+ this.clientOptions.httpOptions = this.patchHttpOptions(initHttpOptions, opts.httpOptions);
11406
11463
  }
11407
- return patchedHttpOptions;
11408
11464
  }
11409
- async requestStream(request) {
11410
- let patchedHttpOptions = this.clientOptions.httpOptions;
11411
- if (request.httpOptions) {
11412
- patchedHttpOptions = this.patchHttpOptions(this.clientOptions.httpOptions, request.httpOptions);
11465
+ /**
11466
+ * Determines the base URL for Vertex AI based on project and location.
11467
+ * Uses the global endpoint if location is 'global' or if project/location
11468
+ * are not specified (implying API key usage).
11469
+ * @private
11470
+ */
11471
+ baseUrlFromProjectLocation() {
11472
+ if (this.clientOptions.project &&
11473
+ this.clientOptions.location &&
11474
+ this.clientOptions.location !== 'global') {
11475
+ // Regional endpoint
11476
+ return `https://${this.clientOptions.location}-aiplatform.googleapis.com/`;
11413
11477
  }
11414
- const prependProjectLocation = this.shouldPrependVertexProjectPath(request);
11415
- const url = this.constructUrl(request.path, patchedHttpOptions, prependProjectLocation);
11416
- if (!url.searchParams.has('alt') || url.searchParams.get('alt') !== 'sse') {
11417
- url.searchParams.set('alt', 'sse');
11478
+ // Global endpoint (covers 'global' location and API key usage)
11479
+ return `https://aiplatform.googleapis.com/`;
11480
+ }
11481
+ /**
11482
+ * Normalizes authentication parameters for Vertex AI.
11483
+ * If project and location are provided, API key is cleared.
11484
+ * If project and location are not provided (implying API key usage),
11485
+ * project and location are cleared.
11486
+ * @private
11487
+ */
11488
+ normalizeAuthParameters() {
11489
+ if (this.clientOptions.project && this.clientOptions.location) {
11490
+ // Using project/location for auth, clear potential API key
11491
+ this.clientOptions.apiKey = undefined;
11492
+ return;
11418
11493
  }
11419
- let requestInit = {};
11420
- requestInit.body = request.body;
11421
- requestInit = await this.includeExtraHttpOptionsToRequestInit(requestInit, patchedHttpOptions, url.toString(), request.abortSignal);
11422
- return this.streamApiCall(url, requestInit, request.httpMethod);
11494
+ // Using API key for auth (or no auth provided yet), clear project/location
11495
+ this.clientOptions.project = undefined;
11496
+ this.clientOptions.location = undefined;
11423
11497
  }
11424
- async includeExtraHttpOptionsToRequestInit(requestInit, httpOptions, url, abortSignal) {
11425
- if ((httpOptions && httpOptions.timeout) || abortSignal) {
11426
- const abortController = new AbortController();
11498
+ isVertexAI() {
11499
+ var _a;
11500
+ return (_a = this.clientOptions.vertexai) !== null && _a !== void 0 ? _a : false;
11501
+ }
11502
+ getProject() {
11503
+ return this.clientOptions.project;
11504
+ }
11505
+ getLocation() {
11506
+ return this.clientOptions.location;
11507
+ }
11508
+ getApiVersion() {
11509
+ if (this.clientOptions.httpOptions &&
11510
+ this.clientOptions.httpOptions.apiVersion !== undefined) {
11511
+ return this.clientOptions.httpOptions.apiVersion;
11512
+ }
11513
+ throw new Error('API version is not set.');
11514
+ }
11515
+ getBaseUrl() {
11516
+ if (this.clientOptions.httpOptions &&
11517
+ this.clientOptions.httpOptions.baseUrl !== undefined) {
11518
+ return this.clientOptions.httpOptions.baseUrl;
11519
+ }
11520
+ throw new Error('Base URL is not set.');
11521
+ }
11522
+ getRequestUrl() {
11523
+ return this.getRequestUrlInternal(this.clientOptions.httpOptions);
11524
+ }
11525
+ getHeaders() {
11526
+ if (this.clientOptions.httpOptions &&
11527
+ this.clientOptions.httpOptions.headers !== undefined) {
11528
+ return this.clientOptions.httpOptions.headers;
11529
+ }
11530
+ else {
11531
+ throw new Error('Headers are not set.');
11532
+ }
11533
+ }
11534
+ getRequestUrlInternal(httpOptions) {
11535
+ if (!httpOptions ||
11536
+ httpOptions.baseUrl === undefined ||
11537
+ httpOptions.apiVersion === undefined) {
11538
+ throw new Error('HTTP options are not correctly set.');
11539
+ }
11540
+ const baseUrl = httpOptions.baseUrl.endsWith('/')
11541
+ ? httpOptions.baseUrl.slice(0, -1)
11542
+ : httpOptions.baseUrl;
11543
+ const urlElement = [baseUrl];
11544
+ if (httpOptions.apiVersion && httpOptions.apiVersion !== '') {
11545
+ urlElement.push(httpOptions.apiVersion);
11546
+ }
11547
+ return urlElement.join('/');
11548
+ }
11549
+ getBaseResourcePath() {
11550
+ return `projects/${this.clientOptions.project}/locations/${this.clientOptions.location}`;
11551
+ }
11552
+ getApiKey() {
11553
+ return this.clientOptions.apiKey;
11554
+ }
11555
+ getWebsocketBaseUrl() {
11556
+ const baseUrl = this.getBaseUrl();
11557
+ const urlParts = new URL(baseUrl);
11558
+ urlParts.protocol = urlParts.protocol == 'http:' ? 'ws' : 'wss';
11559
+ return urlParts.toString();
11560
+ }
11561
+ setBaseUrl(url) {
11562
+ if (this.clientOptions.httpOptions) {
11563
+ this.clientOptions.httpOptions.baseUrl = url;
11564
+ }
11565
+ else {
11566
+ throw new Error('HTTP options are not correctly set.');
11567
+ }
11568
+ }
11569
+ constructUrl(path, httpOptions, prependProjectLocation) {
11570
+ const urlElement = [this.getRequestUrlInternal(httpOptions)];
11571
+ if (prependProjectLocation) {
11572
+ urlElement.push(this.getBaseResourcePath());
11573
+ }
11574
+ if (path !== '') {
11575
+ urlElement.push(path);
11576
+ }
11577
+ const url = new URL(`${urlElement.join('/')}`);
11578
+ return url;
11579
+ }
11580
+ shouldPrependVertexProjectPath(request) {
11581
+ if (this.clientOptions.apiKey) {
11582
+ return false;
11583
+ }
11584
+ if (!this.clientOptions.vertexai) {
11585
+ return false;
11586
+ }
11587
+ if (request.path.startsWith('projects/')) {
11588
+ // Assume the path already starts with
11589
+ // `projects/<project>/location/<location>`.
11590
+ return false;
11591
+ }
11592
+ if (request.httpMethod === 'GET' &&
11593
+ request.path.startsWith('publishers/google/models')) {
11594
+ // These paths are used by Vertex's models.get and models.list
11595
+ // calls. For base models Vertex does not accept a project/location
11596
+ // prefix (for tuned model the prefix is required).
11597
+ return false;
11598
+ }
11599
+ return true;
11600
+ }
11601
+ async request(request) {
11602
+ let patchedHttpOptions = this.clientOptions.httpOptions;
11603
+ if (request.httpOptions) {
11604
+ patchedHttpOptions = this.patchHttpOptions(this.clientOptions.httpOptions, request.httpOptions);
11605
+ }
11606
+ const prependProjectLocation = this.shouldPrependVertexProjectPath(request);
11607
+ const url = this.constructUrl(request.path, patchedHttpOptions, prependProjectLocation);
11608
+ if (request.queryParams) {
11609
+ for (const [key, value] of Object.entries(request.queryParams)) {
11610
+ url.searchParams.append(key, String(value));
11611
+ }
11612
+ }
11613
+ let requestInit = {};
11614
+ if (request.httpMethod === 'GET') {
11615
+ if (request.body && request.body !== '{}') {
11616
+ throw new Error('Request body should be empty for GET request, but got non empty request body');
11617
+ }
11618
+ }
11619
+ else {
11620
+ requestInit.body = request.body;
11621
+ }
11622
+ requestInit = await this.includeExtraHttpOptionsToRequestInit(requestInit, patchedHttpOptions, url.toString(), request.abortSignal);
11623
+ return this.unaryApiCall(url, requestInit, request.httpMethod);
11624
+ }
11625
+ patchHttpOptions(baseHttpOptions, requestHttpOptions) {
11626
+ const patchedHttpOptions = JSON.parse(JSON.stringify(baseHttpOptions));
11627
+ for (const [key, value] of Object.entries(requestHttpOptions)) {
11628
+ // Records compile to objects.
11629
+ if (typeof value === 'object') {
11630
+ // @ts-expect-error TS2345TS7053: Element implicitly has an 'any' type
11631
+ // because expression of type 'string' can't be used to index type
11632
+ // 'HttpOptions'.
11633
+ patchedHttpOptions[key] = Object.assign(Object.assign({}, patchedHttpOptions[key]), value);
11634
+ }
11635
+ else if (value !== undefined) {
11636
+ // @ts-expect-error TS2345TS7053: Element implicitly has an 'any' type
11637
+ // because expression of type 'string' can't be used to index type
11638
+ // 'HttpOptions'.
11639
+ patchedHttpOptions[key] = value;
11640
+ }
11641
+ }
11642
+ return patchedHttpOptions;
11643
+ }
11644
+ async requestStream(request) {
11645
+ let patchedHttpOptions = this.clientOptions.httpOptions;
11646
+ if (request.httpOptions) {
11647
+ patchedHttpOptions = this.patchHttpOptions(this.clientOptions.httpOptions, request.httpOptions);
11648
+ }
11649
+ const prependProjectLocation = this.shouldPrependVertexProjectPath(request);
11650
+ const url = this.constructUrl(request.path, patchedHttpOptions, prependProjectLocation);
11651
+ if (!url.searchParams.has('alt') || url.searchParams.get('alt') !== 'sse') {
11652
+ url.searchParams.set('alt', 'sse');
11653
+ }
11654
+ let requestInit = {};
11655
+ requestInit.body = request.body;
11656
+ requestInit = await this.includeExtraHttpOptionsToRequestInit(requestInit, patchedHttpOptions, url.toString(), request.abortSignal);
11657
+ return this.streamApiCall(url, requestInit, request.httpMethod);
11658
+ }
11659
+ async includeExtraHttpOptionsToRequestInit(requestInit, httpOptions, url, abortSignal) {
11660
+ if ((httpOptions && httpOptions.timeout) || abortSignal) {
11661
+ const abortController = new AbortController();
11427
11662
  const signal = abortController.signal;
11428
11663
  if (httpOptions.timeout && (httpOptions === null || httpOptions === void 0 ? void 0 : httpOptions.timeout) > 0) {
11429
11664
  const timeoutHandle = setTimeout(() => abortController.abort(), httpOptions.timeout);
@@ -11644,11 +11879,8 @@ class ApiClient {
11644
11879
  const path = `upload/v1beta/${fileSearchStoreName}:uploadToFileSearchStore`;
11645
11880
  const fileName = this.getFileName(file);
11646
11881
  const body = {};
11647
- if (config === null || config === void 0 ? void 0 : config.customMetadata) {
11648
- body['customMetadata'] = config.customMetadata;
11649
- }
11650
- if (config === null || config === void 0 ? void 0 : config.chunkingConfig) {
11651
- body['chunkingConfig'] = config.chunkingConfig;
11882
+ if (config != null) {
11883
+ uploadToFileSearchStoreConfigToMldev(config, body);
11652
11884
  }
11653
11885
  const uploadUrl = await this.fetchUploadUrl(path, sizeBytes, mimeType, fileName, body, config === null || config === void 0 ? void 0 : config.httpOptions);
11654
11886
  return uploader.uploadToFileSearchStore(file, uploadUrl, this);
@@ -14200,594 +14432,41 @@ class Models extends BaseModule {
14200
14432
  abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
14201
14433
  })
14202
14434
  .then((httpResponse) => {
14203
- return httpResponse.json();
14204
- });
14205
- return response.then((apiResponse) => {
14206
- const resp = generateVideosOperationFromVertex(apiResponse);
14207
- const typedResp = new GenerateVideosOperation();
14208
- Object.assign(typedResp, resp);
14209
- return typedResp;
14210
- });
14211
- }
14212
- else {
14213
- const body = generateVideosParametersToMldev(this.apiClient, params);
14214
- path = formatMap('{model}:predictLongRunning', body['_url']);
14215
- queryParams = body['_query'];
14216
- delete body['_url'];
14217
- delete body['_query'];
14218
- response = this.apiClient
14219
- .request({
14220
- path: path,
14221
- queryParams: queryParams,
14222
- body: JSON.stringify(body),
14223
- httpMethod: 'POST',
14224
- httpOptions: (_c = params.config) === null || _c === void 0 ? void 0 : _c.httpOptions,
14225
- abortSignal: (_d = params.config) === null || _d === void 0 ? void 0 : _d.abortSignal,
14226
- })
14227
- .then((httpResponse) => {
14228
- return httpResponse.json();
14229
- });
14230
- return response.then((apiResponse) => {
14231
- const resp = generateVideosOperationFromMldev(apiResponse);
14232
- const typedResp = new GenerateVideosOperation();
14233
- Object.assign(typedResp, resp);
14234
- return typedResp;
14235
- });
14236
- }
14237
- }
14238
- }
14239
-
14240
- /**
14241
- * @license
14242
- * Copyright 2025 Google LLC
14243
- * SPDX-License-Identifier: Apache-2.0
14244
- */
14245
- class Operations extends BaseModule {
14246
- constructor(apiClient) {
14247
- super();
14248
- this.apiClient = apiClient;
14249
- }
14250
- /**
14251
- * Gets the status of a long-running operation.
14252
- *
14253
- * @param parameters The parameters for the get operation request.
14254
- * @return The updated Operation object, with the latest status or result.
14255
- */
14256
- async getVideosOperation(parameters) {
14257
- const operation = parameters.operation;
14258
- const config = parameters.config;
14259
- if (operation.name === undefined || operation.name === '') {
14260
- throw new Error('Operation name is required.');
14261
- }
14262
- if (this.apiClient.isVertexAI()) {
14263
- const resourceName = operation.name.split('/operations/')[0];
14264
- let httpOptions = undefined;
14265
- if (config && 'httpOptions' in config) {
14266
- httpOptions = config.httpOptions;
14267
- }
14268
- const rawOperation = await this.fetchPredictVideosOperationInternal({
14269
- operationName: operation.name,
14270
- resourceName: resourceName,
14271
- config: { httpOptions: httpOptions },
14272
- });
14273
- return operation._fromAPIResponse({
14274
- apiResponse: rawOperation,
14275
- _isVertexAI: true,
14276
- });
14277
- }
14278
- else {
14279
- const rawOperation = await this.getVideosOperationInternal({
14280
- operationName: operation.name,
14281
- config: config,
14282
- });
14283
- return operation._fromAPIResponse({
14284
- apiResponse: rawOperation,
14285
- _isVertexAI: false,
14286
- });
14287
- }
14288
- }
14289
- /**
14290
- * Gets the status of a long-running operation.
14291
- *
14292
- * @param parameters The parameters for the get operation request.
14293
- * @return The updated Operation object, with the latest status or result.
14294
- */
14295
- async get(parameters) {
14296
- const operation = parameters.operation;
14297
- const config = parameters.config;
14298
- if (operation.name === undefined || operation.name === '') {
14299
- throw new Error('Operation name is required.');
14300
- }
14301
- if (this.apiClient.isVertexAI()) {
14302
- const resourceName = operation.name.split('/operations/')[0];
14303
- let httpOptions = undefined;
14304
- if (config && 'httpOptions' in config) {
14305
- httpOptions = config.httpOptions;
14306
- }
14307
- const rawOperation = await this.fetchPredictVideosOperationInternal({
14308
- operationName: operation.name,
14309
- resourceName: resourceName,
14310
- config: { httpOptions: httpOptions },
14311
- });
14312
- return operation._fromAPIResponse({
14313
- apiResponse: rawOperation,
14314
- _isVertexAI: true,
14315
- });
14316
- }
14317
- else {
14318
- const rawOperation = await this.getVideosOperationInternal({
14319
- operationName: operation.name,
14320
- config: config,
14321
- });
14322
- return operation._fromAPIResponse({
14323
- apiResponse: rawOperation,
14324
- _isVertexAI: false,
14325
- });
14326
- }
14327
- }
14328
- async getVideosOperationInternal(params) {
14329
- var _a, _b, _c, _d;
14330
- let response;
14331
- let path = '';
14332
- let queryParams = {};
14333
- if (this.apiClient.isVertexAI()) {
14334
- const body = getOperationParametersToVertex(params);
14335
- path = formatMap('{operationName}', body['_url']);
14336
- queryParams = body['_query'];
14337
- delete body['_url'];
14338
- delete body['_query'];
14339
- response = this.apiClient
14340
- .request({
14341
- path: path,
14342
- queryParams: queryParams,
14343
- body: JSON.stringify(body),
14344
- httpMethod: 'GET',
14345
- httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
14346
- abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
14347
- })
14348
- .then((httpResponse) => {
14349
- return httpResponse.json();
14350
- });
14351
- return response;
14352
- }
14353
- else {
14354
- const body = getOperationParametersToMldev(params);
14355
- path = formatMap('{operationName}', body['_url']);
14356
- queryParams = body['_query'];
14357
- delete body['_url'];
14358
- delete body['_query'];
14359
- response = this.apiClient
14360
- .request({
14361
- path: path,
14362
- queryParams: queryParams,
14363
- body: JSON.stringify(body),
14364
- httpMethod: 'GET',
14365
- httpOptions: (_c = params.config) === null || _c === void 0 ? void 0 : _c.httpOptions,
14366
- abortSignal: (_d = params.config) === null || _d === void 0 ? void 0 : _d.abortSignal,
14367
- })
14368
- .then((httpResponse) => {
14369
- return httpResponse.json();
14370
- });
14371
- return response;
14372
- }
14373
- }
14374
- async fetchPredictVideosOperationInternal(params) {
14375
- var _a, _b;
14376
- let response;
14377
- let path = '';
14378
- let queryParams = {};
14379
- if (this.apiClient.isVertexAI()) {
14380
- const body = fetchPredictOperationParametersToVertex(params);
14381
- path = formatMap('{resourceName}:fetchPredictOperation', body['_url']);
14382
- queryParams = body['_query'];
14383
- delete body['_url'];
14384
- delete body['_query'];
14385
- response = this.apiClient
14386
- .request({
14387
- path: path,
14388
- queryParams: queryParams,
14389
- body: JSON.stringify(body),
14390
- httpMethod: 'POST',
14391
- httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
14392
- abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
14393
- })
14394
- .then((httpResponse) => {
14395
- return httpResponse.json();
14396
- });
14397
- return response;
14398
- }
14399
- else {
14400
- throw new Error('This method is only supported by the Vertex AI.');
14401
- }
14402
- }
14403
- }
14404
-
14405
- /**
14406
- * @license
14407
- * Copyright 2025 Google LLC
14408
- * SPDX-License-Identifier: Apache-2.0
14409
- */
14410
- function blobToMldev(fromObject) {
14411
- const toObject = {};
14412
- const fromData = getValueByPath(fromObject, ['data']);
14413
- if (fromData != null) {
14414
- setValueByPath(toObject, ['data'], fromData);
14415
- }
14416
- if (getValueByPath(fromObject, ['displayName']) !== undefined) {
14417
- throw new Error('displayName parameter is not supported in Gemini API.');
14418
- }
14419
- const fromMimeType = getValueByPath(fromObject, ['mimeType']);
14420
- if (fromMimeType != null) {
14421
- setValueByPath(toObject, ['mimeType'], fromMimeType);
14422
- }
14423
- return toObject;
14424
- }
14425
- function contentToMldev(fromObject) {
14426
- const toObject = {};
14427
- const fromParts = getValueByPath(fromObject, ['parts']);
14428
- if (fromParts != null) {
14429
- let transformedList = fromParts;
14430
- if (Array.isArray(transformedList)) {
14431
- transformedList = transformedList.map((item) => {
14432
- return partToMldev(item);
14433
- });
14434
- }
14435
- setValueByPath(toObject, ['parts'], transformedList);
14436
- }
14437
- const fromRole = getValueByPath(fromObject, ['role']);
14438
- if (fromRole != null) {
14439
- setValueByPath(toObject, ['role'], fromRole);
14440
- }
14441
- return toObject;
14442
- }
14443
- function createAuthTokenConfigToMldev(apiClient, fromObject, parentObject) {
14444
- const toObject = {};
14445
- const fromExpireTime = getValueByPath(fromObject, ['expireTime']);
14446
- if (parentObject !== undefined && fromExpireTime != null) {
14447
- setValueByPath(parentObject, ['expireTime'], fromExpireTime);
14448
- }
14449
- const fromNewSessionExpireTime = getValueByPath(fromObject, [
14450
- 'newSessionExpireTime',
14451
- ]);
14452
- if (parentObject !== undefined && fromNewSessionExpireTime != null) {
14453
- setValueByPath(parentObject, ['newSessionExpireTime'], fromNewSessionExpireTime);
14454
- }
14455
- const fromUses = getValueByPath(fromObject, ['uses']);
14456
- if (parentObject !== undefined && fromUses != null) {
14457
- setValueByPath(parentObject, ['uses'], fromUses);
14458
- }
14459
- const fromLiveConnectConstraints = getValueByPath(fromObject, [
14460
- 'liveConnectConstraints',
14461
- ]);
14462
- if (parentObject !== undefined && fromLiveConnectConstraints != null) {
14463
- setValueByPath(parentObject, ['bidiGenerateContentSetup'], liveConnectConstraintsToMldev(apiClient, fromLiveConnectConstraints));
14464
- }
14465
- const fromLockAdditionalFields = getValueByPath(fromObject, [
14466
- 'lockAdditionalFields',
14467
- ]);
14468
- if (parentObject !== undefined && fromLockAdditionalFields != null) {
14469
- setValueByPath(parentObject, ['fieldMask'], fromLockAdditionalFields);
14470
- }
14471
- return toObject;
14472
- }
14473
- function createAuthTokenParametersToMldev(apiClient, fromObject) {
14474
- const toObject = {};
14475
- const fromConfig = getValueByPath(fromObject, ['config']);
14476
- if (fromConfig != null) {
14477
- setValueByPath(toObject, ['config'], createAuthTokenConfigToMldev(apiClient, fromConfig, toObject));
14478
- }
14479
- return toObject;
14480
- }
14481
- function fileDataToMldev(fromObject) {
14482
- const toObject = {};
14483
- if (getValueByPath(fromObject, ['displayName']) !== undefined) {
14484
- throw new Error('displayName parameter is not supported in Gemini API.');
14485
- }
14486
- const fromFileUri = getValueByPath(fromObject, ['fileUri']);
14487
- if (fromFileUri != null) {
14488
- setValueByPath(toObject, ['fileUri'], fromFileUri);
14489
- }
14490
- const fromMimeType = getValueByPath(fromObject, ['mimeType']);
14491
- if (fromMimeType != null) {
14492
- setValueByPath(toObject, ['mimeType'], fromMimeType);
14493
- }
14494
- return toObject;
14495
- }
14496
- function functionCallToMldev(fromObject) {
14497
- const toObject = {};
14498
- const fromId = getValueByPath(fromObject, ['id']);
14499
- if (fromId != null) {
14500
- setValueByPath(toObject, ['id'], fromId);
14501
- }
14502
- const fromArgs = getValueByPath(fromObject, ['args']);
14503
- if (fromArgs != null) {
14504
- setValueByPath(toObject, ['args'], fromArgs);
14505
- }
14506
- const fromName = getValueByPath(fromObject, ['name']);
14507
- if (fromName != null) {
14508
- setValueByPath(toObject, ['name'], fromName);
14509
- }
14510
- if (getValueByPath(fromObject, ['partialArgs']) !== undefined) {
14511
- throw new Error('partialArgs parameter is not supported in Gemini API.');
14512
- }
14513
- if (getValueByPath(fromObject, ['willContinue']) !== undefined) {
14514
- throw new Error('willContinue parameter is not supported in Gemini API.');
14515
- }
14516
- return toObject;
14517
- }
14518
- function googleMapsToMldev(fromObject) {
14519
- const toObject = {};
14520
- if (getValueByPath(fromObject, ['authConfig']) !== undefined) {
14521
- throw new Error('authConfig parameter is not supported in Gemini API.');
14522
- }
14523
- const fromEnableWidget = getValueByPath(fromObject, ['enableWidget']);
14524
- if (fromEnableWidget != null) {
14525
- setValueByPath(toObject, ['enableWidget'], fromEnableWidget);
14526
- }
14527
- return toObject;
14528
- }
14529
- function googleSearchToMldev(fromObject) {
14530
- const toObject = {};
14531
- if (getValueByPath(fromObject, ['excludeDomains']) !== undefined) {
14532
- throw new Error('excludeDomains parameter is not supported in Gemini API.');
14533
- }
14534
- if (getValueByPath(fromObject, ['blockingConfidence']) !== undefined) {
14535
- throw new Error('blockingConfidence parameter is not supported in Gemini API.');
14536
- }
14537
- const fromTimeRangeFilter = getValueByPath(fromObject, [
14538
- 'timeRangeFilter',
14539
- ]);
14540
- if (fromTimeRangeFilter != null) {
14541
- setValueByPath(toObject, ['timeRangeFilter'], fromTimeRangeFilter);
14542
- }
14543
- return toObject;
14544
- }
14545
- function liveConnectConfigToMldev(fromObject, parentObject) {
14546
- const toObject = {};
14547
- const fromGenerationConfig = getValueByPath(fromObject, [
14548
- 'generationConfig',
14549
- ]);
14550
- if (parentObject !== undefined && fromGenerationConfig != null) {
14551
- setValueByPath(parentObject, ['setup', 'generationConfig'], fromGenerationConfig);
14552
- }
14553
- const fromResponseModalities = getValueByPath(fromObject, [
14554
- 'responseModalities',
14555
- ]);
14556
- if (parentObject !== undefined && fromResponseModalities != null) {
14557
- setValueByPath(parentObject, ['setup', 'generationConfig', 'responseModalities'], fromResponseModalities);
14558
- }
14559
- const fromTemperature = getValueByPath(fromObject, ['temperature']);
14560
- if (parentObject !== undefined && fromTemperature != null) {
14561
- setValueByPath(parentObject, ['setup', 'generationConfig', 'temperature'], fromTemperature);
14562
- }
14563
- const fromTopP = getValueByPath(fromObject, ['topP']);
14564
- if (parentObject !== undefined && fromTopP != null) {
14565
- setValueByPath(parentObject, ['setup', 'generationConfig', 'topP'], fromTopP);
14566
- }
14567
- const fromTopK = getValueByPath(fromObject, ['topK']);
14568
- if (parentObject !== undefined && fromTopK != null) {
14569
- setValueByPath(parentObject, ['setup', 'generationConfig', 'topK'], fromTopK);
14570
- }
14571
- const fromMaxOutputTokens = getValueByPath(fromObject, [
14572
- 'maxOutputTokens',
14573
- ]);
14574
- if (parentObject !== undefined && fromMaxOutputTokens != null) {
14575
- setValueByPath(parentObject, ['setup', 'generationConfig', 'maxOutputTokens'], fromMaxOutputTokens);
14576
- }
14577
- const fromMediaResolution = getValueByPath(fromObject, [
14578
- 'mediaResolution',
14579
- ]);
14580
- if (parentObject !== undefined && fromMediaResolution != null) {
14581
- setValueByPath(parentObject, ['setup', 'generationConfig', 'mediaResolution'], fromMediaResolution);
14582
- }
14583
- const fromSeed = getValueByPath(fromObject, ['seed']);
14584
- if (parentObject !== undefined && fromSeed != null) {
14585
- setValueByPath(parentObject, ['setup', 'generationConfig', 'seed'], fromSeed);
14586
- }
14587
- const fromSpeechConfig = getValueByPath(fromObject, ['speechConfig']);
14588
- if (parentObject !== undefined && fromSpeechConfig != null) {
14589
- setValueByPath(parentObject, ['setup', 'generationConfig', 'speechConfig'], tLiveSpeechConfig(fromSpeechConfig));
14590
- }
14591
- const fromThinkingConfig = getValueByPath(fromObject, [
14592
- 'thinkingConfig',
14593
- ]);
14594
- if (parentObject !== undefined && fromThinkingConfig != null) {
14595
- setValueByPath(parentObject, ['setup', 'generationConfig', 'thinkingConfig'], fromThinkingConfig);
14596
- }
14597
- const fromEnableAffectiveDialog = getValueByPath(fromObject, [
14598
- 'enableAffectiveDialog',
14599
- ]);
14600
- if (parentObject !== undefined && fromEnableAffectiveDialog != null) {
14601
- setValueByPath(parentObject, ['setup', 'generationConfig', 'enableAffectiveDialog'], fromEnableAffectiveDialog);
14602
- }
14603
- const fromSystemInstruction = getValueByPath(fromObject, [
14604
- 'systemInstruction',
14605
- ]);
14606
- if (parentObject !== undefined && fromSystemInstruction != null) {
14607
- setValueByPath(parentObject, ['setup', 'systemInstruction'], contentToMldev(tContent(fromSystemInstruction)));
14608
- }
14609
- const fromTools = getValueByPath(fromObject, ['tools']);
14610
- if (parentObject !== undefined && fromTools != null) {
14611
- let transformedList = tTools(fromTools);
14612
- if (Array.isArray(transformedList)) {
14613
- transformedList = transformedList.map((item) => {
14614
- return toolToMldev(tTool(item));
14615
- });
14616
- }
14617
- setValueByPath(parentObject, ['setup', 'tools'], transformedList);
14618
- }
14619
- const fromSessionResumption = getValueByPath(fromObject, [
14620
- 'sessionResumption',
14621
- ]);
14622
- if (parentObject !== undefined && fromSessionResumption != null) {
14623
- setValueByPath(parentObject, ['setup', 'sessionResumption'], sessionResumptionConfigToMldev(fromSessionResumption));
14624
- }
14625
- const fromInputAudioTranscription = getValueByPath(fromObject, [
14626
- 'inputAudioTranscription',
14627
- ]);
14628
- if (parentObject !== undefined && fromInputAudioTranscription != null) {
14629
- setValueByPath(parentObject, ['setup', 'inputAudioTranscription'], fromInputAudioTranscription);
14630
- }
14631
- const fromOutputAudioTranscription = getValueByPath(fromObject, [
14632
- 'outputAudioTranscription',
14633
- ]);
14634
- if (parentObject !== undefined && fromOutputAudioTranscription != null) {
14635
- setValueByPath(parentObject, ['setup', 'outputAudioTranscription'], fromOutputAudioTranscription);
14636
- }
14637
- const fromRealtimeInputConfig = getValueByPath(fromObject, [
14638
- 'realtimeInputConfig',
14639
- ]);
14640
- if (parentObject !== undefined && fromRealtimeInputConfig != null) {
14641
- setValueByPath(parentObject, ['setup', 'realtimeInputConfig'], fromRealtimeInputConfig);
14642
- }
14643
- const fromContextWindowCompression = getValueByPath(fromObject, [
14644
- 'contextWindowCompression',
14645
- ]);
14646
- if (parentObject !== undefined && fromContextWindowCompression != null) {
14647
- setValueByPath(parentObject, ['setup', 'contextWindowCompression'], fromContextWindowCompression);
14648
- }
14649
- const fromProactivity = getValueByPath(fromObject, ['proactivity']);
14650
- if (parentObject !== undefined && fromProactivity != null) {
14651
- setValueByPath(parentObject, ['setup', 'proactivity'], fromProactivity);
14652
- }
14653
- return toObject;
14654
- }
14655
- function liveConnectConstraintsToMldev(apiClient, fromObject) {
14656
- const toObject = {};
14657
- const fromModel = getValueByPath(fromObject, ['model']);
14658
- if (fromModel != null) {
14659
- setValueByPath(toObject, ['setup', 'model'], tModel(apiClient, fromModel));
14660
- }
14661
- const fromConfig = getValueByPath(fromObject, ['config']);
14662
- if (fromConfig != null) {
14663
- setValueByPath(toObject, ['config'], liveConnectConfigToMldev(fromConfig, toObject));
14664
- }
14665
- return toObject;
14666
- }
14667
- function partToMldev(fromObject) {
14668
- const toObject = {};
14669
- const fromMediaResolution = getValueByPath(fromObject, [
14670
- 'mediaResolution',
14671
- ]);
14672
- if (fromMediaResolution != null) {
14673
- setValueByPath(toObject, ['mediaResolution'], fromMediaResolution);
14674
- }
14675
- const fromCodeExecutionResult = getValueByPath(fromObject, [
14676
- 'codeExecutionResult',
14677
- ]);
14678
- if (fromCodeExecutionResult != null) {
14679
- setValueByPath(toObject, ['codeExecutionResult'], fromCodeExecutionResult);
14680
- }
14681
- const fromExecutableCode = getValueByPath(fromObject, [
14682
- 'executableCode',
14683
- ]);
14684
- if (fromExecutableCode != null) {
14685
- setValueByPath(toObject, ['executableCode'], fromExecutableCode);
14686
- }
14687
- const fromFileData = getValueByPath(fromObject, ['fileData']);
14688
- if (fromFileData != null) {
14689
- setValueByPath(toObject, ['fileData'], fileDataToMldev(fromFileData));
14690
- }
14691
- const fromFunctionCall = getValueByPath(fromObject, ['functionCall']);
14692
- if (fromFunctionCall != null) {
14693
- setValueByPath(toObject, ['functionCall'], functionCallToMldev(fromFunctionCall));
14694
- }
14695
- const fromFunctionResponse = getValueByPath(fromObject, [
14696
- 'functionResponse',
14697
- ]);
14698
- if (fromFunctionResponse != null) {
14699
- setValueByPath(toObject, ['functionResponse'], fromFunctionResponse);
14700
- }
14701
- const fromInlineData = getValueByPath(fromObject, ['inlineData']);
14702
- if (fromInlineData != null) {
14703
- setValueByPath(toObject, ['inlineData'], blobToMldev(fromInlineData));
14704
- }
14705
- const fromText = getValueByPath(fromObject, ['text']);
14706
- if (fromText != null) {
14707
- setValueByPath(toObject, ['text'], fromText);
14708
- }
14709
- const fromThought = getValueByPath(fromObject, ['thought']);
14710
- if (fromThought != null) {
14711
- setValueByPath(toObject, ['thought'], fromThought);
14712
- }
14713
- const fromThoughtSignature = getValueByPath(fromObject, [
14714
- 'thoughtSignature',
14715
- ]);
14716
- if (fromThoughtSignature != null) {
14717
- setValueByPath(toObject, ['thoughtSignature'], fromThoughtSignature);
14718
- }
14719
- const fromVideoMetadata = getValueByPath(fromObject, [
14720
- 'videoMetadata',
14721
- ]);
14722
- if (fromVideoMetadata != null) {
14723
- setValueByPath(toObject, ['videoMetadata'], fromVideoMetadata);
14724
- }
14725
- return toObject;
14726
- }
14727
- function sessionResumptionConfigToMldev(fromObject) {
14728
- const toObject = {};
14729
- const fromHandle = getValueByPath(fromObject, ['handle']);
14730
- if (fromHandle != null) {
14731
- setValueByPath(toObject, ['handle'], fromHandle);
14732
- }
14733
- if (getValueByPath(fromObject, ['transparent']) !== undefined) {
14734
- throw new Error('transparent parameter is not supported in Gemini API.');
14735
- }
14736
- return toObject;
14737
- }
14738
- function toolToMldev(fromObject) {
14739
- const toObject = {};
14740
- const fromFunctionDeclarations = getValueByPath(fromObject, [
14741
- 'functionDeclarations',
14742
- ]);
14743
- if (fromFunctionDeclarations != null) {
14744
- let transformedList = fromFunctionDeclarations;
14745
- if (Array.isArray(transformedList)) {
14746
- transformedList = transformedList.map((item) => {
14747
- return item;
14435
+ return httpResponse.json();
14436
+ });
14437
+ return response.then((apiResponse) => {
14438
+ const resp = generateVideosOperationFromVertex(apiResponse);
14439
+ const typedResp = new GenerateVideosOperation();
14440
+ Object.assign(typedResp, resp);
14441
+ return typedResp;
14442
+ });
14443
+ }
14444
+ else {
14445
+ const body = generateVideosParametersToMldev(this.apiClient, params);
14446
+ path = formatMap('{model}:predictLongRunning', body['_url']);
14447
+ queryParams = body['_query'];
14448
+ delete body['_url'];
14449
+ delete body['_query'];
14450
+ response = this.apiClient
14451
+ .request({
14452
+ path: path,
14453
+ queryParams: queryParams,
14454
+ body: JSON.stringify(body),
14455
+ httpMethod: 'POST',
14456
+ httpOptions: (_c = params.config) === null || _c === void 0 ? void 0 : _c.httpOptions,
14457
+ abortSignal: (_d = params.config) === null || _d === void 0 ? void 0 : _d.abortSignal,
14458
+ })
14459
+ .then((httpResponse) => {
14460
+ return httpResponse.json();
14461
+ });
14462
+ return response.then((apiResponse) => {
14463
+ const resp = generateVideosOperationFromMldev(apiResponse);
14464
+ const typedResp = new GenerateVideosOperation();
14465
+ Object.assign(typedResp, resp);
14466
+ return typedResp;
14748
14467
  });
14749
14468
  }
14750
- setValueByPath(toObject, ['functionDeclarations'], transformedList);
14751
- }
14752
- if (getValueByPath(fromObject, ['retrieval']) !== undefined) {
14753
- throw new Error('retrieval parameter is not supported in Gemini API.');
14754
- }
14755
- const fromGoogleSearchRetrieval = getValueByPath(fromObject, [
14756
- 'googleSearchRetrieval',
14757
- ]);
14758
- if (fromGoogleSearchRetrieval != null) {
14759
- setValueByPath(toObject, ['googleSearchRetrieval'], fromGoogleSearchRetrieval);
14760
- }
14761
- const fromComputerUse = getValueByPath(fromObject, ['computerUse']);
14762
- if (fromComputerUse != null) {
14763
- setValueByPath(toObject, ['computerUse'], fromComputerUse);
14764
- }
14765
- const fromFileSearch = getValueByPath(fromObject, ['fileSearch']);
14766
- if (fromFileSearch != null) {
14767
- setValueByPath(toObject, ['fileSearch'], fromFileSearch);
14768
- }
14769
- const fromCodeExecution = getValueByPath(fromObject, [
14770
- 'codeExecution',
14771
- ]);
14772
- if (fromCodeExecution != null) {
14773
- setValueByPath(toObject, ['codeExecution'], fromCodeExecution);
14774
- }
14775
- if (getValueByPath(fromObject, ['enterpriseWebSearch']) !== undefined) {
14776
- throw new Error('enterpriseWebSearch parameter is not supported in Gemini API.');
14777
- }
14778
- const fromGoogleMaps = getValueByPath(fromObject, ['googleMaps']);
14779
- if (fromGoogleMaps != null) {
14780
- setValueByPath(toObject, ['googleMaps'], googleMapsToMldev(fromGoogleMaps));
14781
- }
14782
- const fromGoogleSearch = getValueByPath(fromObject, ['googleSearch']);
14783
- if (fromGoogleSearch != null) {
14784
- setValueByPath(toObject, ['googleSearch'], googleSearchToMldev(fromGoogleSearch));
14785
- }
14786
- const fromUrlContext = getValueByPath(fromObject, ['urlContext']);
14787
- if (fromUrlContext != null) {
14788
- setValueByPath(toObject, ['urlContext'], fromUrlContext);
14789
14469
  }
14790
- return toObject;
14791
14470
  }
14792
14471
 
14793
14472
  /**
@@ -14795,257 +14474,151 @@ function toolToMldev(fromObject) {
14795
14474
  * Copyright 2025 Google LLC
14796
14475
  * SPDX-License-Identifier: Apache-2.0
14797
14476
  */
14798
- /**
14799
- * Returns a comma-separated list of field masks from a given object.
14800
- *
14801
- * @param setup The object to extract field masks from.
14802
- * @return A comma-separated list of field masks.
14803
- */
14804
- function getFieldMasks(setup) {
14805
- const fields = [];
14806
- for (const key in setup) {
14807
- if (Object.prototype.hasOwnProperty.call(setup, key)) {
14808
- const value = setup[key];
14809
- // 2nd layer, recursively get field masks see TODO(b/418290100)
14810
- if (typeof value === 'object' &&
14811
- value != null &&
14812
- Object.keys(value).length > 0) {
14813
- const field = Object.keys(value).map((kk) => `${key}.${kk}`);
14814
- fields.push(...field);
14815
- }
14816
- else {
14817
- fields.push(key); // 1st layer
14818
- }
14819
- }
14477
+ class Operations extends BaseModule {
14478
+ constructor(apiClient) {
14479
+ super();
14480
+ this.apiClient = apiClient;
14820
14481
  }
14821
- return fields.join(',');
14822
- }
14823
- /**
14824
- * Converts bidiGenerateContentSetup.
14825
- * @param requestDict - The request dictionary.
14826
- * @param config - The configuration object.
14827
- * @return - The modified request dictionary.
14828
- */
14829
- function convertBidiSetupToTokenSetup(requestDict, config) {
14830
- // Convert bidiGenerateContentSetup from bidiGenerateContentSetup.setup.
14831
- let setupForMaskGeneration = null;
14832
- const bidiGenerateContentSetupValue = requestDict['bidiGenerateContentSetup'];
14833
- if (typeof bidiGenerateContentSetupValue === 'object' &&
14834
- bidiGenerateContentSetupValue !== null &&
14835
- 'setup' in bidiGenerateContentSetupValue) {
14836
- // Now we know bidiGenerateContentSetupValue is an object and has a 'setup'
14837
- // property.
14838
- const innerSetup = bidiGenerateContentSetupValue
14839
- .setup;
14840
- if (typeof innerSetup === 'object' && innerSetup !== null) {
14841
- // Valid inner setup found.
14842
- requestDict['bidiGenerateContentSetup'] = innerSetup;
14843
- setupForMaskGeneration = innerSetup;
14482
+ /**
14483
+ * Gets the status of a long-running operation.
14484
+ *
14485
+ * @param parameters The parameters for the get operation request.
14486
+ * @return The updated Operation object, with the latest status or result.
14487
+ */
14488
+ async getVideosOperation(parameters) {
14489
+ const operation = parameters.operation;
14490
+ const config = parameters.config;
14491
+ if (operation.name === undefined || operation.name === '') {
14492
+ throw new Error('Operation name is required.');
14493
+ }
14494
+ if (this.apiClient.isVertexAI()) {
14495
+ const resourceName = operation.name.split('/operations/')[0];
14496
+ let httpOptions = undefined;
14497
+ if (config && 'httpOptions' in config) {
14498
+ httpOptions = config.httpOptions;
14499
+ }
14500
+ const rawOperation = await this.fetchPredictVideosOperationInternal({
14501
+ operationName: operation.name,
14502
+ resourceName: resourceName,
14503
+ config: { httpOptions: httpOptions },
14504
+ });
14505
+ return operation._fromAPIResponse({
14506
+ apiResponse: rawOperation,
14507
+ _isVertexAI: true,
14508
+ });
14844
14509
  }
14845
14510
  else {
14846
- // `bidiGenerateContentSetupValue.setup` is not a valid object; treat as
14847
- // if bidiGenerateContentSetup is invalid.
14848
- delete requestDict['bidiGenerateContentSetup'];
14511
+ const rawOperation = await this.getVideosOperationInternal({
14512
+ operationName: operation.name,
14513
+ config: config,
14514
+ });
14515
+ return operation._fromAPIResponse({
14516
+ apiResponse: rawOperation,
14517
+ _isVertexAI: false,
14518
+ });
14849
14519
  }
14850
14520
  }
14851
- else if (bidiGenerateContentSetupValue !== undefined) {
14852
- // `bidiGenerateContentSetup` exists but not in the expected
14853
- // shape {setup: {...}}; treat as invalid.
14854
- delete requestDict['bidiGenerateContentSetup'];
14855
- }
14856
- const preExistingFieldMask = requestDict['fieldMask'];
14857
- // Handle mask generation setup.
14858
- if (setupForMaskGeneration) {
14859
- const generatedMaskFromBidi = getFieldMasks(setupForMaskGeneration);
14860
- if (Array.isArray(config === null || config === void 0 ? void 0 : config.lockAdditionalFields) &&
14861
- (config === null || config === void 0 ? void 0 : config.lockAdditionalFields.length) === 0) {
14862
- // Case 1: lockAdditionalFields is an empty array. Lock only fields from
14863
- // bidi setup.
14864
- if (generatedMaskFromBidi) {
14865
- // Only assign if mask is not empty
14866
- requestDict['fieldMask'] = generatedMaskFromBidi;
14867
- }
14868
- else {
14869
- delete requestDict['fieldMask']; // If mask is empty, effectively no
14870
- // specific fields locked by bidi
14871
- }
14521
+ /**
14522
+ * Gets the status of a long-running operation.
14523
+ *
14524
+ * @param parameters The parameters for the get operation request.
14525
+ * @return The updated Operation object, with the latest status or result.
14526
+ */
14527
+ async get(parameters) {
14528
+ const operation = parameters.operation;
14529
+ const config = parameters.config;
14530
+ if (operation.name === undefined || operation.name === '') {
14531
+ throw new Error('Operation name is required.');
14872
14532
  }
14873
- else if ((config === null || config === void 0 ? void 0 : config.lockAdditionalFields) &&
14874
- config.lockAdditionalFields.length > 0 &&
14875
- preExistingFieldMask !== null &&
14876
- Array.isArray(preExistingFieldMask) &&
14877
- preExistingFieldMask.length > 0) {
14878
- // Case 2: Lock fields from bidi setup + additional fields
14879
- // (preExistingFieldMask).
14880
- const generationConfigFields = [
14881
- 'temperature',
14882
- 'topK',
14883
- 'topP',
14884
- 'maxOutputTokens',
14885
- 'responseModalities',
14886
- 'seed',
14887
- 'speechConfig',
14888
- ];
14889
- let mappedFieldsFromPreExisting = [];
14890
- if (preExistingFieldMask.length > 0) {
14891
- mappedFieldsFromPreExisting = preExistingFieldMask.map((field) => {
14892
- if (generationConfigFields.includes(field)) {
14893
- return `generationConfig.${field}`;
14894
- }
14895
- return field; // Keep original field name if not in
14896
- // generationConfigFields
14897
- });
14898
- }
14899
- const finalMaskParts = [];
14900
- if (generatedMaskFromBidi) {
14901
- finalMaskParts.push(generatedMaskFromBidi);
14902
- }
14903
- if (mappedFieldsFromPreExisting.length > 0) {
14904
- finalMaskParts.push(...mappedFieldsFromPreExisting);
14905
- }
14906
- if (finalMaskParts.length > 0) {
14907
- requestDict['fieldMask'] = finalMaskParts.join(',');
14908
- }
14909
- else {
14910
- // If no fields from bidi and no valid additional fields from
14911
- // pre-existing mask.
14912
- delete requestDict['fieldMask'];
14533
+ if (this.apiClient.isVertexAI()) {
14534
+ const resourceName = operation.name.split('/operations/')[0];
14535
+ let httpOptions = undefined;
14536
+ if (config && 'httpOptions' in config) {
14537
+ httpOptions = config.httpOptions;
14913
14538
  }
14539
+ const rawOperation = await this.fetchPredictVideosOperationInternal({
14540
+ operationName: operation.name,
14541
+ resourceName: resourceName,
14542
+ config: { httpOptions: httpOptions },
14543
+ });
14544
+ return operation._fromAPIResponse({
14545
+ apiResponse: rawOperation,
14546
+ _isVertexAI: true,
14547
+ });
14914
14548
  }
14915
14549
  else {
14916
- // Case 3: "Lock all fields" (meaning, don't send a field_mask, let server
14917
- // defaults apply or all are mutable). This is hit if:
14918
- // - `config.lockAdditionalFields` is undefined.
14919
- // - `config.lockAdditionalFields` is non-empty, BUT
14920
- // `preExistingFieldMask` is null, not a string, or an empty string.
14921
- delete requestDict['fieldMask'];
14550
+ const rawOperation = await this.getVideosOperationInternal({
14551
+ operationName: operation.name,
14552
+ config: config,
14553
+ });
14554
+ return operation._fromAPIResponse({
14555
+ apiResponse: rawOperation,
14556
+ _isVertexAI: false,
14557
+ });
14922
14558
  }
14923
14559
  }
14924
- else {
14925
- // No valid `bidiGenerateContentSetup` was found or extracted.
14926
- // "Lock additional null fields if any".
14927
- if (preExistingFieldMask !== null &&
14928
- Array.isArray(preExistingFieldMask) &&
14929
- preExistingFieldMask.length > 0) {
14930
- // If there's a pre-existing field mask, it's a string, and it's not
14931
- // empty, then we should lock all fields.
14932
- requestDict['fieldMask'] = preExistingFieldMask.join(',');
14560
+ async getVideosOperationInternal(params) {
14561
+ var _a, _b, _c, _d;
14562
+ let response;
14563
+ let path = '';
14564
+ let queryParams = {};
14565
+ if (this.apiClient.isVertexAI()) {
14566
+ const body = getOperationParametersToVertex(params);
14567
+ path = formatMap('{operationName}', body['_url']);
14568
+ queryParams = body['_query'];
14569
+ delete body['_url'];
14570
+ delete body['_query'];
14571
+ response = this.apiClient
14572
+ .request({
14573
+ path: path,
14574
+ queryParams: queryParams,
14575
+ body: JSON.stringify(body),
14576
+ httpMethod: 'GET',
14577
+ httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
14578
+ abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
14579
+ })
14580
+ .then((httpResponse) => {
14581
+ return httpResponse.json();
14582
+ });
14583
+ return response;
14933
14584
  }
14934
14585
  else {
14935
- delete requestDict['fieldMask'];
14586
+ const body = getOperationParametersToMldev(params);
14587
+ path = formatMap('{operationName}', body['_url']);
14588
+ queryParams = body['_query'];
14589
+ delete body['_url'];
14590
+ delete body['_query'];
14591
+ response = this.apiClient
14592
+ .request({
14593
+ path: path,
14594
+ queryParams: queryParams,
14595
+ body: JSON.stringify(body),
14596
+ httpMethod: 'GET',
14597
+ httpOptions: (_c = params.config) === null || _c === void 0 ? void 0 : _c.httpOptions,
14598
+ abortSignal: (_d = params.config) === null || _d === void 0 ? void 0 : _d.abortSignal,
14599
+ })
14600
+ .then((httpResponse) => {
14601
+ return httpResponse.json();
14602
+ });
14603
+ return response;
14936
14604
  }
14937
14605
  }
14938
- return requestDict;
14939
- }
14940
- class Tokens extends BaseModule {
14941
- constructor(apiClient) {
14942
- super();
14943
- this.apiClient = apiClient;
14944
- }
14945
- /**
14946
- * Creates an ephemeral auth token resource.
14947
- *
14948
- * @experimental
14949
- *
14950
- * @remarks
14951
- * Ephemeral auth tokens is only supported in the Gemini Developer API.
14952
- * It can be used for the session connection to the Live constrained API.
14953
- * Support in v1alpha only.
14954
- *
14955
- * @param params - The parameters for the create request.
14956
- * @return The created auth token.
14957
- *
14958
- * @example
14959
- * ```ts
14960
- * const ai = new GoogleGenAI({
14961
- * apiKey: token.name,
14962
- * httpOptions: { apiVersion: 'v1alpha' } // Support in v1alpha only.
14963
- * });
14964
- *
14965
- * // Case 1: If LiveEphemeralParameters is unset, unlock LiveConnectConfig
14966
- * // when using the token in Live API sessions. Each session connection can
14967
- * // use a different configuration.
14968
- * const config: CreateAuthTokenConfig = {
14969
- * uses: 3,
14970
- * expireTime: '2025-05-01T00:00:00Z',
14971
- * }
14972
- * const token = await ai.tokens.create(config);
14973
- *
14974
- * // Case 2: If LiveEphemeralParameters is set, lock all fields in
14975
- * // LiveConnectConfig when using the token in Live API sessions. For
14976
- * // example, changing `outputAudioTranscription` in the Live API
14977
- * // connection will be ignored by the API.
14978
- * const config: CreateAuthTokenConfig =
14979
- * uses: 3,
14980
- * expireTime: '2025-05-01T00:00:00Z',
14981
- * LiveEphemeralParameters: {
14982
- * model: 'gemini-2.0-flash-001',
14983
- * config: {
14984
- * 'responseModalities': ['AUDIO'],
14985
- * 'systemInstruction': 'Always answer in English.',
14986
- * }
14987
- * }
14988
- * }
14989
- * const token = await ai.tokens.create(config);
14990
- *
14991
- * // Case 3: If LiveEphemeralParameters is set and lockAdditionalFields is
14992
- * // set, lock LiveConnectConfig with set and additional fields (e.g.
14993
- * // responseModalities, systemInstruction, temperature in this example) when
14994
- * // using the token in Live API sessions.
14995
- * const config: CreateAuthTokenConfig =
14996
- * uses: 3,
14997
- * expireTime: '2025-05-01T00:00:00Z',
14998
- * LiveEphemeralParameters: {
14999
- * model: 'gemini-2.0-flash-001',
15000
- * config: {
15001
- * 'responseModalities': ['AUDIO'],
15002
- * 'systemInstruction': 'Always answer in English.',
15003
- * }
15004
- * },
15005
- * lockAdditionalFields: ['temperature'],
15006
- * }
15007
- * const token = await ai.tokens.create(config);
15008
- *
15009
- * // Case 4: If LiveEphemeralParameters is set and lockAdditionalFields is
15010
- * // empty array, lock LiveConnectConfig with set fields (e.g.
15011
- * // responseModalities, systemInstruction in this example) when using the
15012
- * // token in Live API sessions.
15013
- * const config: CreateAuthTokenConfig =
15014
- * uses: 3,
15015
- * expireTime: '2025-05-01T00:00:00Z',
15016
- * LiveEphemeralParameters: {
15017
- * model: 'gemini-2.0-flash-001',
15018
- * config: {
15019
- * 'responseModalities': ['AUDIO'],
15020
- * 'systemInstruction': 'Always answer in English.',
15021
- * }
15022
- * },
15023
- * lockAdditionalFields: [],
15024
- * }
15025
- * const token = await ai.tokens.create(config);
15026
- * ```
15027
- */
15028
- async create(params) {
14606
+ async fetchPredictVideosOperationInternal(params) {
15029
14607
  var _a, _b;
15030
14608
  let response;
15031
14609
  let path = '';
15032
14610
  let queryParams = {};
15033
14611
  if (this.apiClient.isVertexAI()) {
15034
- throw new Error('The client.tokens.create method is only supported by the Gemini Developer API.');
15035
- }
15036
- else {
15037
- const body = createAuthTokenParametersToMldev(this.apiClient, params);
15038
- path = formatMap('auth_tokens', body['_url']);
14612
+ const body = fetchPredictOperationParametersToVertex(params);
14613
+ path = formatMap('{resourceName}:fetchPredictOperation', body['_url']);
15039
14614
  queryParams = body['_query'];
15040
- delete body['config'];
15041
14615
  delete body['_url'];
15042
14616
  delete body['_query'];
15043
- const transformedBody = convertBidiSetupToTokenSetup(body, params.config);
15044
14617
  response = this.apiClient
15045
14618
  .request({
15046
14619
  path: path,
15047
14620
  queryParams: queryParams,
15048
- body: JSON.stringify(transformedBody),
14621
+ body: JSON.stringify(body),
15049
14622
  httpMethod: 'POST',
15050
14623
  httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
15051
14624
  abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
@@ -15053,246 +14626,670 @@ class Tokens extends BaseModule {
15053
14626
  .then((httpResponse) => {
15054
14627
  return httpResponse.json();
15055
14628
  });
15056
- return response.then((resp) => {
15057
- return resp;
14629
+ return response;
14630
+ }
14631
+ else {
14632
+ throw new Error('This method is only supported by the Vertex AI.');
14633
+ }
14634
+ }
14635
+ }
14636
+
14637
+ /**
14638
+ * @license
14639
+ * Copyright 2025 Google LLC
14640
+ * SPDX-License-Identifier: Apache-2.0
14641
+ */
14642
+ function blobToMldev(fromObject) {
14643
+ const toObject = {};
14644
+ const fromData = getValueByPath(fromObject, ['data']);
14645
+ if (fromData != null) {
14646
+ setValueByPath(toObject, ['data'], fromData);
14647
+ }
14648
+ if (getValueByPath(fromObject, ['displayName']) !== undefined) {
14649
+ throw new Error('displayName parameter is not supported in Gemini API.');
14650
+ }
14651
+ const fromMimeType = getValueByPath(fromObject, ['mimeType']);
14652
+ if (fromMimeType != null) {
14653
+ setValueByPath(toObject, ['mimeType'], fromMimeType);
14654
+ }
14655
+ return toObject;
14656
+ }
14657
+ function contentToMldev(fromObject) {
14658
+ const toObject = {};
14659
+ const fromParts = getValueByPath(fromObject, ['parts']);
14660
+ if (fromParts != null) {
14661
+ let transformedList = fromParts;
14662
+ if (Array.isArray(transformedList)) {
14663
+ transformedList = transformedList.map((item) => {
14664
+ return partToMldev(item);
15058
14665
  });
15059
14666
  }
14667
+ setValueByPath(toObject, ['parts'], transformedList);
14668
+ }
14669
+ const fromRole = getValueByPath(fromObject, ['role']);
14670
+ if (fromRole != null) {
14671
+ setValueByPath(toObject, ['role'], fromRole);
14672
+ }
14673
+ return toObject;
14674
+ }
14675
+ function createAuthTokenConfigToMldev(apiClient, fromObject, parentObject) {
14676
+ const toObject = {};
14677
+ const fromExpireTime = getValueByPath(fromObject, ['expireTime']);
14678
+ if (parentObject !== undefined && fromExpireTime != null) {
14679
+ setValueByPath(parentObject, ['expireTime'], fromExpireTime);
14680
+ }
14681
+ const fromNewSessionExpireTime = getValueByPath(fromObject, [
14682
+ 'newSessionExpireTime',
14683
+ ]);
14684
+ if (parentObject !== undefined && fromNewSessionExpireTime != null) {
14685
+ setValueByPath(parentObject, ['newSessionExpireTime'], fromNewSessionExpireTime);
14686
+ }
14687
+ const fromUses = getValueByPath(fromObject, ['uses']);
14688
+ if (parentObject !== undefined && fromUses != null) {
14689
+ setValueByPath(parentObject, ['uses'], fromUses);
14690
+ }
14691
+ const fromLiveConnectConstraints = getValueByPath(fromObject, [
14692
+ 'liveConnectConstraints',
14693
+ ]);
14694
+ if (parentObject !== undefined && fromLiveConnectConstraints != null) {
14695
+ setValueByPath(parentObject, ['bidiGenerateContentSetup'], liveConnectConstraintsToMldev(apiClient, fromLiveConnectConstraints));
14696
+ }
14697
+ const fromLockAdditionalFields = getValueByPath(fromObject, [
14698
+ 'lockAdditionalFields',
14699
+ ]);
14700
+ if (parentObject !== undefined && fromLockAdditionalFields != null) {
14701
+ setValueByPath(parentObject, ['fieldMask'], fromLockAdditionalFields);
14702
+ }
14703
+ return toObject;
14704
+ }
14705
+ function createAuthTokenParametersToMldev(apiClient, fromObject) {
14706
+ const toObject = {};
14707
+ const fromConfig = getValueByPath(fromObject, ['config']);
14708
+ if (fromConfig != null) {
14709
+ setValueByPath(toObject, ['config'], createAuthTokenConfigToMldev(apiClient, fromConfig, toObject));
14710
+ }
14711
+ return toObject;
14712
+ }
14713
+ function fileDataToMldev(fromObject) {
14714
+ const toObject = {};
14715
+ if (getValueByPath(fromObject, ['displayName']) !== undefined) {
14716
+ throw new Error('displayName parameter is not supported in Gemini API.');
14717
+ }
14718
+ const fromFileUri = getValueByPath(fromObject, ['fileUri']);
14719
+ if (fromFileUri != null) {
14720
+ setValueByPath(toObject, ['fileUri'], fromFileUri);
14721
+ }
14722
+ const fromMimeType = getValueByPath(fromObject, ['mimeType']);
14723
+ if (fromMimeType != null) {
14724
+ setValueByPath(toObject, ['mimeType'], fromMimeType);
14725
+ }
14726
+ return toObject;
14727
+ }
14728
+ function functionCallToMldev(fromObject) {
14729
+ const toObject = {};
14730
+ const fromId = getValueByPath(fromObject, ['id']);
14731
+ if (fromId != null) {
14732
+ setValueByPath(toObject, ['id'], fromId);
14733
+ }
14734
+ const fromArgs = getValueByPath(fromObject, ['args']);
14735
+ if (fromArgs != null) {
14736
+ setValueByPath(toObject, ['args'], fromArgs);
14737
+ }
14738
+ const fromName = getValueByPath(fromObject, ['name']);
14739
+ if (fromName != null) {
14740
+ setValueByPath(toObject, ['name'], fromName);
14741
+ }
14742
+ if (getValueByPath(fromObject, ['partialArgs']) !== undefined) {
14743
+ throw new Error('partialArgs parameter is not supported in Gemini API.');
14744
+ }
14745
+ if (getValueByPath(fromObject, ['willContinue']) !== undefined) {
14746
+ throw new Error('willContinue parameter is not supported in Gemini API.');
15060
14747
  }
14748
+ return toObject;
15061
14749
  }
15062
-
15063
- /**
15064
- * @license
15065
- * Copyright 2025 Google LLC
15066
- * SPDX-License-Identifier: Apache-2.0
15067
- */
15068
- // Code generated by the Google Gen AI SDK generator DO NOT EDIT.
15069
- function createFileSearchStoreConfigToMldev(fromObject, parentObject) {
14750
+ function googleMapsToMldev(fromObject) {
15070
14751
  const toObject = {};
15071
- const fromDisplayName = getValueByPath(fromObject, ['displayName']);
15072
- if (parentObject !== undefined && fromDisplayName != null) {
15073
- setValueByPath(parentObject, ['displayName'], fromDisplayName);
14752
+ if (getValueByPath(fromObject, ['authConfig']) !== undefined) {
14753
+ throw new Error('authConfig parameter is not supported in Gemini API.');
14754
+ }
14755
+ const fromEnableWidget = getValueByPath(fromObject, ['enableWidget']);
14756
+ if (fromEnableWidget != null) {
14757
+ setValueByPath(toObject, ['enableWidget'], fromEnableWidget);
15074
14758
  }
15075
14759
  return toObject;
15076
14760
  }
15077
- function createFileSearchStoreParametersToMldev(fromObject) {
14761
+ function googleSearchToMldev(fromObject) {
15078
14762
  const toObject = {};
15079
- const fromConfig = getValueByPath(fromObject, ['config']);
15080
- if (fromConfig != null) {
15081
- createFileSearchStoreConfigToMldev(fromConfig, toObject);
14763
+ if (getValueByPath(fromObject, ['excludeDomains']) !== undefined) {
14764
+ throw new Error('excludeDomains parameter is not supported in Gemini API.');
14765
+ }
14766
+ if (getValueByPath(fromObject, ['blockingConfidence']) !== undefined) {
14767
+ throw new Error('blockingConfidence parameter is not supported in Gemini API.');
14768
+ }
14769
+ const fromTimeRangeFilter = getValueByPath(fromObject, [
14770
+ 'timeRangeFilter',
14771
+ ]);
14772
+ if (fromTimeRangeFilter != null) {
14773
+ setValueByPath(toObject, ['timeRangeFilter'], fromTimeRangeFilter);
15082
14774
  }
15083
14775
  return toObject;
15084
14776
  }
15085
- function deleteFileSearchStoreConfigToMldev(fromObject, parentObject) {
14777
+ function liveConnectConfigToMldev(fromObject, parentObject) {
15086
14778
  const toObject = {};
15087
- const fromForce = getValueByPath(fromObject, ['force']);
15088
- if (parentObject !== undefined && fromForce != null) {
15089
- setValueByPath(parentObject, ['_query', 'force'], fromForce);
14779
+ const fromGenerationConfig = getValueByPath(fromObject, [
14780
+ 'generationConfig',
14781
+ ]);
14782
+ if (parentObject !== undefined && fromGenerationConfig != null) {
14783
+ setValueByPath(parentObject, ['setup', 'generationConfig'], fromGenerationConfig);
14784
+ }
14785
+ const fromResponseModalities = getValueByPath(fromObject, [
14786
+ 'responseModalities',
14787
+ ]);
14788
+ if (parentObject !== undefined && fromResponseModalities != null) {
14789
+ setValueByPath(parentObject, ['setup', 'generationConfig', 'responseModalities'], fromResponseModalities);
14790
+ }
14791
+ const fromTemperature = getValueByPath(fromObject, ['temperature']);
14792
+ if (parentObject !== undefined && fromTemperature != null) {
14793
+ setValueByPath(parentObject, ['setup', 'generationConfig', 'temperature'], fromTemperature);
14794
+ }
14795
+ const fromTopP = getValueByPath(fromObject, ['topP']);
14796
+ if (parentObject !== undefined && fromTopP != null) {
14797
+ setValueByPath(parentObject, ['setup', 'generationConfig', 'topP'], fromTopP);
14798
+ }
14799
+ const fromTopK = getValueByPath(fromObject, ['topK']);
14800
+ if (parentObject !== undefined && fromTopK != null) {
14801
+ setValueByPath(parentObject, ['setup', 'generationConfig', 'topK'], fromTopK);
14802
+ }
14803
+ const fromMaxOutputTokens = getValueByPath(fromObject, [
14804
+ 'maxOutputTokens',
14805
+ ]);
14806
+ if (parentObject !== undefined && fromMaxOutputTokens != null) {
14807
+ setValueByPath(parentObject, ['setup', 'generationConfig', 'maxOutputTokens'], fromMaxOutputTokens);
14808
+ }
14809
+ const fromMediaResolution = getValueByPath(fromObject, [
14810
+ 'mediaResolution',
14811
+ ]);
14812
+ if (parentObject !== undefined && fromMediaResolution != null) {
14813
+ setValueByPath(parentObject, ['setup', 'generationConfig', 'mediaResolution'], fromMediaResolution);
14814
+ }
14815
+ const fromSeed = getValueByPath(fromObject, ['seed']);
14816
+ if (parentObject !== undefined && fromSeed != null) {
14817
+ setValueByPath(parentObject, ['setup', 'generationConfig', 'seed'], fromSeed);
14818
+ }
14819
+ const fromSpeechConfig = getValueByPath(fromObject, ['speechConfig']);
14820
+ if (parentObject !== undefined && fromSpeechConfig != null) {
14821
+ setValueByPath(parentObject, ['setup', 'generationConfig', 'speechConfig'], tLiveSpeechConfig(fromSpeechConfig));
14822
+ }
14823
+ const fromThinkingConfig = getValueByPath(fromObject, [
14824
+ 'thinkingConfig',
14825
+ ]);
14826
+ if (parentObject !== undefined && fromThinkingConfig != null) {
14827
+ setValueByPath(parentObject, ['setup', 'generationConfig', 'thinkingConfig'], fromThinkingConfig);
14828
+ }
14829
+ const fromEnableAffectiveDialog = getValueByPath(fromObject, [
14830
+ 'enableAffectiveDialog',
14831
+ ]);
14832
+ if (parentObject !== undefined && fromEnableAffectiveDialog != null) {
14833
+ setValueByPath(parentObject, ['setup', 'generationConfig', 'enableAffectiveDialog'], fromEnableAffectiveDialog);
14834
+ }
14835
+ const fromSystemInstruction = getValueByPath(fromObject, [
14836
+ 'systemInstruction',
14837
+ ]);
14838
+ if (parentObject !== undefined && fromSystemInstruction != null) {
14839
+ setValueByPath(parentObject, ['setup', 'systemInstruction'], contentToMldev(tContent(fromSystemInstruction)));
14840
+ }
14841
+ const fromTools = getValueByPath(fromObject, ['tools']);
14842
+ if (parentObject !== undefined && fromTools != null) {
14843
+ let transformedList = tTools(fromTools);
14844
+ if (Array.isArray(transformedList)) {
14845
+ transformedList = transformedList.map((item) => {
14846
+ return toolToMldev(tTool(item));
14847
+ });
14848
+ }
14849
+ setValueByPath(parentObject, ['setup', 'tools'], transformedList);
14850
+ }
14851
+ const fromSessionResumption = getValueByPath(fromObject, [
14852
+ 'sessionResumption',
14853
+ ]);
14854
+ if (parentObject !== undefined && fromSessionResumption != null) {
14855
+ setValueByPath(parentObject, ['setup', 'sessionResumption'], sessionResumptionConfigToMldev(fromSessionResumption));
14856
+ }
14857
+ const fromInputAudioTranscription = getValueByPath(fromObject, [
14858
+ 'inputAudioTranscription',
14859
+ ]);
14860
+ if (parentObject !== undefined && fromInputAudioTranscription != null) {
14861
+ setValueByPath(parentObject, ['setup', 'inputAudioTranscription'], fromInputAudioTranscription);
14862
+ }
14863
+ const fromOutputAudioTranscription = getValueByPath(fromObject, [
14864
+ 'outputAudioTranscription',
14865
+ ]);
14866
+ if (parentObject !== undefined && fromOutputAudioTranscription != null) {
14867
+ setValueByPath(parentObject, ['setup', 'outputAudioTranscription'], fromOutputAudioTranscription);
14868
+ }
14869
+ const fromRealtimeInputConfig = getValueByPath(fromObject, [
14870
+ 'realtimeInputConfig',
14871
+ ]);
14872
+ if (parentObject !== undefined && fromRealtimeInputConfig != null) {
14873
+ setValueByPath(parentObject, ['setup', 'realtimeInputConfig'], fromRealtimeInputConfig);
14874
+ }
14875
+ const fromContextWindowCompression = getValueByPath(fromObject, [
14876
+ 'contextWindowCompression',
14877
+ ]);
14878
+ if (parentObject !== undefined && fromContextWindowCompression != null) {
14879
+ setValueByPath(parentObject, ['setup', 'contextWindowCompression'], fromContextWindowCompression);
14880
+ }
14881
+ const fromProactivity = getValueByPath(fromObject, ['proactivity']);
14882
+ if (parentObject !== undefined && fromProactivity != null) {
14883
+ setValueByPath(parentObject, ['setup', 'proactivity'], fromProactivity);
15090
14884
  }
15091
14885
  return toObject;
15092
14886
  }
15093
- function deleteFileSearchStoreParametersToMldev(fromObject) {
14887
+ function liveConnectConstraintsToMldev(apiClient, fromObject) {
15094
14888
  const toObject = {};
15095
- const fromName = getValueByPath(fromObject, ['name']);
15096
- if (fromName != null) {
15097
- setValueByPath(toObject, ['_url', 'name'], fromName);
14889
+ const fromModel = getValueByPath(fromObject, ['model']);
14890
+ if (fromModel != null) {
14891
+ setValueByPath(toObject, ['setup', 'model'], tModel(apiClient, fromModel));
15098
14892
  }
15099
14893
  const fromConfig = getValueByPath(fromObject, ['config']);
15100
14894
  if (fromConfig != null) {
15101
- deleteFileSearchStoreConfigToMldev(fromConfig, toObject);
14895
+ setValueByPath(toObject, ['config'], liveConnectConfigToMldev(fromConfig, toObject));
15102
14896
  }
15103
14897
  return toObject;
15104
14898
  }
15105
- function getFileSearchStoreParametersToMldev(fromObject) {
14899
+ function partToMldev(fromObject) {
15106
14900
  const toObject = {};
15107
- const fromName = getValueByPath(fromObject, ['name']);
15108
- if (fromName != null) {
15109
- setValueByPath(toObject, ['_url', 'name'], fromName);
14901
+ const fromMediaResolution = getValueByPath(fromObject, [
14902
+ 'mediaResolution',
14903
+ ]);
14904
+ if (fromMediaResolution != null) {
14905
+ setValueByPath(toObject, ['mediaResolution'], fromMediaResolution);
14906
+ }
14907
+ const fromCodeExecutionResult = getValueByPath(fromObject, [
14908
+ 'codeExecutionResult',
14909
+ ]);
14910
+ if (fromCodeExecutionResult != null) {
14911
+ setValueByPath(toObject, ['codeExecutionResult'], fromCodeExecutionResult);
14912
+ }
14913
+ const fromExecutableCode = getValueByPath(fromObject, [
14914
+ 'executableCode',
14915
+ ]);
14916
+ if (fromExecutableCode != null) {
14917
+ setValueByPath(toObject, ['executableCode'], fromExecutableCode);
14918
+ }
14919
+ const fromFileData = getValueByPath(fromObject, ['fileData']);
14920
+ if (fromFileData != null) {
14921
+ setValueByPath(toObject, ['fileData'], fileDataToMldev(fromFileData));
14922
+ }
14923
+ const fromFunctionCall = getValueByPath(fromObject, ['functionCall']);
14924
+ if (fromFunctionCall != null) {
14925
+ setValueByPath(toObject, ['functionCall'], functionCallToMldev(fromFunctionCall));
14926
+ }
14927
+ const fromFunctionResponse = getValueByPath(fromObject, [
14928
+ 'functionResponse',
14929
+ ]);
14930
+ if (fromFunctionResponse != null) {
14931
+ setValueByPath(toObject, ['functionResponse'], fromFunctionResponse);
14932
+ }
14933
+ const fromInlineData = getValueByPath(fromObject, ['inlineData']);
14934
+ if (fromInlineData != null) {
14935
+ setValueByPath(toObject, ['inlineData'], blobToMldev(fromInlineData));
14936
+ }
14937
+ const fromText = getValueByPath(fromObject, ['text']);
14938
+ if (fromText != null) {
14939
+ setValueByPath(toObject, ['text'], fromText);
14940
+ }
14941
+ const fromThought = getValueByPath(fromObject, ['thought']);
14942
+ if (fromThought != null) {
14943
+ setValueByPath(toObject, ['thought'], fromThought);
14944
+ }
14945
+ const fromThoughtSignature = getValueByPath(fromObject, [
14946
+ 'thoughtSignature',
14947
+ ]);
14948
+ if (fromThoughtSignature != null) {
14949
+ setValueByPath(toObject, ['thoughtSignature'], fromThoughtSignature);
14950
+ }
14951
+ const fromVideoMetadata = getValueByPath(fromObject, [
14952
+ 'videoMetadata',
14953
+ ]);
14954
+ if (fromVideoMetadata != null) {
14955
+ setValueByPath(toObject, ['videoMetadata'], fromVideoMetadata);
15110
14956
  }
15111
14957
  return toObject;
15112
14958
  }
15113
- function importFileConfigToMldev(fromObject, parentObject) {
14959
+ function sessionResumptionConfigToMldev(fromObject) {
15114
14960
  const toObject = {};
15115
- const fromCustomMetadata = getValueByPath(fromObject, [
15116
- 'customMetadata',
14961
+ const fromHandle = getValueByPath(fromObject, ['handle']);
14962
+ if (fromHandle != null) {
14963
+ setValueByPath(toObject, ['handle'], fromHandle);
14964
+ }
14965
+ if (getValueByPath(fromObject, ['transparent']) !== undefined) {
14966
+ throw new Error('transparent parameter is not supported in Gemini API.');
14967
+ }
14968
+ return toObject;
14969
+ }
14970
+ function toolToMldev(fromObject) {
14971
+ const toObject = {};
14972
+ const fromFunctionDeclarations = getValueByPath(fromObject, [
14973
+ 'functionDeclarations',
15117
14974
  ]);
15118
- if (parentObject !== undefined && fromCustomMetadata != null) {
15119
- let transformedList = fromCustomMetadata;
14975
+ if (fromFunctionDeclarations != null) {
14976
+ let transformedList = fromFunctionDeclarations;
15120
14977
  if (Array.isArray(transformedList)) {
15121
14978
  transformedList = transformedList.map((item) => {
15122
14979
  return item;
15123
14980
  });
15124
14981
  }
15125
- setValueByPath(parentObject, ['customMetadata'], transformedList);
15126
- }
15127
- const fromChunkingConfig = getValueByPath(fromObject, [
15128
- 'chunkingConfig',
15129
- ]);
15130
- if (parentObject !== undefined && fromChunkingConfig != null) {
15131
- setValueByPath(parentObject, ['chunkingConfig'], fromChunkingConfig);
15132
- }
15133
- return toObject;
15134
- }
15135
- function importFileOperationFromMldev(fromObject) {
15136
- const toObject = {};
15137
- const fromName = getValueByPath(fromObject, ['name']);
15138
- if (fromName != null) {
15139
- setValueByPath(toObject, ['name'], fromName);
15140
- }
15141
- const fromMetadata = getValueByPath(fromObject, ['metadata']);
15142
- if (fromMetadata != null) {
15143
- setValueByPath(toObject, ['metadata'], fromMetadata);
15144
- }
15145
- const fromDone = getValueByPath(fromObject, ['done']);
15146
- if (fromDone != null) {
15147
- setValueByPath(toObject, ['done'], fromDone);
15148
- }
15149
- const fromError = getValueByPath(fromObject, ['error']);
15150
- if (fromError != null) {
15151
- setValueByPath(toObject, ['error'], fromError);
14982
+ setValueByPath(toObject, ['functionDeclarations'], transformedList);
15152
14983
  }
15153
- const fromResponse = getValueByPath(fromObject, ['response']);
15154
- if (fromResponse != null) {
15155
- setValueByPath(toObject, ['response'], importFileResponseFromMldev(fromResponse));
14984
+ if (getValueByPath(fromObject, ['retrieval']) !== undefined) {
14985
+ throw new Error('retrieval parameter is not supported in Gemini API.');
15156
14986
  }
15157
- return toObject;
15158
- }
15159
- function importFileParametersToMldev(fromObject) {
15160
- const toObject = {};
15161
- const fromFileSearchStoreName = getValueByPath(fromObject, [
15162
- 'fileSearchStoreName',
14987
+ const fromGoogleSearchRetrieval = getValueByPath(fromObject, [
14988
+ 'googleSearchRetrieval',
15163
14989
  ]);
15164
- if (fromFileSearchStoreName != null) {
15165
- setValueByPath(toObject, ['_url', 'file_search_store_name'], fromFileSearchStoreName);
14990
+ if (fromGoogleSearchRetrieval != null) {
14991
+ setValueByPath(toObject, ['googleSearchRetrieval'], fromGoogleSearchRetrieval);
15166
14992
  }
15167
- const fromFileName = getValueByPath(fromObject, ['fileName']);
15168
- if (fromFileName != null) {
15169
- setValueByPath(toObject, ['fileName'], fromFileName);
14993
+ const fromComputerUse = getValueByPath(fromObject, ['computerUse']);
14994
+ if (fromComputerUse != null) {
14995
+ setValueByPath(toObject, ['computerUse'], fromComputerUse);
15170
14996
  }
15171
- const fromConfig = getValueByPath(fromObject, ['config']);
15172
- if (fromConfig != null) {
15173
- importFileConfigToMldev(fromConfig, toObject);
14997
+ const fromFileSearch = getValueByPath(fromObject, ['fileSearch']);
14998
+ if (fromFileSearch != null) {
14999
+ setValueByPath(toObject, ['fileSearch'], fromFileSearch);
15174
15000
  }
15175
- return toObject;
15176
- }
15177
- function importFileResponseFromMldev(fromObject) {
15178
- const toObject = {};
15179
- const fromSdkHttpResponse = getValueByPath(fromObject, [
15180
- 'sdkHttpResponse',
15001
+ const fromCodeExecution = getValueByPath(fromObject, [
15002
+ 'codeExecution',
15181
15003
  ]);
15182
- if (fromSdkHttpResponse != null) {
15183
- setValueByPath(toObject, ['sdkHttpResponse'], fromSdkHttpResponse);
15004
+ if (fromCodeExecution != null) {
15005
+ setValueByPath(toObject, ['codeExecution'], fromCodeExecution);
15184
15006
  }
15185
- const fromParent = getValueByPath(fromObject, ['parent']);
15186
- if (fromParent != null) {
15187
- setValueByPath(toObject, ['parent'], fromParent);
15007
+ if (getValueByPath(fromObject, ['enterpriseWebSearch']) !== undefined) {
15008
+ throw new Error('enterpriseWebSearch parameter is not supported in Gemini API.');
15188
15009
  }
15189
- const fromDocumentName = getValueByPath(fromObject, ['documentName']);
15190
- if (fromDocumentName != null) {
15191
- setValueByPath(toObject, ['documentName'], fromDocumentName);
15010
+ const fromGoogleMaps = getValueByPath(fromObject, ['googleMaps']);
15011
+ if (fromGoogleMaps != null) {
15012
+ setValueByPath(toObject, ['googleMaps'], googleMapsToMldev(fromGoogleMaps));
15192
15013
  }
15193
- return toObject;
15194
- }
15195
- function listFileSearchStoresConfigToMldev(fromObject, parentObject) {
15196
- const toObject = {};
15197
- const fromPageSize = getValueByPath(fromObject, ['pageSize']);
15198
- if (parentObject !== undefined && fromPageSize != null) {
15199
- setValueByPath(parentObject, ['_query', 'pageSize'], fromPageSize);
15014
+ const fromGoogleSearch = getValueByPath(fromObject, ['googleSearch']);
15015
+ if (fromGoogleSearch != null) {
15016
+ setValueByPath(toObject, ['googleSearch'], googleSearchToMldev(fromGoogleSearch));
15200
15017
  }
15201
- const fromPageToken = getValueByPath(fromObject, ['pageToken']);
15202
- if (parentObject !== undefined && fromPageToken != null) {
15203
- setValueByPath(parentObject, ['_query', 'pageToken'], fromPageToken);
15018
+ const fromUrlContext = getValueByPath(fromObject, ['urlContext']);
15019
+ if (fromUrlContext != null) {
15020
+ setValueByPath(toObject, ['urlContext'], fromUrlContext);
15204
15021
  }
15205
15022
  return toObject;
15206
15023
  }
15207
- function listFileSearchStoresParametersToMldev(fromObject) {
15208
- const toObject = {};
15209
- const fromConfig = getValueByPath(fromObject, ['config']);
15210
- if (fromConfig != null) {
15211
- listFileSearchStoresConfigToMldev(fromConfig, toObject);
15024
+
15025
+ /**
15026
+ * @license
15027
+ * Copyright 2025 Google LLC
15028
+ * SPDX-License-Identifier: Apache-2.0
15029
+ */
15030
+ /**
15031
+ * Returns a comma-separated list of field masks from a given object.
15032
+ *
15033
+ * @param setup The object to extract field masks from.
15034
+ * @return A comma-separated list of field masks.
15035
+ */
15036
+ function getFieldMasks(setup) {
15037
+ const fields = [];
15038
+ for (const key in setup) {
15039
+ if (Object.prototype.hasOwnProperty.call(setup, key)) {
15040
+ const value = setup[key];
15041
+ // 2nd layer, recursively get field masks see TODO(b/418290100)
15042
+ if (typeof value === 'object' &&
15043
+ value != null &&
15044
+ Object.keys(value).length > 0) {
15045
+ const field = Object.keys(value).map((kk) => `${key}.${kk}`);
15046
+ fields.push(...field);
15047
+ }
15048
+ else {
15049
+ fields.push(key); // 1st layer
15050
+ }
15051
+ }
15212
15052
  }
15213
- return toObject;
15053
+ return fields.join(',');
15214
15054
  }
15215
- function listFileSearchStoresResponseFromMldev(fromObject) {
15216
- const toObject = {};
15217
- const fromSdkHttpResponse = getValueByPath(fromObject, [
15218
- 'sdkHttpResponse',
15219
- ]);
15220
- if (fromSdkHttpResponse != null) {
15221
- setValueByPath(toObject, ['sdkHttpResponse'], fromSdkHttpResponse);
15055
+ /**
15056
+ * Converts bidiGenerateContentSetup.
15057
+ * @param requestDict - The request dictionary.
15058
+ * @param config - The configuration object.
15059
+ * @return - The modified request dictionary.
15060
+ */
15061
+ function convertBidiSetupToTokenSetup(requestDict, config) {
15062
+ // Convert bidiGenerateContentSetup from bidiGenerateContentSetup.setup.
15063
+ let setupForMaskGeneration = null;
15064
+ const bidiGenerateContentSetupValue = requestDict['bidiGenerateContentSetup'];
15065
+ if (typeof bidiGenerateContentSetupValue === 'object' &&
15066
+ bidiGenerateContentSetupValue !== null &&
15067
+ 'setup' in bidiGenerateContentSetupValue) {
15068
+ // Now we know bidiGenerateContentSetupValue is an object and has a 'setup'
15069
+ // property.
15070
+ const innerSetup = bidiGenerateContentSetupValue
15071
+ .setup;
15072
+ if (typeof innerSetup === 'object' && innerSetup !== null) {
15073
+ // Valid inner setup found.
15074
+ requestDict['bidiGenerateContentSetup'] = innerSetup;
15075
+ setupForMaskGeneration = innerSetup;
15076
+ }
15077
+ else {
15078
+ // `bidiGenerateContentSetupValue.setup` is not a valid object; treat as
15079
+ // if bidiGenerateContentSetup is invalid.
15080
+ delete requestDict['bidiGenerateContentSetup'];
15081
+ }
15222
15082
  }
15223
- const fromNextPageToken = getValueByPath(fromObject, [
15224
- 'nextPageToken',
15225
- ]);
15226
- if (fromNextPageToken != null) {
15227
- setValueByPath(toObject, ['nextPageToken'], fromNextPageToken);
15083
+ else if (bidiGenerateContentSetupValue !== undefined) {
15084
+ // `bidiGenerateContentSetup` exists but not in the expected
15085
+ // shape {setup: {...}}; treat as invalid.
15086
+ delete requestDict['bidiGenerateContentSetup'];
15228
15087
  }
15229
- const fromFileSearchStores = getValueByPath(fromObject, [
15230
- 'fileSearchStores',
15231
- ]);
15232
- if (fromFileSearchStores != null) {
15233
- let transformedList = fromFileSearchStores;
15234
- if (Array.isArray(transformedList)) {
15235
- transformedList = transformedList.map((item) => {
15236
- return item;
15237
- });
15088
+ const preExistingFieldMask = requestDict['fieldMask'];
15089
+ // Handle mask generation setup.
15090
+ if (setupForMaskGeneration) {
15091
+ const generatedMaskFromBidi = getFieldMasks(setupForMaskGeneration);
15092
+ if (Array.isArray(config === null || config === void 0 ? void 0 : config.lockAdditionalFields) &&
15093
+ (config === null || config === void 0 ? void 0 : config.lockAdditionalFields.length) === 0) {
15094
+ // Case 1: lockAdditionalFields is an empty array. Lock only fields from
15095
+ // bidi setup.
15096
+ if (generatedMaskFromBidi) {
15097
+ // Only assign if mask is not empty
15098
+ requestDict['fieldMask'] = generatedMaskFromBidi;
15099
+ }
15100
+ else {
15101
+ delete requestDict['fieldMask']; // If mask is empty, effectively no
15102
+ // specific fields locked by bidi
15103
+ }
15104
+ }
15105
+ else if ((config === null || config === void 0 ? void 0 : config.lockAdditionalFields) &&
15106
+ config.lockAdditionalFields.length > 0 &&
15107
+ preExistingFieldMask !== null &&
15108
+ Array.isArray(preExistingFieldMask) &&
15109
+ preExistingFieldMask.length > 0) {
15110
+ // Case 2: Lock fields from bidi setup + additional fields
15111
+ // (preExistingFieldMask).
15112
+ const generationConfigFields = [
15113
+ 'temperature',
15114
+ 'topK',
15115
+ 'topP',
15116
+ 'maxOutputTokens',
15117
+ 'responseModalities',
15118
+ 'seed',
15119
+ 'speechConfig',
15120
+ ];
15121
+ let mappedFieldsFromPreExisting = [];
15122
+ if (preExistingFieldMask.length > 0) {
15123
+ mappedFieldsFromPreExisting = preExistingFieldMask.map((field) => {
15124
+ if (generationConfigFields.includes(field)) {
15125
+ return `generationConfig.${field}`;
15126
+ }
15127
+ return field; // Keep original field name if not in
15128
+ // generationConfigFields
15129
+ });
15130
+ }
15131
+ const finalMaskParts = [];
15132
+ if (generatedMaskFromBidi) {
15133
+ finalMaskParts.push(generatedMaskFromBidi);
15134
+ }
15135
+ if (mappedFieldsFromPreExisting.length > 0) {
15136
+ finalMaskParts.push(...mappedFieldsFromPreExisting);
15137
+ }
15138
+ if (finalMaskParts.length > 0) {
15139
+ requestDict['fieldMask'] = finalMaskParts.join(',');
15140
+ }
15141
+ else {
15142
+ // If no fields from bidi and no valid additional fields from
15143
+ // pre-existing mask.
15144
+ delete requestDict['fieldMask'];
15145
+ }
15146
+ }
15147
+ else {
15148
+ // Case 3: "Lock all fields" (meaning, don't send a field_mask, let server
15149
+ // defaults apply or all are mutable). This is hit if:
15150
+ // - `config.lockAdditionalFields` is undefined.
15151
+ // - `config.lockAdditionalFields` is non-empty, BUT
15152
+ // `preExistingFieldMask` is null, not a string, or an empty string.
15153
+ delete requestDict['fieldMask'];
15154
+ }
15155
+ }
15156
+ else {
15157
+ // No valid `bidiGenerateContentSetup` was found or extracted.
15158
+ // "Lock additional null fields if any".
15159
+ if (preExistingFieldMask !== null &&
15160
+ Array.isArray(preExistingFieldMask) &&
15161
+ preExistingFieldMask.length > 0) {
15162
+ // If there's a pre-existing field mask, it's a string, and it's not
15163
+ // empty, then we should lock all fields.
15164
+ requestDict['fieldMask'] = preExistingFieldMask.join(',');
15165
+ }
15166
+ else {
15167
+ delete requestDict['fieldMask'];
15238
15168
  }
15239
- setValueByPath(toObject, ['fileSearchStores'], transformedList);
15240
15169
  }
15241
- return toObject;
15170
+ return requestDict;
15242
15171
  }
15243
- function uploadToFileSearchStoreConfigToMldev(fromObject, parentObject) {
15244
- const toObject = {};
15245
- const fromMimeType = getValueByPath(fromObject, ['mimeType']);
15246
- if (parentObject !== undefined && fromMimeType != null) {
15247
- setValueByPath(parentObject, ['mimeType'], fromMimeType);
15248
- }
15249
- const fromDisplayName = getValueByPath(fromObject, ['displayName']);
15250
- if (parentObject !== undefined && fromDisplayName != null) {
15251
- setValueByPath(parentObject, ['displayName'], fromDisplayName);
15172
+ class Tokens extends BaseModule {
15173
+ constructor(apiClient) {
15174
+ super();
15175
+ this.apiClient = apiClient;
15252
15176
  }
15253
- const fromCustomMetadata = getValueByPath(fromObject, [
15254
- 'customMetadata',
15255
- ]);
15256
- if (parentObject !== undefined && fromCustomMetadata != null) {
15257
- let transformedList = fromCustomMetadata;
15258
- if (Array.isArray(transformedList)) {
15259
- transformedList = transformedList.map((item) => {
15260
- return item;
15177
+ /**
15178
+ * Creates an ephemeral auth token resource.
15179
+ *
15180
+ * @experimental
15181
+ *
15182
+ * @remarks
15183
+ * Ephemeral auth tokens is only supported in the Gemini Developer API.
15184
+ * It can be used for the session connection to the Live constrained API.
15185
+ * Support in v1alpha only.
15186
+ *
15187
+ * @param params - The parameters for the create request.
15188
+ * @return The created auth token.
15189
+ *
15190
+ * @example
15191
+ * ```ts
15192
+ * const ai = new GoogleGenAI({
15193
+ * apiKey: token.name,
15194
+ * httpOptions: { apiVersion: 'v1alpha' } // Support in v1alpha only.
15195
+ * });
15196
+ *
15197
+ * // Case 1: If LiveEphemeralParameters is unset, unlock LiveConnectConfig
15198
+ * // when using the token in Live API sessions. Each session connection can
15199
+ * // use a different configuration.
15200
+ * const config: CreateAuthTokenConfig = {
15201
+ * uses: 3,
15202
+ * expireTime: '2025-05-01T00:00:00Z',
15203
+ * }
15204
+ * const token = await ai.tokens.create(config);
15205
+ *
15206
+ * // Case 2: If LiveEphemeralParameters is set, lock all fields in
15207
+ * // LiveConnectConfig when using the token in Live API sessions. For
15208
+ * // example, changing `outputAudioTranscription` in the Live API
15209
+ * // connection will be ignored by the API.
15210
+ * const config: CreateAuthTokenConfig =
15211
+ * uses: 3,
15212
+ * expireTime: '2025-05-01T00:00:00Z',
15213
+ * LiveEphemeralParameters: {
15214
+ * model: 'gemini-2.0-flash-001',
15215
+ * config: {
15216
+ * 'responseModalities': ['AUDIO'],
15217
+ * 'systemInstruction': 'Always answer in English.',
15218
+ * }
15219
+ * }
15220
+ * }
15221
+ * const token = await ai.tokens.create(config);
15222
+ *
15223
+ * // Case 3: If LiveEphemeralParameters is set and lockAdditionalFields is
15224
+ * // set, lock LiveConnectConfig with set and additional fields (e.g.
15225
+ * // responseModalities, systemInstruction, temperature in this example) when
15226
+ * // using the token in Live API sessions.
15227
+ * const config: CreateAuthTokenConfig =
15228
+ * uses: 3,
15229
+ * expireTime: '2025-05-01T00:00:00Z',
15230
+ * LiveEphemeralParameters: {
15231
+ * model: 'gemini-2.0-flash-001',
15232
+ * config: {
15233
+ * 'responseModalities': ['AUDIO'],
15234
+ * 'systemInstruction': 'Always answer in English.',
15235
+ * }
15236
+ * },
15237
+ * lockAdditionalFields: ['temperature'],
15238
+ * }
15239
+ * const token = await ai.tokens.create(config);
15240
+ *
15241
+ * // Case 4: If LiveEphemeralParameters is set and lockAdditionalFields is
15242
+ * // empty array, lock LiveConnectConfig with set fields (e.g.
15243
+ * // responseModalities, systemInstruction in this example) when using the
15244
+ * // token in Live API sessions.
15245
+ * const config: CreateAuthTokenConfig =
15246
+ * uses: 3,
15247
+ * expireTime: '2025-05-01T00:00:00Z',
15248
+ * LiveEphemeralParameters: {
15249
+ * model: 'gemini-2.0-flash-001',
15250
+ * config: {
15251
+ * 'responseModalities': ['AUDIO'],
15252
+ * 'systemInstruction': 'Always answer in English.',
15253
+ * }
15254
+ * },
15255
+ * lockAdditionalFields: [],
15256
+ * }
15257
+ * const token = await ai.tokens.create(config);
15258
+ * ```
15259
+ */
15260
+ async create(params) {
15261
+ var _a, _b;
15262
+ let response;
15263
+ let path = '';
15264
+ let queryParams = {};
15265
+ if (this.apiClient.isVertexAI()) {
15266
+ throw new Error('The client.tokens.create method is only supported by the Gemini Developer API.');
15267
+ }
15268
+ else {
15269
+ const body = createAuthTokenParametersToMldev(this.apiClient, params);
15270
+ path = formatMap('auth_tokens', body['_url']);
15271
+ queryParams = body['_query'];
15272
+ delete body['config'];
15273
+ delete body['_url'];
15274
+ delete body['_query'];
15275
+ const transformedBody = convertBidiSetupToTokenSetup(body, params.config);
15276
+ response = this.apiClient
15277
+ .request({
15278
+ path: path,
15279
+ queryParams: queryParams,
15280
+ body: JSON.stringify(transformedBody),
15281
+ httpMethod: 'POST',
15282
+ httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
15283
+ abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
15284
+ })
15285
+ .then((httpResponse) => {
15286
+ return httpResponse.json();
15287
+ });
15288
+ return response.then((resp) => {
15289
+ return resp;
15261
15290
  });
15262
15291
  }
15263
- setValueByPath(parentObject, ['customMetadata'], transformedList);
15264
- }
15265
- const fromChunkingConfig = getValueByPath(fromObject, [
15266
- 'chunkingConfig',
15267
- ]);
15268
- if (parentObject !== undefined && fromChunkingConfig != null) {
15269
- setValueByPath(parentObject, ['chunkingConfig'], fromChunkingConfig);
15270
- }
15271
- return toObject;
15272
- }
15273
- function uploadToFileSearchStoreParametersToMldev(fromObject) {
15274
- const toObject = {};
15275
- const fromFileSearchStoreName = getValueByPath(fromObject, [
15276
- 'fileSearchStoreName',
15277
- ]);
15278
- if (fromFileSearchStoreName != null) {
15279
- setValueByPath(toObject, ['_url', 'file_search_store_name'], fromFileSearchStoreName);
15280
- }
15281
- const fromConfig = getValueByPath(fromObject, ['config']);
15282
- if (fromConfig != null) {
15283
- uploadToFileSearchStoreConfigToMldev(fromConfig, toObject);
15284
- }
15285
- return toObject;
15286
- }
15287
- function uploadToFileSearchStoreResumableResponseFromMldev(fromObject) {
15288
- const toObject = {};
15289
- const fromSdkHttpResponse = getValueByPath(fromObject, [
15290
- 'sdkHttpResponse',
15291
- ]);
15292
- if (fromSdkHttpResponse != null) {
15293
- setValueByPath(toObject, ['sdkHttpResponse'], fromSdkHttpResponse);
15294
15292
  }
15295
- return toObject;
15296
15293
  }
15297
15294
 
15298
15295
  /**
@@ -15397,17 +15394,14 @@ class Documents extends BaseModule {
15397
15394
  *
15398
15395
  * @example
15399
15396
  * ```ts
15400
- * const documents = await ai.documents.list({config: {'pageSize': 2}});
15397
+ * const documents = await ai.documents.list({parent:'rag_store_name', config: {'pageSize': 2}});
15401
15398
  * for await (const document of documents) {
15402
15399
  * console.log(document);
15403
15400
  * }
15404
15401
  * ```
15405
15402
  */
15406
15403
  this.list = async (params) => {
15407
- return new Pager(PagedItem.PAGED_ITEM_DOCUMENTS, (x) => this.listInternal({
15408
- parent: params.parent,
15409
- config: x.config,
15410
- }), await this.listInternal(params), params);
15404
+ return new Pager(PagedItem.PAGED_ITEM_DOCUMENTS, (x) => this.listInternal({ parent: params.parent, config: x.config }), await this.listInternal(params), params);
15411
15405
  };
15412
15406
  }
15413
15407
  /**
@@ -15475,12 +15469,6 @@ class Documents extends BaseModule {
15475
15469
  });
15476
15470
  }
15477
15471
  }
15478
- /**
15479
- * Lists all Documents in a FileSearchStore.
15480
- *
15481
- * @param params - The parameters for listing documents.
15482
- * @return ListDocumentsResponse.
15483
- */
15484
15472
  async listInternal(params) {
15485
15473
  var _a, _b;
15486
15474
  let response;
@@ -15689,12 +15677,6 @@ class FileSearchStores extends BaseModule {
15689
15677
  });
15690
15678
  }
15691
15679
  }
15692
- /**
15693
- * Lists all FileSearchStore owned by the user.
15694
- *
15695
- * @param params - The parameters for listing file search stores.
15696
- * @return ListFileSearchStoresResponse.
15697
- */
15698
15680
  async listInternal(params) {
15699
15681
  var _a, _b;
15700
15682
  let response;
@@ -16008,6 +15990,26 @@ function cancelTuningJobParametersToVertex(fromObject, _rootObject) {
16008
15990
  }
16009
15991
  return toObject;
16010
15992
  }
15993
+ function cancelTuningJobResponseFromMldev(fromObject, _rootObject) {
15994
+ const toObject = {};
15995
+ const fromSdkHttpResponse = getValueByPath(fromObject, [
15996
+ 'sdkHttpResponse',
15997
+ ]);
15998
+ if (fromSdkHttpResponse != null) {
15999
+ setValueByPath(toObject, ['sdkHttpResponse'], fromSdkHttpResponse);
16000
+ }
16001
+ return toObject;
16002
+ }
16003
+ function cancelTuningJobResponseFromVertex(fromObject, _rootObject) {
16004
+ const toObject = {};
16005
+ const fromSdkHttpResponse = getValueByPath(fromObject, [
16006
+ 'sdkHttpResponse',
16007
+ ]);
16008
+ if (fromSdkHttpResponse != null) {
16009
+ setValueByPath(toObject, ['sdkHttpResponse'], fromSdkHttpResponse);
16010
+ }
16011
+ return toObject;
16012
+ }
16011
16013
  function createTuningJobConfigToMldev(fromObject, parentObject, _rootObject) {
16012
16014
  const toObject = {};
16013
16015
  if (getValueByPath(fromObject, ['validationDataset']) !== undefined) {
@@ -16669,28 +16671,33 @@ class Tunings extends BaseModule {
16669
16671
  super();
16670
16672
  this.apiClient = apiClient;
16671
16673
  /**
16672
- * Gets a TuningJob.
16674
+ * Lists tuning jobs.
16673
16675
  *
16674
- * @param name - The resource name of the tuning job.
16675
- * @return - A TuningJob object.
16676
+ * @param params - The parameters for the list request.
16677
+ * @return - A pager of tuning jobs.
16676
16678
  *
16677
- * @experimental - The SDK's tuning implementation is experimental, and may
16678
- * change in future versions.
16679
+ * @example
16680
+ * ```ts
16681
+ * const tuningJobs = await ai.tunings.list({config: {'pageSize': 2}});
16682
+ * for await (const tuningJob of tuningJobs) {
16683
+ * console.log(tuningJob);
16684
+ * }
16685
+ * ```
16679
16686
  */
16680
- this.get = async (params) => {
16681
- return await this.getInternal(params);
16687
+ this.list = async (params = {}) => {
16688
+ return new Pager(PagedItem.PAGED_ITEM_TUNING_JOBS, (x) => this.listInternal(x), await this.listInternal(params), params);
16682
16689
  };
16683
16690
  /**
16684
- * Lists tuning jobs.
16691
+ * Gets a TuningJob.
16685
16692
  *
16686
- * @param config - The configuration for the list request.
16687
- * @return - A list of tuning jobs.
16693
+ * @param name - The resource name of the tuning job.
16694
+ * @return - A TuningJob object.
16688
16695
  *
16689
16696
  * @experimental - The SDK's tuning implementation is experimental, and may
16690
16697
  * change in future versions.
16691
16698
  */
16692
- this.list = async (params = {}) => {
16693
- return new Pager(PagedItem.PAGED_ITEM_TUNING_JOBS, (x) => this.listInternal(x), await this.listInternal(params), params);
16699
+ this.get = async (params) => {
16700
+ return await this.getInternal(params);
16694
16701
  };
16695
16702
  /**
16696
16703
  * Creates a supervised fine-tuning job.
@@ -16885,6 +16892,7 @@ class Tunings extends BaseModule {
16885
16892
  */
16886
16893
  async cancel(params) {
16887
16894
  var _a, _b, _c, _d;
16895
+ let response;
16888
16896
  let path = '';
16889
16897
  let queryParams = {};
16890
16898
  if (this.apiClient.isVertexAI()) {
@@ -16893,13 +16901,29 @@ class Tunings extends BaseModule {
16893
16901
  queryParams = body['_query'];
16894
16902
  delete body['_url'];
16895
16903
  delete body['_query'];
16896
- await this.apiClient.request({
16904
+ response = this.apiClient
16905
+ .request({
16897
16906
  path: path,
16898
16907
  queryParams: queryParams,
16899
16908
  body: JSON.stringify(body),
16900
16909
  httpMethod: 'POST',
16901
16910
  httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
16902
16911
  abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
16912
+ })
16913
+ .then((httpResponse) => {
16914
+ return httpResponse.json().then((jsonResponse) => {
16915
+ const response = jsonResponse;
16916
+ response.sdkHttpResponse = {
16917
+ headers: httpResponse.headers,
16918
+ };
16919
+ return response;
16920
+ });
16921
+ });
16922
+ return response.then((apiResponse) => {
16923
+ const resp = cancelTuningJobResponseFromVertex(apiResponse);
16924
+ const typedResp = new CancelTuningJobResponse();
16925
+ Object.assign(typedResp, resp);
16926
+ return typedResp;
16903
16927
  });
16904
16928
  }
16905
16929
  else {
@@ -16908,13 +16932,29 @@ class Tunings extends BaseModule {
16908
16932
  queryParams = body['_query'];
16909
16933
  delete body['_url'];
16910
16934
  delete body['_query'];
16911
- await this.apiClient.request({
16935
+ response = this.apiClient
16936
+ .request({
16912
16937
  path: path,
16913
16938
  queryParams: queryParams,
16914
16939
  body: JSON.stringify(body),
16915
16940
  httpMethod: 'POST',
16916
16941
  httpOptions: (_c = params.config) === null || _c === void 0 ? void 0 : _c.httpOptions,
16917
16942
  abortSignal: (_d = params.config) === null || _d === void 0 ? void 0 : _d.abortSignal,
16943
+ })
16944
+ .then((httpResponse) => {
16945
+ return httpResponse.json().then((jsonResponse) => {
16946
+ const response = jsonResponse;
16947
+ response.sdkHttpResponse = {
16948
+ headers: httpResponse.headers,
16949
+ };
16950
+ return response;
16951
+ });
16952
+ });
16953
+ return response.then((apiResponse) => {
16954
+ const resp = cancelTuningJobResponseFromMldev(apiResponse);
16955
+ const typedResp = new CancelTuningJobResponse();
16956
+ Object.assign(typedResp, resp);
16957
+ return typedResp;
16918
16958
  });
16919
16959
  }
16920
16960
  }
@@ -17400,6 +17440,7 @@ class GoogleGenAI {
17400
17440
  }
17401
17441
  }
17402
17442
  this.apiVersion = options.apiVersion;
17443
+ this.httpOptions = options.httpOptions;
17403
17444
  const auth = new NodeAuth({
17404
17445
  apiKey: this.apiKey,
17405
17446
  googleAuthOptions: options.googleAuthOptions,
@@ -17411,7 +17452,7 @@ class GoogleGenAI {
17411
17452
  apiVersion: this.apiVersion,
17412
17453
  apiKey: this.apiKey,
17413
17454
  vertexai: this.vertexai,
17414
- httpOptions: options.httpOptions,
17455
+ httpOptions: this.httpOptions,
17415
17456
  userAgentExtra: LANGUAGE_LABEL_PREFIX + process.version,
17416
17457
  uploader: new NodeUploader(),
17417
17458
  downloader: new NodeDownloader(),
@@ -17450,5 +17491,5 @@ function getApiKeyFromEnv() {
17450
17491
  return envGoogleApiKey || envGeminiApiKey || undefined;
17451
17492
  }
17452
17493
 
17453
- export { ActivityHandling, AdapterSize, ApiError, ApiSpec, AuthType, Batches, Behavior, BlockedReason, Caches, Chat, Chats, ComputeTokensResponse, ContentReferenceImage, ControlReferenceImage, ControlReferenceType, CountTokensResponse, CreateFileResponse, DeleteCachedContentResponse, DeleteFileResponse, DeleteModelResponse, DocumentState, DynamicRetrievalConfigMode, EditImageResponse, EditMode, EmbedContentResponse, EndSensitivity, Environment, FeatureSelectionPreference, FileSource, FileState, Files, FinishReason, FunctionCallingConfigMode, FunctionResponse, FunctionResponseBlob, FunctionResponseFileData, FunctionResponsePart, FunctionResponseScheduling, GenerateContentResponse, GenerateContentResponsePromptFeedback, GenerateContentResponseUsageMetadata, GenerateImagesResponse, GenerateVideosOperation, GenerateVideosResponse, GoogleGenAI, HarmBlockMethod, HarmBlockThreshold, HarmCategory, HarmProbability, HarmSeverity, HttpElementLocation, HttpResponse, ImagePromptLanguage, ImportFileOperation, ImportFileResponse, InlinedEmbedContentResponse, InlinedResponse, JobState, Language, ListBatchJobsResponse, ListCachedContentsResponse, ListDocumentsResponse, ListFileSearchStoresResponse, ListFilesResponse, ListModelsResponse, ListTuningJobsResponse, Live, LiveClientToolResponse, LiveMusicPlaybackControl, LiveMusicServerMessage, LiveSendToolResponseParameters, LiveServerMessage, MaskReferenceImage, MaskReferenceMode, MediaModality, MediaResolution, Modality, Mode, Models, MusicGenerationMode, Operations, Outcome, PagedItem, Pager, PartMediaResolutionLevel, PersonGeneration, PhishBlockThreshold, RawReferenceImage, RecontextImageResponse, ReplayResponse, SafetyFilterLevel, Scale, SegmentImageResponse, SegmentMode, Session, SingleEmbedContentResponse, StartSensitivity, StyleReferenceImage, SubjectReferenceImage, SubjectReferenceType, ThinkingLevel, Tokens, TrafficType, TuningMethod, TuningMode, TuningTask, TurnCompleteReason, TurnCoverage, Type, UploadToFileSearchStoreOperation, UploadToFileSearchStoreResponse, UploadToFileSearchStoreResumableResponse, UpscaleImageResponse, UrlRetrievalStatus, VideoCompressionQuality, VideoGenerationMaskMode, VideoGenerationReferenceType, createFunctionResponsePartFromBase64, createFunctionResponsePartFromUri, createModelContent, createPartFromBase64, createPartFromCodeExecutionResult, createPartFromExecutableCode, createPartFromFunctionCall, createPartFromFunctionResponse, createPartFromText, createPartFromUri, createUserContent, mcpToTool, setDefaultBaseUrls };
17494
+ export { ActivityHandling, AdapterSize, ApiError, ApiSpec, AuthType, Batches, Behavior, BlockedReason, Caches, CancelTuningJobResponse, Chat, Chats, ComputeTokensResponse, ContentReferenceImage, ControlReferenceImage, ControlReferenceType, CountTokensResponse, CreateFileResponse, DeleteCachedContentResponse, DeleteFileResponse, DeleteModelResponse, DocumentState, DynamicRetrievalConfigMode, EditImageResponse, EditMode, EmbedContentResponse, EndSensitivity, Environment, FeatureSelectionPreference, FileSource, FileState, Files, FinishReason, FunctionCallingConfigMode, FunctionResponse, FunctionResponseBlob, FunctionResponseFileData, FunctionResponsePart, FunctionResponseScheduling, GenerateContentResponse, GenerateContentResponsePromptFeedback, GenerateContentResponseUsageMetadata, GenerateImagesResponse, GenerateVideosOperation, GenerateVideosResponse, GoogleGenAI, HarmBlockMethod, HarmBlockThreshold, HarmCategory, HarmProbability, HarmSeverity, HttpElementLocation, HttpResponse, ImagePromptLanguage, ImportFileOperation, ImportFileResponse, InlinedEmbedContentResponse, InlinedResponse, JobState, Language, ListBatchJobsResponse, ListCachedContentsResponse, ListDocumentsResponse, ListFileSearchStoresResponse, ListFilesResponse, ListModelsResponse, ListTuningJobsResponse, Live, LiveClientToolResponse, LiveMusicPlaybackControl, LiveMusicServerMessage, LiveSendToolResponseParameters, LiveServerMessage, MaskReferenceImage, MaskReferenceMode, MediaModality, MediaResolution, Modality, Mode, Models, MusicGenerationMode, Operations, Outcome, PagedItem, Pager, PartMediaResolutionLevel, PersonGeneration, PhishBlockThreshold, RawReferenceImage, RecontextImageResponse, ReplayResponse, SafetyFilterLevel, Scale, SegmentImageResponse, SegmentMode, Session, SingleEmbedContentResponse, StartSensitivity, StyleReferenceImage, SubjectReferenceImage, SubjectReferenceType, ThinkingLevel, Tokens, TrafficType, TuningMethod, TuningMode, TuningTask, TurnCompleteReason, TurnCoverage, Type, UploadToFileSearchStoreOperation, UploadToFileSearchStoreResponse, UploadToFileSearchStoreResumableResponse, UpscaleImageResponse, UrlRetrievalStatus, VideoCompressionQuality, VideoGenerationMaskMode, VideoGenerationReferenceType, createFunctionResponsePartFromBase64, createFunctionResponsePartFromUri, createModelContent, createPartFromBase64, createPartFromCodeExecutionResult, createPartFromExecutableCode, createPartFromFunctionCall, createPartFromFunctionResponse, createPartFromText, createPartFromUri, createUserContent, mcpToTool, setDefaultBaseUrls };
17454
17495
  //# sourceMappingURL=index.mjs.map