@google/genai 0.12.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.
@@ -1,8 +1,10 @@
1
1
  'use strict';
2
2
 
3
3
  var googleAuthLibrary = require('google-auth-library');
4
+ var fs = require('fs');
5
+ var node_stream = require('node:stream');
4
6
  var NodeWs = require('ws');
5
- var fs = require('fs/promises');
7
+ var fs$1 = require('fs/promises');
6
8
 
7
9
  function _interopNamespaceDefault(e) {
8
10
  var n = Object.create(null);
@@ -22,7 +24,7 @@ function _interopNamespaceDefault(e) {
22
24
  }
23
25
 
24
26
  var NodeWs__namespace = /*#__PURE__*/_interopNamespaceDefault(NodeWs);
25
- var fs__namespace = /*#__PURE__*/_interopNamespaceDefault(fs);
27
+ var fs__namespace = /*#__PURE__*/_interopNamespaceDefault(fs$1);
26
28
 
27
29
  /**
28
30
  * @license
@@ -545,15 +547,81 @@ function tBytes(apiClient, fromImageBytes) {
545
547
  // TODO(b/389133914): Remove dummy bytes converter.
546
548
  return fromImageBytes;
547
549
  }
550
+ function _isFile(origin) {
551
+ return (origin !== null &&
552
+ origin !== undefined &&
553
+ typeof origin === 'object' &&
554
+ 'name' in origin);
555
+ }
556
+ function isGeneratedVideo(origin) {
557
+ return (origin !== null &&
558
+ origin !== undefined &&
559
+ typeof origin === 'object' &&
560
+ 'video' in origin);
561
+ }
562
+ function isVideo(origin) {
563
+ return (origin !== null &&
564
+ origin !== undefined &&
565
+ typeof origin === 'object' &&
566
+ 'uri' in origin);
567
+ }
548
568
  function tFileName(apiClient, fromName) {
549
- if (typeof fromName !== 'string') {
550
- throw new Error('fromName must be a string');
569
+ var _a;
570
+ let name;
571
+ if (_isFile(fromName)) {
572
+ name = fromName.name;
573
+ }
574
+ if (isVideo(fromName)) {
575
+ name = fromName.uri;
576
+ if (name === undefined) {
577
+ return undefined;
578
+ }
579
+ }
580
+ if (isGeneratedVideo(fromName)) {
581
+ name = (_a = fromName.video) === null || _a === void 0 ? void 0 : _a.uri;
582
+ if (name === undefined) {
583
+ return undefined;
584
+ }
585
+ }
586
+ if (typeof fromName === 'string') {
587
+ name = fromName;
588
+ }
589
+ if (name === undefined) {
590
+ throw new Error('Could not extract file name from the provided input.');
591
+ }
592
+ if (name.startsWith('https://')) {
593
+ const suffix = name.split('files/')[1];
594
+ const match = suffix.match(/[a-z0-9]+/);
595
+ if (match === null) {
596
+ throw new Error(`Could not extract file name from URI ${name}`);
597
+ }
598
+ name = match[0];
599
+ }
600
+ else if (name.startsWith('files/')) {
601
+ name = name.split('files/')[1];
602
+ }
603
+ return name;
604
+ }
605
+ function tModelsUrl(apiClient, baseModels) {
606
+ let res;
607
+ if (apiClient.isVertexAI()) {
608
+ res = baseModels ? 'publishers/google/models' : 'models';
551
609
  }
552
- // Remove the files/ prefx for MLdev urls to get the actual name of the file.
553
- if (fromName.startsWith('files/')) {
554
- return fromName.split('files/')[1];
610
+ else {
611
+ res = baseModels ? 'models' : 'tunedModels';
555
612
  }
556
- return fromName;
613
+ return res;
614
+ }
615
+ function tExtractModels(apiClient, response) {
616
+ for (const key of ['models', 'tunedModels', 'publisherModels']) {
617
+ if (hasField(response, key)) {
618
+ return response[key];
619
+ }
620
+ }
621
+ return [];
622
+ }
623
+ function hasField(data, fieldName) {
624
+ return data !== null && typeof data === 'object' && fieldName in data;
557
625
  }
558
626
 
559
627
  /**
@@ -667,6 +735,12 @@ function toolToMldev$2(apiClient, fromObject) {
667
735
  if (fromGoogleSearchRetrieval != null) {
668
736
  setValueByPath(toObject, ['googleSearchRetrieval'], googleSearchRetrievalToMldev$2(apiClient, fromGoogleSearchRetrieval));
669
737
  }
738
+ if (getValueByPath(fromObject, ['enterpriseWebSearch']) !== undefined) {
739
+ throw new Error('enterpriseWebSearch parameter is not supported in Gemini API.');
740
+ }
741
+ if (getValueByPath(fromObject, ['googleMaps']) !== undefined) {
742
+ throw new Error('googleMaps parameter is not supported in Gemini API.');
743
+ }
670
744
  const fromCodeExecution = getValueByPath(fromObject, [
671
745
  'codeExecution',
672
746
  ]);
@@ -703,6 +777,9 @@ function toolConfigToMldev$1(apiClient, fromObject) {
703
777
  if (fromFunctionCallingConfig != null) {
704
778
  setValueByPath(toObject, ['functionCallingConfig'], functionCallingConfigToMldev$1(apiClient, fromFunctionCallingConfig));
705
779
  }
780
+ if (getValueByPath(fromObject, ['retrievalConfig']) !== undefined) {
781
+ throw new Error('retrievalConfig parameter is not supported in Gemini API.');
782
+ }
706
783
  return toObject;
707
784
  }
708
785
  function createCachedContentConfigToMldev(apiClient, fromObject, parentObject) {
@@ -925,6 +1002,58 @@ function googleSearchRetrievalToVertex$2(apiClient, fromObject) {
925
1002
  }
926
1003
  return toObject;
927
1004
  }
1005
+ function enterpriseWebSearchToVertex$2() {
1006
+ const toObject = {};
1007
+ return toObject;
1008
+ }
1009
+ function apiKeyConfigToVertex$2(apiClient, fromObject) {
1010
+ const toObject = {};
1011
+ const fromApiKeyString = getValueByPath(fromObject, ['apiKeyString']);
1012
+ if (fromApiKeyString != null) {
1013
+ setValueByPath(toObject, ['apiKeyString'], fromApiKeyString);
1014
+ }
1015
+ return toObject;
1016
+ }
1017
+ function authConfigToVertex$2(apiClient, fromObject) {
1018
+ const toObject = {};
1019
+ const fromApiKeyConfig = getValueByPath(fromObject, ['apiKeyConfig']);
1020
+ if (fromApiKeyConfig != null) {
1021
+ setValueByPath(toObject, ['apiKeyConfig'], apiKeyConfigToVertex$2(apiClient, fromApiKeyConfig));
1022
+ }
1023
+ const fromAuthType = getValueByPath(fromObject, ['authType']);
1024
+ if (fromAuthType != null) {
1025
+ setValueByPath(toObject, ['authType'], fromAuthType);
1026
+ }
1027
+ const fromGoogleServiceAccountConfig = getValueByPath(fromObject, [
1028
+ 'googleServiceAccountConfig',
1029
+ ]);
1030
+ if (fromGoogleServiceAccountConfig != null) {
1031
+ setValueByPath(toObject, ['googleServiceAccountConfig'], fromGoogleServiceAccountConfig);
1032
+ }
1033
+ const fromHttpBasicAuthConfig = getValueByPath(fromObject, [
1034
+ 'httpBasicAuthConfig',
1035
+ ]);
1036
+ if (fromHttpBasicAuthConfig != null) {
1037
+ setValueByPath(toObject, ['httpBasicAuthConfig'], fromHttpBasicAuthConfig);
1038
+ }
1039
+ const fromOauthConfig = getValueByPath(fromObject, ['oauthConfig']);
1040
+ if (fromOauthConfig != null) {
1041
+ setValueByPath(toObject, ['oauthConfig'], fromOauthConfig);
1042
+ }
1043
+ const fromOidcConfig = getValueByPath(fromObject, ['oidcConfig']);
1044
+ if (fromOidcConfig != null) {
1045
+ setValueByPath(toObject, ['oidcConfig'], fromOidcConfig);
1046
+ }
1047
+ return toObject;
1048
+ }
1049
+ function googleMapsToVertex$2(apiClient, fromObject) {
1050
+ const toObject = {};
1051
+ const fromAuthConfig = getValueByPath(fromObject, ['authConfig']);
1052
+ if (fromAuthConfig != null) {
1053
+ setValueByPath(toObject, ['authConfig'], authConfigToVertex$2(apiClient, fromAuthConfig));
1054
+ }
1055
+ return toObject;
1056
+ }
928
1057
  function toolToVertex$2(apiClient, fromObject) {
929
1058
  const toObject = {};
930
1059
  const fromRetrieval = getValueByPath(fromObject, ['retrieval']);
@@ -941,6 +1070,16 @@ function toolToVertex$2(apiClient, fromObject) {
941
1070
  if (fromGoogleSearchRetrieval != null) {
942
1071
  setValueByPath(toObject, ['googleSearchRetrieval'], googleSearchRetrievalToVertex$2(apiClient, fromGoogleSearchRetrieval));
943
1072
  }
1073
+ const fromEnterpriseWebSearch = getValueByPath(fromObject, [
1074
+ 'enterpriseWebSearch',
1075
+ ]);
1076
+ if (fromEnterpriseWebSearch != null) {
1077
+ setValueByPath(toObject, ['enterpriseWebSearch'], enterpriseWebSearchToVertex$2());
1078
+ }
1079
+ const fromGoogleMaps = getValueByPath(fromObject, ['googleMaps']);
1080
+ if (fromGoogleMaps != null) {
1081
+ setValueByPath(toObject, ['googleMaps'], googleMapsToVertex$2(apiClient, fromGoogleMaps));
1082
+ }
944
1083
  const fromCodeExecution = getValueByPath(fromObject, [
945
1084
  'codeExecution',
946
1085
  ]);
@@ -969,6 +1108,26 @@ function functionCallingConfigToVertex$1(apiClient, fromObject) {
969
1108
  }
970
1109
  return toObject;
971
1110
  }
1111
+ function latLngToVertex$1(apiClient, fromObject) {
1112
+ const toObject = {};
1113
+ const fromLatitude = getValueByPath(fromObject, ['latitude']);
1114
+ if (fromLatitude != null) {
1115
+ setValueByPath(toObject, ['latitude'], fromLatitude);
1116
+ }
1117
+ const fromLongitude = getValueByPath(fromObject, ['longitude']);
1118
+ if (fromLongitude != null) {
1119
+ setValueByPath(toObject, ['longitude'], fromLongitude);
1120
+ }
1121
+ return toObject;
1122
+ }
1123
+ function retrievalConfigToVertex$1(apiClient, fromObject) {
1124
+ const toObject = {};
1125
+ const fromLatLng = getValueByPath(fromObject, ['latLng']);
1126
+ if (fromLatLng != null) {
1127
+ setValueByPath(toObject, ['latLng'], latLngToVertex$1(apiClient, fromLatLng));
1128
+ }
1129
+ return toObject;
1130
+ }
972
1131
  function toolConfigToVertex$1(apiClient, fromObject) {
973
1132
  const toObject = {};
974
1133
  const fromFunctionCallingConfig = getValueByPath(fromObject, [
@@ -977,6 +1136,12 @@ function toolConfigToVertex$1(apiClient, fromObject) {
977
1136
  if (fromFunctionCallingConfig != null) {
978
1137
  setValueByPath(toObject, ['functionCallingConfig'], functionCallingConfigToVertex$1(apiClient, fromFunctionCallingConfig));
979
1138
  }
1139
+ const fromRetrievalConfig = getValueByPath(fromObject, [
1140
+ 'retrievalConfig',
1141
+ ]);
1142
+ if (fromRetrievalConfig != null) {
1143
+ setValueByPath(toObject, ['retrievalConfig'], retrievalConfigToVertex$1(apiClient, fromRetrievalConfig));
1144
+ }
980
1145
  return toObject;
981
1146
  }
982
1147
  function createCachedContentConfigToVertex(apiClient, fromObject, parentObject) {
@@ -1456,6 +1621,17 @@ exports.Mode = void 0;
1456
1621
  Mode["MODE_UNSPECIFIED"] = "MODE_UNSPECIFIED";
1457
1622
  Mode["MODE_DYNAMIC"] = "MODE_DYNAMIC";
1458
1623
  })(exports.Mode || (exports.Mode = {}));
1624
+ /** Type of auth scheme. */
1625
+ exports.AuthType = void 0;
1626
+ (function (AuthType) {
1627
+ AuthType["AUTH_TYPE_UNSPECIFIED"] = "AUTH_TYPE_UNSPECIFIED";
1628
+ AuthType["NO_AUTH"] = "NO_AUTH";
1629
+ AuthType["API_KEY_AUTH"] = "API_KEY_AUTH";
1630
+ AuthType["HTTP_BASIC_AUTH"] = "HTTP_BASIC_AUTH";
1631
+ AuthType["GOOGLE_SERVICE_ACCOUNT_AUTH"] = "GOOGLE_SERVICE_ACCOUNT_AUTH";
1632
+ AuthType["OAUTH"] = "OAUTH";
1633
+ AuthType["OIDC_AUTH"] = "OIDC_AUTH";
1634
+ })(exports.AuthType || (exports.AuthType = {}));
1459
1635
  /** Optional. The type of the data. */
1460
1636
  exports.Type = void 0;
1461
1637
  (function (Type) {
@@ -2063,6 +2239,8 @@ class EmbedContentResponse {
2063
2239
  /** The output images response. */
2064
2240
  class GenerateImagesResponse {
2065
2241
  }
2242
+ class ListModelsResponse {
2243
+ }
2066
2244
  class DeleteModelResponse {
2067
2245
  }
2068
2246
  /** Response for counting tokens. */
@@ -2110,6 +2288,70 @@ class DeleteFileResponse {
2110
2288
  /** Represents a single response in a replay. */
2111
2289
  class ReplayResponse {
2112
2290
  }
2291
+ /** Response message for API call. */
2292
+ class LiveServerMessage {
2293
+ /**
2294
+ * Returns the concatenation of all text parts from the server content if present.
2295
+ *
2296
+ * @remarks
2297
+ * If there are non-text parts in the response, the concatenation of all text
2298
+ * parts will be returned, and a warning will be logged.
2299
+ */
2300
+ get text() {
2301
+ var _a, _b, _c;
2302
+ let text = '';
2303
+ let anyTextPartFound = false;
2304
+ const nonTextParts = [];
2305
+ 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 : []) {
2306
+ for (const [fieldName, fieldValue] of Object.entries(part)) {
2307
+ if (fieldName !== 'text' &&
2308
+ fieldName !== 'thought' &&
2309
+ fieldValue !== null) {
2310
+ nonTextParts.push(fieldName);
2311
+ }
2312
+ }
2313
+ if (typeof part.text === 'string') {
2314
+ if (typeof part.thought === 'boolean' && part.thought) {
2315
+ continue;
2316
+ }
2317
+ anyTextPartFound = true;
2318
+ text += part.text;
2319
+ }
2320
+ }
2321
+ if (nonTextParts.length > 0) {
2322
+ 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.`);
2323
+ }
2324
+ // part.text === '' is different from part.text is null
2325
+ return anyTextPartFound ? text : undefined;
2326
+ }
2327
+ /**
2328
+ * Returns the concatenation of all inline data parts from the server content if present.
2329
+ *
2330
+ * @remarks
2331
+ * If there are non-inline data parts in the
2332
+ * response, the concatenation of all inline data parts will be returned, and
2333
+ * a warning will be logged.
2334
+ */
2335
+ get data() {
2336
+ var _a, _b, _c;
2337
+ let data = '';
2338
+ const nonDataParts = [];
2339
+ 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 : []) {
2340
+ for (const [fieldName, fieldValue] of Object.entries(part)) {
2341
+ if (fieldName !== 'inlineData' && fieldValue !== null) {
2342
+ nonDataParts.push(fieldName);
2343
+ }
2344
+ }
2345
+ if (part.inlineData && typeof part.inlineData.data === 'string') {
2346
+ data += atob(part.inlineData.data);
2347
+ }
2348
+ }
2349
+ if (nonDataParts.length > 0) {
2350
+ 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.`);
2351
+ }
2352
+ return data.length > 0 ? btoa(data) : undefined;
2353
+ }
2354
+ }
2113
2355
  /** Client generated response to a `ToolCall` received from the server.
2114
2356
 
2115
2357
  Individual `FunctionResponse` objects are matched to the respective
@@ -3196,6 +3438,25 @@ class Files extends BaseModule {
3196
3438
  return file;
3197
3439
  });
3198
3440
  }
3441
+ /**
3442
+ * Downloads a remotely stored file asynchronously to a location specified in
3443
+ * the `params` object. This method only works on Node environment, to
3444
+ * download files in the browser, use a browser compliant method like an <a>
3445
+ * tag.
3446
+ *
3447
+ * @param params - The parameters for the download request.
3448
+ *
3449
+ * @example
3450
+ * The following code downloads an example file named "files/mehozpxf877d" as
3451
+ * "file.txt".
3452
+ *
3453
+ * ```ts
3454
+ * await ai.files.download({file: file.name, downloadPath: 'file.txt'});
3455
+ * ```
3456
+ */
3457
+ async download(params) {
3458
+ await this.apiClient.downloadFile(params);
3459
+ }
3199
3460
  async listInternal(params) {
3200
3461
  var _a, _b;
3201
3462
  let response;
@@ -3554,6 +3815,58 @@ function googleSearchRetrievalToVertex$1(apiClient, fromObject) {
3554
3815
  }
3555
3816
  return toObject;
3556
3817
  }
3818
+ function enterpriseWebSearchToVertex$1() {
3819
+ const toObject = {};
3820
+ return toObject;
3821
+ }
3822
+ function apiKeyConfigToVertex$1(apiClient, fromObject) {
3823
+ const toObject = {};
3824
+ const fromApiKeyString = getValueByPath(fromObject, ['apiKeyString']);
3825
+ if (fromApiKeyString != null) {
3826
+ setValueByPath(toObject, ['apiKeyString'], fromApiKeyString);
3827
+ }
3828
+ return toObject;
3829
+ }
3830
+ function authConfigToVertex$1(apiClient, fromObject) {
3831
+ const toObject = {};
3832
+ const fromApiKeyConfig = getValueByPath(fromObject, ['apiKeyConfig']);
3833
+ if (fromApiKeyConfig != null) {
3834
+ setValueByPath(toObject, ['apiKeyConfig'], apiKeyConfigToVertex$1(apiClient, fromApiKeyConfig));
3835
+ }
3836
+ const fromAuthType = getValueByPath(fromObject, ['authType']);
3837
+ if (fromAuthType != null) {
3838
+ setValueByPath(toObject, ['authType'], fromAuthType);
3839
+ }
3840
+ const fromGoogleServiceAccountConfig = getValueByPath(fromObject, [
3841
+ 'googleServiceAccountConfig',
3842
+ ]);
3843
+ if (fromGoogleServiceAccountConfig != null) {
3844
+ setValueByPath(toObject, ['googleServiceAccountConfig'], fromGoogleServiceAccountConfig);
3845
+ }
3846
+ const fromHttpBasicAuthConfig = getValueByPath(fromObject, [
3847
+ 'httpBasicAuthConfig',
3848
+ ]);
3849
+ if (fromHttpBasicAuthConfig != null) {
3850
+ setValueByPath(toObject, ['httpBasicAuthConfig'], fromHttpBasicAuthConfig);
3851
+ }
3852
+ const fromOauthConfig = getValueByPath(fromObject, ['oauthConfig']);
3853
+ if (fromOauthConfig != null) {
3854
+ setValueByPath(toObject, ['oauthConfig'], fromOauthConfig);
3855
+ }
3856
+ const fromOidcConfig = getValueByPath(fromObject, ['oidcConfig']);
3857
+ if (fromOidcConfig != null) {
3858
+ setValueByPath(toObject, ['oidcConfig'], fromOidcConfig);
3859
+ }
3860
+ return toObject;
3861
+ }
3862
+ function googleMapsToVertex$1(apiClient, fromObject) {
3863
+ const toObject = {};
3864
+ const fromAuthConfig = getValueByPath(fromObject, ['authConfig']);
3865
+ if (fromAuthConfig != null) {
3866
+ setValueByPath(toObject, ['authConfig'], authConfigToVertex$1(apiClient, fromAuthConfig));
3867
+ }
3868
+ return toObject;
3869
+ }
3557
3870
  function toolToMldev$1(apiClient, fromObject) {
3558
3871
  const toObject = {};
3559
3872
  if (getValueByPath(fromObject, ['retrieval']) !== undefined) {
@@ -3569,6 +3882,12 @@ function toolToMldev$1(apiClient, fromObject) {
3569
3882
  if (fromGoogleSearchRetrieval != null) {
3570
3883
  setValueByPath(toObject, ['googleSearchRetrieval'], googleSearchRetrievalToMldev$1(apiClient, fromGoogleSearchRetrieval));
3571
3884
  }
3885
+ if (getValueByPath(fromObject, ['enterpriseWebSearch']) !== undefined) {
3886
+ throw new Error('enterpriseWebSearch parameter is not supported in Gemini API.');
3887
+ }
3888
+ if (getValueByPath(fromObject, ['googleMaps']) !== undefined) {
3889
+ throw new Error('googleMaps parameter is not supported in Gemini API.');
3890
+ }
3572
3891
  const fromCodeExecution = getValueByPath(fromObject, [
3573
3892
  'codeExecution',
3574
3893
  ]);
@@ -3599,6 +3918,16 @@ function toolToVertex$1(apiClient, fromObject) {
3599
3918
  if (fromGoogleSearchRetrieval != null) {
3600
3919
  setValueByPath(toObject, ['googleSearchRetrieval'], googleSearchRetrievalToVertex$1(apiClient, fromGoogleSearchRetrieval));
3601
3920
  }
3921
+ const fromEnterpriseWebSearch = getValueByPath(fromObject, [
3922
+ 'enterpriseWebSearch',
3923
+ ]);
3924
+ if (fromEnterpriseWebSearch != null) {
3925
+ setValueByPath(toObject, ['enterpriseWebSearch'], enterpriseWebSearchToVertex$1());
3926
+ }
3927
+ const fromGoogleMaps = getValueByPath(fromObject, ['googleMaps']);
3928
+ if (fromGoogleMaps != null) {
3929
+ setValueByPath(toObject, ['googleMaps'], googleMapsToVertex$1(apiClient, fromGoogleMaps));
3930
+ }
3602
3931
  const fromCodeExecution = getValueByPath(fromObject, [
3603
3932
  'codeExecution',
3604
3933
  ]);
@@ -3864,8 +4193,11 @@ function liveConnectConfigToMldev(apiClient, fromObject, parentObject) {
3864
4193
  if (parentObject !== undefined && fromSessionResumption != null) {
3865
4194
  setValueByPath(parentObject, ['setup', 'sessionResumption'], sessionResumptionConfigToMldev(apiClient, fromSessionResumption));
3866
4195
  }
3867
- if (getValueByPath(fromObject, ['inputAudioTranscription']) !== undefined) {
3868
- throw new Error('inputAudioTranscription parameter is not supported in Gemini API.');
4196
+ const fromInputAudioTranscription = getValueByPath(fromObject, [
4197
+ 'inputAudioTranscription',
4198
+ ]);
4199
+ if (parentObject !== undefined && fromInputAudioTranscription != null) {
4200
+ setValueByPath(parentObject, ['setup', 'inputAudioTranscription'], audioTranscriptionConfigToMldev());
3869
4201
  }
3870
4202
  const fromOutputAudioTranscription = getValueByPath(fromObject, [
3871
4203
  'outputAudioTranscription',
@@ -4871,6 +5203,12 @@ function toolToMldev(apiClient, fromObject) {
4871
5203
  if (fromGoogleSearchRetrieval != null) {
4872
5204
  setValueByPath(toObject, ['googleSearchRetrieval'], googleSearchRetrievalToMldev(apiClient, fromGoogleSearchRetrieval));
4873
5205
  }
5206
+ if (getValueByPath(fromObject, ['enterpriseWebSearch']) !== undefined) {
5207
+ throw new Error('enterpriseWebSearch parameter is not supported in Gemini API.');
5208
+ }
5209
+ if (getValueByPath(fromObject, ['googleMaps']) !== undefined) {
5210
+ throw new Error('googleMaps parameter is not supported in Gemini API.');
5211
+ }
4874
5212
  const fromCodeExecution = getValueByPath(fromObject, [
4875
5213
  'codeExecution',
4876
5214
  ]);
@@ -4907,6 +5245,9 @@ function toolConfigToMldev(apiClient, fromObject) {
4907
5245
  if (fromFunctionCallingConfig != null) {
4908
5246
  setValueByPath(toObject, ['functionCallingConfig'], functionCallingConfigToMldev(apiClient, fromFunctionCallingConfig));
4909
5247
  }
5248
+ if (getValueByPath(fromObject, ['retrievalConfig']) !== undefined) {
5249
+ throw new Error('retrievalConfig parameter is not supported in Gemini API.');
5250
+ }
4910
5251
  return toObject;
4911
5252
  }
4912
5253
  function prebuiltVoiceConfigToMldev(apiClient, fromObject) {
@@ -5268,6 +5609,34 @@ function getModelParametersToMldev(apiClient, fromObject) {
5268
5609
  }
5269
5610
  return toObject;
5270
5611
  }
5612
+ function listModelsConfigToMldev(apiClient, fromObject, parentObject) {
5613
+ const toObject = {};
5614
+ const fromPageSize = getValueByPath(fromObject, ['pageSize']);
5615
+ if (parentObject !== undefined && fromPageSize != null) {
5616
+ setValueByPath(parentObject, ['_query', 'pageSize'], fromPageSize);
5617
+ }
5618
+ const fromPageToken = getValueByPath(fromObject, ['pageToken']);
5619
+ if (parentObject !== undefined && fromPageToken != null) {
5620
+ setValueByPath(parentObject, ['_query', 'pageToken'], fromPageToken);
5621
+ }
5622
+ const fromFilter = getValueByPath(fromObject, ['filter']);
5623
+ if (parentObject !== undefined && fromFilter != null) {
5624
+ setValueByPath(parentObject, ['_query', 'filter'], fromFilter);
5625
+ }
5626
+ const fromQueryBase = getValueByPath(fromObject, ['queryBase']);
5627
+ if (parentObject !== undefined && fromQueryBase != null) {
5628
+ setValueByPath(parentObject, ['_url', 'models_url'], tModelsUrl(apiClient, fromQueryBase));
5629
+ }
5630
+ return toObject;
5631
+ }
5632
+ function listModelsParametersToMldev(apiClient, fromObject) {
5633
+ const toObject = {};
5634
+ const fromConfig = getValueByPath(fromObject, ['config']);
5635
+ if (fromConfig != null) {
5636
+ setValueByPath(toObject, ['config'], listModelsConfigToMldev(apiClient, fromConfig, toObject));
5637
+ }
5638
+ return toObject;
5639
+ }
5271
5640
  function updateModelConfigToMldev(apiClient, fromObject, parentObject) {
5272
5641
  const toObject = {};
5273
5642
  const fromDisplayName = getValueByPath(fromObject, ['displayName']);
@@ -5544,6 +5913,58 @@ function googleSearchRetrievalToVertex(apiClient, fromObject) {
5544
5913
  }
5545
5914
  return toObject;
5546
5915
  }
5916
+ function enterpriseWebSearchToVertex() {
5917
+ const toObject = {};
5918
+ return toObject;
5919
+ }
5920
+ function apiKeyConfigToVertex(apiClient, fromObject) {
5921
+ const toObject = {};
5922
+ const fromApiKeyString = getValueByPath(fromObject, ['apiKeyString']);
5923
+ if (fromApiKeyString != null) {
5924
+ setValueByPath(toObject, ['apiKeyString'], fromApiKeyString);
5925
+ }
5926
+ return toObject;
5927
+ }
5928
+ function authConfigToVertex(apiClient, fromObject) {
5929
+ const toObject = {};
5930
+ const fromApiKeyConfig = getValueByPath(fromObject, ['apiKeyConfig']);
5931
+ if (fromApiKeyConfig != null) {
5932
+ setValueByPath(toObject, ['apiKeyConfig'], apiKeyConfigToVertex(apiClient, fromApiKeyConfig));
5933
+ }
5934
+ const fromAuthType = getValueByPath(fromObject, ['authType']);
5935
+ if (fromAuthType != null) {
5936
+ setValueByPath(toObject, ['authType'], fromAuthType);
5937
+ }
5938
+ const fromGoogleServiceAccountConfig = getValueByPath(fromObject, [
5939
+ 'googleServiceAccountConfig',
5940
+ ]);
5941
+ if (fromGoogleServiceAccountConfig != null) {
5942
+ setValueByPath(toObject, ['googleServiceAccountConfig'], fromGoogleServiceAccountConfig);
5943
+ }
5944
+ const fromHttpBasicAuthConfig = getValueByPath(fromObject, [
5945
+ 'httpBasicAuthConfig',
5946
+ ]);
5947
+ if (fromHttpBasicAuthConfig != null) {
5948
+ setValueByPath(toObject, ['httpBasicAuthConfig'], fromHttpBasicAuthConfig);
5949
+ }
5950
+ const fromOauthConfig = getValueByPath(fromObject, ['oauthConfig']);
5951
+ if (fromOauthConfig != null) {
5952
+ setValueByPath(toObject, ['oauthConfig'], fromOauthConfig);
5953
+ }
5954
+ const fromOidcConfig = getValueByPath(fromObject, ['oidcConfig']);
5955
+ if (fromOidcConfig != null) {
5956
+ setValueByPath(toObject, ['oidcConfig'], fromOidcConfig);
5957
+ }
5958
+ return toObject;
5959
+ }
5960
+ function googleMapsToVertex(apiClient, fromObject) {
5961
+ const toObject = {};
5962
+ const fromAuthConfig = getValueByPath(fromObject, ['authConfig']);
5963
+ if (fromAuthConfig != null) {
5964
+ setValueByPath(toObject, ['authConfig'], authConfigToVertex(apiClient, fromAuthConfig));
5965
+ }
5966
+ return toObject;
5967
+ }
5547
5968
  function toolToVertex(apiClient, fromObject) {
5548
5969
  const toObject = {};
5549
5970
  const fromRetrieval = getValueByPath(fromObject, ['retrieval']);
@@ -5560,6 +5981,16 @@ function toolToVertex(apiClient, fromObject) {
5560
5981
  if (fromGoogleSearchRetrieval != null) {
5561
5982
  setValueByPath(toObject, ['googleSearchRetrieval'], googleSearchRetrievalToVertex(apiClient, fromGoogleSearchRetrieval));
5562
5983
  }
5984
+ const fromEnterpriseWebSearch = getValueByPath(fromObject, [
5985
+ 'enterpriseWebSearch',
5986
+ ]);
5987
+ if (fromEnterpriseWebSearch != null) {
5988
+ setValueByPath(toObject, ['enterpriseWebSearch'], enterpriseWebSearchToVertex());
5989
+ }
5990
+ const fromGoogleMaps = getValueByPath(fromObject, ['googleMaps']);
5991
+ if (fromGoogleMaps != null) {
5992
+ setValueByPath(toObject, ['googleMaps'], googleMapsToVertex(apiClient, fromGoogleMaps));
5993
+ }
5563
5994
  const fromCodeExecution = getValueByPath(fromObject, [
5564
5995
  'codeExecution',
5565
5996
  ]);
@@ -5588,6 +6019,26 @@ function functionCallingConfigToVertex(apiClient, fromObject) {
5588
6019
  }
5589
6020
  return toObject;
5590
6021
  }
6022
+ function latLngToVertex(apiClient, fromObject) {
6023
+ const toObject = {};
6024
+ const fromLatitude = getValueByPath(fromObject, ['latitude']);
6025
+ if (fromLatitude != null) {
6026
+ setValueByPath(toObject, ['latitude'], fromLatitude);
6027
+ }
6028
+ const fromLongitude = getValueByPath(fromObject, ['longitude']);
6029
+ if (fromLongitude != null) {
6030
+ setValueByPath(toObject, ['longitude'], fromLongitude);
6031
+ }
6032
+ return toObject;
6033
+ }
6034
+ function retrievalConfigToVertex(apiClient, fromObject) {
6035
+ const toObject = {};
6036
+ const fromLatLng = getValueByPath(fromObject, ['latLng']);
6037
+ if (fromLatLng != null) {
6038
+ setValueByPath(toObject, ['latLng'], latLngToVertex(apiClient, fromLatLng));
6039
+ }
6040
+ return toObject;
6041
+ }
5591
6042
  function toolConfigToVertex(apiClient, fromObject) {
5592
6043
  const toObject = {};
5593
6044
  const fromFunctionCallingConfig = getValueByPath(fromObject, [
@@ -5596,6 +6047,12 @@ function toolConfigToVertex(apiClient, fromObject) {
5596
6047
  if (fromFunctionCallingConfig != null) {
5597
6048
  setValueByPath(toObject, ['functionCallingConfig'], functionCallingConfigToVertex(apiClient, fromFunctionCallingConfig));
5598
6049
  }
6050
+ const fromRetrievalConfig = getValueByPath(fromObject, [
6051
+ 'retrievalConfig',
6052
+ ]);
6053
+ if (fromRetrievalConfig != null) {
6054
+ setValueByPath(toObject, ['retrievalConfig'], retrievalConfigToVertex(apiClient, fromRetrievalConfig));
6055
+ }
5599
6056
  return toObject;
5600
6057
  }
5601
6058
  function prebuiltVoiceConfigToVertex(apiClient, fromObject) {
@@ -5974,6 +6431,34 @@ function getModelParametersToVertex(apiClient, fromObject) {
5974
6431
  }
5975
6432
  return toObject;
5976
6433
  }
6434
+ function listModelsConfigToVertex(apiClient, fromObject, parentObject) {
6435
+ const toObject = {};
6436
+ const fromPageSize = getValueByPath(fromObject, ['pageSize']);
6437
+ if (parentObject !== undefined && fromPageSize != null) {
6438
+ setValueByPath(parentObject, ['_query', 'pageSize'], fromPageSize);
6439
+ }
6440
+ const fromPageToken = getValueByPath(fromObject, ['pageToken']);
6441
+ if (parentObject !== undefined && fromPageToken != null) {
6442
+ setValueByPath(parentObject, ['_query', 'pageToken'], fromPageToken);
6443
+ }
6444
+ const fromFilter = getValueByPath(fromObject, ['filter']);
6445
+ if (parentObject !== undefined && fromFilter != null) {
6446
+ setValueByPath(parentObject, ['_query', 'filter'], fromFilter);
6447
+ }
6448
+ const fromQueryBase = getValueByPath(fromObject, ['queryBase']);
6449
+ if (parentObject !== undefined && fromQueryBase != null) {
6450
+ setValueByPath(parentObject, ['_url', 'models_url'], tModelsUrl(apiClient, fromQueryBase));
6451
+ }
6452
+ return toObject;
6453
+ }
6454
+ function listModelsParametersToVertex(apiClient, fromObject) {
6455
+ const toObject = {};
6456
+ const fromConfig = getValueByPath(fromObject, ['config']);
6457
+ if (fromConfig != null) {
6458
+ setValueByPath(toObject, ['config'], listModelsConfigToVertex(apiClient, fromConfig, toObject));
6459
+ }
6460
+ return toObject;
6461
+ }
5977
6462
  function updateModelConfigToVertex(apiClient, fromObject, parentObject) {
5978
6463
  const toObject = {};
5979
6464
  const fromDisplayName = getValueByPath(fromObject, ['displayName']);
@@ -6484,6 +6969,26 @@ function modelFromMldev(apiClient, fromObject) {
6484
6969
  }
6485
6970
  return toObject;
6486
6971
  }
6972
+ function listModelsResponseFromMldev(apiClient, fromObject) {
6973
+ const toObject = {};
6974
+ const fromNextPageToken = getValueByPath(fromObject, [
6975
+ 'nextPageToken',
6976
+ ]);
6977
+ if (fromNextPageToken != null) {
6978
+ setValueByPath(toObject, ['nextPageToken'], fromNextPageToken);
6979
+ }
6980
+ const fromModels = getValueByPath(fromObject, ['_self']);
6981
+ if (fromModels != null) {
6982
+ let transformedList = tExtractModels(apiClient, fromModels);
6983
+ if (Array.isArray(transformedList)) {
6984
+ transformedList = transformedList.map((item) => {
6985
+ return modelFromMldev(apiClient, item);
6986
+ });
6987
+ }
6988
+ setValueByPath(toObject, ['models'], transformedList);
6989
+ }
6990
+ return toObject;
6991
+ }
6487
6992
  function deleteModelResponseFromMldev() {
6488
6993
  const toObject = {};
6489
6994
  return toObject;
@@ -6956,6 +7461,26 @@ function modelFromVertex(apiClient, fromObject) {
6956
7461
  }
6957
7462
  return toObject;
6958
7463
  }
7464
+ function listModelsResponseFromVertex(apiClient, fromObject) {
7465
+ const toObject = {};
7466
+ const fromNextPageToken = getValueByPath(fromObject, [
7467
+ 'nextPageToken',
7468
+ ]);
7469
+ if (fromNextPageToken != null) {
7470
+ setValueByPath(toObject, ['nextPageToken'], fromNextPageToken);
7471
+ }
7472
+ const fromModels = getValueByPath(fromObject, ['_self']);
7473
+ if (fromModels != null) {
7474
+ let transformedList = tExtractModels(apiClient, fromModels);
7475
+ if (Array.isArray(transformedList)) {
7476
+ transformedList = transformedList.map((item) => {
7477
+ return modelFromVertex(apiClient, item);
7478
+ });
7479
+ }
7480
+ setValueByPath(toObject, ['models'], transformedList);
7481
+ }
7482
+ return toObject;
7483
+ }
6959
7484
  function deleteModelResponseFromVertex() {
6960
7485
  const toObject = {};
6961
7486
  return toObject;
@@ -7073,7 +7598,7 @@ const FUNCTION_RESPONSE_REQUIRES_ID = 'FunctionResponse request must have an `id
7073
7598
  * @param event The MessageEvent from the WebSocket.
7074
7599
  */
7075
7600
  async function handleWebSocketMessage(apiClient, onmessage, event) {
7076
- let serverMessage;
7601
+ const serverMessage = new LiveServerMessage();
7077
7602
  let data;
7078
7603
  if (event.data instanceof Blob) {
7079
7604
  data = JSON.parse(await event.data.text());
@@ -7082,10 +7607,12 @@ async function handleWebSocketMessage(apiClient, onmessage, event) {
7082
7607
  data = JSON.parse(event.data);
7083
7608
  }
7084
7609
  if (apiClient.isVertexAI()) {
7085
- serverMessage = liveServerMessageFromVertex(apiClient, data);
7610
+ const resp = liveServerMessageFromVertex(apiClient, data);
7611
+ Object.assign(serverMessage, resp);
7086
7612
  }
7087
7613
  else {
7088
- serverMessage = liveServerMessageFromMldev(apiClient, data);
7614
+ const resp = liveServerMessageFromMldev(apiClient, data);
7615
+ Object.assign(serverMessage, resp);
7089
7616
  }
7090
7617
  onmessage(serverMessage);
7091
7618
  }
@@ -7592,6 +8119,27 @@ class Models extends BaseModule {
7592
8119
  return response;
7593
8120
  });
7594
8121
  };
8122
+ this.list = async (params) => {
8123
+ var _a;
8124
+ const defaultConfig = {
8125
+ queryBase: true,
8126
+ };
8127
+ const actualConfig = Object.assign(Object.assign({}, defaultConfig), params === null || params === void 0 ? void 0 : params.config);
8128
+ const actualParams = {
8129
+ config: actualConfig,
8130
+ };
8131
+ if (this.apiClient.isVertexAI()) {
8132
+ if (!actualParams.config.queryBase) {
8133
+ if ((_a = actualParams.config) === null || _a === void 0 ? void 0 : _a.filter) {
8134
+ throw new Error('Filtering tuned models list for Vertex AI is not currently supported');
8135
+ }
8136
+ else {
8137
+ actualParams.config.filter = 'labels.tune-type:*';
8138
+ }
8139
+ }
8140
+ }
8141
+ return new Pager(exports.PagedItem.PAGED_ITEM_MODELS, (x) => this.listInternal(x), await this.listInternal(actualParams), actualParams);
8142
+ };
7595
8143
  }
7596
8144
  async generateContentInternal(params) {
7597
8145
  var _a, _b, _c, _d;
@@ -7955,6 +8503,64 @@ class Models extends BaseModule {
7955
8503
  });
7956
8504
  }
7957
8505
  }
8506
+ async listInternal(params) {
8507
+ var _a, _b, _c, _d;
8508
+ let response;
8509
+ let path = '';
8510
+ let queryParams = {};
8511
+ if (this.apiClient.isVertexAI()) {
8512
+ const body = listModelsParametersToVertex(this.apiClient, params);
8513
+ path = formatMap('{models_url}', body['_url']);
8514
+ queryParams = body['_query'];
8515
+ delete body['config'];
8516
+ delete body['_url'];
8517
+ delete body['_query'];
8518
+ response = this.apiClient
8519
+ .request({
8520
+ path: path,
8521
+ queryParams: queryParams,
8522
+ body: JSON.stringify(body),
8523
+ httpMethod: 'GET',
8524
+ httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
8525
+ abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
8526
+ })
8527
+ .then((httpResponse) => {
8528
+ return httpResponse.json();
8529
+ });
8530
+ return response.then((apiResponse) => {
8531
+ const resp = listModelsResponseFromVertex(this.apiClient, apiResponse);
8532
+ const typedResp = new ListModelsResponse();
8533
+ Object.assign(typedResp, resp);
8534
+ return typedResp;
8535
+ });
8536
+ }
8537
+ else {
8538
+ const body = listModelsParametersToMldev(this.apiClient, params);
8539
+ path = formatMap('{models_url}', body['_url']);
8540
+ queryParams = body['_query'];
8541
+ delete body['config'];
8542
+ delete body['_url'];
8543
+ delete body['_query'];
8544
+ response = this.apiClient
8545
+ .request({
8546
+ path: path,
8547
+ queryParams: queryParams,
8548
+ body: JSON.stringify(body),
8549
+ httpMethod: 'GET',
8550
+ httpOptions: (_c = params.config) === null || _c === void 0 ? void 0 : _c.httpOptions,
8551
+ abortSignal: (_d = params.config) === null || _d === void 0 ? void 0 : _d.abortSignal,
8552
+ })
8553
+ .then((httpResponse) => {
8554
+ return httpResponse.json();
8555
+ });
8556
+ return response.then((apiResponse) => {
8557
+ const resp = listModelsResponseFromMldev(this.apiClient, apiResponse);
8558
+ const typedResp = new ListModelsResponse();
8559
+ Object.assign(typedResp, resp);
8560
+ return typedResp;
8561
+ });
8562
+ }
8563
+ }
7958
8564
  /**
7959
8565
  * Updates a tuned model by its name.
7960
8566
  *
@@ -8650,7 +9256,7 @@ const CONTENT_TYPE_HEADER = 'Content-Type';
8650
9256
  const SERVER_TIMEOUT_HEADER = 'X-Server-Timeout';
8651
9257
  const USER_AGENT_HEADER = 'User-Agent';
8652
9258
  const GOOGLE_API_CLIENT_HEADER = 'x-goog-api-client';
8653
- const SDK_VERSION = '0.12.0'; // x-release-please-version
9259
+ const SDK_VERSION = '0.13.0'; // x-release-please-version
8654
9260
  const LIBRARY_LABEL = `google-genai-sdk/${SDK_VERSION}`;
8655
9261
  const VERTEX_AI_API_DEFAULT_VERSION = 'v1beta1';
8656
9262
  const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
@@ -8697,18 +9303,11 @@ class ApiClient {
8697
9303
  if (this.clientOptions.vertexai) {
8698
9304
  initHttpOptions.apiVersion =
8699
9305
  (_a = this.clientOptions.apiVersion) !== null && _a !== void 0 ? _a : VERTEX_AI_API_DEFAULT_VERSION;
8700
- // Assume that proj/api key validation occurs before they are passed in.
8701
- if (this.getProject() || this.getLocation()) {
8702
- initHttpOptions.baseUrl = `https://${this.clientOptions.location}-aiplatform.googleapis.com/`;
8703
- this.clientOptions.apiKey = undefined; // unset API key.
8704
- }
8705
- else {
8706
- initHttpOptions.baseUrl = `https://aiplatform.googleapis.com/`;
8707
- this.clientOptions.project = undefined; // unset project.
8708
- this.clientOptions.location = undefined; // unset location.
8709
- }
9306
+ initHttpOptions.baseUrl = this.baseUrlFromProjectLocation();
9307
+ this.normalizeAuthParameters();
8710
9308
  }
8711
9309
  else {
9310
+ // Gemini API
8712
9311
  initHttpOptions.apiVersion =
8713
9312
  (_b = this.clientOptions.apiVersion) !== null && _b !== void 0 ? _b : GOOGLE_AI_API_DEFAULT_VERSION;
8714
9313
  initHttpOptions.baseUrl = `https://generativelanguage.googleapis.com/`;
@@ -8719,6 +9318,39 @@ class ApiClient {
8719
9318
  this.clientOptions.httpOptions = this.patchHttpOptions(initHttpOptions, opts.httpOptions);
8720
9319
  }
8721
9320
  }
9321
+ /**
9322
+ * Determines the base URL for Vertex AI based on project and location.
9323
+ * Uses the global endpoint if location is 'global' or if project/location
9324
+ * are not specified (implying API key usage).
9325
+ * @private
9326
+ */
9327
+ baseUrlFromProjectLocation() {
9328
+ if (this.clientOptions.project &&
9329
+ this.clientOptions.location &&
9330
+ this.clientOptions.location !== 'global') {
9331
+ // Regional endpoint
9332
+ return `https://${this.clientOptions.location}-aiplatform.googleapis.com/`;
9333
+ }
9334
+ // Global endpoint (covers 'global' location and API key usage)
9335
+ return `https://aiplatform.googleapis.com/`;
9336
+ }
9337
+ /**
9338
+ * Normalizes authentication parameters for Vertex AI.
9339
+ * If project and location are provided, API key is cleared.
9340
+ * If project and location are not provided (implying API key usage),
9341
+ * project and location are cleared.
9342
+ * @private
9343
+ */
9344
+ normalizeAuthParameters() {
9345
+ if (this.clientOptions.project && this.clientOptions.location) {
9346
+ // Using project/location for auth, clear potential API key
9347
+ this.clientOptions.apiKey = undefined;
9348
+ return;
9349
+ }
9350
+ // Using API key for auth (or no auth provided yet), clear project/location
9351
+ this.clientOptions.project = undefined;
9352
+ this.clientOptions.location = undefined;
9353
+ }
8722
9354
  isVertexAI() {
8723
9355
  var _a;
8724
9356
  return (_a = this.clientOptions.vertexai) !== null && _a !== void 0 ? _a : false;
@@ -9056,6 +9688,16 @@ class ApiClient {
9056
9688
  const uploadUrl = await this.fetchUploadUrl(fileToUpload, config);
9057
9689
  return uploader.upload(file, uploadUrl, this);
9058
9690
  }
9691
+ /**
9692
+ * Downloads a file asynchronously to the specified path.
9693
+ *
9694
+ * @params params - The parameters for the download request, see {@link
9695
+ * DownloadFileParameters}
9696
+ */
9697
+ async downloadFile(params) {
9698
+ const downloader = this.clientOptions.downloader;
9699
+ await downloader.download(params, this);
9700
+ }
9059
9701
  async fetchUploadUrl(file, config) {
9060
9702
  var _a;
9061
9703
  let httpOptions = {};
@@ -9201,6 +9843,66 @@ function buildGoogleAuthOptions(googleAuthOptions) {
9201
9843
  }
9202
9844
  }
9203
9845
 
9846
+ /**
9847
+ * @license
9848
+ * Copyright 2025 Google LLC
9849
+ * SPDX-License-Identifier: Apache-2.0
9850
+ */
9851
+ class NodeDownloader {
9852
+ async download(params, apiClient) {
9853
+ if (params.downloadPath) {
9854
+ const response = await downloadFile(params, apiClient);
9855
+ if (response instanceof HttpResponse) {
9856
+ const writer = fs.createWriteStream(params.downloadPath);
9857
+ node_stream.Readable.fromWeb(response.responseInternal.body).pipe(writer);
9858
+ }
9859
+ else {
9860
+ fs.writeFile(params.downloadPath, response, { encoding: 'base64' }, (error) => {
9861
+ if (error) {
9862
+ throw new Error(`Failed to write file to ${params.downloadPath}: ${error}`);
9863
+ }
9864
+ });
9865
+ }
9866
+ }
9867
+ }
9868
+ }
9869
+ async function downloadFile(params, apiClient) {
9870
+ var _a, _b, _c;
9871
+ const name = tFileName(apiClient, params.file);
9872
+ if (name !== undefined) {
9873
+ return await apiClient.request({
9874
+ path: `files/${name}:download`,
9875
+ httpMethod: 'GET',
9876
+ queryParams: {
9877
+ 'alt': 'media',
9878
+ },
9879
+ httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
9880
+ abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
9881
+ });
9882
+ }
9883
+ else if (isGeneratedVideo(params.file)) {
9884
+ const videoBytes = (_c = params.file.video) === null || _c === void 0 ? void 0 : _c.videoBytes;
9885
+ if (typeof videoBytes === 'string') {
9886
+ return videoBytes;
9887
+ }
9888
+ else {
9889
+ throw new Error('Failed to download generated video, Uri or videoBytes not found.');
9890
+ }
9891
+ }
9892
+ else if (isVideo(params.file)) {
9893
+ const videoBytes = params.file.videoBytes;
9894
+ if (typeof videoBytes === 'string') {
9895
+ return videoBytes;
9896
+ }
9897
+ else {
9898
+ throw new Error('Failed to download video, Uri or videoBytes not found.');
9899
+ }
9900
+ }
9901
+ else {
9902
+ throw new Error('Unsupported file type');
9903
+ }
9904
+ }
9905
+
9204
9906
  /**
9205
9907
  * @license
9206
9908
  * Copyright 2025 Google LLC
@@ -9969,8 +10671,12 @@ class Tunings extends BaseModule {
9969
10671
  }
9970
10672
 
9971
10673
  const MAX_CHUNK_SIZE = 1024 * 1024 * 8; // bytes
10674
+ const MAX_RETRY_COUNT = 3;
10675
+ const INITIAL_RETRY_DELAY_MS = 1000;
10676
+ const DELAY_MULTIPLIER = 2;
10677
+ const X_GOOG_UPLOAD_STATUS_HEADER_FIELD = 'x-goog-upload-status';
9972
10678
  async function uploadBlob(file, uploadUrl, apiClient) {
9973
- var _a, _b;
10679
+ var _a, _b, _c;
9974
10680
  let fileSize = 0;
9975
10681
  let offset = 0;
9976
10682
  let response = new HttpResponse(new Response());
@@ -9982,24 +10688,34 @@ async function uploadBlob(file, uploadUrl, apiClient) {
9982
10688
  if (offset + chunkSize >= fileSize) {
9983
10689
  uploadCommand += ', finalize';
9984
10690
  }
9985
- response = await apiClient.request({
9986
- path: '',
9987
- body: chunk,
9988
- httpMethod: 'POST',
9989
- httpOptions: {
9990
- apiVersion: '',
9991
- baseUrl: uploadUrl,
9992
- headers: {
9993
- 'X-Goog-Upload-Command': uploadCommand,
9994
- 'X-Goog-Upload-Offset': String(offset),
9995
- 'Content-Length': String(chunkSize),
10691
+ let retryCount = 0;
10692
+ let currentDelayMs = INITIAL_RETRY_DELAY_MS;
10693
+ while (retryCount < MAX_RETRY_COUNT) {
10694
+ response = await apiClient.request({
10695
+ path: '',
10696
+ body: chunk,
10697
+ httpMethod: 'POST',
10698
+ httpOptions: {
10699
+ apiVersion: '',
10700
+ baseUrl: uploadUrl,
10701
+ headers: {
10702
+ 'X-Goog-Upload-Command': uploadCommand,
10703
+ 'X-Goog-Upload-Offset': String(offset),
10704
+ 'Content-Length': String(chunkSize),
10705
+ },
9996
10706
  },
9997
- },
9998
- });
10707
+ });
10708
+ if ((_a = response === null || response === void 0 ? void 0 : response.headers) === null || _a === void 0 ? void 0 : _a[X_GOOG_UPLOAD_STATUS_HEADER_FIELD]) {
10709
+ break;
10710
+ }
10711
+ retryCount++;
10712
+ await sleep(currentDelayMs);
10713
+ currentDelayMs = currentDelayMs * DELAY_MULTIPLIER;
10714
+ }
9999
10715
  offset += chunkSize;
10000
10716
  // The `x-goog-upload-status` header field can be `active`, `final` and
10001
10717
  //`cancelled` in resposne.
10002
- if (((_a = response === null || response === void 0 ? void 0 : response.headers) === null || _a === void 0 ? void 0 : _a['x-goog-upload-status']) !== 'active') {
10718
+ 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') {
10003
10719
  break;
10004
10720
  }
10005
10721
  // TODO(b/401391430) Investigate why the upload status is not finalized
@@ -10009,7 +10725,7 @@ async function uploadBlob(file, uploadUrl, apiClient) {
10009
10725
  }
10010
10726
  }
10011
10727
  const responseJson = (await (response === null || response === void 0 ? void 0 : response.json()));
10012
- if (((_b = response === null || response === void 0 ? void 0 : response.headers) === null || _b === void 0 ? void 0 : _b['x-goog-upload-status']) !== 'final') {
10728
+ 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') {
10013
10729
  throw new Error('Failed to upload file: Upload status is not finalized.');
10014
10730
  }
10015
10731
  return responseJson['file'];
@@ -10018,6 +10734,9 @@ async function getBlobStat(file) {
10018
10734
  const fileStat = { size: file.size, type: file.type };
10019
10735
  return fileStat;
10020
10736
  }
10737
+ function sleep(ms) {
10738
+ return new Promise((resolvePromise) => setTimeout(resolvePromise, ms));
10739
+ }
10021
10740
 
10022
10741
  /**
10023
10742
  * @license
@@ -10136,7 +10855,7 @@ class NodeUploader {
10136
10855
  return mimeType;
10137
10856
  }
10138
10857
  async uploadFileFromPath(file, uploadUrl, apiClient) {
10139
- var _a, _b;
10858
+ var _a, _b, _c;
10140
10859
  let fileSize = 0;
10141
10860
  let offset = 0;
10142
10861
  let response = new HttpResponse(new Response());
@@ -10159,24 +10878,34 @@ class NodeUploader {
10159
10878
  throw new Error(`Failed to read ${chunkSize} bytes from file at offset ${offset}. bytes actually read: ${bytesRead}`);
10160
10879
  }
10161
10880
  const chunk = new Blob([buffer]);
10162
- response = await apiClient.request({
10163
- path: '',
10164
- body: chunk,
10165
- httpMethod: 'POST',
10166
- httpOptions: {
10167
- apiVersion: '',
10168
- baseUrl: uploadUrl,
10169
- headers: {
10170
- 'X-Goog-Upload-Command': uploadCommand,
10171
- 'X-Goog-Upload-Offset': String(offset),
10172
- 'Content-Length': String(bytesRead),
10881
+ let retryCount = 0;
10882
+ let currentDelayMs = INITIAL_RETRY_DELAY_MS;
10883
+ while (retryCount < MAX_RETRY_COUNT) {
10884
+ response = await apiClient.request({
10885
+ path: '',
10886
+ body: chunk,
10887
+ httpMethod: 'POST',
10888
+ httpOptions: {
10889
+ apiVersion: '',
10890
+ baseUrl: uploadUrl,
10891
+ headers: {
10892
+ 'X-Goog-Upload-Command': uploadCommand,
10893
+ 'X-Goog-Upload-Offset': String(offset),
10894
+ 'Content-Length': String(bytesRead),
10895
+ },
10173
10896
  },
10174
- },
10175
- });
10897
+ });
10898
+ if ((_a = response === null || response === void 0 ? void 0 : response.headers) === null || _a === void 0 ? void 0 : _a[X_GOOG_UPLOAD_STATUS_HEADER_FIELD]) {
10899
+ break;
10900
+ }
10901
+ retryCount++;
10902
+ await sleep(currentDelayMs);
10903
+ currentDelayMs = currentDelayMs * DELAY_MULTIPLIER;
10904
+ }
10176
10905
  offset += bytesRead;
10177
10906
  // The `x-goog-upload-status` header field can be `active`, `final` and
10178
10907
  //`cancelled` in resposne.
10179
- if (((_a = response === null || response === void 0 ? void 0 : response.headers) === null || _a === void 0 ? void 0 : _a['x-goog-upload-status']) !== 'active') {
10908
+ 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') {
10180
10909
  break;
10181
10910
  }
10182
10911
  if (fileSize <= offset) {
@@ -10184,7 +10913,7 @@ class NodeUploader {
10184
10913
  }
10185
10914
  }
10186
10915
  const responseJson = (await (response === null || response === void 0 ? void 0 : response.json()));
10187
- if (((_b = response === null || response === void 0 ? void 0 : response.headers) === null || _b === void 0 ? void 0 : _b['x-goog-upload-status']) !== 'final') {
10916
+ 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') {
10188
10917
  throw new Error('Failed to upload file: Upload status is not finalized.');
10189
10918
  }
10190
10919
  return responseJson['file'];
@@ -10306,6 +11035,7 @@ class GoogleGenAI {
10306
11035
  httpOptions: options.httpOptions,
10307
11036
  userAgentExtra: LANGUAGE_LABEL_PREFIX + process.version,
10308
11037
  uploader: new NodeUploader(),
11038
+ downloader: new NodeDownloader(),
10309
11039
  });
10310
11040
  this.models = new Models(this.apiClient);
10311
11041
  this.live = new Live(this.apiClient, auth, new NodeWebSocketFactory());
@@ -10351,10 +11081,12 @@ exports.GoogleGenAI = GoogleGenAI;
10351
11081
  exports.HttpResponse = HttpResponse;
10352
11082
  exports.ListCachedContentsResponse = ListCachedContentsResponse;
10353
11083
  exports.ListFilesResponse = ListFilesResponse;
11084
+ exports.ListModelsResponse = ListModelsResponse;
10354
11085
  exports.ListTuningJobsResponse = ListTuningJobsResponse;
10355
11086
  exports.Live = Live;
10356
11087
  exports.LiveClientToolResponse = LiveClientToolResponse;
10357
11088
  exports.LiveSendToolResponseParameters = LiveSendToolResponseParameters;
11089
+ exports.LiveServerMessage = LiveServerMessage;
10358
11090
  exports.Models = Models;
10359
11091
  exports.Operations = Operations;
10360
11092
  exports.Pager = Pager;