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