@google/genai 0.11.0 → 0.13.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/index.js CHANGED
@@ -491,15 +491,81 @@ function tBytes(apiClient, fromImageBytes) {
491
491
  // TODO(b/389133914): Remove dummy bytes converter.
492
492
  return fromImageBytes;
493
493
  }
494
+ function _isFile(origin) {
495
+ return (origin !== null &&
496
+ origin !== undefined &&
497
+ typeof origin === 'object' &&
498
+ 'name' in origin);
499
+ }
500
+ function isGeneratedVideo(origin) {
501
+ return (origin !== null &&
502
+ origin !== undefined &&
503
+ typeof origin === 'object' &&
504
+ 'video' in origin);
505
+ }
506
+ function isVideo(origin) {
507
+ return (origin !== null &&
508
+ origin !== undefined &&
509
+ typeof origin === 'object' &&
510
+ 'uri' in origin);
511
+ }
494
512
  function tFileName(apiClient, fromName) {
495
- if (typeof fromName !== 'string') {
496
- throw new Error('fromName must be a string');
513
+ var _a;
514
+ let name;
515
+ if (_isFile(fromName)) {
516
+ name = fromName.name;
517
+ }
518
+ if (isVideo(fromName)) {
519
+ name = fromName.uri;
520
+ if (name === undefined) {
521
+ return undefined;
522
+ }
523
+ }
524
+ if (isGeneratedVideo(fromName)) {
525
+ name = (_a = fromName.video) === null || _a === void 0 ? void 0 : _a.uri;
526
+ if (name === undefined) {
527
+ return undefined;
528
+ }
529
+ }
530
+ if (typeof fromName === 'string') {
531
+ name = fromName;
532
+ }
533
+ if (name === undefined) {
534
+ throw new Error('Could not extract file name from the provided input.');
535
+ }
536
+ if (name.startsWith('https://')) {
537
+ const suffix = name.split('files/')[1];
538
+ const match = suffix.match(/[a-z0-9]+/);
539
+ if (match === null) {
540
+ throw new Error(`Could not extract file name from URI ${name}`);
541
+ }
542
+ name = match[0];
543
+ }
544
+ else if (name.startsWith('files/')) {
545
+ name = name.split('files/')[1];
497
546
  }
498
- // Remove the files/ prefx for MLdev urls to get the actual name of the file.
499
- if (fromName.startsWith('files/')) {
500
- return fromName.split('files/')[1];
547
+ return name;
548
+ }
549
+ function tModelsUrl(apiClient, baseModels) {
550
+ let res;
551
+ if (apiClient.isVertexAI()) {
552
+ res = baseModels ? 'publishers/google/models' : 'models';
553
+ }
554
+ else {
555
+ res = baseModels ? 'models' : 'tunedModels';
556
+ }
557
+ return res;
558
+ }
559
+ function tExtractModels(apiClient, response) {
560
+ for (const key of ['models', 'tunedModels', 'publisherModels']) {
561
+ if (hasField(response, key)) {
562
+ return response[key];
563
+ }
501
564
  }
502
- return fromName;
565
+ return [];
566
+ }
567
+ function hasField(data, fieldName) {
568
+ return data !== null && typeof data === 'object' && fieldName in data;
503
569
  }
504
570
 
505
571
  /**
@@ -613,6 +679,12 @@ function toolToMldev$2(apiClient, fromObject) {
613
679
  if (fromGoogleSearchRetrieval != null) {
614
680
  setValueByPath(toObject, ['googleSearchRetrieval'], googleSearchRetrievalToMldev$2(apiClient, fromGoogleSearchRetrieval));
615
681
  }
682
+ if (getValueByPath(fromObject, ['enterpriseWebSearch']) !== undefined) {
683
+ throw new Error('enterpriseWebSearch parameter is not supported in Gemini API.');
684
+ }
685
+ if (getValueByPath(fromObject, ['googleMaps']) !== undefined) {
686
+ throw new Error('googleMaps parameter is not supported in Gemini API.');
687
+ }
616
688
  const fromCodeExecution = getValueByPath(fromObject, [
617
689
  'codeExecution',
618
690
  ]);
@@ -649,6 +721,9 @@ function toolConfigToMldev$1(apiClient, fromObject) {
649
721
  if (fromFunctionCallingConfig != null) {
650
722
  setValueByPath(toObject, ['functionCallingConfig'], functionCallingConfigToMldev$1(apiClient, fromFunctionCallingConfig));
651
723
  }
724
+ if (getValueByPath(fromObject, ['retrievalConfig']) !== undefined) {
725
+ throw new Error('retrievalConfig parameter is not supported in Gemini API.');
726
+ }
652
727
  return toObject;
653
728
  }
654
729
  function createCachedContentConfigToMldev(apiClient, fromObject, parentObject) {
@@ -871,6 +946,58 @@ function googleSearchRetrievalToVertex$2(apiClient, fromObject) {
871
946
  }
872
947
  return toObject;
873
948
  }
949
+ function enterpriseWebSearchToVertex$2() {
950
+ const toObject = {};
951
+ return toObject;
952
+ }
953
+ function apiKeyConfigToVertex$2(apiClient, fromObject) {
954
+ const toObject = {};
955
+ const fromApiKeyString = getValueByPath(fromObject, ['apiKeyString']);
956
+ if (fromApiKeyString != null) {
957
+ setValueByPath(toObject, ['apiKeyString'], fromApiKeyString);
958
+ }
959
+ return toObject;
960
+ }
961
+ function authConfigToVertex$2(apiClient, fromObject) {
962
+ const toObject = {};
963
+ const fromApiKeyConfig = getValueByPath(fromObject, ['apiKeyConfig']);
964
+ if (fromApiKeyConfig != null) {
965
+ setValueByPath(toObject, ['apiKeyConfig'], apiKeyConfigToVertex$2(apiClient, fromApiKeyConfig));
966
+ }
967
+ const fromAuthType = getValueByPath(fromObject, ['authType']);
968
+ if (fromAuthType != null) {
969
+ setValueByPath(toObject, ['authType'], fromAuthType);
970
+ }
971
+ const fromGoogleServiceAccountConfig = getValueByPath(fromObject, [
972
+ 'googleServiceAccountConfig',
973
+ ]);
974
+ if (fromGoogleServiceAccountConfig != null) {
975
+ setValueByPath(toObject, ['googleServiceAccountConfig'], fromGoogleServiceAccountConfig);
976
+ }
977
+ const fromHttpBasicAuthConfig = getValueByPath(fromObject, [
978
+ 'httpBasicAuthConfig',
979
+ ]);
980
+ if (fromHttpBasicAuthConfig != null) {
981
+ setValueByPath(toObject, ['httpBasicAuthConfig'], fromHttpBasicAuthConfig);
982
+ }
983
+ const fromOauthConfig = getValueByPath(fromObject, ['oauthConfig']);
984
+ if (fromOauthConfig != null) {
985
+ setValueByPath(toObject, ['oauthConfig'], fromOauthConfig);
986
+ }
987
+ const fromOidcConfig = getValueByPath(fromObject, ['oidcConfig']);
988
+ if (fromOidcConfig != null) {
989
+ setValueByPath(toObject, ['oidcConfig'], fromOidcConfig);
990
+ }
991
+ return toObject;
992
+ }
993
+ function googleMapsToVertex$2(apiClient, fromObject) {
994
+ const toObject = {};
995
+ const fromAuthConfig = getValueByPath(fromObject, ['authConfig']);
996
+ if (fromAuthConfig != null) {
997
+ setValueByPath(toObject, ['authConfig'], authConfigToVertex$2(apiClient, fromAuthConfig));
998
+ }
999
+ return toObject;
1000
+ }
874
1001
  function toolToVertex$2(apiClient, fromObject) {
875
1002
  const toObject = {};
876
1003
  const fromRetrieval = getValueByPath(fromObject, ['retrieval']);
@@ -887,6 +1014,16 @@ function toolToVertex$2(apiClient, fromObject) {
887
1014
  if (fromGoogleSearchRetrieval != null) {
888
1015
  setValueByPath(toObject, ['googleSearchRetrieval'], googleSearchRetrievalToVertex$2(apiClient, fromGoogleSearchRetrieval));
889
1016
  }
1017
+ const fromEnterpriseWebSearch = getValueByPath(fromObject, [
1018
+ 'enterpriseWebSearch',
1019
+ ]);
1020
+ if (fromEnterpriseWebSearch != null) {
1021
+ setValueByPath(toObject, ['enterpriseWebSearch'], enterpriseWebSearchToVertex$2());
1022
+ }
1023
+ const fromGoogleMaps = getValueByPath(fromObject, ['googleMaps']);
1024
+ if (fromGoogleMaps != null) {
1025
+ setValueByPath(toObject, ['googleMaps'], googleMapsToVertex$2(apiClient, fromGoogleMaps));
1026
+ }
890
1027
  const fromCodeExecution = getValueByPath(fromObject, [
891
1028
  'codeExecution',
892
1029
  ]);
@@ -915,6 +1052,26 @@ function functionCallingConfigToVertex$1(apiClient, fromObject) {
915
1052
  }
916
1053
  return toObject;
917
1054
  }
1055
+ function latLngToVertex$1(apiClient, fromObject) {
1056
+ const toObject = {};
1057
+ const fromLatitude = getValueByPath(fromObject, ['latitude']);
1058
+ if (fromLatitude != null) {
1059
+ setValueByPath(toObject, ['latitude'], fromLatitude);
1060
+ }
1061
+ const fromLongitude = getValueByPath(fromObject, ['longitude']);
1062
+ if (fromLongitude != null) {
1063
+ setValueByPath(toObject, ['longitude'], fromLongitude);
1064
+ }
1065
+ return toObject;
1066
+ }
1067
+ function retrievalConfigToVertex$1(apiClient, fromObject) {
1068
+ const toObject = {};
1069
+ const fromLatLng = getValueByPath(fromObject, ['latLng']);
1070
+ if (fromLatLng != null) {
1071
+ setValueByPath(toObject, ['latLng'], latLngToVertex$1(apiClient, fromLatLng));
1072
+ }
1073
+ return toObject;
1074
+ }
918
1075
  function toolConfigToVertex$1(apiClient, fromObject) {
919
1076
  const toObject = {};
920
1077
  const fromFunctionCallingConfig = getValueByPath(fromObject, [
@@ -923,6 +1080,12 @@ function toolConfigToVertex$1(apiClient, fromObject) {
923
1080
  if (fromFunctionCallingConfig != null) {
924
1081
  setValueByPath(toObject, ['functionCallingConfig'], functionCallingConfigToVertex$1(apiClient, fromFunctionCallingConfig));
925
1082
  }
1083
+ const fromRetrievalConfig = getValueByPath(fromObject, [
1084
+ 'retrievalConfig',
1085
+ ]);
1086
+ if (fromRetrievalConfig != null) {
1087
+ setValueByPath(toObject, ['retrievalConfig'], retrievalConfigToVertex$1(apiClient, fromRetrievalConfig));
1088
+ }
926
1089
  return toObject;
927
1090
  }
928
1091
  function createCachedContentConfigToVertex(apiClient, fromObject, parentObject) {
@@ -1402,6 +1565,17 @@ exports.Mode = void 0;
1402
1565
  Mode["MODE_UNSPECIFIED"] = "MODE_UNSPECIFIED";
1403
1566
  Mode["MODE_DYNAMIC"] = "MODE_DYNAMIC";
1404
1567
  })(exports.Mode || (exports.Mode = {}));
1568
+ /** Type of auth scheme. */
1569
+ exports.AuthType = void 0;
1570
+ (function (AuthType) {
1571
+ AuthType["AUTH_TYPE_UNSPECIFIED"] = "AUTH_TYPE_UNSPECIFIED";
1572
+ AuthType["NO_AUTH"] = "NO_AUTH";
1573
+ AuthType["API_KEY_AUTH"] = "API_KEY_AUTH";
1574
+ AuthType["HTTP_BASIC_AUTH"] = "HTTP_BASIC_AUTH";
1575
+ AuthType["GOOGLE_SERVICE_ACCOUNT_AUTH"] = "GOOGLE_SERVICE_ACCOUNT_AUTH";
1576
+ AuthType["OAUTH"] = "OAUTH";
1577
+ AuthType["OIDC_AUTH"] = "OIDC_AUTH";
1578
+ })(exports.AuthType || (exports.AuthType = {}));
1405
1579
  /** Optional. The type of the data. */
1406
1580
  exports.Type = void 0;
1407
1581
  (function (Type) {
@@ -2009,6 +2183,8 @@ class EmbedContentResponse {
2009
2183
  /** The output images response. */
2010
2184
  class GenerateImagesResponse {
2011
2185
  }
2186
+ class ListModelsResponse {
2187
+ }
2012
2188
  class DeleteModelResponse {
2013
2189
  }
2014
2190
  /** Response for counting tokens. */
@@ -2056,6 +2232,70 @@ class DeleteFileResponse {
2056
2232
  /** Represents a single response in a replay. */
2057
2233
  class ReplayResponse {
2058
2234
  }
2235
+ /** Response message for API call. */
2236
+ class LiveServerMessage {
2237
+ /**
2238
+ * Returns the concatenation of all text parts from the server content if present.
2239
+ *
2240
+ * @remarks
2241
+ * If there are non-text parts in the response, the concatenation of all text
2242
+ * parts will be returned, and a warning will be logged.
2243
+ */
2244
+ get text() {
2245
+ var _a, _b, _c;
2246
+ let text = '';
2247
+ let anyTextPartFound = false;
2248
+ const nonTextParts = [];
2249
+ for (const part of (_c = (_b = (_a = this.serverContent) === null || _a === void 0 ? void 0 : _a.modelTurn) === null || _b === void 0 ? void 0 : _b.parts) !== null && _c !== void 0 ? _c : []) {
2250
+ for (const [fieldName, fieldValue] of Object.entries(part)) {
2251
+ if (fieldName !== 'text' &&
2252
+ fieldName !== 'thought' &&
2253
+ fieldValue !== null) {
2254
+ nonTextParts.push(fieldName);
2255
+ }
2256
+ }
2257
+ if (typeof part.text === 'string') {
2258
+ if (typeof part.thought === 'boolean' && part.thought) {
2259
+ continue;
2260
+ }
2261
+ anyTextPartFound = true;
2262
+ text += part.text;
2263
+ }
2264
+ }
2265
+ if (nonTextParts.length > 0) {
2266
+ console.warn(`there are non-text parts ${nonTextParts} in the response, returning concatenation of all text parts. Please refer to the non text parts for a full response from model.`);
2267
+ }
2268
+ // part.text === '' is different from part.text is null
2269
+ return anyTextPartFound ? text : undefined;
2270
+ }
2271
+ /**
2272
+ * Returns the concatenation of all inline data parts from the server content if present.
2273
+ *
2274
+ * @remarks
2275
+ * If there are non-inline data parts in the
2276
+ * response, the concatenation of all inline data parts will be returned, and
2277
+ * a warning will be logged.
2278
+ */
2279
+ get data() {
2280
+ var _a, _b, _c;
2281
+ let data = '';
2282
+ const nonDataParts = [];
2283
+ for (const part of (_c = (_b = (_a = this.serverContent) === null || _a === void 0 ? void 0 : _a.modelTurn) === null || _b === void 0 ? void 0 : _b.parts) !== null && _c !== void 0 ? _c : []) {
2284
+ for (const [fieldName, fieldValue] of Object.entries(part)) {
2285
+ if (fieldName !== 'inlineData' && fieldValue !== null) {
2286
+ nonDataParts.push(fieldName);
2287
+ }
2288
+ }
2289
+ if (part.inlineData && typeof part.inlineData.data === 'string') {
2290
+ data += atob(part.inlineData.data);
2291
+ }
2292
+ }
2293
+ if (nonDataParts.length > 0) {
2294
+ console.warn(`there are non-data parts ${nonDataParts} in the response, returning concatenation of all data parts. Please refer to the non data parts for a full response from model.`);
2295
+ }
2296
+ return data.length > 0 ? btoa(data) : undefined;
2297
+ }
2298
+ }
2059
2299
  /** Client generated response to a `ToolCall` received from the server.
2060
2300
 
2061
2301
  Individual `FunctionResponse` objects are matched to the respective
@@ -2817,7 +3057,7 @@ const CONTENT_TYPE_HEADER = 'Content-Type';
2817
3057
  const SERVER_TIMEOUT_HEADER = 'X-Server-Timeout';
2818
3058
  const USER_AGENT_HEADER = 'User-Agent';
2819
3059
  const GOOGLE_API_CLIENT_HEADER = 'x-goog-api-client';
2820
- const SDK_VERSION = '0.11.0'; // x-release-please-version
3060
+ const SDK_VERSION = '0.13.0'; // x-release-please-version
2821
3061
  const LIBRARY_LABEL = `google-genai-sdk/${SDK_VERSION}`;
2822
3062
  const VERTEX_AI_API_DEFAULT_VERSION = 'v1beta1';
2823
3063
  const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
@@ -2864,18 +3104,11 @@ class ApiClient {
2864
3104
  if (this.clientOptions.vertexai) {
2865
3105
  initHttpOptions.apiVersion =
2866
3106
  (_a = this.clientOptions.apiVersion) !== null && _a !== void 0 ? _a : VERTEX_AI_API_DEFAULT_VERSION;
2867
- // Assume that proj/api key validation occurs before they are passed in.
2868
- if (this.getProject() || this.getLocation()) {
2869
- initHttpOptions.baseUrl = `https://${this.clientOptions.location}-aiplatform.googleapis.com/`;
2870
- this.clientOptions.apiKey = undefined; // unset API key.
2871
- }
2872
- else {
2873
- initHttpOptions.baseUrl = `https://aiplatform.googleapis.com/`;
2874
- this.clientOptions.project = undefined; // unset project.
2875
- this.clientOptions.location = undefined; // unset location.
2876
- }
3107
+ initHttpOptions.baseUrl = this.baseUrlFromProjectLocation();
3108
+ this.normalizeAuthParameters();
2877
3109
  }
2878
3110
  else {
3111
+ // Gemini API
2879
3112
  initHttpOptions.apiVersion =
2880
3113
  (_b = this.clientOptions.apiVersion) !== null && _b !== void 0 ? _b : GOOGLE_AI_API_DEFAULT_VERSION;
2881
3114
  initHttpOptions.baseUrl = `https://generativelanguage.googleapis.com/`;
@@ -2886,6 +3119,39 @@ class ApiClient {
2886
3119
  this.clientOptions.httpOptions = this.patchHttpOptions(initHttpOptions, opts.httpOptions);
2887
3120
  }
2888
3121
  }
3122
+ /**
3123
+ * Determines the base URL for Vertex AI based on project and location.
3124
+ * Uses the global endpoint if location is 'global' or if project/location
3125
+ * are not specified (implying API key usage).
3126
+ * @private
3127
+ */
3128
+ baseUrlFromProjectLocation() {
3129
+ if (this.clientOptions.project &&
3130
+ this.clientOptions.location &&
3131
+ this.clientOptions.location !== 'global') {
3132
+ // Regional endpoint
3133
+ return `https://${this.clientOptions.location}-aiplatform.googleapis.com/`;
3134
+ }
3135
+ // Global endpoint (covers 'global' location and API key usage)
3136
+ return `https://aiplatform.googleapis.com/`;
3137
+ }
3138
+ /**
3139
+ * Normalizes authentication parameters for Vertex AI.
3140
+ * If project and location are provided, API key is cleared.
3141
+ * If project and location are not provided (implying API key usage),
3142
+ * project and location are cleared.
3143
+ * @private
3144
+ */
3145
+ normalizeAuthParameters() {
3146
+ if (this.clientOptions.project && this.clientOptions.location) {
3147
+ // Using project/location for auth, clear potential API key
3148
+ this.clientOptions.apiKey = undefined;
3149
+ return;
3150
+ }
3151
+ // Using API key for auth (or no auth provided yet), clear project/location
3152
+ this.clientOptions.project = undefined;
3153
+ this.clientOptions.location = undefined;
3154
+ }
2889
3155
  isVertexAI() {
2890
3156
  var _a;
2891
3157
  return (_a = this.clientOptions.vertexai) !== null && _a !== void 0 ? _a : false;
@@ -3223,6 +3489,16 @@ class ApiClient {
3223
3489
  const uploadUrl = await this.fetchUploadUrl(fileToUpload, config);
3224
3490
  return uploader.upload(file, uploadUrl, this);
3225
3491
  }
3492
+ /**
3493
+ * Downloads a file asynchronously to the specified path.
3494
+ *
3495
+ * @params params - The parameters for the download request, see {@link
3496
+ * DownloadFileParameters}
3497
+ */
3498
+ async downloadFile(params) {
3499
+ const downloader = this.clientOptions.downloader;
3500
+ await downloader.download(params, this);
3501
+ }
3226
3502
  async fetchUploadUrl(file, config) {
3227
3503
  var _a;
3228
3504
  let httpOptions = {};
@@ -3309,7 +3585,22 @@ function crossError() {
3309
3585
  `);
3310
3586
  }
3311
3587
 
3588
+ /**
3589
+ * @license
3590
+ * Copyright 2025 Google LLC
3591
+ * SPDX-License-Identifier: Apache-2.0
3592
+ */
3593
+ class CrossDownloader {
3594
+ async download(_params, _apiClient) {
3595
+ throw crossError();
3596
+ }
3597
+ }
3598
+
3312
3599
  const MAX_CHUNK_SIZE = 1024 * 1024 * 8; // bytes
3600
+ const MAX_RETRY_COUNT = 3;
3601
+ const INITIAL_RETRY_DELAY_MS = 1000;
3602
+ const DELAY_MULTIPLIER = 2;
3603
+ const X_GOOG_UPLOAD_STATUS_HEADER_FIELD = 'x-goog-upload-status';
3313
3604
  class CrossUploader {
3314
3605
  async upload(file, uploadUrl, apiClient) {
3315
3606
  if (typeof file === 'string') {
@@ -3329,7 +3620,7 @@ class CrossUploader {
3329
3620
  }
3330
3621
  }
3331
3622
  async function uploadBlob(file, uploadUrl, apiClient) {
3332
- var _a, _b;
3623
+ var _a, _b, _c;
3333
3624
  let fileSize = 0;
3334
3625
  let offset = 0;
3335
3626
  let response = new HttpResponse(new Response());
@@ -3341,24 +3632,34 @@ async function uploadBlob(file, uploadUrl, apiClient) {
3341
3632
  if (offset + chunkSize >= fileSize) {
3342
3633
  uploadCommand += ', finalize';
3343
3634
  }
3344
- response = await apiClient.request({
3345
- path: '',
3346
- body: chunk,
3347
- httpMethod: 'POST',
3348
- httpOptions: {
3349
- apiVersion: '',
3350
- baseUrl: uploadUrl,
3351
- headers: {
3352
- 'X-Goog-Upload-Command': uploadCommand,
3353
- 'X-Goog-Upload-Offset': String(offset),
3354
- 'Content-Length': String(chunkSize),
3635
+ let retryCount = 0;
3636
+ let currentDelayMs = INITIAL_RETRY_DELAY_MS;
3637
+ while (retryCount < MAX_RETRY_COUNT) {
3638
+ response = await apiClient.request({
3639
+ path: '',
3640
+ body: chunk,
3641
+ httpMethod: 'POST',
3642
+ httpOptions: {
3643
+ apiVersion: '',
3644
+ baseUrl: uploadUrl,
3645
+ headers: {
3646
+ 'X-Goog-Upload-Command': uploadCommand,
3647
+ 'X-Goog-Upload-Offset': String(offset),
3648
+ 'Content-Length': String(chunkSize),
3649
+ },
3355
3650
  },
3356
- },
3357
- });
3651
+ });
3652
+ if ((_a = response === null || response === void 0 ? void 0 : response.headers) === null || _a === void 0 ? void 0 : _a[X_GOOG_UPLOAD_STATUS_HEADER_FIELD]) {
3653
+ break;
3654
+ }
3655
+ retryCount++;
3656
+ await sleep(currentDelayMs);
3657
+ currentDelayMs = currentDelayMs * DELAY_MULTIPLIER;
3658
+ }
3358
3659
  offset += chunkSize;
3359
3660
  // The `x-goog-upload-status` header field can be `active`, `final` and
3360
3661
  //`cancelled` in resposne.
3361
- if (((_a = response === null || response === void 0 ? void 0 : response.headers) === null || _a === void 0 ? void 0 : _a['x-goog-upload-status']) !== 'active') {
3662
+ if (((_b = response === null || response === void 0 ? void 0 : response.headers) === null || _b === void 0 ? void 0 : _b[X_GOOG_UPLOAD_STATUS_HEADER_FIELD]) !== 'active') {
3362
3663
  break;
3363
3664
  }
3364
3665
  // TODO(b/401391430) Investigate why the upload status is not finalized
@@ -3368,7 +3669,7 @@ async function uploadBlob(file, uploadUrl, apiClient) {
3368
3669
  }
3369
3670
  }
3370
3671
  const responseJson = (await (response === null || response === void 0 ? void 0 : response.json()));
3371
- if (((_b = response === null || response === void 0 ? void 0 : response.headers) === null || _b === void 0 ? void 0 : _b['x-goog-upload-status']) !== 'final') {
3672
+ if (((_c = response === null || response === void 0 ? void 0 : response.headers) === null || _c === void 0 ? void 0 : _c[X_GOOG_UPLOAD_STATUS_HEADER_FIELD]) !== 'final') {
3372
3673
  throw new Error('Failed to upload file: Upload status is not finalized.');
3373
3674
  }
3374
3675
  return responseJson['file'];
@@ -3377,6 +3678,9 @@ async function getBlobStat(file) {
3377
3678
  const fileStat = { size: file.size, type: file.type };
3378
3679
  return fileStat;
3379
3680
  }
3681
+ function sleep(ms) {
3682
+ return new Promise((resolvePromise) => setTimeout(resolvePromise, ms));
3683
+ }
3380
3684
 
3381
3685
  /**
3382
3686
  * @license
@@ -3725,6 +4029,25 @@ class Files extends BaseModule {
3725
4029
  return file;
3726
4030
  });
3727
4031
  }
4032
+ /**
4033
+ * Downloads a remotely stored file asynchronously to a location specified in
4034
+ * the `params` object. This method only works on Node environment, to
4035
+ * download files in the browser, use a browser compliant method like an <a>
4036
+ * tag.
4037
+ *
4038
+ * @param params - The parameters for the download request.
4039
+ *
4040
+ * @example
4041
+ * The following code downloads an example file named "files/mehozpxf877d" as
4042
+ * "file.txt".
4043
+ *
4044
+ * ```ts
4045
+ * await ai.files.download({file: file.name, downloadPath: 'file.txt'});
4046
+ * ```
4047
+ */
4048
+ async download(params) {
4049
+ await this.apiClient.downloadFile(params);
4050
+ }
3728
4051
  async listInternal(params) {
3729
4052
  var _a, _b;
3730
4053
  let response;
@@ -4083,6 +4406,58 @@ function googleSearchRetrievalToVertex$1(apiClient, fromObject) {
4083
4406
  }
4084
4407
  return toObject;
4085
4408
  }
4409
+ function enterpriseWebSearchToVertex$1() {
4410
+ const toObject = {};
4411
+ return toObject;
4412
+ }
4413
+ function apiKeyConfigToVertex$1(apiClient, fromObject) {
4414
+ const toObject = {};
4415
+ const fromApiKeyString = getValueByPath(fromObject, ['apiKeyString']);
4416
+ if (fromApiKeyString != null) {
4417
+ setValueByPath(toObject, ['apiKeyString'], fromApiKeyString);
4418
+ }
4419
+ return toObject;
4420
+ }
4421
+ function authConfigToVertex$1(apiClient, fromObject) {
4422
+ const toObject = {};
4423
+ const fromApiKeyConfig = getValueByPath(fromObject, ['apiKeyConfig']);
4424
+ if (fromApiKeyConfig != null) {
4425
+ setValueByPath(toObject, ['apiKeyConfig'], apiKeyConfigToVertex$1(apiClient, fromApiKeyConfig));
4426
+ }
4427
+ const fromAuthType = getValueByPath(fromObject, ['authType']);
4428
+ if (fromAuthType != null) {
4429
+ setValueByPath(toObject, ['authType'], fromAuthType);
4430
+ }
4431
+ const fromGoogleServiceAccountConfig = getValueByPath(fromObject, [
4432
+ 'googleServiceAccountConfig',
4433
+ ]);
4434
+ if (fromGoogleServiceAccountConfig != null) {
4435
+ setValueByPath(toObject, ['googleServiceAccountConfig'], fromGoogleServiceAccountConfig);
4436
+ }
4437
+ const fromHttpBasicAuthConfig = getValueByPath(fromObject, [
4438
+ 'httpBasicAuthConfig',
4439
+ ]);
4440
+ if (fromHttpBasicAuthConfig != null) {
4441
+ setValueByPath(toObject, ['httpBasicAuthConfig'], fromHttpBasicAuthConfig);
4442
+ }
4443
+ const fromOauthConfig = getValueByPath(fromObject, ['oauthConfig']);
4444
+ if (fromOauthConfig != null) {
4445
+ setValueByPath(toObject, ['oauthConfig'], fromOauthConfig);
4446
+ }
4447
+ const fromOidcConfig = getValueByPath(fromObject, ['oidcConfig']);
4448
+ if (fromOidcConfig != null) {
4449
+ setValueByPath(toObject, ['oidcConfig'], fromOidcConfig);
4450
+ }
4451
+ return toObject;
4452
+ }
4453
+ function googleMapsToVertex$1(apiClient, fromObject) {
4454
+ const toObject = {};
4455
+ const fromAuthConfig = getValueByPath(fromObject, ['authConfig']);
4456
+ if (fromAuthConfig != null) {
4457
+ setValueByPath(toObject, ['authConfig'], authConfigToVertex$1(apiClient, fromAuthConfig));
4458
+ }
4459
+ return toObject;
4460
+ }
4086
4461
  function toolToMldev$1(apiClient, fromObject) {
4087
4462
  const toObject = {};
4088
4463
  if (getValueByPath(fromObject, ['retrieval']) !== undefined) {
@@ -4098,6 +4473,12 @@ function toolToMldev$1(apiClient, fromObject) {
4098
4473
  if (fromGoogleSearchRetrieval != null) {
4099
4474
  setValueByPath(toObject, ['googleSearchRetrieval'], googleSearchRetrievalToMldev$1(apiClient, fromGoogleSearchRetrieval));
4100
4475
  }
4476
+ if (getValueByPath(fromObject, ['enterpriseWebSearch']) !== undefined) {
4477
+ throw new Error('enterpriseWebSearch parameter is not supported in Gemini API.');
4478
+ }
4479
+ if (getValueByPath(fromObject, ['googleMaps']) !== undefined) {
4480
+ throw new Error('googleMaps parameter is not supported in Gemini API.');
4481
+ }
4101
4482
  const fromCodeExecution = getValueByPath(fromObject, [
4102
4483
  'codeExecution',
4103
4484
  ]);
@@ -4128,6 +4509,16 @@ function toolToVertex$1(apiClient, fromObject) {
4128
4509
  if (fromGoogleSearchRetrieval != null) {
4129
4510
  setValueByPath(toObject, ['googleSearchRetrieval'], googleSearchRetrievalToVertex$1(apiClient, fromGoogleSearchRetrieval));
4130
4511
  }
4512
+ const fromEnterpriseWebSearch = getValueByPath(fromObject, [
4513
+ 'enterpriseWebSearch',
4514
+ ]);
4515
+ if (fromEnterpriseWebSearch != null) {
4516
+ setValueByPath(toObject, ['enterpriseWebSearch'], enterpriseWebSearchToVertex$1());
4517
+ }
4518
+ const fromGoogleMaps = getValueByPath(fromObject, ['googleMaps']);
4519
+ if (fromGoogleMaps != null) {
4520
+ setValueByPath(toObject, ['googleMaps'], googleMapsToVertex$1(apiClient, fromGoogleMaps));
4521
+ }
4131
4522
  const fromCodeExecution = getValueByPath(fromObject, [
4132
4523
  'codeExecution',
4133
4524
  ]);
@@ -4393,8 +4784,11 @@ function liveConnectConfigToMldev(apiClient, fromObject, parentObject) {
4393
4784
  if (parentObject !== undefined && fromSessionResumption != null) {
4394
4785
  setValueByPath(parentObject, ['setup', 'sessionResumption'], sessionResumptionConfigToMldev(apiClient, fromSessionResumption));
4395
4786
  }
4396
- if (getValueByPath(fromObject, ['inputAudioTranscription']) !== undefined) {
4397
- throw new Error('inputAudioTranscription parameter is not supported in Gemini API.');
4787
+ const fromInputAudioTranscription = getValueByPath(fromObject, [
4788
+ 'inputAudioTranscription',
4789
+ ]);
4790
+ if (parentObject !== undefined && fromInputAudioTranscription != null) {
4791
+ setValueByPath(parentObject, ['setup', 'inputAudioTranscription'], audioTranscriptionConfigToMldev());
4398
4792
  }
4399
4793
  const fromOutputAudioTranscription = getValueByPath(fromObject, [
4400
4794
  'outputAudioTranscription',
@@ -4791,6 +5185,12 @@ function liveServerContentFromMldev(apiClient, fromObject) {
4791
5185
  if (fromInterrupted != null) {
4792
5186
  setValueByPath(toObject, ['interrupted'], fromInterrupted);
4793
5187
  }
5188
+ const fromGroundingMetadata = getValueByPath(fromObject, [
5189
+ 'groundingMetadata',
5190
+ ]);
5191
+ if (fromGroundingMetadata != null) {
5192
+ setValueByPath(toObject, ['groundingMetadata'], fromGroundingMetadata);
5193
+ }
4794
5194
  const fromGenerationComplete = getValueByPath(fromObject, [
4795
5195
  'generationComplete',
4796
5196
  ]);
@@ -4825,6 +5225,12 @@ function liveServerContentFromVertex(apiClient, fromObject) {
4825
5225
  if (fromInterrupted != null) {
4826
5226
  setValueByPath(toObject, ['interrupted'], fromInterrupted);
4827
5227
  }
5228
+ const fromGroundingMetadata = getValueByPath(fromObject, [
5229
+ 'groundingMetadata',
5230
+ ]);
5231
+ if (fromGroundingMetadata != null) {
5232
+ setValueByPath(toObject, ['groundingMetadata'], fromGroundingMetadata);
5233
+ }
4828
5234
  const fromGenerationComplete = getValueByPath(fromObject, [
4829
5235
  'generationComplete',
4830
5236
  ]);
@@ -5388,6 +5794,12 @@ function toolToMldev(apiClient, fromObject) {
5388
5794
  if (fromGoogleSearchRetrieval != null) {
5389
5795
  setValueByPath(toObject, ['googleSearchRetrieval'], googleSearchRetrievalToMldev(apiClient, fromGoogleSearchRetrieval));
5390
5796
  }
5797
+ if (getValueByPath(fromObject, ['enterpriseWebSearch']) !== undefined) {
5798
+ throw new Error('enterpriseWebSearch parameter is not supported in Gemini API.');
5799
+ }
5800
+ if (getValueByPath(fromObject, ['googleMaps']) !== undefined) {
5801
+ throw new Error('googleMaps parameter is not supported in Gemini API.');
5802
+ }
5391
5803
  const fromCodeExecution = getValueByPath(fromObject, [
5392
5804
  'codeExecution',
5393
5805
  ]);
@@ -5424,6 +5836,9 @@ function toolConfigToMldev(apiClient, fromObject) {
5424
5836
  if (fromFunctionCallingConfig != null) {
5425
5837
  setValueByPath(toObject, ['functionCallingConfig'], functionCallingConfigToMldev(apiClient, fromFunctionCallingConfig));
5426
5838
  }
5839
+ if (getValueByPath(fromObject, ['retrievalConfig']) !== undefined) {
5840
+ throw new Error('retrievalConfig parameter is not supported in Gemini API.');
5841
+ }
5427
5842
  return toObject;
5428
5843
  }
5429
5844
  function prebuiltVoiceConfigToMldev(apiClient, fromObject) {
@@ -5785,6 +6200,34 @@ function getModelParametersToMldev(apiClient, fromObject) {
5785
6200
  }
5786
6201
  return toObject;
5787
6202
  }
6203
+ function listModelsConfigToMldev(apiClient, fromObject, parentObject) {
6204
+ const toObject = {};
6205
+ const fromPageSize = getValueByPath(fromObject, ['pageSize']);
6206
+ if (parentObject !== undefined && fromPageSize != null) {
6207
+ setValueByPath(parentObject, ['_query', 'pageSize'], fromPageSize);
6208
+ }
6209
+ const fromPageToken = getValueByPath(fromObject, ['pageToken']);
6210
+ if (parentObject !== undefined && fromPageToken != null) {
6211
+ setValueByPath(parentObject, ['_query', 'pageToken'], fromPageToken);
6212
+ }
6213
+ const fromFilter = getValueByPath(fromObject, ['filter']);
6214
+ if (parentObject !== undefined && fromFilter != null) {
6215
+ setValueByPath(parentObject, ['_query', 'filter'], fromFilter);
6216
+ }
6217
+ const fromQueryBase = getValueByPath(fromObject, ['queryBase']);
6218
+ if (parentObject !== undefined && fromQueryBase != null) {
6219
+ setValueByPath(parentObject, ['_url', 'models_url'], tModelsUrl(apiClient, fromQueryBase));
6220
+ }
6221
+ return toObject;
6222
+ }
6223
+ function listModelsParametersToMldev(apiClient, fromObject) {
6224
+ const toObject = {};
6225
+ const fromConfig = getValueByPath(fromObject, ['config']);
6226
+ if (fromConfig != null) {
6227
+ setValueByPath(toObject, ['config'], listModelsConfigToMldev(apiClient, fromConfig, toObject));
6228
+ }
6229
+ return toObject;
6230
+ }
5788
6231
  function updateModelConfigToMldev(apiClient, fromObject, parentObject) {
5789
6232
  const toObject = {};
5790
6233
  const fromDisplayName = getValueByPath(fromObject, ['displayName']);
@@ -6061,6 +6504,58 @@ function googleSearchRetrievalToVertex(apiClient, fromObject) {
6061
6504
  }
6062
6505
  return toObject;
6063
6506
  }
6507
+ function enterpriseWebSearchToVertex() {
6508
+ const toObject = {};
6509
+ return toObject;
6510
+ }
6511
+ function apiKeyConfigToVertex(apiClient, fromObject) {
6512
+ const toObject = {};
6513
+ const fromApiKeyString = getValueByPath(fromObject, ['apiKeyString']);
6514
+ if (fromApiKeyString != null) {
6515
+ setValueByPath(toObject, ['apiKeyString'], fromApiKeyString);
6516
+ }
6517
+ return toObject;
6518
+ }
6519
+ function authConfigToVertex(apiClient, fromObject) {
6520
+ const toObject = {};
6521
+ const fromApiKeyConfig = getValueByPath(fromObject, ['apiKeyConfig']);
6522
+ if (fromApiKeyConfig != null) {
6523
+ setValueByPath(toObject, ['apiKeyConfig'], apiKeyConfigToVertex(apiClient, fromApiKeyConfig));
6524
+ }
6525
+ const fromAuthType = getValueByPath(fromObject, ['authType']);
6526
+ if (fromAuthType != null) {
6527
+ setValueByPath(toObject, ['authType'], fromAuthType);
6528
+ }
6529
+ const fromGoogleServiceAccountConfig = getValueByPath(fromObject, [
6530
+ 'googleServiceAccountConfig',
6531
+ ]);
6532
+ if (fromGoogleServiceAccountConfig != null) {
6533
+ setValueByPath(toObject, ['googleServiceAccountConfig'], fromGoogleServiceAccountConfig);
6534
+ }
6535
+ const fromHttpBasicAuthConfig = getValueByPath(fromObject, [
6536
+ 'httpBasicAuthConfig',
6537
+ ]);
6538
+ if (fromHttpBasicAuthConfig != null) {
6539
+ setValueByPath(toObject, ['httpBasicAuthConfig'], fromHttpBasicAuthConfig);
6540
+ }
6541
+ const fromOauthConfig = getValueByPath(fromObject, ['oauthConfig']);
6542
+ if (fromOauthConfig != null) {
6543
+ setValueByPath(toObject, ['oauthConfig'], fromOauthConfig);
6544
+ }
6545
+ const fromOidcConfig = getValueByPath(fromObject, ['oidcConfig']);
6546
+ if (fromOidcConfig != null) {
6547
+ setValueByPath(toObject, ['oidcConfig'], fromOidcConfig);
6548
+ }
6549
+ return toObject;
6550
+ }
6551
+ function googleMapsToVertex(apiClient, fromObject) {
6552
+ const toObject = {};
6553
+ const fromAuthConfig = getValueByPath(fromObject, ['authConfig']);
6554
+ if (fromAuthConfig != null) {
6555
+ setValueByPath(toObject, ['authConfig'], authConfigToVertex(apiClient, fromAuthConfig));
6556
+ }
6557
+ return toObject;
6558
+ }
6064
6559
  function toolToVertex(apiClient, fromObject) {
6065
6560
  const toObject = {};
6066
6561
  const fromRetrieval = getValueByPath(fromObject, ['retrieval']);
@@ -6077,6 +6572,16 @@ function toolToVertex(apiClient, fromObject) {
6077
6572
  if (fromGoogleSearchRetrieval != null) {
6078
6573
  setValueByPath(toObject, ['googleSearchRetrieval'], googleSearchRetrievalToVertex(apiClient, fromGoogleSearchRetrieval));
6079
6574
  }
6575
+ const fromEnterpriseWebSearch = getValueByPath(fromObject, [
6576
+ 'enterpriseWebSearch',
6577
+ ]);
6578
+ if (fromEnterpriseWebSearch != null) {
6579
+ setValueByPath(toObject, ['enterpriseWebSearch'], enterpriseWebSearchToVertex());
6580
+ }
6581
+ const fromGoogleMaps = getValueByPath(fromObject, ['googleMaps']);
6582
+ if (fromGoogleMaps != null) {
6583
+ setValueByPath(toObject, ['googleMaps'], googleMapsToVertex(apiClient, fromGoogleMaps));
6584
+ }
6080
6585
  const fromCodeExecution = getValueByPath(fromObject, [
6081
6586
  'codeExecution',
6082
6587
  ]);
@@ -6105,6 +6610,26 @@ function functionCallingConfigToVertex(apiClient, fromObject) {
6105
6610
  }
6106
6611
  return toObject;
6107
6612
  }
6613
+ function latLngToVertex(apiClient, fromObject) {
6614
+ const toObject = {};
6615
+ const fromLatitude = getValueByPath(fromObject, ['latitude']);
6616
+ if (fromLatitude != null) {
6617
+ setValueByPath(toObject, ['latitude'], fromLatitude);
6618
+ }
6619
+ const fromLongitude = getValueByPath(fromObject, ['longitude']);
6620
+ if (fromLongitude != null) {
6621
+ setValueByPath(toObject, ['longitude'], fromLongitude);
6622
+ }
6623
+ return toObject;
6624
+ }
6625
+ function retrievalConfigToVertex(apiClient, fromObject) {
6626
+ const toObject = {};
6627
+ const fromLatLng = getValueByPath(fromObject, ['latLng']);
6628
+ if (fromLatLng != null) {
6629
+ setValueByPath(toObject, ['latLng'], latLngToVertex(apiClient, fromLatLng));
6630
+ }
6631
+ return toObject;
6632
+ }
6108
6633
  function toolConfigToVertex(apiClient, fromObject) {
6109
6634
  const toObject = {};
6110
6635
  const fromFunctionCallingConfig = getValueByPath(fromObject, [
@@ -6113,6 +6638,12 @@ function toolConfigToVertex(apiClient, fromObject) {
6113
6638
  if (fromFunctionCallingConfig != null) {
6114
6639
  setValueByPath(toObject, ['functionCallingConfig'], functionCallingConfigToVertex(apiClient, fromFunctionCallingConfig));
6115
6640
  }
6641
+ const fromRetrievalConfig = getValueByPath(fromObject, [
6642
+ 'retrievalConfig',
6643
+ ]);
6644
+ if (fromRetrievalConfig != null) {
6645
+ setValueByPath(toObject, ['retrievalConfig'], retrievalConfigToVertex(apiClient, fromRetrievalConfig));
6646
+ }
6116
6647
  return toObject;
6117
6648
  }
6118
6649
  function prebuiltVoiceConfigToVertex(apiClient, fromObject) {
@@ -6491,6 +7022,34 @@ function getModelParametersToVertex(apiClient, fromObject) {
6491
7022
  }
6492
7023
  return toObject;
6493
7024
  }
7025
+ function listModelsConfigToVertex(apiClient, fromObject, parentObject) {
7026
+ const toObject = {};
7027
+ const fromPageSize = getValueByPath(fromObject, ['pageSize']);
7028
+ if (parentObject !== undefined && fromPageSize != null) {
7029
+ setValueByPath(parentObject, ['_query', 'pageSize'], fromPageSize);
7030
+ }
7031
+ const fromPageToken = getValueByPath(fromObject, ['pageToken']);
7032
+ if (parentObject !== undefined && fromPageToken != null) {
7033
+ setValueByPath(parentObject, ['_query', 'pageToken'], fromPageToken);
7034
+ }
7035
+ const fromFilter = getValueByPath(fromObject, ['filter']);
7036
+ if (parentObject !== undefined && fromFilter != null) {
7037
+ setValueByPath(parentObject, ['_query', 'filter'], fromFilter);
7038
+ }
7039
+ const fromQueryBase = getValueByPath(fromObject, ['queryBase']);
7040
+ if (parentObject !== undefined && fromQueryBase != null) {
7041
+ setValueByPath(parentObject, ['_url', 'models_url'], tModelsUrl(apiClient, fromQueryBase));
7042
+ }
7043
+ return toObject;
7044
+ }
7045
+ function listModelsParametersToVertex(apiClient, fromObject) {
7046
+ const toObject = {};
7047
+ const fromConfig = getValueByPath(fromObject, ['config']);
7048
+ if (fromConfig != null) {
7049
+ setValueByPath(toObject, ['config'], listModelsConfigToVertex(apiClient, fromConfig, toObject));
7050
+ }
7051
+ return toObject;
7052
+ }
6494
7053
  function updateModelConfigToVertex(apiClient, fromObject, parentObject) {
6495
7054
  const toObject = {};
6496
7055
  const fromDisplayName = getValueByPath(fromObject, ['displayName']);
@@ -7001,6 +7560,26 @@ function modelFromMldev(apiClient, fromObject) {
7001
7560
  }
7002
7561
  return toObject;
7003
7562
  }
7563
+ function listModelsResponseFromMldev(apiClient, fromObject) {
7564
+ const toObject = {};
7565
+ const fromNextPageToken = getValueByPath(fromObject, [
7566
+ 'nextPageToken',
7567
+ ]);
7568
+ if (fromNextPageToken != null) {
7569
+ setValueByPath(toObject, ['nextPageToken'], fromNextPageToken);
7570
+ }
7571
+ const fromModels = getValueByPath(fromObject, ['_self']);
7572
+ if (fromModels != null) {
7573
+ let transformedList = tExtractModels(apiClient, fromModels);
7574
+ if (Array.isArray(transformedList)) {
7575
+ transformedList = transformedList.map((item) => {
7576
+ return modelFromMldev(apiClient, item);
7577
+ });
7578
+ }
7579
+ setValueByPath(toObject, ['models'], transformedList);
7580
+ }
7581
+ return toObject;
7582
+ }
7004
7583
  function deleteModelResponseFromMldev() {
7005
7584
  const toObject = {};
7006
7585
  return toObject;
@@ -7473,6 +8052,26 @@ function modelFromVertex(apiClient, fromObject) {
7473
8052
  }
7474
8053
  return toObject;
7475
8054
  }
8055
+ function listModelsResponseFromVertex(apiClient, fromObject) {
8056
+ const toObject = {};
8057
+ const fromNextPageToken = getValueByPath(fromObject, [
8058
+ 'nextPageToken',
8059
+ ]);
8060
+ if (fromNextPageToken != null) {
8061
+ setValueByPath(toObject, ['nextPageToken'], fromNextPageToken);
8062
+ }
8063
+ const fromModels = getValueByPath(fromObject, ['_self']);
8064
+ if (fromModels != null) {
8065
+ let transformedList = tExtractModels(apiClient, fromModels);
8066
+ if (Array.isArray(transformedList)) {
8067
+ transformedList = transformedList.map((item) => {
8068
+ return modelFromVertex(apiClient, item);
8069
+ });
8070
+ }
8071
+ setValueByPath(toObject, ['models'], transformedList);
8072
+ }
8073
+ return toObject;
8074
+ }
7476
8075
  function deleteModelResponseFromVertex() {
7477
8076
  const toObject = {};
7478
8077
  return toObject;
@@ -7590,7 +8189,7 @@ const FUNCTION_RESPONSE_REQUIRES_ID = 'FunctionResponse request must have an `id
7590
8189
  * @param event The MessageEvent from the WebSocket.
7591
8190
  */
7592
8191
  async function handleWebSocketMessage(apiClient, onmessage, event) {
7593
- let serverMessage;
8192
+ const serverMessage = new LiveServerMessage();
7594
8193
  let data;
7595
8194
  if (event.data instanceof Blob) {
7596
8195
  data = JSON.parse(await event.data.text());
@@ -7599,10 +8198,12 @@ async function handleWebSocketMessage(apiClient, onmessage, event) {
7599
8198
  data = JSON.parse(event.data);
7600
8199
  }
7601
8200
  if (apiClient.isVertexAI()) {
7602
- serverMessage = liveServerMessageFromVertex(apiClient, data);
8201
+ const resp = liveServerMessageFromVertex(apiClient, data);
8202
+ Object.assign(serverMessage, resp);
7603
8203
  }
7604
8204
  else {
7605
- serverMessage = liveServerMessageFromMldev(apiClient, data);
8205
+ const resp = liveServerMessageFromMldev(apiClient, data);
8206
+ Object.assign(serverMessage, resp);
7606
8207
  }
7607
8208
  onmessage(serverMessage);
7608
8209
  }
@@ -8109,6 +8710,27 @@ class Models extends BaseModule {
8109
8710
  return response;
8110
8711
  });
8111
8712
  };
8713
+ this.list = async (params) => {
8714
+ var _a;
8715
+ const defaultConfig = {
8716
+ queryBase: true,
8717
+ };
8718
+ const actualConfig = Object.assign(Object.assign({}, defaultConfig), params === null || params === void 0 ? void 0 : params.config);
8719
+ const actualParams = {
8720
+ config: actualConfig,
8721
+ };
8722
+ if (this.apiClient.isVertexAI()) {
8723
+ if (!actualParams.config.queryBase) {
8724
+ if ((_a = actualParams.config) === null || _a === void 0 ? void 0 : _a.filter) {
8725
+ throw new Error('Filtering tuned models list for Vertex AI is not currently supported');
8726
+ }
8727
+ else {
8728
+ actualParams.config.filter = 'labels.tune-type:*';
8729
+ }
8730
+ }
8731
+ }
8732
+ return new Pager(exports.PagedItem.PAGED_ITEM_MODELS, (x) => this.listInternal(x), await this.listInternal(actualParams), actualParams);
8733
+ };
8112
8734
  }
8113
8735
  async generateContentInternal(params) {
8114
8736
  var _a, _b, _c, _d;
@@ -8472,6 +9094,64 @@ class Models extends BaseModule {
8472
9094
  });
8473
9095
  }
8474
9096
  }
9097
+ async listInternal(params) {
9098
+ var _a, _b, _c, _d;
9099
+ let response;
9100
+ let path = '';
9101
+ let queryParams = {};
9102
+ if (this.apiClient.isVertexAI()) {
9103
+ const body = listModelsParametersToVertex(this.apiClient, params);
9104
+ path = formatMap('{models_url}', body['_url']);
9105
+ queryParams = body['_query'];
9106
+ delete body['config'];
9107
+ delete body['_url'];
9108
+ delete body['_query'];
9109
+ response = this.apiClient
9110
+ .request({
9111
+ path: path,
9112
+ queryParams: queryParams,
9113
+ body: JSON.stringify(body),
9114
+ httpMethod: 'GET',
9115
+ httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
9116
+ abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
9117
+ })
9118
+ .then((httpResponse) => {
9119
+ return httpResponse.json();
9120
+ });
9121
+ return response.then((apiResponse) => {
9122
+ const resp = listModelsResponseFromVertex(this.apiClient, apiResponse);
9123
+ const typedResp = new ListModelsResponse();
9124
+ Object.assign(typedResp, resp);
9125
+ return typedResp;
9126
+ });
9127
+ }
9128
+ else {
9129
+ const body = listModelsParametersToMldev(this.apiClient, params);
9130
+ path = formatMap('{models_url}', body['_url']);
9131
+ queryParams = body['_query'];
9132
+ delete body['config'];
9133
+ delete body['_url'];
9134
+ delete body['_query'];
9135
+ response = this.apiClient
9136
+ .request({
9137
+ path: path,
9138
+ queryParams: queryParams,
9139
+ body: JSON.stringify(body),
9140
+ httpMethod: 'GET',
9141
+ httpOptions: (_c = params.config) === null || _c === void 0 ? void 0 : _c.httpOptions,
9142
+ abortSignal: (_d = params.config) === null || _d === void 0 ? void 0 : _d.abortSignal,
9143
+ })
9144
+ .then((httpResponse) => {
9145
+ return httpResponse.json();
9146
+ });
9147
+ return response.then((apiResponse) => {
9148
+ const resp = listModelsResponseFromMldev(this.apiClient, apiResponse);
9149
+ const typedResp = new ListModelsResponse();
9150
+ Object.assign(typedResp, resp);
9151
+ return typedResp;
9152
+ });
9153
+ }
9154
+ }
8475
9155
  /**
8476
9156
  * Updates a tuned model by its name.
8477
9157
  *
@@ -9962,6 +10642,7 @@ class GoogleGenAI {
9962
10642
  httpOptions: options.httpOptions,
9963
10643
  userAgentExtra: LANGUAGE_LABEL_PREFIX + 'cross',
9964
10644
  uploader: new CrossUploader(),
10645
+ downloader: new CrossDownloader(),
9965
10646
  });
9966
10647
  this.models = new Models(this.apiClient);
9967
10648
  this.live = new Live(this.apiClient, auth, new CrossWebSocketFactory());
@@ -9994,10 +10675,12 @@ exports.GoogleGenAI = GoogleGenAI;
9994
10675
  exports.HttpResponse = HttpResponse;
9995
10676
  exports.ListCachedContentsResponse = ListCachedContentsResponse;
9996
10677
  exports.ListFilesResponse = ListFilesResponse;
10678
+ exports.ListModelsResponse = ListModelsResponse;
9997
10679
  exports.ListTuningJobsResponse = ListTuningJobsResponse;
9998
10680
  exports.Live = Live;
9999
10681
  exports.LiveClientToolResponse = LiveClientToolResponse;
10000
10682
  exports.LiveSendToolResponseParameters = LiveSendToolResponseParameters;
10683
+ exports.LiveServerMessage = LiveServerMessage;
10001
10684
  exports.Models = Models;
10002
10685
  exports.Operations = Operations;
10003
10686
  exports.Pager = Pager;