@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.
- package/dist/genai.d.ts +66 -65
- package/dist/index.cjs +906 -864
- package/dist/index.mjs +906 -865
- package/dist/index.mjs.map +1 -1
- package/dist/node/index.cjs +1302 -1260
- package/dist/node/index.mjs +1302 -1261
- package/dist/node/index.mjs.map +1 -1
- package/dist/node/node.d.ts +66 -65
- package/dist/web/index.mjs +1302 -1261
- package/dist/web/index.mjs.map +1 -1
- package/dist/web/web.d.ts +66 -65
- package/package.json +2 -2
package/dist/node/index.cjs
CHANGED
|
@@ -2255,6 +2255,9 @@ class GenerateVideosOperation {
|
|
|
2255
2255
|
/** Response for the list tuning jobs method. */
|
|
2256
2256
|
class ListTuningJobsResponse {
|
|
2257
2257
|
}
|
|
2258
|
+
/** Empty response for tunings.cancel method. */
|
|
2259
|
+
class CancelTuningJobResponse {
|
|
2260
|
+
}
|
|
2258
2261
|
/** Empty response for caches.delete method. */
|
|
2259
2262
|
class DeleteCachedContentResponse {
|
|
2260
2263
|
}
|
|
@@ -4722,6 +4725,23 @@ class Batches extends BaseModule {
|
|
|
4722
4725
|
constructor(apiClient) {
|
|
4723
4726
|
super();
|
|
4724
4727
|
this.apiClient = apiClient;
|
|
4728
|
+
/**
|
|
4729
|
+
* Lists batch jobs.
|
|
4730
|
+
*
|
|
4731
|
+
* @param params - The parameters for the list request.
|
|
4732
|
+
* @return - A pager of batch jobs.
|
|
4733
|
+
*
|
|
4734
|
+
* @example
|
|
4735
|
+
* ```ts
|
|
4736
|
+
* const batchJobs = await ai.batches.list({config: {'pageSize': 2}});
|
|
4737
|
+
* for await (const batchJob of batchJobs) {
|
|
4738
|
+
* console.log(batchJob);
|
|
4739
|
+
* }
|
|
4740
|
+
* ```
|
|
4741
|
+
*/
|
|
4742
|
+
this.list = async (params = {}) => {
|
|
4743
|
+
return new Pager(exports.PagedItem.PAGED_ITEM_BATCH_JOBS, (x) => this.listInternal(x), await this.listInternal(params), params);
|
|
4744
|
+
};
|
|
4725
4745
|
/**
|
|
4726
4746
|
* Create batch job.
|
|
4727
4747
|
*
|
|
@@ -4770,23 +4790,6 @@ class Batches extends BaseModule {
|
|
|
4770
4790
|
}
|
|
4771
4791
|
return this.createEmbeddingsInternal(params);
|
|
4772
4792
|
};
|
|
4773
|
-
/**
|
|
4774
|
-
* Lists batch job configurations.
|
|
4775
|
-
*
|
|
4776
|
-
* @param params - The parameters for the list request.
|
|
4777
|
-
* @return The paginated results of the list of batch jobs.
|
|
4778
|
-
*
|
|
4779
|
-
* @example
|
|
4780
|
-
* ```ts
|
|
4781
|
-
* const batchJobs = await ai.batches.list({config: {'pageSize': 2}});
|
|
4782
|
-
* for await (const batchJob of batchJobs) {
|
|
4783
|
-
* console.log(batchJob);
|
|
4784
|
-
* }
|
|
4785
|
-
* ```
|
|
4786
|
-
*/
|
|
4787
|
-
this.list = async (params = {}) => {
|
|
4788
|
-
return new Pager(exports.PagedItem.PAGED_ITEM_BATCH_JOBS, (x) => this.listInternal(x), await this.listInternal(params), params);
|
|
4789
|
-
};
|
|
4790
4793
|
}
|
|
4791
4794
|
// Helper function to handle inlined generate content requests
|
|
4792
4795
|
createInlinedGenerateContentRequest(params) {
|
|
@@ -5889,10 +5892,10 @@ class Caches extends BaseModule {
|
|
|
5889
5892
|
super();
|
|
5890
5893
|
this.apiClient = apiClient;
|
|
5891
5894
|
/**
|
|
5892
|
-
* Lists cached
|
|
5895
|
+
* Lists cached contents.
|
|
5893
5896
|
*
|
|
5894
5897
|
* @param params - The parameters for the list request.
|
|
5895
|
-
* @return
|
|
5898
|
+
* @return - A pager of cached contents.
|
|
5896
5899
|
*
|
|
5897
5900
|
* @example
|
|
5898
5901
|
* ```ts
|
|
@@ -6762,19 +6765,16 @@ class Files extends BaseModule {
|
|
|
6762
6765
|
super();
|
|
6763
6766
|
this.apiClient = apiClient;
|
|
6764
6767
|
/**
|
|
6765
|
-
* Lists
|
|
6768
|
+
* Lists files.
|
|
6766
6769
|
*
|
|
6767
|
-
* @param params - The parameters for the list request
|
|
6768
|
-
* @return
|
|
6770
|
+
* @param params - The parameters for the list request.
|
|
6771
|
+
* @return - A pager of files.
|
|
6769
6772
|
*
|
|
6770
6773
|
* @example
|
|
6771
|
-
* The following code prints the names of all files from the service, the
|
|
6772
|
-
* size of each page is 10.
|
|
6773
|
-
*
|
|
6774
6774
|
* ```ts
|
|
6775
|
-
* const
|
|
6776
|
-
* for await (const file of
|
|
6777
|
-
* console.log(file
|
|
6775
|
+
* const files = await ai.files.list({config: {'pageSize': 2}});
|
|
6776
|
+
* for await (const file of files) {
|
|
6777
|
+
* console.log(file);
|
|
6778
6778
|
* }
|
|
6779
6779
|
* ```
|
|
6780
6780
|
*/
|
|
@@ -11213,239 +11213,474 @@ function videoToVertex(fromObject) {
|
|
|
11213
11213
|
* Copyright 2025 Google LLC
|
|
11214
11214
|
* SPDX-License-Identifier: Apache-2.0
|
|
11215
11215
|
*/
|
|
11216
|
-
|
|
11217
|
-
|
|
11218
|
-
const
|
|
11219
|
-
const
|
|
11220
|
-
|
|
11221
|
-
|
|
11222
|
-
const VERTEX_AI_API_DEFAULT_VERSION = 'v1beta1';
|
|
11223
|
-
const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
|
|
11224
|
-
const responseLineRE = /^\s*data: (.*)(?:\n\n|\r\r|\r\n\r\n)/;
|
|
11225
|
-
/**
|
|
11226
|
-
* The ApiClient class is used to send requests to the Gemini API or Vertex AI
|
|
11227
|
-
* endpoints.
|
|
11228
|
-
*/
|
|
11229
|
-
class ApiClient {
|
|
11230
|
-
constructor(opts) {
|
|
11231
|
-
var _a, _b;
|
|
11232
|
-
this.clientOptions = Object.assign(Object.assign({}, opts), { project: opts.project, location: opts.location, apiKey: opts.apiKey, vertexai: opts.vertexai });
|
|
11233
|
-
const initHttpOptions = {};
|
|
11234
|
-
if (this.clientOptions.vertexai) {
|
|
11235
|
-
initHttpOptions.apiVersion =
|
|
11236
|
-
(_a = this.clientOptions.apiVersion) !== null && _a !== void 0 ? _a : VERTEX_AI_API_DEFAULT_VERSION;
|
|
11237
|
-
initHttpOptions.baseUrl = this.baseUrlFromProjectLocation();
|
|
11238
|
-
this.normalizeAuthParameters();
|
|
11239
|
-
}
|
|
11240
|
-
else {
|
|
11241
|
-
// Gemini API
|
|
11242
|
-
initHttpOptions.apiVersion =
|
|
11243
|
-
(_b = this.clientOptions.apiVersion) !== null && _b !== void 0 ? _b : GOOGLE_AI_API_DEFAULT_VERSION;
|
|
11244
|
-
initHttpOptions.baseUrl = `https://generativelanguage.googleapis.com/`;
|
|
11245
|
-
}
|
|
11246
|
-
initHttpOptions.headers = this.getDefaultHeaders();
|
|
11247
|
-
this.clientOptions.httpOptions = initHttpOptions;
|
|
11248
|
-
if (opts.httpOptions) {
|
|
11249
|
-
this.clientOptions.httpOptions = this.patchHttpOptions(initHttpOptions, opts.httpOptions);
|
|
11250
|
-
}
|
|
11216
|
+
// Code generated by the Google Gen AI SDK generator DO NOT EDIT.
|
|
11217
|
+
function createFileSearchStoreConfigToMldev(fromObject, parentObject) {
|
|
11218
|
+
const toObject = {};
|
|
11219
|
+
const fromDisplayName = getValueByPath(fromObject, ['displayName']);
|
|
11220
|
+
if (parentObject !== undefined && fromDisplayName != null) {
|
|
11221
|
+
setValueByPath(parentObject, ['displayName'], fromDisplayName);
|
|
11251
11222
|
}
|
|
11252
|
-
|
|
11253
|
-
|
|
11254
|
-
|
|
11255
|
-
|
|
11256
|
-
|
|
11257
|
-
|
|
11258
|
-
|
|
11259
|
-
if (this.clientOptions.project &&
|
|
11260
|
-
this.clientOptions.location &&
|
|
11261
|
-
this.clientOptions.location !== 'global') {
|
|
11262
|
-
// Regional endpoint
|
|
11263
|
-
return `https://${this.clientOptions.location}-aiplatform.googleapis.com/`;
|
|
11264
|
-
}
|
|
11265
|
-
// Global endpoint (covers 'global' location and API key usage)
|
|
11266
|
-
return `https://aiplatform.googleapis.com/`;
|
|
11223
|
+
return toObject;
|
|
11224
|
+
}
|
|
11225
|
+
function createFileSearchStoreParametersToMldev(fromObject) {
|
|
11226
|
+
const toObject = {};
|
|
11227
|
+
const fromConfig = getValueByPath(fromObject, ['config']);
|
|
11228
|
+
if (fromConfig != null) {
|
|
11229
|
+
createFileSearchStoreConfigToMldev(fromConfig, toObject);
|
|
11267
11230
|
}
|
|
11268
|
-
|
|
11269
|
-
|
|
11270
|
-
|
|
11271
|
-
|
|
11272
|
-
|
|
11273
|
-
|
|
11274
|
-
|
|
11275
|
-
normalizeAuthParameters() {
|
|
11276
|
-
if (this.clientOptions.project && this.clientOptions.location) {
|
|
11277
|
-
// Using project/location for auth, clear potential API key
|
|
11278
|
-
this.clientOptions.apiKey = undefined;
|
|
11279
|
-
return;
|
|
11280
|
-
}
|
|
11281
|
-
// Using API key for auth (or no auth provided yet), clear project/location
|
|
11282
|
-
this.clientOptions.project = undefined;
|
|
11283
|
-
this.clientOptions.location = undefined;
|
|
11231
|
+
return toObject;
|
|
11232
|
+
}
|
|
11233
|
+
function deleteFileSearchStoreConfigToMldev(fromObject, parentObject) {
|
|
11234
|
+
const toObject = {};
|
|
11235
|
+
const fromForce = getValueByPath(fromObject, ['force']);
|
|
11236
|
+
if (parentObject !== undefined && fromForce != null) {
|
|
11237
|
+
setValueByPath(parentObject, ['_query', 'force'], fromForce);
|
|
11284
11238
|
}
|
|
11285
|
-
|
|
11286
|
-
|
|
11287
|
-
|
|
11239
|
+
return toObject;
|
|
11240
|
+
}
|
|
11241
|
+
function deleteFileSearchStoreParametersToMldev(fromObject) {
|
|
11242
|
+
const toObject = {};
|
|
11243
|
+
const fromName = getValueByPath(fromObject, ['name']);
|
|
11244
|
+
if (fromName != null) {
|
|
11245
|
+
setValueByPath(toObject, ['_url', 'name'], fromName);
|
|
11288
11246
|
}
|
|
11289
|
-
|
|
11290
|
-
|
|
11247
|
+
const fromConfig = getValueByPath(fromObject, ['config']);
|
|
11248
|
+
if (fromConfig != null) {
|
|
11249
|
+
deleteFileSearchStoreConfigToMldev(fromConfig, toObject);
|
|
11291
11250
|
}
|
|
11292
|
-
|
|
11293
|
-
|
|
11251
|
+
return toObject;
|
|
11252
|
+
}
|
|
11253
|
+
function getFileSearchStoreParametersToMldev(fromObject) {
|
|
11254
|
+
const toObject = {};
|
|
11255
|
+
const fromName = getValueByPath(fromObject, ['name']);
|
|
11256
|
+
if (fromName != null) {
|
|
11257
|
+
setValueByPath(toObject, ['_url', 'name'], fromName);
|
|
11294
11258
|
}
|
|
11295
|
-
|
|
11296
|
-
|
|
11297
|
-
|
|
11298
|
-
|
|
11259
|
+
return toObject;
|
|
11260
|
+
}
|
|
11261
|
+
function importFileConfigToMldev(fromObject, parentObject) {
|
|
11262
|
+
const toObject = {};
|
|
11263
|
+
const fromCustomMetadata = getValueByPath(fromObject, [
|
|
11264
|
+
'customMetadata',
|
|
11265
|
+
]);
|
|
11266
|
+
if (parentObject !== undefined && fromCustomMetadata != null) {
|
|
11267
|
+
let transformedList = fromCustomMetadata;
|
|
11268
|
+
if (Array.isArray(transformedList)) {
|
|
11269
|
+
transformedList = transformedList.map((item) => {
|
|
11270
|
+
return item;
|
|
11271
|
+
});
|
|
11299
11272
|
}
|
|
11300
|
-
|
|
11273
|
+
setValueByPath(parentObject, ['customMetadata'], transformedList);
|
|
11301
11274
|
}
|
|
11302
|
-
|
|
11303
|
-
|
|
11304
|
-
|
|
11305
|
-
|
|
11306
|
-
|
|
11307
|
-
throw new Error('Base URL is not set.');
|
|
11275
|
+
const fromChunkingConfig = getValueByPath(fromObject, [
|
|
11276
|
+
'chunkingConfig',
|
|
11277
|
+
]);
|
|
11278
|
+
if (parentObject !== undefined && fromChunkingConfig != null) {
|
|
11279
|
+
setValueByPath(parentObject, ['chunkingConfig'], fromChunkingConfig);
|
|
11308
11280
|
}
|
|
11309
|
-
|
|
11310
|
-
|
|
11281
|
+
return toObject;
|
|
11282
|
+
}
|
|
11283
|
+
function importFileOperationFromMldev(fromObject) {
|
|
11284
|
+
const toObject = {};
|
|
11285
|
+
const fromName = getValueByPath(fromObject, ['name']);
|
|
11286
|
+
if (fromName != null) {
|
|
11287
|
+
setValueByPath(toObject, ['name'], fromName);
|
|
11311
11288
|
}
|
|
11312
|
-
|
|
11313
|
-
|
|
11314
|
-
|
|
11315
|
-
return this.clientOptions.httpOptions.headers;
|
|
11316
|
-
}
|
|
11317
|
-
else {
|
|
11318
|
-
throw new Error('Headers are not set.');
|
|
11319
|
-
}
|
|
11289
|
+
const fromMetadata = getValueByPath(fromObject, ['metadata']);
|
|
11290
|
+
if (fromMetadata != null) {
|
|
11291
|
+
setValueByPath(toObject, ['metadata'], fromMetadata);
|
|
11320
11292
|
}
|
|
11321
|
-
|
|
11322
|
-
|
|
11323
|
-
|
|
11324
|
-
httpOptions.apiVersion === undefined) {
|
|
11325
|
-
throw new Error('HTTP options are not correctly set.');
|
|
11326
|
-
}
|
|
11327
|
-
const baseUrl = httpOptions.baseUrl.endsWith('/')
|
|
11328
|
-
? httpOptions.baseUrl.slice(0, -1)
|
|
11329
|
-
: httpOptions.baseUrl;
|
|
11330
|
-
const urlElement = [baseUrl];
|
|
11331
|
-
if (httpOptions.apiVersion && httpOptions.apiVersion !== '') {
|
|
11332
|
-
urlElement.push(httpOptions.apiVersion);
|
|
11333
|
-
}
|
|
11334
|
-
return urlElement.join('/');
|
|
11293
|
+
const fromDone = getValueByPath(fromObject, ['done']);
|
|
11294
|
+
if (fromDone != null) {
|
|
11295
|
+
setValueByPath(toObject, ['done'], fromDone);
|
|
11335
11296
|
}
|
|
11336
|
-
|
|
11337
|
-
|
|
11297
|
+
const fromError = getValueByPath(fromObject, ['error']);
|
|
11298
|
+
if (fromError != null) {
|
|
11299
|
+
setValueByPath(toObject, ['error'], fromError);
|
|
11338
11300
|
}
|
|
11339
|
-
|
|
11340
|
-
|
|
11301
|
+
const fromResponse = getValueByPath(fromObject, ['response']);
|
|
11302
|
+
if (fromResponse != null) {
|
|
11303
|
+
setValueByPath(toObject, ['response'], importFileResponseFromMldev(fromResponse));
|
|
11341
11304
|
}
|
|
11342
|
-
|
|
11343
|
-
|
|
11344
|
-
|
|
11345
|
-
|
|
11346
|
-
|
|
11305
|
+
return toObject;
|
|
11306
|
+
}
|
|
11307
|
+
function importFileParametersToMldev(fromObject) {
|
|
11308
|
+
const toObject = {};
|
|
11309
|
+
const fromFileSearchStoreName = getValueByPath(fromObject, [
|
|
11310
|
+
'fileSearchStoreName',
|
|
11311
|
+
]);
|
|
11312
|
+
if (fromFileSearchStoreName != null) {
|
|
11313
|
+
setValueByPath(toObject, ['_url', 'file_search_store_name'], fromFileSearchStoreName);
|
|
11347
11314
|
}
|
|
11348
|
-
|
|
11349
|
-
|
|
11350
|
-
|
|
11351
|
-
}
|
|
11352
|
-
else {
|
|
11353
|
-
throw new Error('HTTP options are not correctly set.');
|
|
11354
|
-
}
|
|
11315
|
+
const fromFileName = getValueByPath(fromObject, ['fileName']);
|
|
11316
|
+
if (fromFileName != null) {
|
|
11317
|
+
setValueByPath(toObject, ['fileName'], fromFileName);
|
|
11355
11318
|
}
|
|
11356
|
-
|
|
11357
|
-
|
|
11358
|
-
|
|
11359
|
-
urlElement.push(this.getBaseResourcePath());
|
|
11360
|
-
}
|
|
11361
|
-
if (path !== '') {
|
|
11362
|
-
urlElement.push(path);
|
|
11363
|
-
}
|
|
11364
|
-
const url = new URL(`${urlElement.join('/')}`);
|
|
11365
|
-
return url;
|
|
11319
|
+
const fromConfig = getValueByPath(fromObject, ['config']);
|
|
11320
|
+
if (fromConfig != null) {
|
|
11321
|
+
importFileConfigToMldev(fromConfig, toObject);
|
|
11366
11322
|
}
|
|
11367
|
-
|
|
11368
|
-
|
|
11369
|
-
|
|
11370
|
-
|
|
11371
|
-
|
|
11372
|
-
|
|
11373
|
-
|
|
11374
|
-
|
|
11375
|
-
|
|
11376
|
-
// `projects/<project>/location/<location>`.
|
|
11377
|
-
return false;
|
|
11378
|
-
}
|
|
11379
|
-
if (request.httpMethod === 'GET' &&
|
|
11380
|
-
request.path.startsWith('publishers/google/models')) {
|
|
11381
|
-
// These paths are used by Vertex's models.get and models.list
|
|
11382
|
-
// calls. For base models Vertex does not accept a project/location
|
|
11383
|
-
// prefix (for tuned model the prefix is required).
|
|
11384
|
-
return false;
|
|
11385
|
-
}
|
|
11386
|
-
return true;
|
|
11323
|
+
return toObject;
|
|
11324
|
+
}
|
|
11325
|
+
function importFileResponseFromMldev(fromObject) {
|
|
11326
|
+
const toObject = {};
|
|
11327
|
+
const fromSdkHttpResponse = getValueByPath(fromObject, [
|
|
11328
|
+
'sdkHttpResponse',
|
|
11329
|
+
]);
|
|
11330
|
+
if (fromSdkHttpResponse != null) {
|
|
11331
|
+
setValueByPath(toObject, ['sdkHttpResponse'], fromSdkHttpResponse);
|
|
11387
11332
|
}
|
|
11388
|
-
|
|
11389
|
-
|
|
11390
|
-
|
|
11391
|
-
|
|
11333
|
+
const fromParent = getValueByPath(fromObject, ['parent']);
|
|
11334
|
+
if (fromParent != null) {
|
|
11335
|
+
setValueByPath(toObject, ['parent'], fromParent);
|
|
11336
|
+
}
|
|
11337
|
+
const fromDocumentName = getValueByPath(fromObject, ['documentName']);
|
|
11338
|
+
if (fromDocumentName != null) {
|
|
11339
|
+
setValueByPath(toObject, ['documentName'], fromDocumentName);
|
|
11340
|
+
}
|
|
11341
|
+
return toObject;
|
|
11342
|
+
}
|
|
11343
|
+
function listFileSearchStoresConfigToMldev(fromObject, parentObject) {
|
|
11344
|
+
const toObject = {};
|
|
11345
|
+
const fromPageSize = getValueByPath(fromObject, ['pageSize']);
|
|
11346
|
+
if (parentObject !== undefined && fromPageSize != null) {
|
|
11347
|
+
setValueByPath(parentObject, ['_query', 'pageSize'], fromPageSize);
|
|
11348
|
+
}
|
|
11349
|
+
const fromPageToken = getValueByPath(fromObject, ['pageToken']);
|
|
11350
|
+
if (parentObject !== undefined && fromPageToken != null) {
|
|
11351
|
+
setValueByPath(parentObject, ['_query', 'pageToken'], fromPageToken);
|
|
11352
|
+
}
|
|
11353
|
+
return toObject;
|
|
11354
|
+
}
|
|
11355
|
+
function listFileSearchStoresParametersToMldev(fromObject) {
|
|
11356
|
+
const toObject = {};
|
|
11357
|
+
const fromConfig = getValueByPath(fromObject, ['config']);
|
|
11358
|
+
if (fromConfig != null) {
|
|
11359
|
+
listFileSearchStoresConfigToMldev(fromConfig, toObject);
|
|
11360
|
+
}
|
|
11361
|
+
return toObject;
|
|
11362
|
+
}
|
|
11363
|
+
function listFileSearchStoresResponseFromMldev(fromObject) {
|
|
11364
|
+
const toObject = {};
|
|
11365
|
+
const fromSdkHttpResponse = getValueByPath(fromObject, [
|
|
11366
|
+
'sdkHttpResponse',
|
|
11367
|
+
]);
|
|
11368
|
+
if (fromSdkHttpResponse != null) {
|
|
11369
|
+
setValueByPath(toObject, ['sdkHttpResponse'], fromSdkHttpResponse);
|
|
11370
|
+
}
|
|
11371
|
+
const fromNextPageToken = getValueByPath(fromObject, [
|
|
11372
|
+
'nextPageToken',
|
|
11373
|
+
]);
|
|
11374
|
+
if (fromNextPageToken != null) {
|
|
11375
|
+
setValueByPath(toObject, ['nextPageToken'], fromNextPageToken);
|
|
11376
|
+
}
|
|
11377
|
+
const fromFileSearchStores = getValueByPath(fromObject, [
|
|
11378
|
+
'fileSearchStores',
|
|
11379
|
+
]);
|
|
11380
|
+
if (fromFileSearchStores != null) {
|
|
11381
|
+
let transformedList = fromFileSearchStores;
|
|
11382
|
+
if (Array.isArray(transformedList)) {
|
|
11383
|
+
transformedList = transformedList.map((item) => {
|
|
11384
|
+
return item;
|
|
11385
|
+
});
|
|
11392
11386
|
}
|
|
11393
|
-
|
|
11394
|
-
|
|
11395
|
-
|
|
11396
|
-
|
|
11397
|
-
|
|
11398
|
-
|
|
11387
|
+
setValueByPath(toObject, ['fileSearchStores'], transformedList);
|
|
11388
|
+
}
|
|
11389
|
+
return toObject;
|
|
11390
|
+
}
|
|
11391
|
+
function uploadToFileSearchStoreConfigToMldev(fromObject, parentObject) {
|
|
11392
|
+
const toObject = {};
|
|
11393
|
+
const fromMimeType = getValueByPath(fromObject, ['mimeType']);
|
|
11394
|
+
if (parentObject !== undefined && fromMimeType != null) {
|
|
11395
|
+
setValueByPath(parentObject, ['mimeType'], fromMimeType);
|
|
11396
|
+
}
|
|
11397
|
+
const fromDisplayName = getValueByPath(fromObject, ['displayName']);
|
|
11398
|
+
if (parentObject !== undefined && fromDisplayName != null) {
|
|
11399
|
+
setValueByPath(parentObject, ['displayName'], fromDisplayName);
|
|
11400
|
+
}
|
|
11401
|
+
const fromCustomMetadata = getValueByPath(fromObject, [
|
|
11402
|
+
'customMetadata',
|
|
11403
|
+
]);
|
|
11404
|
+
if (parentObject !== undefined && fromCustomMetadata != null) {
|
|
11405
|
+
let transformedList = fromCustomMetadata;
|
|
11406
|
+
if (Array.isArray(transformedList)) {
|
|
11407
|
+
transformedList = transformedList.map((item) => {
|
|
11408
|
+
return item;
|
|
11409
|
+
});
|
|
11399
11410
|
}
|
|
11400
|
-
|
|
11401
|
-
|
|
11402
|
-
|
|
11403
|
-
|
|
11404
|
-
|
|
11411
|
+
setValueByPath(parentObject, ['customMetadata'], transformedList);
|
|
11412
|
+
}
|
|
11413
|
+
const fromChunkingConfig = getValueByPath(fromObject, [
|
|
11414
|
+
'chunkingConfig',
|
|
11415
|
+
]);
|
|
11416
|
+
if (parentObject !== undefined && fromChunkingConfig != null) {
|
|
11417
|
+
setValueByPath(parentObject, ['chunkingConfig'], fromChunkingConfig);
|
|
11418
|
+
}
|
|
11419
|
+
return toObject;
|
|
11420
|
+
}
|
|
11421
|
+
function uploadToFileSearchStoreParametersToMldev(fromObject) {
|
|
11422
|
+
const toObject = {};
|
|
11423
|
+
const fromFileSearchStoreName = getValueByPath(fromObject, [
|
|
11424
|
+
'fileSearchStoreName',
|
|
11425
|
+
]);
|
|
11426
|
+
if (fromFileSearchStoreName != null) {
|
|
11427
|
+
setValueByPath(toObject, ['_url', 'file_search_store_name'], fromFileSearchStoreName);
|
|
11428
|
+
}
|
|
11429
|
+
const fromConfig = getValueByPath(fromObject, ['config']);
|
|
11430
|
+
if (fromConfig != null) {
|
|
11431
|
+
uploadToFileSearchStoreConfigToMldev(fromConfig, toObject);
|
|
11432
|
+
}
|
|
11433
|
+
return toObject;
|
|
11434
|
+
}
|
|
11435
|
+
function uploadToFileSearchStoreResumableResponseFromMldev(fromObject) {
|
|
11436
|
+
const toObject = {};
|
|
11437
|
+
const fromSdkHttpResponse = getValueByPath(fromObject, [
|
|
11438
|
+
'sdkHttpResponse',
|
|
11439
|
+
]);
|
|
11440
|
+
if (fromSdkHttpResponse != null) {
|
|
11441
|
+
setValueByPath(toObject, ['sdkHttpResponse'], fromSdkHttpResponse);
|
|
11442
|
+
}
|
|
11443
|
+
return toObject;
|
|
11444
|
+
}
|
|
11445
|
+
|
|
11446
|
+
/**
|
|
11447
|
+
* @license
|
|
11448
|
+
* Copyright 2025 Google LLC
|
|
11449
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
11450
|
+
*/
|
|
11451
|
+
const CONTENT_TYPE_HEADER = 'Content-Type';
|
|
11452
|
+
const SERVER_TIMEOUT_HEADER = 'X-Server-Timeout';
|
|
11453
|
+
const USER_AGENT_HEADER = 'User-Agent';
|
|
11454
|
+
const GOOGLE_API_CLIENT_HEADER = 'x-goog-api-client';
|
|
11455
|
+
const SDK_VERSION = '1.31.0'; // x-release-please-version
|
|
11456
|
+
const LIBRARY_LABEL = `google-genai-sdk/${SDK_VERSION}`;
|
|
11457
|
+
const VERTEX_AI_API_DEFAULT_VERSION = 'v1beta1';
|
|
11458
|
+
const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
|
|
11459
|
+
const responseLineRE = /^\s*data: (.*)(?:\n\n|\r\r|\r\n\r\n)/;
|
|
11460
|
+
/**
|
|
11461
|
+
* The ApiClient class is used to send requests to the Gemini API or Vertex AI
|
|
11462
|
+
* endpoints.
|
|
11463
|
+
*/
|
|
11464
|
+
class ApiClient {
|
|
11465
|
+
constructor(opts) {
|
|
11466
|
+
var _a, _b;
|
|
11467
|
+
this.clientOptions = Object.assign(Object.assign({}, opts), { project: opts.project, location: opts.location, apiKey: opts.apiKey, vertexai: opts.vertexai });
|
|
11468
|
+
const initHttpOptions = {};
|
|
11469
|
+
if (this.clientOptions.vertexai) {
|
|
11470
|
+
initHttpOptions.apiVersion =
|
|
11471
|
+
(_a = this.clientOptions.apiVersion) !== null && _a !== void 0 ? _a : VERTEX_AI_API_DEFAULT_VERSION;
|
|
11472
|
+
initHttpOptions.baseUrl = this.baseUrlFromProjectLocation();
|
|
11473
|
+
this.normalizeAuthParameters();
|
|
11405
11474
|
}
|
|
11406
11475
|
else {
|
|
11407
|
-
|
|
11476
|
+
// Gemini API
|
|
11477
|
+
initHttpOptions.apiVersion =
|
|
11478
|
+
(_b = this.clientOptions.apiVersion) !== null && _b !== void 0 ? _b : GOOGLE_AI_API_DEFAULT_VERSION;
|
|
11479
|
+
initHttpOptions.baseUrl = `https://generativelanguage.googleapis.com/`;
|
|
11408
11480
|
}
|
|
11409
|
-
|
|
11410
|
-
|
|
11411
|
-
|
|
11412
|
-
|
|
11413
|
-
const patchedHttpOptions = JSON.parse(JSON.stringify(baseHttpOptions));
|
|
11414
|
-
for (const [key, value] of Object.entries(requestHttpOptions)) {
|
|
11415
|
-
// Records compile to objects.
|
|
11416
|
-
if (typeof value === 'object') {
|
|
11417
|
-
// @ts-expect-error TS2345TS7053: Element implicitly has an 'any' type
|
|
11418
|
-
// because expression of type 'string' can't be used to index type
|
|
11419
|
-
// 'HttpOptions'.
|
|
11420
|
-
patchedHttpOptions[key] = Object.assign(Object.assign({}, patchedHttpOptions[key]), value);
|
|
11421
|
-
}
|
|
11422
|
-
else if (value !== undefined) {
|
|
11423
|
-
// @ts-expect-error TS2345TS7053: Element implicitly has an 'any' type
|
|
11424
|
-
// because expression of type 'string' can't be used to index type
|
|
11425
|
-
// 'HttpOptions'.
|
|
11426
|
-
patchedHttpOptions[key] = value;
|
|
11427
|
-
}
|
|
11481
|
+
initHttpOptions.headers = this.getDefaultHeaders();
|
|
11482
|
+
this.clientOptions.httpOptions = initHttpOptions;
|
|
11483
|
+
if (opts.httpOptions) {
|
|
11484
|
+
this.clientOptions.httpOptions = this.patchHttpOptions(initHttpOptions, opts.httpOptions);
|
|
11428
11485
|
}
|
|
11429
|
-
return patchedHttpOptions;
|
|
11430
11486
|
}
|
|
11431
|
-
|
|
11432
|
-
|
|
11433
|
-
|
|
11434
|
-
|
|
11487
|
+
/**
|
|
11488
|
+
* Determines the base URL for Vertex AI based on project and location.
|
|
11489
|
+
* Uses the global endpoint if location is 'global' or if project/location
|
|
11490
|
+
* are not specified (implying API key usage).
|
|
11491
|
+
* @private
|
|
11492
|
+
*/
|
|
11493
|
+
baseUrlFromProjectLocation() {
|
|
11494
|
+
if (this.clientOptions.project &&
|
|
11495
|
+
this.clientOptions.location &&
|
|
11496
|
+
this.clientOptions.location !== 'global') {
|
|
11497
|
+
// Regional endpoint
|
|
11498
|
+
return `https://${this.clientOptions.location}-aiplatform.googleapis.com/`;
|
|
11435
11499
|
}
|
|
11436
|
-
|
|
11437
|
-
|
|
11438
|
-
|
|
11439
|
-
|
|
11500
|
+
// Global endpoint (covers 'global' location and API key usage)
|
|
11501
|
+
return `https://aiplatform.googleapis.com/`;
|
|
11502
|
+
}
|
|
11503
|
+
/**
|
|
11504
|
+
* Normalizes authentication parameters for Vertex AI.
|
|
11505
|
+
* If project and location are provided, API key is cleared.
|
|
11506
|
+
* If project and location are not provided (implying API key usage),
|
|
11507
|
+
* project and location are cleared.
|
|
11508
|
+
* @private
|
|
11509
|
+
*/
|
|
11510
|
+
normalizeAuthParameters() {
|
|
11511
|
+
if (this.clientOptions.project && this.clientOptions.location) {
|
|
11512
|
+
// Using project/location for auth, clear potential API key
|
|
11513
|
+
this.clientOptions.apiKey = undefined;
|
|
11514
|
+
return;
|
|
11440
11515
|
}
|
|
11441
|
-
|
|
11442
|
-
|
|
11443
|
-
|
|
11444
|
-
return this.streamApiCall(url, requestInit, request.httpMethod);
|
|
11516
|
+
// Using API key for auth (or no auth provided yet), clear project/location
|
|
11517
|
+
this.clientOptions.project = undefined;
|
|
11518
|
+
this.clientOptions.location = undefined;
|
|
11445
11519
|
}
|
|
11446
|
-
|
|
11447
|
-
|
|
11448
|
-
|
|
11520
|
+
isVertexAI() {
|
|
11521
|
+
var _a;
|
|
11522
|
+
return (_a = this.clientOptions.vertexai) !== null && _a !== void 0 ? _a : false;
|
|
11523
|
+
}
|
|
11524
|
+
getProject() {
|
|
11525
|
+
return this.clientOptions.project;
|
|
11526
|
+
}
|
|
11527
|
+
getLocation() {
|
|
11528
|
+
return this.clientOptions.location;
|
|
11529
|
+
}
|
|
11530
|
+
getApiVersion() {
|
|
11531
|
+
if (this.clientOptions.httpOptions &&
|
|
11532
|
+
this.clientOptions.httpOptions.apiVersion !== undefined) {
|
|
11533
|
+
return this.clientOptions.httpOptions.apiVersion;
|
|
11534
|
+
}
|
|
11535
|
+
throw new Error('API version is not set.');
|
|
11536
|
+
}
|
|
11537
|
+
getBaseUrl() {
|
|
11538
|
+
if (this.clientOptions.httpOptions &&
|
|
11539
|
+
this.clientOptions.httpOptions.baseUrl !== undefined) {
|
|
11540
|
+
return this.clientOptions.httpOptions.baseUrl;
|
|
11541
|
+
}
|
|
11542
|
+
throw new Error('Base URL is not set.');
|
|
11543
|
+
}
|
|
11544
|
+
getRequestUrl() {
|
|
11545
|
+
return this.getRequestUrlInternal(this.clientOptions.httpOptions);
|
|
11546
|
+
}
|
|
11547
|
+
getHeaders() {
|
|
11548
|
+
if (this.clientOptions.httpOptions &&
|
|
11549
|
+
this.clientOptions.httpOptions.headers !== undefined) {
|
|
11550
|
+
return this.clientOptions.httpOptions.headers;
|
|
11551
|
+
}
|
|
11552
|
+
else {
|
|
11553
|
+
throw new Error('Headers are not set.');
|
|
11554
|
+
}
|
|
11555
|
+
}
|
|
11556
|
+
getRequestUrlInternal(httpOptions) {
|
|
11557
|
+
if (!httpOptions ||
|
|
11558
|
+
httpOptions.baseUrl === undefined ||
|
|
11559
|
+
httpOptions.apiVersion === undefined) {
|
|
11560
|
+
throw new Error('HTTP options are not correctly set.');
|
|
11561
|
+
}
|
|
11562
|
+
const baseUrl = httpOptions.baseUrl.endsWith('/')
|
|
11563
|
+
? httpOptions.baseUrl.slice(0, -1)
|
|
11564
|
+
: httpOptions.baseUrl;
|
|
11565
|
+
const urlElement = [baseUrl];
|
|
11566
|
+
if (httpOptions.apiVersion && httpOptions.apiVersion !== '') {
|
|
11567
|
+
urlElement.push(httpOptions.apiVersion);
|
|
11568
|
+
}
|
|
11569
|
+
return urlElement.join('/');
|
|
11570
|
+
}
|
|
11571
|
+
getBaseResourcePath() {
|
|
11572
|
+
return `projects/${this.clientOptions.project}/locations/${this.clientOptions.location}`;
|
|
11573
|
+
}
|
|
11574
|
+
getApiKey() {
|
|
11575
|
+
return this.clientOptions.apiKey;
|
|
11576
|
+
}
|
|
11577
|
+
getWebsocketBaseUrl() {
|
|
11578
|
+
const baseUrl = this.getBaseUrl();
|
|
11579
|
+
const urlParts = new URL(baseUrl);
|
|
11580
|
+
urlParts.protocol = urlParts.protocol == 'http:' ? 'ws' : 'wss';
|
|
11581
|
+
return urlParts.toString();
|
|
11582
|
+
}
|
|
11583
|
+
setBaseUrl(url) {
|
|
11584
|
+
if (this.clientOptions.httpOptions) {
|
|
11585
|
+
this.clientOptions.httpOptions.baseUrl = url;
|
|
11586
|
+
}
|
|
11587
|
+
else {
|
|
11588
|
+
throw new Error('HTTP options are not correctly set.');
|
|
11589
|
+
}
|
|
11590
|
+
}
|
|
11591
|
+
constructUrl(path, httpOptions, prependProjectLocation) {
|
|
11592
|
+
const urlElement = [this.getRequestUrlInternal(httpOptions)];
|
|
11593
|
+
if (prependProjectLocation) {
|
|
11594
|
+
urlElement.push(this.getBaseResourcePath());
|
|
11595
|
+
}
|
|
11596
|
+
if (path !== '') {
|
|
11597
|
+
urlElement.push(path);
|
|
11598
|
+
}
|
|
11599
|
+
const url = new URL(`${urlElement.join('/')}`);
|
|
11600
|
+
return url;
|
|
11601
|
+
}
|
|
11602
|
+
shouldPrependVertexProjectPath(request) {
|
|
11603
|
+
if (this.clientOptions.apiKey) {
|
|
11604
|
+
return false;
|
|
11605
|
+
}
|
|
11606
|
+
if (!this.clientOptions.vertexai) {
|
|
11607
|
+
return false;
|
|
11608
|
+
}
|
|
11609
|
+
if (request.path.startsWith('projects/')) {
|
|
11610
|
+
// Assume the path already starts with
|
|
11611
|
+
// `projects/<project>/location/<location>`.
|
|
11612
|
+
return false;
|
|
11613
|
+
}
|
|
11614
|
+
if (request.httpMethod === 'GET' &&
|
|
11615
|
+
request.path.startsWith('publishers/google/models')) {
|
|
11616
|
+
// These paths are used by Vertex's models.get and models.list
|
|
11617
|
+
// calls. For base models Vertex does not accept a project/location
|
|
11618
|
+
// prefix (for tuned model the prefix is required).
|
|
11619
|
+
return false;
|
|
11620
|
+
}
|
|
11621
|
+
return true;
|
|
11622
|
+
}
|
|
11623
|
+
async request(request) {
|
|
11624
|
+
let patchedHttpOptions = this.clientOptions.httpOptions;
|
|
11625
|
+
if (request.httpOptions) {
|
|
11626
|
+
patchedHttpOptions = this.patchHttpOptions(this.clientOptions.httpOptions, request.httpOptions);
|
|
11627
|
+
}
|
|
11628
|
+
const prependProjectLocation = this.shouldPrependVertexProjectPath(request);
|
|
11629
|
+
const url = this.constructUrl(request.path, patchedHttpOptions, prependProjectLocation);
|
|
11630
|
+
if (request.queryParams) {
|
|
11631
|
+
for (const [key, value] of Object.entries(request.queryParams)) {
|
|
11632
|
+
url.searchParams.append(key, String(value));
|
|
11633
|
+
}
|
|
11634
|
+
}
|
|
11635
|
+
let requestInit = {};
|
|
11636
|
+
if (request.httpMethod === 'GET') {
|
|
11637
|
+
if (request.body && request.body !== '{}') {
|
|
11638
|
+
throw new Error('Request body should be empty for GET request, but got non empty request body');
|
|
11639
|
+
}
|
|
11640
|
+
}
|
|
11641
|
+
else {
|
|
11642
|
+
requestInit.body = request.body;
|
|
11643
|
+
}
|
|
11644
|
+
requestInit = await this.includeExtraHttpOptionsToRequestInit(requestInit, patchedHttpOptions, url.toString(), request.abortSignal);
|
|
11645
|
+
return this.unaryApiCall(url, requestInit, request.httpMethod);
|
|
11646
|
+
}
|
|
11647
|
+
patchHttpOptions(baseHttpOptions, requestHttpOptions) {
|
|
11648
|
+
const patchedHttpOptions = JSON.parse(JSON.stringify(baseHttpOptions));
|
|
11649
|
+
for (const [key, value] of Object.entries(requestHttpOptions)) {
|
|
11650
|
+
// Records compile to objects.
|
|
11651
|
+
if (typeof value === 'object') {
|
|
11652
|
+
// @ts-expect-error TS2345TS7053: Element implicitly has an 'any' type
|
|
11653
|
+
// because expression of type 'string' can't be used to index type
|
|
11654
|
+
// 'HttpOptions'.
|
|
11655
|
+
patchedHttpOptions[key] = Object.assign(Object.assign({}, patchedHttpOptions[key]), value);
|
|
11656
|
+
}
|
|
11657
|
+
else if (value !== undefined) {
|
|
11658
|
+
// @ts-expect-error TS2345TS7053: Element implicitly has an 'any' type
|
|
11659
|
+
// because expression of type 'string' can't be used to index type
|
|
11660
|
+
// 'HttpOptions'.
|
|
11661
|
+
patchedHttpOptions[key] = value;
|
|
11662
|
+
}
|
|
11663
|
+
}
|
|
11664
|
+
return patchedHttpOptions;
|
|
11665
|
+
}
|
|
11666
|
+
async requestStream(request) {
|
|
11667
|
+
let patchedHttpOptions = this.clientOptions.httpOptions;
|
|
11668
|
+
if (request.httpOptions) {
|
|
11669
|
+
patchedHttpOptions = this.patchHttpOptions(this.clientOptions.httpOptions, request.httpOptions);
|
|
11670
|
+
}
|
|
11671
|
+
const prependProjectLocation = this.shouldPrependVertexProjectPath(request);
|
|
11672
|
+
const url = this.constructUrl(request.path, patchedHttpOptions, prependProjectLocation);
|
|
11673
|
+
if (!url.searchParams.has('alt') || url.searchParams.get('alt') !== 'sse') {
|
|
11674
|
+
url.searchParams.set('alt', 'sse');
|
|
11675
|
+
}
|
|
11676
|
+
let requestInit = {};
|
|
11677
|
+
requestInit.body = request.body;
|
|
11678
|
+
requestInit = await this.includeExtraHttpOptionsToRequestInit(requestInit, patchedHttpOptions, url.toString(), request.abortSignal);
|
|
11679
|
+
return this.streamApiCall(url, requestInit, request.httpMethod);
|
|
11680
|
+
}
|
|
11681
|
+
async includeExtraHttpOptionsToRequestInit(requestInit, httpOptions, url, abortSignal) {
|
|
11682
|
+
if ((httpOptions && httpOptions.timeout) || abortSignal) {
|
|
11683
|
+
const abortController = new AbortController();
|
|
11449
11684
|
const signal = abortController.signal;
|
|
11450
11685
|
if (httpOptions.timeout && (httpOptions === null || httpOptions === void 0 ? void 0 : httpOptions.timeout) > 0) {
|
|
11451
11686
|
const timeoutHandle = setTimeout(() => abortController.abort(), httpOptions.timeout);
|
|
@@ -11666,11 +11901,8 @@ class ApiClient {
|
|
|
11666
11901
|
const path = `upload/v1beta/${fileSearchStoreName}:uploadToFileSearchStore`;
|
|
11667
11902
|
const fileName = this.getFileName(file);
|
|
11668
11903
|
const body = {};
|
|
11669
|
-
if (config
|
|
11670
|
-
body
|
|
11671
|
-
}
|
|
11672
|
-
if (config === null || config === void 0 ? void 0 : config.chunkingConfig) {
|
|
11673
|
-
body['chunkingConfig'] = config.chunkingConfig;
|
|
11904
|
+
if (config != null) {
|
|
11905
|
+
uploadToFileSearchStoreConfigToMldev(config, body);
|
|
11674
11906
|
}
|
|
11675
11907
|
const uploadUrl = await this.fetchUploadUrl(path, sizeBytes, mimeType, fileName, body, config === null || config === void 0 ? void 0 : config.httpOptions);
|
|
11676
11908
|
return uploader.uploadToFileSearchStore(file, uploadUrl, this);
|
|
@@ -14222,594 +14454,41 @@ class Models extends BaseModule {
|
|
|
14222
14454
|
abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
|
|
14223
14455
|
})
|
|
14224
14456
|
.then((httpResponse) => {
|
|
14225
|
-
return httpResponse.json();
|
|
14226
|
-
});
|
|
14227
|
-
return response.then((apiResponse) => {
|
|
14228
|
-
const resp = generateVideosOperationFromVertex(apiResponse);
|
|
14229
|
-
const typedResp = new GenerateVideosOperation();
|
|
14230
|
-
Object.assign(typedResp, resp);
|
|
14231
|
-
return typedResp;
|
|
14232
|
-
});
|
|
14233
|
-
}
|
|
14234
|
-
else {
|
|
14235
|
-
const body = generateVideosParametersToMldev(this.apiClient, params);
|
|
14236
|
-
path = formatMap('{model}:predictLongRunning', body['_url']);
|
|
14237
|
-
queryParams = body['_query'];
|
|
14238
|
-
delete body['_url'];
|
|
14239
|
-
delete body['_query'];
|
|
14240
|
-
response = this.apiClient
|
|
14241
|
-
.request({
|
|
14242
|
-
path: path,
|
|
14243
|
-
queryParams: queryParams,
|
|
14244
|
-
body: JSON.stringify(body),
|
|
14245
|
-
httpMethod: 'POST',
|
|
14246
|
-
httpOptions: (_c = params.config) === null || _c === void 0 ? void 0 : _c.httpOptions,
|
|
14247
|
-
abortSignal: (_d = params.config) === null || _d === void 0 ? void 0 : _d.abortSignal,
|
|
14248
|
-
})
|
|
14249
|
-
.then((httpResponse) => {
|
|
14250
|
-
return httpResponse.json();
|
|
14251
|
-
});
|
|
14252
|
-
return response.then((apiResponse) => {
|
|
14253
|
-
const resp = generateVideosOperationFromMldev(apiResponse);
|
|
14254
|
-
const typedResp = new GenerateVideosOperation();
|
|
14255
|
-
Object.assign(typedResp, resp);
|
|
14256
|
-
return typedResp;
|
|
14257
|
-
});
|
|
14258
|
-
}
|
|
14259
|
-
}
|
|
14260
|
-
}
|
|
14261
|
-
|
|
14262
|
-
/**
|
|
14263
|
-
* @license
|
|
14264
|
-
* Copyright 2025 Google LLC
|
|
14265
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
14266
|
-
*/
|
|
14267
|
-
class Operations extends BaseModule {
|
|
14268
|
-
constructor(apiClient) {
|
|
14269
|
-
super();
|
|
14270
|
-
this.apiClient = apiClient;
|
|
14271
|
-
}
|
|
14272
|
-
/**
|
|
14273
|
-
* Gets the status of a long-running operation.
|
|
14274
|
-
*
|
|
14275
|
-
* @param parameters The parameters for the get operation request.
|
|
14276
|
-
* @return The updated Operation object, with the latest status or result.
|
|
14277
|
-
*/
|
|
14278
|
-
async getVideosOperation(parameters) {
|
|
14279
|
-
const operation = parameters.operation;
|
|
14280
|
-
const config = parameters.config;
|
|
14281
|
-
if (operation.name === undefined || operation.name === '') {
|
|
14282
|
-
throw new Error('Operation name is required.');
|
|
14283
|
-
}
|
|
14284
|
-
if (this.apiClient.isVertexAI()) {
|
|
14285
|
-
const resourceName = operation.name.split('/operations/')[0];
|
|
14286
|
-
let httpOptions = undefined;
|
|
14287
|
-
if (config && 'httpOptions' in config) {
|
|
14288
|
-
httpOptions = config.httpOptions;
|
|
14289
|
-
}
|
|
14290
|
-
const rawOperation = await this.fetchPredictVideosOperationInternal({
|
|
14291
|
-
operationName: operation.name,
|
|
14292
|
-
resourceName: resourceName,
|
|
14293
|
-
config: { httpOptions: httpOptions },
|
|
14294
|
-
});
|
|
14295
|
-
return operation._fromAPIResponse({
|
|
14296
|
-
apiResponse: rawOperation,
|
|
14297
|
-
_isVertexAI: true,
|
|
14298
|
-
});
|
|
14299
|
-
}
|
|
14300
|
-
else {
|
|
14301
|
-
const rawOperation = await this.getVideosOperationInternal({
|
|
14302
|
-
operationName: operation.name,
|
|
14303
|
-
config: config,
|
|
14304
|
-
});
|
|
14305
|
-
return operation._fromAPIResponse({
|
|
14306
|
-
apiResponse: rawOperation,
|
|
14307
|
-
_isVertexAI: false,
|
|
14308
|
-
});
|
|
14309
|
-
}
|
|
14310
|
-
}
|
|
14311
|
-
/**
|
|
14312
|
-
* Gets the status of a long-running operation.
|
|
14313
|
-
*
|
|
14314
|
-
* @param parameters The parameters for the get operation request.
|
|
14315
|
-
* @return The updated Operation object, with the latest status or result.
|
|
14316
|
-
*/
|
|
14317
|
-
async get(parameters) {
|
|
14318
|
-
const operation = parameters.operation;
|
|
14319
|
-
const config = parameters.config;
|
|
14320
|
-
if (operation.name === undefined || operation.name === '') {
|
|
14321
|
-
throw new Error('Operation name is required.');
|
|
14322
|
-
}
|
|
14323
|
-
if (this.apiClient.isVertexAI()) {
|
|
14324
|
-
const resourceName = operation.name.split('/operations/')[0];
|
|
14325
|
-
let httpOptions = undefined;
|
|
14326
|
-
if (config && 'httpOptions' in config) {
|
|
14327
|
-
httpOptions = config.httpOptions;
|
|
14328
|
-
}
|
|
14329
|
-
const rawOperation = await this.fetchPredictVideosOperationInternal({
|
|
14330
|
-
operationName: operation.name,
|
|
14331
|
-
resourceName: resourceName,
|
|
14332
|
-
config: { httpOptions: httpOptions },
|
|
14333
|
-
});
|
|
14334
|
-
return operation._fromAPIResponse({
|
|
14335
|
-
apiResponse: rawOperation,
|
|
14336
|
-
_isVertexAI: true,
|
|
14337
|
-
});
|
|
14338
|
-
}
|
|
14339
|
-
else {
|
|
14340
|
-
const rawOperation = await this.getVideosOperationInternal({
|
|
14341
|
-
operationName: operation.name,
|
|
14342
|
-
config: config,
|
|
14343
|
-
});
|
|
14344
|
-
return operation._fromAPIResponse({
|
|
14345
|
-
apiResponse: rawOperation,
|
|
14346
|
-
_isVertexAI: false,
|
|
14347
|
-
});
|
|
14348
|
-
}
|
|
14349
|
-
}
|
|
14350
|
-
async getVideosOperationInternal(params) {
|
|
14351
|
-
var _a, _b, _c, _d;
|
|
14352
|
-
let response;
|
|
14353
|
-
let path = '';
|
|
14354
|
-
let queryParams = {};
|
|
14355
|
-
if (this.apiClient.isVertexAI()) {
|
|
14356
|
-
const body = getOperationParametersToVertex(params);
|
|
14357
|
-
path = formatMap('{operationName}', body['_url']);
|
|
14358
|
-
queryParams = body['_query'];
|
|
14359
|
-
delete body['_url'];
|
|
14360
|
-
delete body['_query'];
|
|
14361
|
-
response = this.apiClient
|
|
14362
|
-
.request({
|
|
14363
|
-
path: path,
|
|
14364
|
-
queryParams: queryParams,
|
|
14365
|
-
body: JSON.stringify(body),
|
|
14366
|
-
httpMethod: 'GET',
|
|
14367
|
-
httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
|
|
14368
|
-
abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
|
|
14369
|
-
})
|
|
14370
|
-
.then((httpResponse) => {
|
|
14371
|
-
return httpResponse.json();
|
|
14372
|
-
});
|
|
14373
|
-
return response;
|
|
14374
|
-
}
|
|
14375
|
-
else {
|
|
14376
|
-
const body = getOperationParametersToMldev(params);
|
|
14377
|
-
path = formatMap('{operationName}', body['_url']);
|
|
14378
|
-
queryParams = body['_query'];
|
|
14379
|
-
delete body['_url'];
|
|
14380
|
-
delete body['_query'];
|
|
14381
|
-
response = this.apiClient
|
|
14382
|
-
.request({
|
|
14383
|
-
path: path,
|
|
14384
|
-
queryParams: queryParams,
|
|
14385
|
-
body: JSON.stringify(body),
|
|
14386
|
-
httpMethod: 'GET',
|
|
14387
|
-
httpOptions: (_c = params.config) === null || _c === void 0 ? void 0 : _c.httpOptions,
|
|
14388
|
-
abortSignal: (_d = params.config) === null || _d === void 0 ? void 0 : _d.abortSignal,
|
|
14389
|
-
})
|
|
14390
|
-
.then((httpResponse) => {
|
|
14391
|
-
return httpResponse.json();
|
|
14392
|
-
});
|
|
14393
|
-
return response;
|
|
14394
|
-
}
|
|
14395
|
-
}
|
|
14396
|
-
async fetchPredictVideosOperationInternal(params) {
|
|
14397
|
-
var _a, _b;
|
|
14398
|
-
let response;
|
|
14399
|
-
let path = '';
|
|
14400
|
-
let queryParams = {};
|
|
14401
|
-
if (this.apiClient.isVertexAI()) {
|
|
14402
|
-
const body = fetchPredictOperationParametersToVertex(params);
|
|
14403
|
-
path = formatMap('{resourceName}:fetchPredictOperation', body['_url']);
|
|
14404
|
-
queryParams = body['_query'];
|
|
14405
|
-
delete body['_url'];
|
|
14406
|
-
delete body['_query'];
|
|
14407
|
-
response = this.apiClient
|
|
14408
|
-
.request({
|
|
14409
|
-
path: path,
|
|
14410
|
-
queryParams: queryParams,
|
|
14411
|
-
body: JSON.stringify(body),
|
|
14412
|
-
httpMethod: 'POST',
|
|
14413
|
-
httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
|
|
14414
|
-
abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
|
|
14415
|
-
})
|
|
14416
|
-
.then((httpResponse) => {
|
|
14417
|
-
return httpResponse.json();
|
|
14418
|
-
});
|
|
14419
|
-
return response;
|
|
14420
|
-
}
|
|
14421
|
-
else {
|
|
14422
|
-
throw new Error('This method is only supported by the Vertex AI.');
|
|
14423
|
-
}
|
|
14424
|
-
}
|
|
14425
|
-
}
|
|
14426
|
-
|
|
14427
|
-
/**
|
|
14428
|
-
* @license
|
|
14429
|
-
* Copyright 2025 Google LLC
|
|
14430
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
14431
|
-
*/
|
|
14432
|
-
function blobToMldev(fromObject) {
|
|
14433
|
-
const toObject = {};
|
|
14434
|
-
const fromData = getValueByPath(fromObject, ['data']);
|
|
14435
|
-
if (fromData != null) {
|
|
14436
|
-
setValueByPath(toObject, ['data'], fromData);
|
|
14437
|
-
}
|
|
14438
|
-
if (getValueByPath(fromObject, ['displayName']) !== undefined) {
|
|
14439
|
-
throw new Error('displayName parameter is not supported in Gemini API.');
|
|
14440
|
-
}
|
|
14441
|
-
const fromMimeType = getValueByPath(fromObject, ['mimeType']);
|
|
14442
|
-
if (fromMimeType != null) {
|
|
14443
|
-
setValueByPath(toObject, ['mimeType'], fromMimeType);
|
|
14444
|
-
}
|
|
14445
|
-
return toObject;
|
|
14446
|
-
}
|
|
14447
|
-
function contentToMldev(fromObject) {
|
|
14448
|
-
const toObject = {};
|
|
14449
|
-
const fromParts = getValueByPath(fromObject, ['parts']);
|
|
14450
|
-
if (fromParts != null) {
|
|
14451
|
-
let transformedList = fromParts;
|
|
14452
|
-
if (Array.isArray(transformedList)) {
|
|
14453
|
-
transformedList = transformedList.map((item) => {
|
|
14454
|
-
return partToMldev(item);
|
|
14455
|
-
});
|
|
14456
|
-
}
|
|
14457
|
-
setValueByPath(toObject, ['parts'], transformedList);
|
|
14458
|
-
}
|
|
14459
|
-
const fromRole = getValueByPath(fromObject, ['role']);
|
|
14460
|
-
if (fromRole != null) {
|
|
14461
|
-
setValueByPath(toObject, ['role'], fromRole);
|
|
14462
|
-
}
|
|
14463
|
-
return toObject;
|
|
14464
|
-
}
|
|
14465
|
-
function createAuthTokenConfigToMldev(apiClient, fromObject, parentObject) {
|
|
14466
|
-
const toObject = {};
|
|
14467
|
-
const fromExpireTime = getValueByPath(fromObject, ['expireTime']);
|
|
14468
|
-
if (parentObject !== undefined && fromExpireTime != null) {
|
|
14469
|
-
setValueByPath(parentObject, ['expireTime'], fromExpireTime);
|
|
14470
|
-
}
|
|
14471
|
-
const fromNewSessionExpireTime = getValueByPath(fromObject, [
|
|
14472
|
-
'newSessionExpireTime',
|
|
14473
|
-
]);
|
|
14474
|
-
if (parentObject !== undefined && fromNewSessionExpireTime != null) {
|
|
14475
|
-
setValueByPath(parentObject, ['newSessionExpireTime'], fromNewSessionExpireTime);
|
|
14476
|
-
}
|
|
14477
|
-
const fromUses = getValueByPath(fromObject, ['uses']);
|
|
14478
|
-
if (parentObject !== undefined && fromUses != null) {
|
|
14479
|
-
setValueByPath(parentObject, ['uses'], fromUses);
|
|
14480
|
-
}
|
|
14481
|
-
const fromLiveConnectConstraints = getValueByPath(fromObject, [
|
|
14482
|
-
'liveConnectConstraints',
|
|
14483
|
-
]);
|
|
14484
|
-
if (parentObject !== undefined && fromLiveConnectConstraints != null) {
|
|
14485
|
-
setValueByPath(parentObject, ['bidiGenerateContentSetup'], liveConnectConstraintsToMldev(apiClient, fromLiveConnectConstraints));
|
|
14486
|
-
}
|
|
14487
|
-
const fromLockAdditionalFields = getValueByPath(fromObject, [
|
|
14488
|
-
'lockAdditionalFields',
|
|
14489
|
-
]);
|
|
14490
|
-
if (parentObject !== undefined && fromLockAdditionalFields != null) {
|
|
14491
|
-
setValueByPath(parentObject, ['fieldMask'], fromLockAdditionalFields);
|
|
14492
|
-
}
|
|
14493
|
-
return toObject;
|
|
14494
|
-
}
|
|
14495
|
-
function createAuthTokenParametersToMldev(apiClient, fromObject) {
|
|
14496
|
-
const toObject = {};
|
|
14497
|
-
const fromConfig = getValueByPath(fromObject, ['config']);
|
|
14498
|
-
if (fromConfig != null) {
|
|
14499
|
-
setValueByPath(toObject, ['config'], createAuthTokenConfigToMldev(apiClient, fromConfig, toObject));
|
|
14500
|
-
}
|
|
14501
|
-
return toObject;
|
|
14502
|
-
}
|
|
14503
|
-
function fileDataToMldev(fromObject) {
|
|
14504
|
-
const toObject = {};
|
|
14505
|
-
if (getValueByPath(fromObject, ['displayName']) !== undefined) {
|
|
14506
|
-
throw new Error('displayName parameter is not supported in Gemini API.');
|
|
14507
|
-
}
|
|
14508
|
-
const fromFileUri = getValueByPath(fromObject, ['fileUri']);
|
|
14509
|
-
if (fromFileUri != null) {
|
|
14510
|
-
setValueByPath(toObject, ['fileUri'], fromFileUri);
|
|
14511
|
-
}
|
|
14512
|
-
const fromMimeType = getValueByPath(fromObject, ['mimeType']);
|
|
14513
|
-
if (fromMimeType != null) {
|
|
14514
|
-
setValueByPath(toObject, ['mimeType'], fromMimeType);
|
|
14515
|
-
}
|
|
14516
|
-
return toObject;
|
|
14517
|
-
}
|
|
14518
|
-
function functionCallToMldev(fromObject) {
|
|
14519
|
-
const toObject = {};
|
|
14520
|
-
const fromId = getValueByPath(fromObject, ['id']);
|
|
14521
|
-
if (fromId != null) {
|
|
14522
|
-
setValueByPath(toObject, ['id'], fromId);
|
|
14523
|
-
}
|
|
14524
|
-
const fromArgs = getValueByPath(fromObject, ['args']);
|
|
14525
|
-
if (fromArgs != null) {
|
|
14526
|
-
setValueByPath(toObject, ['args'], fromArgs);
|
|
14527
|
-
}
|
|
14528
|
-
const fromName = getValueByPath(fromObject, ['name']);
|
|
14529
|
-
if (fromName != null) {
|
|
14530
|
-
setValueByPath(toObject, ['name'], fromName);
|
|
14531
|
-
}
|
|
14532
|
-
if (getValueByPath(fromObject, ['partialArgs']) !== undefined) {
|
|
14533
|
-
throw new Error('partialArgs parameter is not supported in Gemini API.');
|
|
14534
|
-
}
|
|
14535
|
-
if (getValueByPath(fromObject, ['willContinue']) !== undefined) {
|
|
14536
|
-
throw new Error('willContinue parameter is not supported in Gemini API.');
|
|
14537
|
-
}
|
|
14538
|
-
return toObject;
|
|
14539
|
-
}
|
|
14540
|
-
function googleMapsToMldev(fromObject) {
|
|
14541
|
-
const toObject = {};
|
|
14542
|
-
if (getValueByPath(fromObject, ['authConfig']) !== undefined) {
|
|
14543
|
-
throw new Error('authConfig parameter is not supported in Gemini API.');
|
|
14544
|
-
}
|
|
14545
|
-
const fromEnableWidget = getValueByPath(fromObject, ['enableWidget']);
|
|
14546
|
-
if (fromEnableWidget != null) {
|
|
14547
|
-
setValueByPath(toObject, ['enableWidget'], fromEnableWidget);
|
|
14548
|
-
}
|
|
14549
|
-
return toObject;
|
|
14550
|
-
}
|
|
14551
|
-
function googleSearchToMldev(fromObject) {
|
|
14552
|
-
const toObject = {};
|
|
14553
|
-
if (getValueByPath(fromObject, ['excludeDomains']) !== undefined) {
|
|
14554
|
-
throw new Error('excludeDomains parameter is not supported in Gemini API.');
|
|
14555
|
-
}
|
|
14556
|
-
if (getValueByPath(fromObject, ['blockingConfidence']) !== undefined) {
|
|
14557
|
-
throw new Error('blockingConfidence parameter is not supported in Gemini API.');
|
|
14558
|
-
}
|
|
14559
|
-
const fromTimeRangeFilter = getValueByPath(fromObject, [
|
|
14560
|
-
'timeRangeFilter',
|
|
14561
|
-
]);
|
|
14562
|
-
if (fromTimeRangeFilter != null) {
|
|
14563
|
-
setValueByPath(toObject, ['timeRangeFilter'], fromTimeRangeFilter);
|
|
14564
|
-
}
|
|
14565
|
-
return toObject;
|
|
14566
|
-
}
|
|
14567
|
-
function liveConnectConfigToMldev(fromObject, parentObject) {
|
|
14568
|
-
const toObject = {};
|
|
14569
|
-
const fromGenerationConfig = getValueByPath(fromObject, [
|
|
14570
|
-
'generationConfig',
|
|
14571
|
-
]);
|
|
14572
|
-
if (parentObject !== undefined && fromGenerationConfig != null) {
|
|
14573
|
-
setValueByPath(parentObject, ['setup', 'generationConfig'], fromGenerationConfig);
|
|
14574
|
-
}
|
|
14575
|
-
const fromResponseModalities = getValueByPath(fromObject, [
|
|
14576
|
-
'responseModalities',
|
|
14577
|
-
]);
|
|
14578
|
-
if (parentObject !== undefined && fromResponseModalities != null) {
|
|
14579
|
-
setValueByPath(parentObject, ['setup', 'generationConfig', 'responseModalities'], fromResponseModalities);
|
|
14580
|
-
}
|
|
14581
|
-
const fromTemperature = getValueByPath(fromObject, ['temperature']);
|
|
14582
|
-
if (parentObject !== undefined && fromTemperature != null) {
|
|
14583
|
-
setValueByPath(parentObject, ['setup', 'generationConfig', 'temperature'], fromTemperature);
|
|
14584
|
-
}
|
|
14585
|
-
const fromTopP = getValueByPath(fromObject, ['topP']);
|
|
14586
|
-
if (parentObject !== undefined && fromTopP != null) {
|
|
14587
|
-
setValueByPath(parentObject, ['setup', 'generationConfig', 'topP'], fromTopP);
|
|
14588
|
-
}
|
|
14589
|
-
const fromTopK = getValueByPath(fromObject, ['topK']);
|
|
14590
|
-
if (parentObject !== undefined && fromTopK != null) {
|
|
14591
|
-
setValueByPath(parentObject, ['setup', 'generationConfig', 'topK'], fromTopK);
|
|
14592
|
-
}
|
|
14593
|
-
const fromMaxOutputTokens = getValueByPath(fromObject, [
|
|
14594
|
-
'maxOutputTokens',
|
|
14595
|
-
]);
|
|
14596
|
-
if (parentObject !== undefined && fromMaxOutputTokens != null) {
|
|
14597
|
-
setValueByPath(parentObject, ['setup', 'generationConfig', 'maxOutputTokens'], fromMaxOutputTokens);
|
|
14598
|
-
}
|
|
14599
|
-
const fromMediaResolution = getValueByPath(fromObject, [
|
|
14600
|
-
'mediaResolution',
|
|
14601
|
-
]);
|
|
14602
|
-
if (parentObject !== undefined && fromMediaResolution != null) {
|
|
14603
|
-
setValueByPath(parentObject, ['setup', 'generationConfig', 'mediaResolution'], fromMediaResolution);
|
|
14604
|
-
}
|
|
14605
|
-
const fromSeed = getValueByPath(fromObject, ['seed']);
|
|
14606
|
-
if (parentObject !== undefined && fromSeed != null) {
|
|
14607
|
-
setValueByPath(parentObject, ['setup', 'generationConfig', 'seed'], fromSeed);
|
|
14608
|
-
}
|
|
14609
|
-
const fromSpeechConfig = getValueByPath(fromObject, ['speechConfig']);
|
|
14610
|
-
if (parentObject !== undefined && fromSpeechConfig != null) {
|
|
14611
|
-
setValueByPath(parentObject, ['setup', 'generationConfig', 'speechConfig'], tLiveSpeechConfig(fromSpeechConfig));
|
|
14612
|
-
}
|
|
14613
|
-
const fromThinkingConfig = getValueByPath(fromObject, [
|
|
14614
|
-
'thinkingConfig',
|
|
14615
|
-
]);
|
|
14616
|
-
if (parentObject !== undefined && fromThinkingConfig != null) {
|
|
14617
|
-
setValueByPath(parentObject, ['setup', 'generationConfig', 'thinkingConfig'], fromThinkingConfig);
|
|
14618
|
-
}
|
|
14619
|
-
const fromEnableAffectiveDialog = getValueByPath(fromObject, [
|
|
14620
|
-
'enableAffectiveDialog',
|
|
14621
|
-
]);
|
|
14622
|
-
if (parentObject !== undefined && fromEnableAffectiveDialog != null) {
|
|
14623
|
-
setValueByPath(parentObject, ['setup', 'generationConfig', 'enableAffectiveDialog'], fromEnableAffectiveDialog);
|
|
14624
|
-
}
|
|
14625
|
-
const fromSystemInstruction = getValueByPath(fromObject, [
|
|
14626
|
-
'systemInstruction',
|
|
14627
|
-
]);
|
|
14628
|
-
if (parentObject !== undefined && fromSystemInstruction != null) {
|
|
14629
|
-
setValueByPath(parentObject, ['setup', 'systemInstruction'], contentToMldev(tContent(fromSystemInstruction)));
|
|
14630
|
-
}
|
|
14631
|
-
const fromTools = getValueByPath(fromObject, ['tools']);
|
|
14632
|
-
if (parentObject !== undefined && fromTools != null) {
|
|
14633
|
-
let transformedList = tTools(fromTools);
|
|
14634
|
-
if (Array.isArray(transformedList)) {
|
|
14635
|
-
transformedList = transformedList.map((item) => {
|
|
14636
|
-
return toolToMldev(tTool(item));
|
|
14637
|
-
});
|
|
14638
|
-
}
|
|
14639
|
-
setValueByPath(parentObject, ['setup', 'tools'], transformedList);
|
|
14640
|
-
}
|
|
14641
|
-
const fromSessionResumption = getValueByPath(fromObject, [
|
|
14642
|
-
'sessionResumption',
|
|
14643
|
-
]);
|
|
14644
|
-
if (parentObject !== undefined && fromSessionResumption != null) {
|
|
14645
|
-
setValueByPath(parentObject, ['setup', 'sessionResumption'], sessionResumptionConfigToMldev(fromSessionResumption));
|
|
14646
|
-
}
|
|
14647
|
-
const fromInputAudioTranscription = getValueByPath(fromObject, [
|
|
14648
|
-
'inputAudioTranscription',
|
|
14649
|
-
]);
|
|
14650
|
-
if (parentObject !== undefined && fromInputAudioTranscription != null) {
|
|
14651
|
-
setValueByPath(parentObject, ['setup', 'inputAudioTranscription'], fromInputAudioTranscription);
|
|
14652
|
-
}
|
|
14653
|
-
const fromOutputAudioTranscription = getValueByPath(fromObject, [
|
|
14654
|
-
'outputAudioTranscription',
|
|
14655
|
-
]);
|
|
14656
|
-
if (parentObject !== undefined && fromOutputAudioTranscription != null) {
|
|
14657
|
-
setValueByPath(parentObject, ['setup', 'outputAudioTranscription'], fromOutputAudioTranscription);
|
|
14658
|
-
}
|
|
14659
|
-
const fromRealtimeInputConfig = getValueByPath(fromObject, [
|
|
14660
|
-
'realtimeInputConfig',
|
|
14661
|
-
]);
|
|
14662
|
-
if (parentObject !== undefined && fromRealtimeInputConfig != null) {
|
|
14663
|
-
setValueByPath(parentObject, ['setup', 'realtimeInputConfig'], fromRealtimeInputConfig);
|
|
14664
|
-
}
|
|
14665
|
-
const fromContextWindowCompression = getValueByPath(fromObject, [
|
|
14666
|
-
'contextWindowCompression',
|
|
14667
|
-
]);
|
|
14668
|
-
if (parentObject !== undefined && fromContextWindowCompression != null) {
|
|
14669
|
-
setValueByPath(parentObject, ['setup', 'contextWindowCompression'], fromContextWindowCompression);
|
|
14670
|
-
}
|
|
14671
|
-
const fromProactivity = getValueByPath(fromObject, ['proactivity']);
|
|
14672
|
-
if (parentObject !== undefined && fromProactivity != null) {
|
|
14673
|
-
setValueByPath(parentObject, ['setup', 'proactivity'], fromProactivity);
|
|
14674
|
-
}
|
|
14675
|
-
return toObject;
|
|
14676
|
-
}
|
|
14677
|
-
function liveConnectConstraintsToMldev(apiClient, fromObject) {
|
|
14678
|
-
const toObject = {};
|
|
14679
|
-
const fromModel = getValueByPath(fromObject, ['model']);
|
|
14680
|
-
if (fromModel != null) {
|
|
14681
|
-
setValueByPath(toObject, ['setup', 'model'], tModel(apiClient, fromModel));
|
|
14682
|
-
}
|
|
14683
|
-
const fromConfig = getValueByPath(fromObject, ['config']);
|
|
14684
|
-
if (fromConfig != null) {
|
|
14685
|
-
setValueByPath(toObject, ['config'], liveConnectConfigToMldev(fromConfig, toObject));
|
|
14686
|
-
}
|
|
14687
|
-
return toObject;
|
|
14688
|
-
}
|
|
14689
|
-
function partToMldev(fromObject) {
|
|
14690
|
-
const toObject = {};
|
|
14691
|
-
const fromMediaResolution = getValueByPath(fromObject, [
|
|
14692
|
-
'mediaResolution',
|
|
14693
|
-
]);
|
|
14694
|
-
if (fromMediaResolution != null) {
|
|
14695
|
-
setValueByPath(toObject, ['mediaResolution'], fromMediaResolution);
|
|
14696
|
-
}
|
|
14697
|
-
const fromCodeExecutionResult = getValueByPath(fromObject, [
|
|
14698
|
-
'codeExecutionResult',
|
|
14699
|
-
]);
|
|
14700
|
-
if (fromCodeExecutionResult != null) {
|
|
14701
|
-
setValueByPath(toObject, ['codeExecutionResult'], fromCodeExecutionResult);
|
|
14702
|
-
}
|
|
14703
|
-
const fromExecutableCode = getValueByPath(fromObject, [
|
|
14704
|
-
'executableCode',
|
|
14705
|
-
]);
|
|
14706
|
-
if (fromExecutableCode != null) {
|
|
14707
|
-
setValueByPath(toObject, ['executableCode'], fromExecutableCode);
|
|
14708
|
-
}
|
|
14709
|
-
const fromFileData = getValueByPath(fromObject, ['fileData']);
|
|
14710
|
-
if (fromFileData != null) {
|
|
14711
|
-
setValueByPath(toObject, ['fileData'], fileDataToMldev(fromFileData));
|
|
14712
|
-
}
|
|
14713
|
-
const fromFunctionCall = getValueByPath(fromObject, ['functionCall']);
|
|
14714
|
-
if (fromFunctionCall != null) {
|
|
14715
|
-
setValueByPath(toObject, ['functionCall'], functionCallToMldev(fromFunctionCall));
|
|
14716
|
-
}
|
|
14717
|
-
const fromFunctionResponse = getValueByPath(fromObject, [
|
|
14718
|
-
'functionResponse',
|
|
14719
|
-
]);
|
|
14720
|
-
if (fromFunctionResponse != null) {
|
|
14721
|
-
setValueByPath(toObject, ['functionResponse'], fromFunctionResponse);
|
|
14722
|
-
}
|
|
14723
|
-
const fromInlineData = getValueByPath(fromObject, ['inlineData']);
|
|
14724
|
-
if (fromInlineData != null) {
|
|
14725
|
-
setValueByPath(toObject, ['inlineData'], blobToMldev(fromInlineData));
|
|
14726
|
-
}
|
|
14727
|
-
const fromText = getValueByPath(fromObject, ['text']);
|
|
14728
|
-
if (fromText != null) {
|
|
14729
|
-
setValueByPath(toObject, ['text'], fromText);
|
|
14730
|
-
}
|
|
14731
|
-
const fromThought = getValueByPath(fromObject, ['thought']);
|
|
14732
|
-
if (fromThought != null) {
|
|
14733
|
-
setValueByPath(toObject, ['thought'], fromThought);
|
|
14734
|
-
}
|
|
14735
|
-
const fromThoughtSignature = getValueByPath(fromObject, [
|
|
14736
|
-
'thoughtSignature',
|
|
14737
|
-
]);
|
|
14738
|
-
if (fromThoughtSignature != null) {
|
|
14739
|
-
setValueByPath(toObject, ['thoughtSignature'], fromThoughtSignature);
|
|
14740
|
-
}
|
|
14741
|
-
const fromVideoMetadata = getValueByPath(fromObject, [
|
|
14742
|
-
'videoMetadata',
|
|
14743
|
-
]);
|
|
14744
|
-
if (fromVideoMetadata != null) {
|
|
14745
|
-
setValueByPath(toObject, ['videoMetadata'], fromVideoMetadata);
|
|
14746
|
-
}
|
|
14747
|
-
return toObject;
|
|
14748
|
-
}
|
|
14749
|
-
function sessionResumptionConfigToMldev(fromObject) {
|
|
14750
|
-
const toObject = {};
|
|
14751
|
-
const fromHandle = getValueByPath(fromObject, ['handle']);
|
|
14752
|
-
if (fromHandle != null) {
|
|
14753
|
-
setValueByPath(toObject, ['handle'], fromHandle);
|
|
14754
|
-
}
|
|
14755
|
-
if (getValueByPath(fromObject, ['transparent']) !== undefined) {
|
|
14756
|
-
throw new Error('transparent parameter is not supported in Gemini API.');
|
|
14757
|
-
}
|
|
14758
|
-
return toObject;
|
|
14759
|
-
}
|
|
14760
|
-
function toolToMldev(fromObject) {
|
|
14761
|
-
const toObject = {};
|
|
14762
|
-
const fromFunctionDeclarations = getValueByPath(fromObject, [
|
|
14763
|
-
'functionDeclarations',
|
|
14764
|
-
]);
|
|
14765
|
-
if (fromFunctionDeclarations != null) {
|
|
14766
|
-
let transformedList = fromFunctionDeclarations;
|
|
14767
|
-
if (Array.isArray(transformedList)) {
|
|
14768
|
-
transformedList = transformedList.map((item) => {
|
|
14769
|
-
return item;
|
|
14457
|
+
return httpResponse.json();
|
|
14458
|
+
});
|
|
14459
|
+
return response.then((apiResponse) => {
|
|
14460
|
+
const resp = generateVideosOperationFromVertex(apiResponse);
|
|
14461
|
+
const typedResp = new GenerateVideosOperation();
|
|
14462
|
+
Object.assign(typedResp, resp);
|
|
14463
|
+
return typedResp;
|
|
14464
|
+
});
|
|
14465
|
+
}
|
|
14466
|
+
else {
|
|
14467
|
+
const body = generateVideosParametersToMldev(this.apiClient, params);
|
|
14468
|
+
path = formatMap('{model}:predictLongRunning', body['_url']);
|
|
14469
|
+
queryParams = body['_query'];
|
|
14470
|
+
delete body['_url'];
|
|
14471
|
+
delete body['_query'];
|
|
14472
|
+
response = this.apiClient
|
|
14473
|
+
.request({
|
|
14474
|
+
path: path,
|
|
14475
|
+
queryParams: queryParams,
|
|
14476
|
+
body: JSON.stringify(body),
|
|
14477
|
+
httpMethod: 'POST',
|
|
14478
|
+
httpOptions: (_c = params.config) === null || _c === void 0 ? void 0 : _c.httpOptions,
|
|
14479
|
+
abortSignal: (_d = params.config) === null || _d === void 0 ? void 0 : _d.abortSignal,
|
|
14480
|
+
})
|
|
14481
|
+
.then((httpResponse) => {
|
|
14482
|
+
return httpResponse.json();
|
|
14483
|
+
});
|
|
14484
|
+
return response.then((apiResponse) => {
|
|
14485
|
+
const resp = generateVideosOperationFromMldev(apiResponse);
|
|
14486
|
+
const typedResp = new GenerateVideosOperation();
|
|
14487
|
+
Object.assign(typedResp, resp);
|
|
14488
|
+
return typedResp;
|
|
14770
14489
|
});
|
|
14771
14490
|
}
|
|
14772
|
-
setValueByPath(toObject, ['functionDeclarations'], transformedList);
|
|
14773
|
-
}
|
|
14774
|
-
if (getValueByPath(fromObject, ['retrieval']) !== undefined) {
|
|
14775
|
-
throw new Error('retrieval parameter is not supported in Gemini API.');
|
|
14776
|
-
}
|
|
14777
|
-
const fromGoogleSearchRetrieval = getValueByPath(fromObject, [
|
|
14778
|
-
'googleSearchRetrieval',
|
|
14779
|
-
]);
|
|
14780
|
-
if (fromGoogleSearchRetrieval != null) {
|
|
14781
|
-
setValueByPath(toObject, ['googleSearchRetrieval'], fromGoogleSearchRetrieval);
|
|
14782
|
-
}
|
|
14783
|
-
const fromComputerUse = getValueByPath(fromObject, ['computerUse']);
|
|
14784
|
-
if (fromComputerUse != null) {
|
|
14785
|
-
setValueByPath(toObject, ['computerUse'], fromComputerUse);
|
|
14786
|
-
}
|
|
14787
|
-
const fromFileSearch = getValueByPath(fromObject, ['fileSearch']);
|
|
14788
|
-
if (fromFileSearch != null) {
|
|
14789
|
-
setValueByPath(toObject, ['fileSearch'], fromFileSearch);
|
|
14790
|
-
}
|
|
14791
|
-
const fromCodeExecution = getValueByPath(fromObject, [
|
|
14792
|
-
'codeExecution',
|
|
14793
|
-
]);
|
|
14794
|
-
if (fromCodeExecution != null) {
|
|
14795
|
-
setValueByPath(toObject, ['codeExecution'], fromCodeExecution);
|
|
14796
|
-
}
|
|
14797
|
-
if (getValueByPath(fromObject, ['enterpriseWebSearch']) !== undefined) {
|
|
14798
|
-
throw new Error('enterpriseWebSearch parameter is not supported in Gemini API.');
|
|
14799
|
-
}
|
|
14800
|
-
const fromGoogleMaps = getValueByPath(fromObject, ['googleMaps']);
|
|
14801
|
-
if (fromGoogleMaps != null) {
|
|
14802
|
-
setValueByPath(toObject, ['googleMaps'], googleMapsToMldev(fromGoogleMaps));
|
|
14803
|
-
}
|
|
14804
|
-
const fromGoogleSearch = getValueByPath(fromObject, ['googleSearch']);
|
|
14805
|
-
if (fromGoogleSearch != null) {
|
|
14806
|
-
setValueByPath(toObject, ['googleSearch'], googleSearchToMldev(fromGoogleSearch));
|
|
14807
|
-
}
|
|
14808
|
-
const fromUrlContext = getValueByPath(fromObject, ['urlContext']);
|
|
14809
|
-
if (fromUrlContext != null) {
|
|
14810
|
-
setValueByPath(toObject, ['urlContext'], fromUrlContext);
|
|
14811
14491
|
}
|
|
14812
|
-
return toObject;
|
|
14813
14492
|
}
|
|
14814
14493
|
|
|
14815
14494
|
/**
|
|
@@ -14817,257 +14496,151 @@ function toolToMldev(fromObject) {
|
|
|
14817
14496
|
* Copyright 2025 Google LLC
|
|
14818
14497
|
* SPDX-License-Identifier: Apache-2.0
|
|
14819
14498
|
*/
|
|
14820
|
-
|
|
14821
|
-
|
|
14822
|
-
|
|
14823
|
-
|
|
14824
|
-
* @return A comma-separated list of field masks.
|
|
14825
|
-
*/
|
|
14826
|
-
function getFieldMasks(setup) {
|
|
14827
|
-
const fields = [];
|
|
14828
|
-
for (const key in setup) {
|
|
14829
|
-
if (Object.prototype.hasOwnProperty.call(setup, key)) {
|
|
14830
|
-
const value = setup[key];
|
|
14831
|
-
// 2nd layer, recursively get field masks see TODO(b/418290100)
|
|
14832
|
-
if (typeof value === 'object' &&
|
|
14833
|
-
value != null &&
|
|
14834
|
-
Object.keys(value).length > 0) {
|
|
14835
|
-
const field = Object.keys(value).map((kk) => `${key}.${kk}`);
|
|
14836
|
-
fields.push(...field);
|
|
14837
|
-
}
|
|
14838
|
-
else {
|
|
14839
|
-
fields.push(key); // 1st layer
|
|
14840
|
-
}
|
|
14841
|
-
}
|
|
14499
|
+
class Operations extends BaseModule {
|
|
14500
|
+
constructor(apiClient) {
|
|
14501
|
+
super();
|
|
14502
|
+
this.apiClient = apiClient;
|
|
14842
14503
|
}
|
|
14843
|
-
|
|
14844
|
-
|
|
14845
|
-
|
|
14846
|
-
|
|
14847
|
-
|
|
14848
|
-
|
|
14849
|
-
|
|
14850
|
-
|
|
14851
|
-
|
|
14852
|
-
|
|
14853
|
-
|
|
14854
|
-
|
|
14855
|
-
|
|
14856
|
-
|
|
14857
|
-
|
|
14858
|
-
|
|
14859
|
-
|
|
14860
|
-
|
|
14861
|
-
.
|
|
14862
|
-
|
|
14863
|
-
|
|
14864
|
-
|
|
14865
|
-
|
|
14504
|
+
/**
|
|
14505
|
+
* Gets the status of a long-running operation.
|
|
14506
|
+
*
|
|
14507
|
+
* @param parameters The parameters for the get operation request.
|
|
14508
|
+
* @return The updated Operation object, with the latest status or result.
|
|
14509
|
+
*/
|
|
14510
|
+
async getVideosOperation(parameters) {
|
|
14511
|
+
const operation = parameters.operation;
|
|
14512
|
+
const config = parameters.config;
|
|
14513
|
+
if (operation.name === undefined || operation.name === '') {
|
|
14514
|
+
throw new Error('Operation name is required.');
|
|
14515
|
+
}
|
|
14516
|
+
if (this.apiClient.isVertexAI()) {
|
|
14517
|
+
const resourceName = operation.name.split('/operations/')[0];
|
|
14518
|
+
let httpOptions = undefined;
|
|
14519
|
+
if (config && 'httpOptions' in config) {
|
|
14520
|
+
httpOptions = config.httpOptions;
|
|
14521
|
+
}
|
|
14522
|
+
const rawOperation = await this.fetchPredictVideosOperationInternal({
|
|
14523
|
+
operationName: operation.name,
|
|
14524
|
+
resourceName: resourceName,
|
|
14525
|
+
config: { httpOptions: httpOptions },
|
|
14526
|
+
});
|
|
14527
|
+
return operation._fromAPIResponse({
|
|
14528
|
+
apiResponse: rawOperation,
|
|
14529
|
+
_isVertexAI: true,
|
|
14530
|
+
});
|
|
14866
14531
|
}
|
|
14867
14532
|
else {
|
|
14868
|
-
|
|
14869
|
-
|
|
14870
|
-
|
|
14533
|
+
const rawOperation = await this.getVideosOperationInternal({
|
|
14534
|
+
operationName: operation.name,
|
|
14535
|
+
config: config,
|
|
14536
|
+
});
|
|
14537
|
+
return operation._fromAPIResponse({
|
|
14538
|
+
apiResponse: rawOperation,
|
|
14539
|
+
_isVertexAI: false,
|
|
14540
|
+
});
|
|
14871
14541
|
}
|
|
14872
14542
|
}
|
|
14873
|
-
|
|
14874
|
-
|
|
14875
|
-
|
|
14876
|
-
|
|
14877
|
-
|
|
14878
|
-
|
|
14879
|
-
|
|
14880
|
-
|
|
14881
|
-
const
|
|
14882
|
-
if (
|
|
14883
|
-
|
|
14884
|
-
// Case 1: lockAdditionalFields is an empty array. Lock only fields from
|
|
14885
|
-
// bidi setup.
|
|
14886
|
-
if (generatedMaskFromBidi) {
|
|
14887
|
-
// Only assign if mask is not empty
|
|
14888
|
-
requestDict['fieldMask'] = generatedMaskFromBidi;
|
|
14889
|
-
}
|
|
14890
|
-
else {
|
|
14891
|
-
delete requestDict['fieldMask']; // If mask is empty, effectively no
|
|
14892
|
-
// specific fields locked by bidi
|
|
14893
|
-
}
|
|
14543
|
+
/**
|
|
14544
|
+
* Gets the status of a long-running operation.
|
|
14545
|
+
*
|
|
14546
|
+
* @param parameters The parameters for the get operation request.
|
|
14547
|
+
* @return The updated Operation object, with the latest status or result.
|
|
14548
|
+
*/
|
|
14549
|
+
async get(parameters) {
|
|
14550
|
+
const operation = parameters.operation;
|
|
14551
|
+
const config = parameters.config;
|
|
14552
|
+
if (operation.name === undefined || operation.name === '') {
|
|
14553
|
+
throw new Error('Operation name is required.');
|
|
14894
14554
|
}
|
|
14895
|
-
|
|
14896
|
-
|
|
14897
|
-
|
|
14898
|
-
|
|
14899
|
-
|
|
14900
|
-
// Case 2: Lock fields from bidi setup + additional fields
|
|
14901
|
-
// (preExistingFieldMask).
|
|
14902
|
-
const generationConfigFields = [
|
|
14903
|
-
'temperature',
|
|
14904
|
-
'topK',
|
|
14905
|
-
'topP',
|
|
14906
|
-
'maxOutputTokens',
|
|
14907
|
-
'responseModalities',
|
|
14908
|
-
'seed',
|
|
14909
|
-
'speechConfig',
|
|
14910
|
-
];
|
|
14911
|
-
let mappedFieldsFromPreExisting = [];
|
|
14912
|
-
if (preExistingFieldMask.length > 0) {
|
|
14913
|
-
mappedFieldsFromPreExisting = preExistingFieldMask.map((field) => {
|
|
14914
|
-
if (generationConfigFields.includes(field)) {
|
|
14915
|
-
return `generationConfig.${field}`;
|
|
14916
|
-
}
|
|
14917
|
-
return field; // Keep original field name if not in
|
|
14918
|
-
// generationConfigFields
|
|
14919
|
-
});
|
|
14920
|
-
}
|
|
14921
|
-
const finalMaskParts = [];
|
|
14922
|
-
if (generatedMaskFromBidi) {
|
|
14923
|
-
finalMaskParts.push(generatedMaskFromBidi);
|
|
14924
|
-
}
|
|
14925
|
-
if (mappedFieldsFromPreExisting.length > 0) {
|
|
14926
|
-
finalMaskParts.push(...mappedFieldsFromPreExisting);
|
|
14927
|
-
}
|
|
14928
|
-
if (finalMaskParts.length > 0) {
|
|
14929
|
-
requestDict['fieldMask'] = finalMaskParts.join(',');
|
|
14930
|
-
}
|
|
14931
|
-
else {
|
|
14932
|
-
// If no fields from bidi and no valid additional fields from
|
|
14933
|
-
// pre-existing mask.
|
|
14934
|
-
delete requestDict['fieldMask'];
|
|
14555
|
+
if (this.apiClient.isVertexAI()) {
|
|
14556
|
+
const resourceName = operation.name.split('/operations/')[0];
|
|
14557
|
+
let httpOptions = undefined;
|
|
14558
|
+
if (config && 'httpOptions' in config) {
|
|
14559
|
+
httpOptions = config.httpOptions;
|
|
14935
14560
|
}
|
|
14561
|
+
const rawOperation = await this.fetchPredictVideosOperationInternal({
|
|
14562
|
+
operationName: operation.name,
|
|
14563
|
+
resourceName: resourceName,
|
|
14564
|
+
config: { httpOptions: httpOptions },
|
|
14565
|
+
});
|
|
14566
|
+
return operation._fromAPIResponse({
|
|
14567
|
+
apiResponse: rawOperation,
|
|
14568
|
+
_isVertexAI: true,
|
|
14569
|
+
});
|
|
14936
14570
|
}
|
|
14937
14571
|
else {
|
|
14938
|
-
|
|
14939
|
-
|
|
14940
|
-
|
|
14941
|
-
|
|
14942
|
-
|
|
14943
|
-
|
|
14572
|
+
const rawOperation = await this.getVideosOperationInternal({
|
|
14573
|
+
operationName: operation.name,
|
|
14574
|
+
config: config,
|
|
14575
|
+
});
|
|
14576
|
+
return operation._fromAPIResponse({
|
|
14577
|
+
apiResponse: rawOperation,
|
|
14578
|
+
_isVertexAI: false,
|
|
14579
|
+
});
|
|
14944
14580
|
}
|
|
14945
14581
|
}
|
|
14946
|
-
|
|
14947
|
-
|
|
14948
|
-
|
|
14949
|
-
|
|
14950
|
-
|
|
14951
|
-
|
|
14952
|
-
|
|
14953
|
-
|
|
14954
|
-
|
|
14582
|
+
async getVideosOperationInternal(params) {
|
|
14583
|
+
var _a, _b, _c, _d;
|
|
14584
|
+
let response;
|
|
14585
|
+
let path = '';
|
|
14586
|
+
let queryParams = {};
|
|
14587
|
+
if (this.apiClient.isVertexAI()) {
|
|
14588
|
+
const body = getOperationParametersToVertex(params);
|
|
14589
|
+
path = formatMap('{operationName}', body['_url']);
|
|
14590
|
+
queryParams = body['_query'];
|
|
14591
|
+
delete body['_url'];
|
|
14592
|
+
delete body['_query'];
|
|
14593
|
+
response = this.apiClient
|
|
14594
|
+
.request({
|
|
14595
|
+
path: path,
|
|
14596
|
+
queryParams: queryParams,
|
|
14597
|
+
body: JSON.stringify(body),
|
|
14598
|
+
httpMethod: 'GET',
|
|
14599
|
+
httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
|
|
14600
|
+
abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
|
|
14601
|
+
})
|
|
14602
|
+
.then((httpResponse) => {
|
|
14603
|
+
return httpResponse.json();
|
|
14604
|
+
});
|
|
14605
|
+
return response;
|
|
14955
14606
|
}
|
|
14956
14607
|
else {
|
|
14957
|
-
|
|
14608
|
+
const body = getOperationParametersToMldev(params);
|
|
14609
|
+
path = formatMap('{operationName}', body['_url']);
|
|
14610
|
+
queryParams = body['_query'];
|
|
14611
|
+
delete body['_url'];
|
|
14612
|
+
delete body['_query'];
|
|
14613
|
+
response = this.apiClient
|
|
14614
|
+
.request({
|
|
14615
|
+
path: path,
|
|
14616
|
+
queryParams: queryParams,
|
|
14617
|
+
body: JSON.stringify(body),
|
|
14618
|
+
httpMethod: 'GET',
|
|
14619
|
+
httpOptions: (_c = params.config) === null || _c === void 0 ? void 0 : _c.httpOptions,
|
|
14620
|
+
abortSignal: (_d = params.config) === null || _d === void 0 ? void 0 : _d.abortSignal,
|
|
14621
|
+
})
|
|
14622
|
+
.then((httpResponse) => {
|
|
14623
|
+
return httpResponse.json();
|
|
14624
|
+
});
|
|
14625
|
+
return response;
|
|
14958
14626
|
}
|
|
14959
14627
|
}
|
|
14960
|
-
|
|
14961
|
-
}
|
|
14962
|
-
class Tokens extends BaseModule {
|
|
14963
|
-
constructor(apiClient) {
|
|
14964
|
-
super();
|
|
14965
|
-
this.apiClient = apiClient;
|
|
14966
|
-
}
|
|
14967
|
-
/**
|
|
14968
|
-
* Creates an ephemeral auth token resource.
|
|
14969
|
-
*
|
|
14970
|
-
* @experimental
|
|
14971
|
-
*
|
|
14972
|
-
* @remarks
|
|
14973
|
-
* Ephemeral auth tokens is only supported in the Gemini Developer API.
|
|
14974
|
-
* It can be used for the session connection to the Live constrained API.
|
|
14975
|
-
* Support in v1alpha only.
|
|
14976
|
-
*
|
|
14977
|
-
* @param params - The parameters for the create request.
|
|
14978
|
-
* @return The created auth token.
|
|
14979
|
-
*
|
|
14980
|
-
* @example
|
|
14981
|
-
* ```ts
|
|
14982
|
-
* const ai = new GoogleGenAI({
|
|
14983
|
-
* apiKey: token.name,
|
|
14984
|
-
* httpOptions: { apiVersion: 'v1alpha' } // Support in v1alpha only.
|
|
14985
|
-
* });
|
|
14986
|
-
*
|
|
14987
|
-
* // Case 1: If LiveEphemeralParameters is unset, unlock LiveConnectConfig
|
|
14988
|
-
* // when using the token in Live API sessions. Each session connection can
|
|
14989
|
-
* // use a different configuration.
|
|
14990
|
-
* const config: CreateAuthTokenConfig = {
|
|
14991
|
-
* uses: 3,
|
|
14992
|
-
* expireTime: '2025-05-01T00:00:00Z',
|
|
14993
|
-
* }
|
|
14994
|
-
* const token = await ai.tokens.create(config);
|
|
14995
|
-
*
|
|
14996
|
-
* // Case 2: If LiveEphemeralParameters is set, lock all fields in
|
|
14997
|
-
* // LiveConnectConfig when using the token in Live API sessions. For
|
|
14998
|
-
* // example, changing `outputAudioTranscription` in the Live API
|
|
14999
|
-
* // connection will be ignored by the API.
|
|
15000
|
-
* const config: CreateAuthTokenConfig =
|
|
15001
|
-
* uses: 3,
|
|
15002
|
-
* expireTime: '2025-05-01T00:00:00Z',
|
|
15003
|
-
* LiveEphemeralParameters: {
|
|
15004
|
-
* model: 'gemini-2.0-flash-001',
|
|
15005
|
-
* config: {
|
|
15006
|
-
* 'responseModalities': ['AUDIO'],
|
|
15007
|
-
* 'systemInstruction': 'Always answer in English.',
|
|
15008
|
-
* }
|
|
15009
|
-
* }
|
|
15010
|
-
* }
|
|
15011
|
-
* const token = await ai.tokens.create(config);
|
|
15012
|
-
*
|
|
15013
|
-
* // Case 3: If LiveEphemeralParameters is set and lockAdditionalFields is
|
|
15014
|
-
* // set, lock LiveConnectConfig with set and additional fields (e.g.
|
|
15015
|
-
* // responseModalities, systemInstruction, temperature in this example) when
|
|
15016
|
-
* // using the token in Live API sessions.
|
|
15017
|
-
* const config: CreateAuthTokenConfig =
|
|
15018
|
-
* uses: 3,
|
|
15019
|
-
* expireTime: '2025-05-01T00:00:00Z',
|
|
15020
|
-
* LiveEphemeralParameters: {
|
|
15021
|
-
* model: 'gemini-2.0-flash-001',
|
|
15022
|
-
* config: {
|
|
15023
|
-
* 'responseModalities': ['AUDIO'],
|
|
15024
|
-
* 'systemInstruction': 'Always answer in English.',
|
|
15025
|
-
* }
|
|
15026
|
-
* },
|
|
15027
|
-
* lockAdditionalFields: ['temperature'],
|
|
15028
|
-
* }
|
|
15029
|
-
* const token = await ai.tokens.create(config);
|
|
15030
|
-
*
|
|
15031
|
-
* // Case 4: If LiveEphemeralParameters is set and lockAdditionalFields is
|
|
15032
|
-
* // empty array, lock LiveConnectConfig with set fields (e.g.
|
|
15033
|
-
* // responseModalities, systemInstruction in this example) when using the
|
|
15034
|
-
* // token in Live API sessions.
|
|
15035
|
-
* const config: CreateAuthTokenConfig =
|
|
15036
|
-
* uses: 3,
|
|
15037
|
-
* expireTime: '2025-05-01T00:00:00Z',
|
|
15038
|
-
* LiveEphemeralParameters: {
|
|
15039
|
-
* model: 'gemini-2.0-flash-001',
|
|
15040
|
-
* config: {
|
|
15041
|
-
* 'responseModalities': ['AUDIO'],
|
|
15042
|
-
* 'systemInstruction': 'Always answer in English.',
|
|
15043
|
-
* }
|
|
15044
|
-
* },
|
|
15045
|
-
* lockAdditionalFields: [],
|
|
15046
|
-
* }
|
|
15047
|
-
* const token = await ai.tokens.create(config);
|
|
15048
|
-
* ```
|
|
15049
|
-
*/
|
|
15050
|
-
async create(params) {
|
|
14628
|
+
async fetchPredictVideosOperationInternal(params) {
|
|
15051
14629
|
var _a, _b;
|
|
15052
14630
|
let response;
|
|
15053
14631
|
let path = '';
|
|
15054
14632
|
let queryParams = {};
|
|
15055
14633
|
if (this.apiClient.isVertexAI()) {
|
|
15056
|
-
|
|
15057
|
-
|
|
15058
|
-
else {
|
|
15059
|
-
const body = createAuthTokenParametersToMldev(this.apiClient, params);
|
|
15060
|
-
path = formatMap('auth_tokens', body['_url']);
|
|
14634
|
+
const body = fetchPredictOperationParametersToVertex(params);
|
|
14635
|
+
path = formatMap('{resourceName}:fetchPredictOperation', body['_url']);
|
|
15061
14636
|
queryParams = body['_query'];
|
|
15062
|
-
delete body['config'];
|
|
15063
14637
|
delete body['_url'];
|
|
15064
14638
|
delete body['_query'];
|
|
15065
|
-
const transformedBody = convertBidiSetupToTokenSetup(body, params.config);
|
|
15066
14639
|
response = this.apiClient
|
|
15067
14640
|
.request({
|
|
15068
14641
|
path: path,
|
|
15069
14642
|
queryParams: queryParams,
|
|
15070
|
-
body: JSON.stringify(
|
|
14643
|
+
body: JSON.stringify(body),
|
|
15071
14644
|
httpMethod: 'POST',
|
|
15072
14645
|
httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
|
|
15073
14646
|
abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
|
|
@@ -15075,246 +14648,670 @@ class Tokens extends BaseModule {
|
|
|
15075
14648
|
.then((httpResponse) => {
|
|
15076
14649
|
return httpResponse.json();
|
|
15077
14650
|
});
|
|
15078
|
-
return response
|
|
15079
|
-
|
|
14651
|
+
return response;
|
|
14652
|
+
}
|
|
14653
|
+
else {
|
|
14654
|
+
throw new Error('This method is only supported by the Vertex AI.');
|
|
14655
|
+
}
|
|
14656
|
+
}
|
|
14657
|
+
}
|
|
14658
|
+
|
|
14659
|
+
/**
|
|
14660
|
+
* @license
|
|
14661
|
+
* Copyright 2025 Google LLC
|
|
14662
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
14663
|
+
*/
|
|
14664
|
+
function blobToMldev(fromObject) {
|
|
14665
|
+
const toObject = {};
|
|
14666
|
+
const fromData = getValueByPath(fromObject, ['data']);
|
|
14667
|
+
if (fromData != null) {
|
|
14668
|
+
setValueByPath(toObject, ['data'], fromData);
|
|
14669
|
+
}
|
|
14670
|
+
if (getValueByPath(fromObject, ['displayName']) !== undefined) {
|
|
14671
|
+
throw new Error('displayName parameter is not supported in Gemini API.');
|
|
14672
|
+
}
|
|
14673
|
+
const fromMimeType = getValueByPath(fromObject, ['mimeType']);
|
|
14674
|
+
if (fromMimeType != null) {
|
|
14675
|
+
setValueByPath(toObject, ['mimeType'], fromMimeType);
|
|
14676
|
+
}
|
|
14677
|
+
return toObject;
|
|
14678
|
+
}
|
|
14679
|
+
function contentToMldev(fromObject) {
|
|
14680
|
+
const toObject = {};
|
|
14681
|
+
const fromParts = getValueByPath(fromObject, ['parts']);
|
|
14682
|
+
if (fromParts != null) {
|
|
14683
|
+
let transformedList = fromParts;
|
|
14684
|
+
if (Array.isArray(transformedList)) {
|
|
14685
|
+
transformedList = transformedList.map((item) => {
|
|
14686
|
+
return partToMldev(item);
|
|
15080
14687
|
});
|
|
15081
14688
|
}
|
|
14689
|
+
setValueByPath(toObject, ['parts'], transformedList);
|
|
14690
|
+
}
|
|
14691
|
+
const fromRole = getValueByPath(fromObject, ['role']);
|
|
14692
|
+
if (fromRole != null) {
|
|
14693
|
+
setValueByPath(toObject, ['role'], fromRole);
|
|
14694
|
+
}
|
|
14695
|
+
return toObject;
|
|
14696
|
+
}
|
|
14697
|
+
function createAuthTokenConfigToMldev(apiClient, fromObject, parentObject) {
|
|
14698
|
+
const toObject = {};
|
|
14699
|
+
const fromExpireTime = getValueByPath(fromObject, ['expireTime']);
|
|
14700
|
+
if (parentObject !== undefined && fromExpireTime != null) {
|
|
14701
|
+
setValueByPath(parentObject, ['expireTime'], fromExpireTime);
|
|
14702
|
+
}
|
|
14703
|
+
const fromNewSessionExpireTime = getValueByPath(fromObject, [
|
|
14704
|
+
'newSessionExpireTime',
|
|
14705
|
+
]);
|
|
14706
|
+
if (parentObject !== undefined && fromNewSessionExpireTime != null) {
|
|
14707
|
+
setValueByPath(parentObject, ['newSessionExpireTime'], fromNewSessionExpireTime);
|
|
14708
|
+
}
|
|
14709
|
+
const fromUses = getValueByPath(fromObject, ['uses']);
|
|
14710
|
+
if (parentObject !== undefined && fromUses != null) {
|
|
14711
|
+
setValueByPath(parentObject, ['uses'], fromUses);
|
|
14712
|
+
}
|
|
14713
|
+
const fromLiveConnectConstraints = getValueByPath(fromObject, [
|
|
14714
|
+
'liveConnectConstraints',
|
|
14715
|
+
]);
|
|
14716
|
+
if (parentObject !== undefined && fromLiveConnectConstraints != null) {
|
|
14717
|
+
setValueByPath(parentObject, ['bidiGenerateContentSetup'], liveConnectConstraintsToMldev(apiClient, fromLiveConnectConstraints));
|
|
14718
|
+
}
|
|
14719
|
+
const fromLockAdditionalFields = getValueByPath(fromObject, [
|
|
14720
|
+
'lockAdditionalFields',
|
|
14721
|
+
]);
|
|
14722
|
+
if (parentObject !== undefined && fromLockAdditionalFields != null) {
|
|
14723
|
+
setValueByPath(parentObject, ['fieldMask'], fromLockAdditionalFields);
|
|
14724
|
+
}
|
|
14725
|
+
return toObject;
|
|
14726
|
+
}
|
|
14727
|
+
function createAuthTokenParametersToMldev(apiClient, fromObject) {
|
|
14728
|
+
const toObject = {};
|
|
14729
|
+
const fromConfig = getValueByPath(fromObject, ['config']);
|
|
14730
|
+
if (fromConfig != null) {
|
|
14731
|
+
setValueByPath(toObject, ['config'], createAuthTokenConfigToMldev(apiClient, fromConfig, toObject));
|
|
14732
|
+
}
|
|
14733
|
+
return toObject;
|
|
14734
|
+
}
|
|
14735
|
+
function fileDataToMldev(fromObject) {
|
|
14736
|
+
const toObject = {};
|
|
14737
|
+
if (getValueByPath(fromObject, ['displayName']) !== undefined) {
|
|
14738
|
+
throw new Error('displayName parameter is not supported in Gemini API.');
|
|
14739
|
+
}
|
|
14740
|
+
const fromFileUri = getValueByPath(fromObject, ['fileUri']);
|
|
14741
|
+
if (fromFileUri != null) {
|
|
14742
|
+
setValueByPath(toObject, ['fileUri'], fromFileUri);
|
|
14743
|
+
}
|
|
14744
|
+
const fromMimeType = getValueByPath(fromObject, ['mimeType']);
|
|
14745
|
+
if (fromMimeType != null) {
|
|
14746
|
+
setValueByPath(toObject, ['mimeType'], fromMimeType);
|
|
14747
|
+
}
|
|
14748
|
+
return toObject;
|
|
14749
|
+
}
|
|
14750
|
+
function functionCallToMldev(fromObject) {
|
|
14751
|
+
const toObject = {};
|
|
14752
|
+
const fromId = getValueByPath(fromObject, ['id']);
|
|
14753
|
+
if (fromId != null) {
|
|
14754
|
+
setValueByPath(toObject, ['id'], fromId);
|
|
14755
|
+
}
|
|
14756
|
+
const fromArgs = getValueByPath(fromObject, ['args']);
|
|
14757
|
+
if (fromArgs != null) {
|
|
14758
|
+
setValueByPath(toObject, ['args'], fromArgs);
|
|
14759
|
+
}
|
|
14760
|
+
const fromName = getValueByPath(fromObject, ['name']);
|
|
14761
|
+
if (fromName != null) {
|
|
14762
|
+
setValueByPath(toObject, ['name'], fromName);
|
|
14763
|
+
}
|
|
14764
|
+
if (getValueByPath(fromObject, ['partialArgs']) !== undefined) {
|
|
14765
|
+
throw new Error('partialArgs parameter is not supported in Gemini API.');
|
|
14766
|
+
}
|
|
14767
|
+
if (getValueByPath(fromObject, ['willContinue']) !== undefined) {
|
|
14768
|
+
throw new Error('willContinue parameter is not supported in Gemini API.');
|
|
15082
14769
|
}
|
|
14770
|
+
return toObject;
|
|
15083
14771
|
}
|
|
15084
|
-
|
|
15085
|
-
/**
|
|
15086
|
-
* @license
|
|
15087
|
-
* Copyright 2025 Google LLC
|
|
15088
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
15089
|
-
*/
|
|
15090
|
-
// Code generated by the Google Gen AI SDK generator DO NOT EDIT.
|
|
15091
|
-
function createFileSearchStoreConfigToMldev(fromObject, parentObject) {
|
|
14772
|
+
function googleMapsToMldev(fromObject) {
|
|
15092
14773
|
const toObject = {};
|
|
15093
|
-
|
|
15094
|
-
|
|
15095
|
-
|
|
14774
|
+
if (getValueByPath(fromObject, ['authConfig']) !== undefined) {
|
|
14775
|
+
throw new Error('authConfig parameter is not supported in Gemini API.');
|
|
14776
|
+
}
|
|
14777
|
+
const fromEnableWidget = getValueByPath(fromObject, ['enableWidget']);
|
|
14778
|
+
if (fromEnableWidget != null) {
|
|
14779
|
+
setValueByPath(toObject, ['enableWidget'], fromEnableWidget);
|
|
15096
14780
|
}
|
|
15097
14781
|
return toObject;
|
|
15098
14782
|
}
|
|
15099
|
-
function
|
|
14783
|
+
function googleSearchToMldev(fromObject) {
|
|
15100
14784
|
const toObject = {};
|
|
15101
|
-
|
|
15102
|
-
|
|
15103
|
-
|
|
14785
|
+
if (getValueByPath(fromObject, ['excludeDomains']) !== undefined) {
|
|
14786
|
+
throw new Error('excludeDomains parameter is not supported in Gemini API.');
|
|
14787
|
+
}
|
|
14788
|
+
if (getValueByPath(fromObject, ['blockingConfidence']) !== undefined) {
|
|
14789
|
+
throw new Error('blockingConfidence parameter is not supported in Gemini API.');
|
|
14790
|
+
}
|
|
14791
|
+
const fromTimeRangeFilter = getValueByPath(fromObject, [
|
|
14792
|
+
'timeRangeFilter',
|
|
14793
|
+
]);
|
|
14794
|
+
if (fromTimeRangeFilter != null) {
|
|
14795
|
+
setValueByPath(toObject, ['timeRangeFilter'], fromTimeRangeFilter);
|
|
15104
14796
|
}
|
|
15105
14797
|
return toObject;
|
|
15106
14798
|
}
|
|
15107
|
-
function
|
|
14799
|
+
function liveConnectConfigToMldev(fromObject, parentObject) {
|
|
15108
14800
|
const toObject = {};
|
|
15109
|
-
const
|
|
15110
|
-
|
|
15111
|
-
|
|
14801
|
+
const fromGenerationConfig = getValueByPath(fromObject, [
|
|
14802
|
+
'generationConfig',
|
|
14803
|
+
]);
|
|
14804
|
+
if (parentObject !== undefined && fromGenerationConfig != null) {
|
|
14805
|
+
setValueByPath(parentObject, ['setup', 'generationConfig'], fromGenerationConfig);
|
|
14806
|
+
}
|
|
14807
|
+
const fromResponseModalities = getValueByPath(fromObject, [
|
|
14808
|
+
'responseModalities',
|
|
14809
|
+
]);
|
|
14810
|
+
if (parentObject !== undefined && fromResponseModalities != null) {
|
|
14811
|
+
setValueByPath(parentObject, ['setup', 'generationConfig', 'responseModalities'], fromResponseModalities);
|
|
14812
|
+
}
|
|
14813
|
+
const fromTemperature = getValueByPath(fromObject, ['temperature']);
|
|
14814
|
+
if (parentObject !== undefined && fromTemperature != null) {
|
|
14815
|
+
setValueByPath(parentObject, ['setup', 'generationConfig', 'temperature'], fromTemperature);
|
|
14816
|
+
}
|
|
14817
|
+
const fromTopP = getValueByPath(fromObject, ['topP']);
|
|
14818
|
+
if (parentObject !== undefined && fromTopP != null) {
|
|
14819
|
+
setValueByPath(parentObject, ['setup', 'generationConfig', 'topP'], fromTopP);
|
|
14820
|
+
}
|
|
14821
|
+
const fromTopK = getValueByPath(fromObject, ['topK']);
|
|
14822
|
+
if (parentObject !== undefined && fromTopK != null) {
|
|
14823
|
+
setValueByPath(parentObject, ['setup', 'generationConfig', 'topK'], fromTopK);
|
|
14824
|
+
}
|
|
14825
|
+
const fromMaxOutputTokens = getValueByPath(fromObject, [
|
|
14826
|
+
'maxOutputTokens',
|
|
14827
|
+
]);
|
|
14828
|
+
if (parentObject !== undefined && fromMaxOutputTokens != null) {
|
|
14829
|
+
setValueByPath(parentObject, ['setup', 'generationConfig', 'maxOutputTokens'], fromMaxOutputTokens);
|
|
14830
|
+
}
|
|
14831
|
+
const fromMediaResolution = getValueByPath(fromObject, [
|
|
14832
|
+
'mediaResolution',
|
|
14833
|
+
]);
|
|
14834
|
+
if (parentObject !== undefined && fromMediaResolution != null) {
|
|
14835
|
+
setValueByPath(parentObject, ['setup', 'generationConfig', 'mediaResolution'], fromMediaResolution);
|
|
14836
|
+
}
|
|
14837
|
+
const fromSeed = getValueByPath(fromObject, ['seed']);
|
|
14838
|
+
if (parentObject !== undefined && fromSeed != null) {
|
|
14839
|
+
setValueByPath(parentObject, ['setup', 'generationConfig', 'seed'], fromSeed);
|
|
14840
|
+
}
|
|
14841
|
+
const fromSpeechConfig = getValueByPath(fromObject, ['speechConfig']);
|
|
14842
|
+
if (parentObject !== undefined && fromSpeechConfig != null) {
|
|
14843
|
+
setValueByPath(parentObject, ['setup', 'generationConfig', 'speechConfig'], tLiveSpeechConfig(fromSpeechConfig));
|
|
14844
|
+
}
|
|
14845
|
+
const fromThinkingConfig = getValueByPath(fromObject, [
|
|
14846
|
+
'thinkingConfig',
|
|
14847
|
+
]);
|
|
14848
|
+
if (parentObject !== undefined && fromThinkingConfig != null) {
|
|
14849
|
+
setValueByPath(parentObject, ['setup', 'generationConfig', 'thinkingConfig'], fromThinkingConfig);
|
|
14850
|
+
}
|
|
14851
|
+
const fromEnableAffectiveDialog = getValueByPath(fromObject, [
|
|
14852
|
+
'enableAffectiveDialog',
|
|
14853
|
+
]);
|
|
14854
|
+
if (parentObject !== undefined && fromEnableAffectiveDialog != null) {
|
|
14855
|
+
setValueByPath(parentObject, ['setup', 'generationConfig', 'enableAffectiveDialog'], fromEnableAffectiveDialog);
|
|
14856
|
+
}
|
|
14857
|
+
const fromSystemInstruction = getValueByPath(fromObject, [
|
|
14858
|
+
'systemInstruction',
|
|
14859
|
+
]);
|
|
14860
|
+
if (parentObject !== undefined && fromSystemInstruction != null) {
|
|
14861
|
+
setValueByPath(parentObject, ['setup', 'systemInstruction'], contentToMldev(tContent(fromSystemInstruction)));
|
|
14862
|
+
}
|
|
14863
|
+
const fromTools = getValueByPath(fromObject, ['tools']);
|
|
14864
|
+
if (parentObject !== undefined && fromTools != null) {
|
|
14865
|
+
let transformedList = tTools(fromTools);
|
|
14866
|
+
if (Array.isArray(transformedList)) {
|
|
14867
|
+
transformedList = transformedList.map((item) => {
|
|
14868
|
+
return toolToMldev(tTool(item));
|
|
14869
|
+
});
|
|
14870
|
+
}
|
|
14871
|
+
setValueByPath(parentObject, ['setup', 'tools'], transformedList);
|
|
14872
|
+
}
|
|
14873
|
+
const fromSessionResumption = getValueByPath(fromObject, [
|
|
14874
|
+
'sessionResumption',
|
|
14875
|
+
]);
|
|
14876
|
+
if (parentObject !== undefined && fromSessionResumption != null) {
|
|
14877
|
+
setValueByPath(parentObject, ['setup', 'sessionResumption'], sessionResumptionConfigToMldev(fromSessionResumption));
|
|
14878
|
+
}
|
|
14879
|
+
const fromInputAudioTranscription = getValueByPath(fromObject, [
|
|
14880
|
+
'inputAudioTranscription',
|
|
14881
|
+
]);
|
|
14882
|
+
if (parentObject !== undefined && fromInputAudioTranscription != null) {
|
|
14883
|
+
setValueByPath(parentObject, ['setup', 'inputAudioTranscription'], fromInputAudioTranscription);
|
|
14884
|
+
}
|
|
14885
|
+
const fromOutputAudioTranscription = getValueByPath(fromObject, [
|
|
14886
|
+
'outputAudioTranscription',
|
|
14887
|
+
]);
|
|
14888
|
+
if (parentObject !== undefined && fromOutputAudioTranscription != null) {
|
|
14889
|
+
setValueByPath(parentObject, ['setup', 'outputAudioTranscription'], fromOutputAudioTranscription);
|
|
14890
|
+
}
|
|
14891
|
+
const fromRealtimeInputConfig = getValueByPath(fromObject, [
|
|
14892
|
+
'realtimeInputConfig',
|
|
14893
|
+
]);
|
|
14894
|
+
if (parentObject !== undefined && fromRealtimeInputConfig != null) {
|
|
14895
|
+
setValueByPath(parentObject, ['setup', 'realtimeInputConfig'], fromRealtimeInputConfig);
|
|
14896
|
+
}
|
|
14897
|
+
const fromContextWindowCompression = getValueByPath(fromObject, [
|
|
14898
|
+
'contextWindowCompression',
|
|
14899
|
+
]);
|
|
14900
|
+
if (parentObject !== undefined && fromContextWindowCompression != null) {
|
|
14901
|
+
setValueByPath(parentObject, ['setup', 'contextWindowCompression'], fromContextWindowCompression);
|
|
14902
|
+
}
|
|
14903
|
+
const fromProactivity = getValueByPath(fromObject, ['proactivity']);
|
|
14904
|
+
if (parentObject !== undefined && fromProactivity != null) {
|
|
14905
|
+
setValueByPath(parentObject, ['setup', 'proactivity'], fromProactivity);
|
|
15112
14906
|
}
|
|
15113
14907
|
return toObject;
|
|
15114
14908
|
}
|
|
15115
|
-
function
|
|
14909
|
+
function liveConnectConstraintsToMldev(apiClient, fromObject) {
|
|
15116
14910
|
const toObject = {};
|
|
15117
|
-
const
|
|
15118
|
-
if (
|
|
15119
|
-
setValueByPath(toObject, ['
|
|
14911
|
+
const fromModel = getValueByPath(fromObject, ['model']);
|
|
14912
|
+
if (fromModel != null) {
|
|
14913
|
+
setValueByPath(toObject, ['setup', 'model'], tModel(apiClient, fromModel));
|
|
15120
14914
|
}
|
|
15121
14915
|
const fromConfig = getValueByPath(fromObject, ['config']);
|
|
15122
14916
|
if (fromConfig != null) {
|
|
15123
|
-
|
|
14917
|
+
setValueByPath(toObject, ['config'], liveConnectConfigToMldev(fromConfig, toObject));
|
|
15124
14918
|
}
|
|
15125
14919
|
return toObject;
|
|
15126
14920
|
}
|
|
15127
|
-
function
|
|
14921
|
+
function partToMldev(fromObject) {
|
|
15128
14922
|
const toObject = {};
|
|
15129
|
-
const
|
|
15130
|
-
|
|
15131
|
-
|
|
14923
|
+
const fromMediaResolution = getValueByPath(fromObject, [
|
|
14924
|
+
'mediaResolution',
|
|
14925
|
+
]);
|
|
14926
|
+
if (fromMediaResolution != null) {
|
|
14927
|
+
setValueByPath(toObject, ['mediaResolution'], fromMediaResolution);
|
|
14928
|
+
}
|
|
14929
|
+
const fromCodeExecutionResult = getValueByPath(fromObject, [
|
|
14930
|
+
'codeExecutionResult',
|
|
14931
|
+
]);
|
|
14932
|
+
if (fromCodeExecutionResult != null) {
|
|
14933
|
+
setValueByPath(toObject, ['codeExecutionResult'], fromCodeExecutionResult);
|
|
14934
|
+
}
|
|
14935
|
+
const fromExecutableCode = getValueByPath(fromObject, [
|
|
14936
|
+
'executableCode',
|
|
14937
|
+
]);
|
|
14938
|
+
if (fromExecutableCode != null) {
|
|
14939
|
+
setValueByPath(toObject, ['executableCode'], fromExecutableCode);
|
|
14940
|
+
}
|
|
14941
|
+
const fromFileData = getValueByPath(fromObject, ['fileData']);
|
|
14942
|
+
if (fromFileData != null) {
|
|
14943
|
+
setValueByPath(toObject, ['fileData'], fileDataToMldev(fromFileData));
|
|
14944
|
+
}
|
|
14945
|
+
const fromFunctionCall = getValueByPath(fromObject, ['functionCall']);
|
|
14946
|
+
if (fromFunctionCall != null) {
|
|
14947
|
+
setValueByPath(toObject, ['functionCall'], functionCallToMldev(fromFunctionCall));
|
|
14948
|
+
}
|
|
14949
|
+
const fromFunctionResponse = getValueByPath(fromObject, [
|
|
14950
|
+
'functionResponse',
|
|
14951
|
+
]);
|
|
14952
|
+
if (fromFunctionResponse != null) {
|
|
14953
|
+
setValueByPath(toObject, ['functionResponse'], fromFunctionResponse);
|
|
14954
|
+
}
|
|
14955
|
+
const fromInlineData = getValueByPath(fromObject, ['inlineData']);
|
|
14956
|
+
if (fromInlineData != null) {
|
|
14957
|
+
setValueByPath(toObject, ['inlineData'], blobToMldev(fromInlineData));
|
|
14958
|
+
}
|
|
14959
|
+
const fromText = getValueByPath(fromObject, ['text']);
|
|
14960
|
+
if (fromText != null) {
|
|
14961
|
+
setValueByPath(toObject, ['text'], fromText);
|
|
14962
|
+
}
|
|
14963
|
+
const fromThought = getValueByPath(fromObject, ['thought']);
|
|
14964
|
+
if (fromThought != null) {
|
|
14965
|
+
setValueByPath(toObject, ['thought'], fromThought);
|
|
14966
|
+
}
|
|
14967
|
+
const fromThoughtSignature = getValueByPath(fromObject, [
|
|
14968
|
+
'thoughtSignature',
|
|
14969
|
+
]);
|
|
14970
|
+
if (fromThoughtSignature != null) {
|
|
14971
|
+
setValueByPath(toObject, ['thoughtSignature'], fromThoughtSignature);
|
|
14972
|
+
}
|
|
14973
|
+
const fromVideoMetadata = getValueByPath(fromObject, [
|
|
14974
|
+
'videoMetadata',
|
|
14975
|
+
]);
|
|
14976
|
+
if (fromVideoMetadata != null) {
|
|
14977
|
+
setValueByPath(toObject, ['videoMetadata'], fromVideoMetadata);
|
|
15132
14978
|
}
|
|
15133
14979
|
return toObject;
|
|
15134
14980
|
}
|
|
15135
|
-
function
|
|
14981
|
+
function sessionResumptionConfigToMldev(fromObject) {
|
|
15136
14982
|
const toObject = {};
|
|
15137
|
-
const
|
|
15138
|
-
|
|
14983
|
+
const fromHandle = getValueByPath(fromObject, ['handle']);
|
|
14984
|
+
if (fromHandle != null) {
|
|
14985
|
+
setValueByPath(toObject, ['handle'], fromHandle);
|
|
14986
|
+
}
|
|
14987
|
+
if (getValueByPath(fromObject, ['transparent']) !== undefined) {
|
|
14988
|
+
throw new Error('transparent parameter is not supported in Gemini API.');
|
|
14989
|
+
}
|
|
14990
|
+
return toObject;
|
|
14991
|
+
}
|
|
14992
|
+
function toolToMldev(fromObject) {
|
|
14993
|
+
const toObject = {};
|
|
14994
|
+
const fromFunctionDeclarations = getValueByPath(fromObject, [
|
|
14995
|
+
'functionDeclarations',
|
|
15139
14996
|
]);
|
|
15140
|
-
if (
|
|
15141
|
-
let transformedList =
|
|
14997
|
+
if (fromFunctionDeclarations != null) {
|
|
14998
|
+
let transformedList = fromFunctionDeclarations;
|
|
15142
14999
|
if (Array.isArray(transformedList)) {
|
|
15143
15000
|
transformedList = transformedList.map((item) => {
|
|
15144
15001
|
return item;
|
|
15145
15002
|
});
|
|
15146
15003
|
}
|
|
15147
|
-
setValueByPath(
|
|
15148
|
-
}
|
|
15149
|
-
const fromChunkingConfig = getValueByPath(fromObject, [
|
|
15150
|
-
'chunkingConfig',
|
|
15151
|
-
]);
|
|
15152
|
-
if (parentObject !== undefined && fromChunkingConfig != null) {
|
|
15153
|
-
setValueByPath(parentObject, ['chunkingConfig'], fromChunkingConfig);
|
|
15154
|
-
}
|
|
15155
|
-
return toObject;
|
|
15156
|
-
}
|
|
15157
|
-
function importFileOperationFromMldev(fromObject) {
|
|
15158
|
-
const toObject = {};
|
|
15159
|
-
const fromName = getValueByPath(fromObject, ['name']);
|
|
15160
|
-
if (fromName != null) {
|
|
15161
|
-
setValueByPath(toObject, ['name'], fromName);
|
|
15162
|
-
}
|
|
15163
|
-
const fromMetadata = getValueByPath(fromObject, ['metadata']);
|
|
15164
|
-
if (fromMetadata != null) {
|
|
15165
|
-
setValueByPath(toObject, ['metadata'], fromMetadata);
|
|
15166
|
-
}
|
|
15167
|
-
const fromDone = getValueByPath(fromObject, ['done']);
|
|
15168
|
-
if (fromDone != null) {
|
|
15169
|
-
setValueByPath(toObject, ['done'], fromDone);
|
|
15170
|
-
}
|
|
15171
|
-
const fromError = getValueByPath(fromObject, ['error']);
|
|
15172
|
-
if (fromError != null) {
|
|
15173
|
-
setValueByPath(toObject, ['error'], fromError);
|
|
15004
|
+
setValueByPath(toObject, ['functionDeclarations'], transformedList);
|
|
15174
15005
|
}
|
|
15175
|
-
|
|
15176
|
-
|
|
15177
|
-
setValueByPath(toObject, ['response'], importFileResponseFromMldev(fromResponse));
|
|
15006
|
+
if (getValueByPath(fromObject, ['retrieval']) !== undefined) {
|
|
15007
|
+
throw new Error('retrieval parameter is not supported in Gemini API.');
|
|
15178
15008
|
}
|
|
15179
|
-
|
|
15180
|
-
|
|
15181
|
-
function importFileParametersToMldev(fromObject) {
|
|
15182
|
-
const toObject = {};
|
|
15183
|
-
const fromFileSearchStoreName = getValueByPath(fromObject, [
|
|
15184
|
-
'fileSearchStoreName',
|
|
15009
|
+
const fromGoogleSearchRetrieval = getValueByPath(fromObject, [
|
|
15010
|
+
'googleSearchRetrieval',
|
|
15185
15011
|
]);
|
|
15186
|
-
if (
|
|
15187
|
-
setValueByPath(toObject, ['
|
|
15012
|
+
if (fromGoogleSearchRetrieval != null) {
|
|
15013
|
+
setValueByPath(toObject, ['googleSearchRetrieval'], fromGoogleSearchRetrieval);
|
|
15188
15014
|
}
|
|
15189
|
-
const
|
|
15190
|
-
if (
|
|
15191
|
-
setValueByPath(toObject, ['
|
|
15015
|
+
const fromComputerUse = getValueByPath(fromObject, ['computerUse']);
|
|
15016
|
+
if (fromComputerUse != null) {
|
|
15017
|
+
setValueByPath(toObject, ['computerUse'], fromComputerUse);
|
|
15192
15018
|
}
|
|
15193
|
-
const
|
|
15194
|
-
if (
|
|
15195
|
-
|
|
15019
|
+
const fromFileSearch = getValueByPath(fromObject, ['fileSearch']);
|
|
15020
|
+
if (fromFileSearch != null) {
|
|
15021
|
+
setValueByPath(toObject, ['fileSearch'], fromFileSearch);
|
|
15196
15022
|
}
|
|
15197
|
-
|
|
15198
|
-
|
|
15199
|
-
function importFileResponseFromMldev(fromObject) {
|
|
15200
|
-
const toObject = {};
|
|
15201
|
-
const fromSdkHttpResponse = getValueByPath(fromObject, [
|
|
15202
|
-
'sdkHttpResponse',
|
|
15023
|
+
const fromCodeExecution = getValueByPath(fromObject, [
|
|
15024
|
+
'codeExecution',
|
|
15203
15025
|
]);
|
|
15204
|
-
if (
|
|
15205
|
-
setValueByPath(toObject, ['
|
|
15026
|
+
if (fromCodeExecution != null) {
|
|
15027
|
+
setValueByPath(toObject, ['codeExecution'], fromCodeExecution);
|
|
15206
15028
|
}
|
|
15207
|
-
|
|
15208
|
-
|
|
15209
|
-
setValueByPath(toObject, ['parent'], fromParent);
|
|
15029
|
+
if (getValueByPath(fromObject, ['enterpriseWebSearch']) !== undefined) {
|
|
15030
|
+
throw new Error('enterpriseWebSearch parameter is not supported in Gemini API.');
|
|
15210
15031
|
}
|
|
15211
|
-
const
|
|
15212
|
-
if (
|
|
15213
|
-
setValueByPath(toObject, ['
|
|
15032
|
+
const fromGoogleMaps = getValueByPath(fromObject, ['googleMaps']);
|
|
15033
|
+
if (fromGoogleMaps != null) {
|
|
15034
|
+
setValueByPath(toObject, ['googleMaps'], googleMapsToMldev(fromGoogleMaps));
|
|
15214
15035
|
}
|
|
15215
|
-
|
|
15216
|
-
|
|
15217
|
-
|
|
15218
|
-
const toObject = {};
|
|
15219
|
-
const fromPageSize = getValueByPath(fromObject, ['pageSize']);
|
|
15220
|
-
if (parentObject !== undefined && fromPageSize != null) {
|
|
15221
|
-
setValueByPath(parentObject, ['_query', 'pageSize'], fromPageSize);
|
|
15036
|
+
const fromGoogleSearch = getValueByPath(fromObject, ['googleSearch']);
|
|
15037
|
+
if (fromGoogleSearch != null) {
|
|
15038
|
+
setValueByPath(toObject, ['googleSearch'], googleSearchToMldev(fromGoogleSearch));
|
|
15222
15039
|
}
|
|
15223
|
-
const
|
|
15224
|
-
if (
|
|
15225
|
-
setValueByPath(
|
|
15040
|
+
const fromUrlContext = getValueByPath(fromObject, ['urlContext']);
|
|
15041
|
+
if (fromUrlContext != null) {
|
|
15042
|
+
setValueByPath(toObject, ['urlContext'], fromUrlContext);
|
|
15226
15043
|
}
|
|
15227
15044
|
return toObject;
|
|
15228
15045
|
}
|
|
15229
|
-
|
|
15230
|
-
|
|
15231
|
-
|
|
15232
|
-
|
|
15233
|
-
|
|
15046
|
+
|
|
15047
|
+
/**
|
|
15048
|
+
* @license
|
|
15049
|
+
* Copyright 2025 Google LLC
|
|
15050
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
15051
|
+
*/
|
|
15052
|
+
/**
|
|
15053
|
+
* Returns a comma-separated list of field masks from a given object.
|
|
15054
|
+
*
|
|
15055
|
+
* @param setup The object to extract field masks from.
|
|
15056
|
+
* @return A comma-separated list of field masks.
|
|
15057
|
+
*/
|
|
15058
|
+
function getFieldMasks(setup) {
|
|
15059
|
+
const fields = [];
|
|
15060
|
+
for (const key in setup) {
|
|
15061
|
+
if (Object.prototype.hasOwnProperty.call(setup, key)) {
|
|
15062
|
+
const value = setup[key];
|
|
15063
|
+
// 2nd layer, recursively get field masks see TODO(b/418290100)
|
|
15064
|
+
if (typeof value === 'object' &&
|
|
15065
|
+
value != null &&
|
|
15066
|
+
Object.keys(value).length > 0) {
|
|
15067
|
+
const field = Object.keys(value).map((kk) => `${key}.${kk}`);
|
|
15068
|
+
fields.push(...field);
|
|
15069
|
+
}
|
|
15070
|
+
else {
|
|
15071
|
+
fields.push(key); // 1st layer
|
|
15072
|
+
}
|
|
15073
|
+
}
|
|
15234
15074
|
}
|
|
15235
|
-
return
|
|
15075
|
+
return fields.join(',');
|
|
15236
15076
|
}
|
|
15237
|
-
|
|
15238
|
-
|
|
15239
|
-
|
|
15240
|
-
|
|
15241
|
-
|
|
15242
|
-
|
|
15243
|
-
|
|
15077
|
+
/**
|
|
15078
|
+
* Converts bidiGenerateContentSetup.
|
|
15079
|
+
* @param requestDict - The request dictionary.
|
|
15080
|
+
* @param config - The configuration object.
|
|
15081
|
+
* @return - The modified request dictionary.
|
|
15082
|
+
*/
|
|
15083
|
+
function convertBidiSetupToTokenSetup(requestDict, config) {
|
|
15084
|
+
// Convert bidiGenerateContentSetup from bidiGenerateContentSetup.setup.
|
|
15085
|
+
let setupForMaskGeneration = null;
|
|
15086
|
+
const bidiGenerateContentSetupValue = requestDict['bidiGenerateContentSetup'];
|
|
15087
|
+
if (typeof bidiGenerateContentSetupValue === 'object' &&
|
|
15088
|
+
bidiGenerateContentSetupValue !== null &&
|
|
15089
|
+
'setup' in bidiGenerateContentSetupValue) {
|
|
15090
|
+
// Now we know bidiGenerateContentSetupValue is an object and has a 'setup'
|
|
15091
|
+
// property.
|
|
15092
|
+
const innerSetup = bidiGenerateContentSetupValue
|
|
15093
|
+
.setup;
|
|
15094
|
+
if (typeof innerSetup === 'object' && innerSetup !== null) {
|
|
15095
|
+
// Valid inner setup found.
|
|
15096
|
+
requestDict['bidiGenerateContentSetup'] = innerSetup;
|
|
15097
|
+
setupForMaskGeneration = innerSetup;
|
|
15098
|
+
}
|
|
15099
|
+
else {
|
|
15100
|
+
// `bidiGenerateContentSetupValue.setup` is not a valid object; treat as
|
|
15101
|
+
// if bidiGenerateContentSetup is invalid.
|
|
15102
|
+
delete requestDict['bidiGenerateContentSetup'];
|
|
15103
|
+
}
|
|
15244
15104
|
}
|
|
15245
|
-
|
|
15246
|
-
|
|
15247
|
-
|
|
15248
|
-
|
|
15249
|
-
setValueByPath(toObject, ['nextPageToken'], fromNextPageToken);
|
|
15105
|
+
else if (bidiGenerateContentSetupValue !== undefined) {
|
|
15106
|
+
// `bidiGenerateContentSetup` exists but not in the expected
|
|
15107
|
+
// shape {setup: {...}}; treat as invalid.
|
|
15108
|
+
delete requestDict['bidiGenerateContentSetup'];
|
|
15250
15109
|
}
|
|
15251
|
-
const
|
|
15252
|
-
|
|
15253
|
-
|
|
15254
|
-
|
|
15255
|
-
|
|
15256
|
-
|
|
15257
|
-
|
|
15258
|
-
|
|
15259
|
-
|
|
15110
|
+
const preExistingFieldMask = requestDict['fieldMask'];
|
|
15111
|
+
// Handle mask generation setup.
|
|
15112
|
+
if (setupForMaskGeneration) {
|
|
15113
|
+
const generatedMaskFromBidi = getFieldMasks(setupForMaskGeneration);
|
|
15114
|
+
if (Array.isArray(config === null || config === void 0 ? void 0 : config.lockAdditionalFields) &&
|
|
15115
|
+
(config === null || config === void 0 ? void 0 : config.lockAdditionalFields.length) === 0) {
|
|
15116
|
+
// Case 1: lockAdditionalFields is an empty array. Lock only fields from
|
|
15117
|
+
// bidi setup.
|
|
15118
|
+
if (generatedMaskFromBidi) {
|
|
15119
|
+
// Only assign if mask is not empty
|
|
15120
|
+
requestDict['fieldMask'] = generatedMaskFromBidi;
|
|
15121
|
+
}
|
|
15122
|
+
else {
|
|
15123
|
+
delete requestDict['fieldMask']; // If mask is empty, effectively no
|
|
15124
|
+
// specific fields locked by bidi
|
|
15125
|
+
}
|
|
15126
|
+
}
|
|
15127
|
+
else if ((config === null || config === void 0 ? void 0 : config.lockAdditionalFields) &&
|
|
15128
|
+
config.lockAdditionalFields.length > 0 &&
|
|
15129
|
+
preExistingFieldMask !== null &&
|
|
15130
|
+
Array.isArray(preExistingFieldMask) &&
|
|
15131
|
+
preExistingFieldMask.length > 0) {
|
|
15132
|
+
// Case 2: Lock fields from bidi setup + additional fields
|
|
15133
|
+
// (preExistingFieldMask).
|
|
15134
|
+
const generationConfigFields = [
|
|
15135
|
+
'temperature',
|
|
15136
|
+
'topK',
|
|
15137
|
+
'topP',
|
|
15138
|
+
'maxOutputTokens',
|
|
15139
|
+
'responseModalities',
|
|
15140
|
+
'seed',
|
|
15141
|
+
'speechConfig',
|
|
15142
|
+
];
|
|
15143
|
+
let mappedFieldsFromPreExisting = [];
|
|
15144
|
+
if (preExistingFieldMask.length > 0) {
|
|
15145
|
+
mappedFieldsFromPreExisting = preExistingFieldMask.map((field) => {
|
|
15146
|
+
if (generationConfigFields.includes(field)) {
|
|
15147
|
+
return `generationConfig.${field}`;
|
|
15148
|
+
}
|
|
15149
|
+
return field; // Keep original field name if not in
|
|
15150
|
+
// generationConfigFields
|
|
15151
|
+
});
|
|
15152
|
+
}
|
|
15153
|
+
const finalMaskParts = [];
|
|
15154
|
+
if (generatedMaskFromBidi) {
|
|
15155
|
+
finalMaskParts.push(generatedMaskFromBidi);
|
|
15156
|
+
}
|
|
15157
|
+
if (mappedFieldsFromPreExisting.length > 0) {
|
|
15158
|
+
finalMaskParts.push(...mappedFieldsFromPreExisting);
|
|
15159
|
+
}
|
|
15160
|
+
if (finalMaskParts.length > 0) {
|
|
15161
|
+
requestDict['fieldMask'] = finalMaskParts.join(',');
|
|
15162
|
+
}
|
|
15163
|
+
else {
|
|
15164
|
+
// If no fields from bidi and no valid additional fields from
|
|
15165
|
+
// pre-existing mask.
|
|
15166
|
+
delete requestDict['fieldMask'];
|
|
15167
|
+
}
|
|
15168
|
+
}
|
|
15169
|
+
else {
|
|
15170
|
+
// Case 3: "Lock all fields" (meaning, don't send a field_mask, let server
|
|
15171
|
+
// defaults apply or all are mutable). This is hit if:
|
|
15172
|
+
// - `config.lockAdditionalFields` is undefined.
|
|
15173
|
+
// - `config.lockAdditionalFields` is non-empty, BUT
|
|
15174
|
+
// `preExistingFieldMask` is null, not a string, or an empty string.
|
|
15175
|
+
delete requestDict['fieldMask'];
|
|
15176
|
+
}
|
|
15177
|
+
}
|
|
15178
|
+
else {
|
|
15179
|
+
// No valid `bidiGenerateContentSetup` was found or extracted.
|
|
15180
|
+
// "Lock additional null fields if any".
|
|
15181
|
+
if (preExistingFieldMask !== null &&
|
|
15182
|
+
Array.isArray(preExistingFieldMask) &&
|
|
15183
|
+
preExistingFieldMask.length > 0) {
|
|
15184
|
+
// If there's a pre-existing field mask, it's a string, and it's not
|
|
15185
|
+
// empty, then we should lock all fields.
|
|
15186
|
+
requestDict['fieldMask'] = preExistingFieldMask.join(',');
|
|
15187
|
+
}
|
|
15188
|
+
else {
|
|
15189
|
+
delete requestDict['fieldMask'];
|
|
15260
15190
|
}
|
|
15261
|
-
setValueByPath(toObject, ['fileSearchStores'], transformedList);
|
|
15262
15191
|
}
|
|
15263
|
-
return
|
|
15192
|
+
return requestDict;
|
|
15264
15193
|
}
|
|
15265
|
-
|
|
15266
|
-
|
|
15267
|
-
|
|
15268
|
-
|
|
15269
|
-
setValueByPath(parentObject, ['mimeType'], fromMimeType);
|
|
15270
|
-
}
|
|
15271
|
-
const fromDisplayName = getValueByPath(fromObject, ['displayName']);
|
|
15272
|
-
if (parentObject !== undefined && fromDisplayName != null) {
|
|
15273
|
-
setValueByPath(parentObject, ['displayName'], fromDisplayName);
|
|
15194
|
+
class Tokens extends BaseModule {
|
|
15195
|
+
constructor(apiClient) {
|
|
15196
|
+
super();
|
|
15197
|
+
this.apiClient = apiClient;
|
|
15274
15198
|
}
|
|
15275
|
-
|
|
15276
|
-
|
|
15277
|
-
|
|
15278
|
-
|
|
15279
|
-
|
|
15280
|
-
|
|
15281
|
-
|
|
15282
|
-
|
|
15199
|
+
/**
|
|
15200
|
+
* Creates an ephemeral auth token resource.
|
|
15201
|
+
*
|
|
15202
|
+
* @experimental
|
|
15203
|
+
*
|
|
15204
|
+
* @remarks
|
|
15205
|
+
* Ephemeral auth tokens is only supported in the Gemini Developer API.
|
|
15206
|
+
* It can be used for the session connection to the Live constrained API.
|
|
15207
|
+
* Support in v1alpha only.
|
|
15208
|
+
*
|
|
15209
|
+
* @param params - The parameters for the create request.
|
|
15210
|
+
* @return The created auth token.
|
|
15211
|
+
*
|
|
15212
|
+
* @example
|
|
15213
|
+
* ```ts
|
|
15214
|
+
* const ai = new GoogleGenAI({
|
|
15215
|
+
* apiKey: token.name,
|
|
15216
|
+
* httpOptions: { apiVersion: 'v1alpha' } // Support in v1alpha only.
|
|
15217
|
+
* });
|
|
15218
|
+
*
|
|
15219
|
+
* // Case 1: If LiveEphemeralParameters is unset, unlock LiveConnectConfig
|
|
15220
|
+
* // when using the token in Live API sessions. Each session connection can
|
|
15221
|
+
* // use a different configuration.
|
|
15222
|
+
* const config: CreateAuthTokenConfig = {
|
|
15223
|
+
* uses: 3,
|
|
15224
|
+
* expireTime: '2025-05-01T00:00:00Z',
|
|
15225
|
+
* }
|
|
15226
|
+
* const token = await ai.tokens.create(config);
|
|
15227
|
+
*
|
|
15228
|
+
* // Case 2: If LiveEphemeralParameters is set, lock all fields in
|
|
15229
|
+
* // LiveConnectConfig when using the token in Live API sessions. For
|
|
15230
|
+
* // example, changing `outputAudioTranscription` in the Live API
|
|
15231
|
+
* // connection will be ignored by the API.
|
|
15232
|
+
* const config: CreateAuthTokenConfig =
|
|
15233
|
+
* uses: 3,
|
|
15234
|
+
* expireTime: '2025-05-01T00:00:00Z',
|
|
15235
|
+
* LiveEphemeralParameters: {
|
|
15236
|
+
* model: 'gemini-2.0-flash-001',
|
|
15237
|
+
* config: {
|
|
15238
|
+
* 'responseModalities': ['AUDIO'],
|
|
15239
|
+
* 'systemInstruction': 'Always answer in English.',
|
|
15240
|
+
* }
|
|
15241
|
+
* }
|
|
15242
|
+
* }
|
|
15243
|
+
* const token = await ai.tokens.create(config);
|
|
15244
|
+
*
|
|
15245
|
+
* // Case 3: If LiveEphemeralParameters is set and lockAdditionalFields is
|
|
15246
|
+
* // set, lock LiveConnectConfig with set and additional fields (e.g.
|
|
15247
|
+
* // responseModalities, systemInstruction, temperature in this example) when
|
|
15248
|
+
* // using the token in Live API sessions.
|
|
15249
|
+
* const config: CreateAuthTokenConfig =
|
|
15250
|
+
* uses: 3,
|
|
15251
|
+
* expireTime: '2025-05-01T00:00:00Z',
|
|
15252
|
+
* LiveEphemeralParameters: {
|
|
15253
|
+
* model: 'gemini-2.0-flash-001',
|
|
15254
|
+
* config: {
|
|
15255
|
+
* 'responseModalities': ['AUDIO'],
|
|
15256
|
+
* 'systemInstruction': 'Always answer in English.',
|
|
15257
|
+
* }
|
|
15258
|
+
* },
|
|
15259
|
+
* lockAdditionalFields: ['temperature'],
|
|
15260
|
+
* }
|
|
15261
|
+
* const token = await ai.tokens.create(config);
|
|
15262
|
+
*
|
|
15263
|
+
* // Case 4: If LiveEphemeralParameters is set and lockAdditionalFields is
|
|
15264
|
+
* // empty array, lock LiveConnectConfig with set fields (e.g.
|
|
15265
|
+
* // responseModalities, systemInstruction in this example) when using the
|
|
15266
|
+
* // token in Live API sessions.
|
|
15267
|
+
* const config: CreateAuthTokenConfig =
|
|
15268
|
+
* uses: 3,
|
|
15269
|
+
* expireTime: '2025-05-01T00:00:00Z',
|
|
15270
|
+
* LiveEphemeralParameters: {
|
|
15271
|
+
* model: 'gemini-2.0-flash-001',
|
|
15272
|
+
* config: {
|
|
15273
|
+
* 'responseModalities': ['AUDIO'],
|
|
15274
|
+
* 'systemInstruction': 'Always answer in English.',
|
|
15275
|
+
* }
|
|
15276
|
+
* },
|
|
15277
|
+
* lockAdditionalFields: [],
|
|
15278
|
+
* }
|
|
15279
|
+
* const token = await ai.tokens.create(config);
|
|
15280
|
+
* ```
|
|
15281
|
+
*/
|
|
15282
|
+
async create(params) {
|
|
15283
|
+
var _a, _b;
|
|
15284
|
+
let response;
|
|
15285
|
+
let path = '';
|
|
15286
|
+
let queryParams = {};
|
|
15287
|
+
if (this.apiClient.isVertexAI()) {
|
|
15288
|
+
throw new Error('The client.tokens.create method is only supported by the Gemini Developer API.');
|
|
15289
|
+
}
|
|
15290
|
+
else {
|
|
15291
|
+
const body = createAuthTokenParametersToMldev(this.apiClient, params);
|
|
15292
|
+
path = formatMap('auth_tokens', body['_url']);
|
|
15293
|
+
queryParams = body['_query'];
|
|
15294
|
+
delete body['config'];
|
|
15295
|
+
delete body['_url'];
|
|
15296
|
+
delete body['_query'];
|
|
15297
|
+
const transformedBody = convertBidiSetupToTokenSetup(body, params.config);
|
|
15298
|
+
response = this.apiClient
|
|
15299
|
+
.request({
|
|
15300
|
+
path: path,
|
|
15301
|
+
queryParams: queryParams,
|
|
15302
|
+
body: JSON.stringify(transformedBody),
|
|
15303
|
+
httpMethod: 'POST',
|
|
15304
|
+
httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
|
|
15305
|
+
abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
|
|
15306
|
+
})
|
|
15307
|
+
.then((httpResponse) => {
|
|
15308
|
+
return httpResponse.json();
|
|
15309
|
+
});
|
|
15310
|
+
return response.then((resp) => {
|
|
15311
|
+
return resp;
|
|
15283
15312
|
});
|
|
15284
15313
|
}
|
|
15285
|
-
setValueByPath(parentObject, ['customMetadata'], transformedList);
|
|
15286
|
-
}
|
|
15287
|
-
const fromChunkingConfig = getValueByPath(fromObject, [
|
|
15288
|
-
'chunkingConfig',
|
|
15289
|
-
]);
|
|
15290
|
-
if (parentObject !== undefined && fromChunkingConfig != null) {
|
|
15291
|
-
setValueByPath(parentObject, ['chunkingConfig'], fromChunkingConfig);
|
|
15292
|
-
}
|
|
15293
|
-
return toObject;
|
|
15294
|
-
}
|
|
15295
|
-
function uploadToFileSearchStoreParametersToMldev(fromObject) {
|
|
15296
|
-
const toObject = {};
|
|
15297
|
-
const fromFileSearchStoreName = getValueByPath(fromObject, [
|
|
15298
|
-
'fileSearchStoreName',
|
|
15299
|
-
]);
|
|
15300
|
-
if (fromFileSearchStoreName != null) {
|
|
15301
|
-
setValueByPath(toObject, ['_url', 'file_search_store_name'], fromFileSearchStoreName);
|
|
15302
|
-
}
|
|
15303
|
-
const fromConfig = getValueByPath(fromObject, ['config']);
|
|
15304
|
-
if (fromConfig != null) {
|
|
15305
|
-
uploadToFileSearchStoreConfigToMldev(fromConfig, toObject);
|
|
15306
|
-
}
|
|
15307
|
-
return toObject;
|
|
15308
|
-
}
|
|
15309
|
-
function uploadToFileSearchStoreResumableResponseFromMldev(fromObject) {
|
|
15310
|
-
const toObject = {};
|
|
15311
|
-
const fromSdkHttpResponse = getValueByPath(fromObject, [
|
|
15312
|
-
'sdkHttpResponse',
|
|
15313
|
-
]);
|
|
15314
|
-
if (fromSdkHttpResponse != null) {
|
|
15315
|
-
setValueByPath(toObject, ['sdkHttpResponse'], fromSdkHttpResponse);
|
|
15316
15314
|
}
|
|
15317
|
-
return toObject;
|
|
15318
15315
|
}
|
|
15319
15316
|
|
|
15320
15317
|
/**
|
|
@@ -15419,17 +15416,14 @@ class Documents extends BaseModule {
|
|
|
15419
15416
|
*
|
|
15420
15417
|
* @example
|
|
15421
15418
|
* ```ts
|
|
15422
|
-
* const documents = await ai.documents.list({config: {'pageSize': 2}});
|
|
15419
|
+
* const documents = await ai.documents.list({parent:'rag_store_name', config: {'pageSize': 2}});
|
|
15423
15420
|
* for await (const document of documents) {
|
|
15424
15421
|
* console.log(document);
|
|
15425
15422
|
* }
|
|
15426
15423
|
* ```
|
|
15427
15424
|
*/
|
|
15428
15425
|
this.list = async (params) => {
|
|
15429
|
-
return new Pager(exports.PagedItem.PAGED_ITEM_DOCUMENTS, (x) => this.listInternal({
|
|
15430
|
-
parent: params.parent,
|
|
15431
|
-
config: x.config,
|
|
15432
|
-
}), await this.listInternal(params), params);
|
|
15426
|
+
return new Pager(exports.PagedItem.PAGED_ITEM_DOCUMENTS, (x) => this.listInternal({ parent: params.parent, config: x.config }), await this.listInternal(params), params);
|
|
15433
15427
|
};
|
|
15434
15428
|
}
|
|
15435
15429
|
/**
|
|
@@ -15497,12 +15491,6 @@ class Documents extends BaseModule {
|
|
|
15497
15491
|
});
|
|
15498
15492
|
}
|
|
15499
15493
|
}
|
|
15500
|
-
/**
|
|
15501
|
-
* Lists all Documents in a FileSearchStore.
|
|
15502
|
-
*
|
|
15503
|
-
* @param params - The parameters for listing documents.
|
|
15504
|
-
* @return ListDocumentsResponse.
|
|
15505
|
-
*/
|
|
15506
15494
|
async listInternal(params) {
|
|
15507
15495
|
var _a, _b;
|
|
15508
15496
|
let response;
|
|
@@ -15711,12 +15699,6 @@ class FileSearchStores extends BaseModule {
|
|
|
15711
15699
|
});
|
|
15712
15700
|
}
|
|
15713
15701
|
}
|
|
15714
|
-
/**
|
|
15715
|
-
* Lists all FileSearchStore owned by the user.
|
|
15716
|
-
*
|
|
15717
|
-
* @param params - The parameters for listing file search stores.
|
|
15718
|
-
* @return ListFileSearchStoresResponse.
|
|
15719
|
-
*/
|
|
15720
15702
|
async listInternal(params) {
|
|
15721
15703
|
var _a, _b;
|
|
15722
15704
|
let response;
|
|
@@ -16030,6 +16012,26 @@ function cancelTuningJobParametersToVertex(fromObject, _rootObject) {
|
|
|
16030
16012
|
}
|
|
16031
16013
|
return toObject;
|
|
16032
16014
|
}
|
|
16015
|
+
function cancelTuningJobResponseFromMldev(fromObject, _rootObject) {
|
|
16016
|
+
const toObject = {};
|
|
16017
|
+
const fromSdkHttpResponse = getValueByPath(fromObject, [
|
|
16018
|
+
'sdkHttpResponse',
|
|
16019
|
+
]);
|
|
16020
|
+
if (fromSdkHttpResponse != null) {
|
|
16021
|
+
setValueByPath(toObject, ['sdkHttpResponse'], fromSdkHttpResponse);
|
|
16022
|
+
}
|
|
16023
|
+
return toObject;
|
|
16024
|
+
}
|
|
16025
|
+
function cancelTuningJobResponseFromVertex(fromObject, _rootObject) {
|
|
16026
|
+
const toObject = {};
|
|
16027
|
+
const fromSdkHttpResponse = getValueByPath(fromObject, [
|
|
16028
|
+
'sdkHttpResponse',
|
|
16029
|
+
]);
|
|
16030
|
+
if (fromSdkHttpResponse != null) {
|
|
16031
|
+
setValueByPath(toObject, ['sdkHttpResponse'], fromSdkHttpResponse);
|
|
16032
|
+
}
|
|
16033
|
+
return toObject;
|
|
16034
|
+
}
|
|
16033
16035
|
function createTuningJobConfigToMldev(fromObject, parentObject, _rootObject) {
|
|
16034
16036
|
const toObject = {};
|
|
16035
16037
|
if (getValueByPath(fromObject, ['validationDataset']) !== undefined) {
|
|
@@ -16691,28 +16693,33 @@ class Tunings extends BaseModule {
|
|
|
16691
16693
|
super();
|
|
16692
16694
|
this.apiClient = apiClient;
|
|
16693
16695
|
/**
|
|
16694
|
-
*
|
|
16696
|
+
* Lists tuning jobs.
|
|
16695
16697
|
*
|
|
16696
|
-
* @param
|
|
16697
|
-
* @return - A
|
|
16698
|
+
* @param params - The parameters for the list request.
|
|
16699
|
+
* @return - A pager of tuning jobs.
|
|
16698
16700
|
*
|
|
16699
|
-
* @
|
|
16700
|
-
*
|
|
16701
|
+
* @example
|
|
16702
|
+
* ```ts
|
|
16703
|
+
* const tuningJobs = await ai.tunings.list({config: {'pageSize': 2}});
|
|
16704
|
+
* for await (const tuningJob of tuningJobs) {
|
|
16705
|
+
* console.log(tuningJob);
|
|
16706
|
+
* }
|
|
16707
|
+
* ```
|
|
16701
16708
|
*/
|
|
16702
|
-
this.
|
|
16703
|
-
return await this.
|
|
16709
|
+
this.list = async (params = {}) => {
|
|
16710
|
+
return new Pager(exports.PagedItem.PAGED_ITEM_TUNING_JOBS, (x) => this.listInternal(x), await this.listInternal(params), params);
|
|
16704
16711
|
};
|
|
16705
16712
|
/**
|
|
16706
|
-
*
|
|
16713
|
+
* Gets a TuningJob.
|
|
16707
16714
|
*
|
|
16708
|
-
* @param
|
|
16709
|
-
* @return - A
|
|
16715
|
+
* @param name - The resource name of the tuning job.
|
|
16716
|
+
* @return - A TuningJob object.
|
|
16710
16717
|
*
|
|
16711
16718
|
* @experimental - The SDK's tuning implementation is experimental, and may
|
|
16712
16719
|
* change in future versions.
|
|
16713
16720
|
*/
|
|
16714
|
-
this.
|
|
16715
|
-
return
|
|
16721
|
+
this.get = async (params) => {
|
|
16722
|
+
return await this.getInternal(params);
|
|
16716
16723
|
};
|
|
16717
16724
|
/**
|
|
16718
16725
|
* Creates a supervised fine-tuning job.
|
|
@@ -16907,6 +16914,7 @@ class Tunings extends BaseModule {
|
|
|
16907
16914
|
*/
|
|
16908
16915
|
async cancel(params) {
|
|
16909
16916
|
var _a, _b, _c, _d;
|
|
16917
|
+
let response;
|
|
16910
16918
|
let path = '';
|
|
16911
16919
|
let queryParams = {};
|
|
16912
16920
|
if (this.apiClient.isVertexAI()) {
|
|
@@ -16915,13 +16923,29 @@ class Tunings extends BaseModule {
|
|
|
16915
16923
|
queryParams = body['_query'];
|
|
16916
16924
|
delete body['_url'];
|
|
16917
16925
|
delete body['_query'];
|
|
16918
|
-
|
|
16926
|
+
response = this.apiClient
|
|
16927
|
+
.request({
|
|
16919
16928
|
path: path,
|
|
16920
16929
|
queryParams: queryParams,
|
|
16921
16930
|
body: JSON.stringify(body),
|
|
16922
16931
|
httpMethod: 'POST',
|
|
16923
16932
|
httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
|
|
16924
16933
|
abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
|
|
16934
|
+
})
|
|
16935
|
+
.then((httpResponse) => {
|
|
16936
|
+
return httpResponse.json().then((jsonResponse) => {
|
|
16937
|
+
const response = jsonResponse;
|
|
16938
|
+
response.sdkHttpResponse = {
|
|
16939
|
+
headers: httpResponse.headers,
|
|
16940
|
+
};
|
|
16941
|
+
return response;
|
|
16942
|
+
});
|
|
16943
|
+
});
|
|
16944
|
+
return response.then((apiResponse) => {
|
|
16945
|
+
const resp = cancelTuningJobResponseFromVertex(apiResponse);
|
|
16946
|
+
const typedResp = new CancelTuningJobResponse();
|
|
16947
|
+
Object.assign(typedResp, resp);
|
|
16948
|
+
return typedResp;
|
|
16925
16949
|
});
|
|
16926
16950
|
}
|
|
16927
16951
|
else {
|
|
@@ -16930,13 +16954,29 @@ class Tunings extends BaseModule {
|
|
|
16930
16954
|
queryParams = body['_query'];
|
|
16931
16955
|
delete body['_url'];
|
|
16932
16956
|
delete body['_query'];
|
|
16933
|
-
|
|
16957
|
+
response = this.apiClient
|
|
16958
|
+
.request({
|
|
16934
16959
|
path: path,
|
|
16935
16960
|
queryParams: queryParams,
|
|
16936
16961
|
body: JSON.stringify(body),
|
|
16937
16962
|
httpMethod: 'POST',
|
|
16938
16963
|
httpOptions: (_c = params.config) === null || _c === void 0 ? void 0 : _c.httpOptions,
|
|
16939
16964
|
abortSignal: (_d = params.config) === null || _d === void 0 ? void 0 : _d.abortSignal,
|
|
16965
|
+
})
|
|
16966
|
+
.then((httpResponse) => {
|
|
16967
|
+
return httpResponse.json().then((jsonResponse) => {
|
|
16968
|
+
const response = jsonResponse;
|
|
16969
|
+
response.sdkHttpResponse = {
|
|
16970
|
+
headers: httpResponse.headers,
|
|
16971
|
+
};
|
|
16972
|
+
return response;
|
|
16973
|
+
});
|
|
16974
|
+
});
|
|
16975
|
+
return response.then((apiResponse) => {
|
|
16976
|
+
const resp = cancelTuningJobResponseFromMldev(apiResponse);
|
|
16977
|
+
const typedResp = new CancelTuningJobResponse();
|
|
16978
|
+
Object.assign(typedResp, resp);
|
|
16979
|
+
return typedResp;
|
|
16940
16980
|
});
|
|
16941
16981
|
}
|
|
16942
16982
|
}
|
|
@@ -17422,6 +17462,7 @@ class GoogleGenAI {
|
|
|
17422
17462
|
}
|
|
17423
17463
|
}
|
|
17424
17464
|
this.apiVersion = options.apiVersion;
|
|
17465
|
+
this.httpOptions = options.httpOptions;
|
|
17425
17466
|
const auth = new NodeAuth({
|
|
17426
17467
|
apiKey: this.apiKey,
|
|
17427
17468
|
googleAuthOptions: options.googleAuthOptions,
|
|
@@ -17433,7 +17474,7 @@ class GoogleGenAI {
|
|
|
17433
17474
|
apiVersion: this.apiVersion,
|
|
17434
17475
|
apiKey: this.apiKey,
|
|
17435
17476
|
vertexai: this.vertexai,
|
|
17436
|
-
httpOptions:
|
|
17477
|
+
httpOptions: this.httpOptions,
|
|
17437
17478
|
userAgentExtra: LANGUAGE_LABEL_PREFIX + process.version,
|
|
17438
17479
|
uploader: new NodeUploader(),
|
|
17439
17480
|
downloader: new NodeDownloader(),
|
|
@@ -17475,6 +17516,7 @@ function getApiKeyFromEnv() {
|
|
|
17475
17516
|
exports.ApiError = ApiError;
|
|
17476
17517
|
exports.Batches = Batches;
|
|
17477
17518
|
exports.Caches = Caches;
|
|
17519
|
+
exports.CancelTuningJobResponse = CancelTuningJobResponse;
|
|
17478
17520
|
exports.Chat = Chat;
|
|
17479
17521
|
exports.Chats = Chats;
|
|
17480
17522
|
exports.ComputeTokensResponse = ComputeTokensResponse;
|