@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.
@@ -519,15 +519,81 @@ function tBytes(apiClient, fromImageBytes) {
519
519
  // TODO(b/389133914): Remove dummy bytes converter.
520
520
  return fromImageBytes;
521
521
  }
522
+ function _isFile(origin) {
523
+ return (origin !== null &&
524
+ origin !== undefined &&
525
+ typeof origin === 'object' &&
526
+ 'name' in origin);
527
+ }
528
+ function isGeneratedVideo(origin) {
529
+ return (origin !== null &&
530
+ origin !== undefined &&
531
+ typeof origin === 'object' &&
532
+ 'video' in origin);
533
+ }
534
+ function isVideo(origin) {
535
+ return (origin !== null &&
536
+ origin !== undefined &&
537
+ typeof origin === 'object' &&
538
+ 'uri' in origin);
539
+ }
522
540
  function tFileName(apiClient, fromName) {
523
- if (typeof fromName !== 'string') {
524
- throw new Error('fromName must be a string');
541
+ var _a;
542
+ let name;
543
+ if (_isFile(fromName)) {
544
+ name = fromName.name;
545
+ }
546
+ if (isVideo(fromName)) {
547
+ name = fromName.uri;
548
+ if (name === undefined) {
549
+ return undefined;
550
+ }
551
+ }
552
+ if (isGeneratedVideo(fromName)) {
553
+ name = (_a = fromName.video) === null || _a === void 0 ? void 0 : _a.uri;
554
+ if (name === undefined) {
555
+ return undefined;
556
+ }
557
+ }
558
+ if (typeof fromName === 'string') {
559
+ name = fromName;
560
+ }
561
+ if (name === undefined) {
562
+ throw new Error('Could not extract file name from the provided input.');
563
+ }
564
+ if (name.startsWith('https://')) {
565
+ const suffix = name.split('files/')[1];
566
+ const match = suffix.match(/[a-z0-9]+/);
567
+ if (match === null) {
568
+ throw new Error(`Could not extract file name from URI ${name}`);
569
+ }
570
+ name = match[0];
525
571
  }
526
- // Remove the files/ prefx for MLdev urls to get the actual name of the file.
527
- if (fromName.startsWith('files/')) {
528
- return fromName.split('files/')[1];
572
+ else if (name.startsWith('files/')) {
573
+ name = name.split('files/')[1];
529
574
  }
530
- return fromName;
575
+ return name;
576
+ }
577
+ function tModelsUrl(apiClient, baseModels) {
578
+ let res;
579
+ if (apiClient.isVertexAI()) {
580
+ res = baseModels ? 'publishers/google/models' : 'models';
581
+ }
582
+ else {
583
+ res = baseModels ? 'models' : 'tunedModels';
584
+ }
585
+ return res;
586
+ }
587
+ function tExtractModels(apiClient, response) {
588
+ for (const key of ['models', 'tunedModels', 'publisherModels']) {
589
+ if (hasField(response, key)) {
590
+ return response[key];
591
+ }
592
+ }
593
+ return [];
594
+ }
595
+ function hasField(data, fieldName) {
596
+ return data !== null && typeof data === 'object' && fieldName in data;
531
597
  }
532
598
 
533
599
  /**
@@ -641,6 +707,12 @@ function toolToMldev$2(apiClient, fromObject) {
641
707
  if (fromGoogleSearchRetrieval != null) {
642
708
  setValueByPath(toObject, ['googleSearchRetrieval'], googleSearchRetrievalToMldev$2(apiClient, fromGoogleSearchRetrieval));
643
709
  }
710
+ if (getValueByPath(fromObject, ['enterpriseWebSearch']) !== undefined) {
711
+ throw new Error('enterpriseWebSearch parameter is not supported in Gemini API.');
712
+ }
713
+ if (getValueByPath(fromObject, ['googleMaps']) !== undefined) {
714
+ throw new Error('googleMaps parameter is not supported in Gemini API.');
715
+ }
644
716
  const fromCodeExecution = getValueByPath(fromObject, [
645
717
  'codeExecution',
646
718
  ]);
@@ -677,6 +749,9 @@ function toolConfigToMldev$1(apiClient, fromObject) {
677
749
  if (fromFunctionCallingConfig != null) {
678
750
  setValueByPath(toObject, ['functionCallingConfig'], functionCallingConfigToMldev$1(apiClient, fromFunctionCallingConfig));
679
751
  }
752
+ if (getValueByPath(fromObject, ['retrievalConfig']) !== undefined) {
753
+ throw new Error('retrievalConfig parameter is not supported in Gemini API.');
754
+ }
680
755
  return toObject;
681
756
  }
682
757
  function createCachedContentConfigToMldev(apiClient, fromObject, parentObject) {
@@ -899,6 +974,58 @@ function googleSearchRetrievalToVertex$2(apiClient, fromObject) {
899
974
  }
900
975
  return toObject;
901
976
  }
977
+ function enterpriseWebSearchToVertex$2() {
978
+ const toObject = {};
979
+ return toObject;
980
+ }
981
+ function apiKeyConfigToVertex$2(apiClient, fromObject) {
982
+ const toObject = {};
983
+ const fromApiKeyString = getValueByPath(fromObject, ['apiKeyString']);
984
+ if (fromApiKeyString != null) {
985
+ setValueByPath(toObject, ['apiKeyString'], fromApiKeyString);
986
+ }
987
+ return toObject;
988
+ }
989
+ function authConfigToVertex$2(apiClient, fromObject) {
990
+ const toObject = {};
991
+ const fromApiKeyConfig = getValueByPath(fromObject, ['apiKeyConfig']);
992
+ if (fromApiKeyConfig != null) {
993
+ setValueByPath(toObject, ['apiKeyConfig'], apiKeyConfigToVertex$2(apiClient, fromApiKeyConfig));
994
+ }
995
+ const fromAuthType = getValueByPath(fromObject, ['authType']);
996
+ if (fromAuthType != null) {
997
+ setValueByPath(toObject, ['authType'], fromAuthType);
998
+ }
999
+ const fromGoogleServiceAccountConfig = getValueByPath(fromObject, [
1000
+ 'googleServiceAccountConfig',
1001
+ ]);
1002
+ if (fromGoogleServiceAccountConfig != null) {
1003
+ setValueByPath(toObject, ['googleServiceAccountConfig'], fromGoogleServiceAccountConfig);
1004
+ }
1005
+ const fromHttpBasicAuthConfig = getValueByPath(fromObject, [
1006
+ 'httpBasicAuthConfig',
1007
+ ]);
1008
+ if (fromHttpBasicAuthConfig != null) {
1009
+ setValueByPath(toObject, ['httpBasicAuthConfig'], fromHttpBasicAuthConfig);
1010
+ }
1011
+ const fromOauthConfig = getValueByPath(fromObject, ['oauthConfig']);
1012
+ if (fromOauthConfig != null) {
1013
+ setValueByPath(toObject, ['oauthConfig'], fromOauthConfig);
1014
+ }
1015
+ const fromOidcConfig = getValueByPath(fromObject, ['oidcConfig']);
1016
+ if (fromOidcConfig != null) {
1017
+ setValueByPath(toObject, ['oidcConfig'], fromOidcConfig);
1018
+ }
1019
+ return toObject;
1020
+ }
1021
+ function googleMapsToVertex$2(apiClient, fromObject) {
1022
+ const toObject = {};
1023
+ const fromAuthConfig = getValueByPath(fromObject, ['authConfig']);
1024
+ if (fromAuthConfig != null) {
1025
+ setValueByPath(toObject, ['authConfig'], authConfigToVertex$2(apiClient, fromAuthConfig));
1026
+ }
1027
+ return toObject;
1028
+ }
902
1029
  function toolToVertex$2(apiClient, fromObject) {
903
1030
  const toObject = {};
904
1031
  const fromRetrieval = getValueByPath(fromObject, ['retrieval']);
@@ -915,6 +1042,16 @@ function toolToVertex$2(apiClient, fromObject) {
915
1042
  if (fromGoogleSearchRetrieval != null) {
916
1043
  setValueByPath(toObject, ['googleSearchRetrieval'], googleSearchRetrievalToVertex$2(apiClient, fromGoogleSearchRetrieval));
917
1044
  }
1045
+ const fromEnterpriseWebSearch = getValueByPath(fromObject, [
1046
+ 'enterpriseWebSearch',
1047
+ ]);
1048
+ if (fromEnterpriseWebSearch != null) {
1049
+ setValueByPath(toObject, ['enterpriseWebSearch'], enterpriseWebSearchToVertex$2());
1050
+ }
1051
+ const fromGoogleMaps = getValueByPath(fromObject, ['googleMaps']);
1052
+ if (fromGoogleMaps != null) {
1053
+ setValueByPath(toObject, ['googleMaps'], googleMapsToVertex$2(apiClient, fromGoogleMaps));
1054
+ }
918
1055
  const fromCodeExecution = getValueByPath(fromObject, [
919
1056
  'codeExecution',
920
1057
  ]);
@@ -943,6 +1080,26 @@ function functionCallingConfigToVertex$1(apiClient, fromObject) {
943
1080
  }
944
1081
  return toObject;
945
1082
  }
1083
+ function latLngToVertex$1(apiClient, fromObject) {
1084
+ const toObject = {};
1085
+ const fromLatitude = getValueByPath(fromObject, ['latitude']);
1086
+ if (fromLatitude != null) {
1087
+ setValueByPath(toObject, ['latitude'], fromLatitude);
1088
+ }
1089
+ const fromLongitude = getValueByPath(fromObject, ['longitude']);
1090
+ if (fromLongitude != null) {
1091
+ setValueByPath(toObject, ['longitude'], fromLongitude);
1092
+ }
1093
+ return toObject;
1094
+ }
1095
+ function retrievalConfigToVertex$1(apiClient, fromObject) {
1096
+ const toObject = {};
1097
+ const fromLatLng = getValueByPath(fromObject, ['latLng']);
1098
+ if (fromLatLng != null) {
1099
+ setValueByPath(toObject, ['latLng'], latLngToVertex$1(apiClient, fromLatLng));
1100
+ }
1101
+ return toObject;
1102
+ }
946
1103
  function toolConfigToVertex$1(apiClient, fromObject) {
947
1104
  const toObject = {};
948
1105
  const fromFunctionCallingConfig = getValueByPath(fromObject, [
@@ -951,6 +1108,12 @@ function toolConfigToVertex$1(apiClient, fromObject) {
951
1108
  if (fromFunctionCallingConfig != null) {
952
1109
  setValueByPath(toObject, ['functionCallingConfig'], functionCallingConfigToVertex$1(apiClient, fromFunctionCallingConfig));
953
1110
  }
1111
+ const fromRetrievalConfig = getValueByPath(fromObject, [
1112
+ 'retrievalConfig',
1113
+ ]);
1114
+ if (fromRetrievalConfig != null) {
1115
+ setValueByPath(toObject, ['retrievalConfig'], retrievalConfigToVertex$1(apiClient, fromRetrievalConfig));
1116
+ }
954
1117
  return toObject;
955
1118
  }
956
1119
  function createCachedContentConfigToVertex(apiClient, fromObject, parentObject) {
@@ -1430,6 +1593,17 @@ var Mode;
1430
1593
  Mode["MODE_UNSPECIFIED"] = "MODE_UNSPECIFIED";
1431
1594
  Mode["MODE_DYNAMIC"] = "MODE_DYNAMIC";
1432
1595
  })(Mode || (Mode = {}));
1596
+ /** Type of auth scheme. */
1597
+ var AuthType;
1598
+ (function (AuthType) {
1599
+ AuthType["AUTH_TYPE_UNSPECIFIED"] = "AUTH_TYPE_UNSPECIFIED";
1600
+ AuthType["NO_AUTH"] = "NO_AUTH";
1601
+ AuthType["API_KEY_AUTH"] = "API_KEY_AUTH";
1602
+ AuthType["HTTP_BASIC_AUTH"] = "HTTP_BASIC_AUTH";
1603
+ AuthType["GOOGLE_SERVICE_ACCOUNT_AUTH"] = "GOOGLE_SERVICE_ACCOUNT_AUTH";
1604
+ AuthType["OAUTH"] = "OAUTH";
1605
+ AuthType["OIDC_AUTH"] = "OIDC_AUTH";
1606
+ })(AuthType || (AuthType = {}));
1433
1607
  /** Optional. The type of the data. */
1434
1608
  var Type;
1435
1609
  (function (Type) {
@@ -2037,6 +2211,8 @@ class EmbedContentResponse {
2037
2211
  /** The output images response. */
2038
2212
  class GenerateImagesResponse {
2039
2213
  }
2214
+ class ListModelsResponse {
2215
+ }
2040
2216
  class DeleteModelResponse {
2041
2217
  }
2042
2218
  /** Response for counting tokens. */
@@ -2084,6 +2260,70 @@ class DeleteFileResponse {
2084
2260
  /** Represents a single response in a replay. */
2085
2261
  class ReplayResponse {
2086
2262
  }
2263
+ /** Response message for API call. */
2264
+ class LiveServerMessage {
2265
+ /**
2266
+ * Returns the concatenation of all text parts from the server content if present.
2267
+ *
2268
+ * @remarks
2269
+ * If there are non-text parts in the response, the concatenation of all text
2270
+ * parts will be returned, and a warning will be logged.
2271
+ */
2272
+ get text() {
2273
+ var _a, _b, _c;
2274
+ let text = '';
2275
+ let anyTextPartFound = false;
2276
+ const nonTextParts = [];
2277
+ 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 : []) {
2278
+ for (const [fieldName, fieldValue] of Object.entries(part)) {
2279
+ if (fieldName !== 'text' &&
2280
+ fieldName !== 'thought' &&
2281
+ fieldValue !== null) {
2282
+ nonTextParts.push(fieldName);
2283
+ }
2284
+ }
2285
+ if (typeof part.text === 'string') {
2286
+ if (typeof part.thought === 'boolean' && part.thought) {
2287
+ continue;
2288
+ }
2289
+ anyTextPartFound = true;
2290
+ text += part.text;
2291
+ }
2292
+ }
2293
+ if (nonTextParts.length > 0) {
2294
+ 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.`);
2295
+ }
2296
+ // part.text === '' is different from part.text is null
2297
+ return anyTextPartFound ? text : undefined;
2298
+ }
2299
+ /**
2300
+ * Returns the concatenation of all inline data parts from the server content if present.
2301
+ *
2302
+ * @remarks
2303
+ * If there are non-inline data parts in the
2304
+ * response, the concatenation of all inline data parts will be returned, and
2305
+ * a warning will be logged.
2306
+ */
2307
+ get data() {
2308
+ var _a, _b, _c;
2309
+ let data = '';
2310
+ const nonDataParts = [];
2311
+ 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 : []) {
2312
+ for (const [fieldName, fieldValue] of Object.entries(part)) {
2313
+ if (fieldName !== 'inlineData' && fieldValue !== null) {
2314
+ nonDataParts.push(fieldName);
2315
+ }
2316
+ }
2317
+ if (part.inlineData && typeof part.inlineData.data === 'string') {
2318
+ data += atob(part.inlineData.data);
2319
+ }
2320
+ }
2321
+ if (nonDataParts.length > 0) {
2322
+ 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.`);
2323
+ }
2324
+ return data.length > 0 ? btoa(data) : undefined;
2325
+ }
2326
+ }
2087
2327
  /** Client generated response to a `ToolCall` received from the server.
2088
2328
 
2089
2329
  Individual `FunctionResponse` objects are matched to the respective
@@ -3170,6 +3410,25 @@ class Files extends BaseModule {
3170
3410
  return file;
3171
3411
  });
3172
3412
  }
3413
+ /**
3414
+ * Downloads a remotely stored file asynchronously to a location specified in
3415
+ * the `params` object. This method only works on Node environment, to
3416
+ * download files in the browser, use a browser compliant method like an <a>
3417
+ * tag.
3418
+ *
3419
+ * @param params - The parameters for the download request.
3420
+ *
3421
+ * @example
3422
+ * The following code downloads an example file named "files/mehozpxf877d" as
3423
+ * "file.txt".
3424
+ *
3425
+ * ```ts
3426
+ * await ai.files.download({file: file.name, downloadPath: 'file.txt'});
3427
+ * ```
3428
+ */
3429
+ async download(params) {
3430
+ await this.apiClient.downloadFile(params);
3431
+ }
3173
3432
  async listInternal(params) {
3174
3433
  var _a, _b;
3175
3434
  let response;
@@ -3528,6 +3787,58 @@ function googleSearchRetrievalToVertex$1(apiClient, fromObject) {
3528
3787
  }
3529
3788
  return toObject;
3530
3789
  }
3790
+ function enterpriseWebSearchToVertex$1() {
3791
+ const toObject = {};
3792
+ return toObject;
3793
+ }
3794
+ function apiKeyConfigToVertex$1(apiClient, fromObject) {
3795
+ const toObject = {};
3796
+ const fromApiKeyString = getValueByPath(fromObject, ['apiKeyString']);
3797
+ if (fromApiKeyString != null) {
3798
+ setValueByPath(toObject, ['apiKeyString'], fromApiKeyString);
3799
+ }
3800
+ return toObject;
3801
+ }
3802
+ function authConfigToVertex$1(apiClient, fromObject) {
3803
+ const toObject = {};
3804
+ const fromApiKeyConfig = getValueByPath(fromObject, ['apiKeyConfig']);
3805
+ if (fromApiKeyConfig != null) {
3806
+ setValueByPath(toObject, ['apiKeyConfig'], apiKeyConfigToVertex$1(apiClient, fromApiKeyConfig));
3807
+ }
3808
+ const fromAuthType = getValueByPath(fromObject, ['authType']);
3809
+ if (fromAuthType != null) {
3810
+ setValueByPath(toObject, ['authType'], fromAuthType);
3811
+ }
3812
+ const fromGoogleServiceAccountConfig = getValueByPath(fromObject, [
3813
+ 'googleServiceAccountConfig',
3814
+ ]);
3815
+ if (fromGoogleServiceAccountConfig != null) {
3816
+ setValueByPath(toObject, ['googleServiceAccountConfig'], fromGoogleServiceAccountConfig);
3817
+ }
3818
+ const fromHttpBasicAuthConfig = getValueByPath(fromObject, [
3819
+ 'httpBasicAuthConfig',
3820
+ ]);
3821
+ if (fromHttpBasicAuthConfig != null) {
3822
+ setValueByPath(toObject, ['httpBasicAuthConfig'], fromHttpBasicAuthConfig);
3823
+ }
3824
+ const fromOauthConfig = getValueByPath(fromObject, ['oauthConfig']);
3825
+ if (fromOauthConfig != null) {
3826
+ setValueByPath(toObject, ['oauthConfig'], fromOauthConfig);
3827
+ }
3828
+ const fromOidcConfig = getValueByPath(fromObject, ['oidcConfig']);
3829
+ if (fromOidcConfig != null) {
3830
+ setValueByPath(toObject, ['oidcConfig'], fromOidcConfig);
3831
+ }
3832
+ return toObject;
3833
+ }
3834
+ function googleMapsToVertex$1(apiClient, fromObject) {
3835
+ const toObject = {};
3836
+ const fromAuthConfig = getValueByPath(fromObject, ['authConfig']);
3837
+ if (fromAuthConfig != null) {
3838
+ setValueByPath(toObject, ['authConfig'], authConfigToVertex$1(apiClient, fromAuthConfig));
3839
+ }
3840
+ return toObject;
3841
+ }
3531
3842
  function toolToMldev$1(apiClient, fromObject) {
3532
3843
  const toObject = {};
3533
3844
  if (getValueByPath(fromObject, ['retrieval']) !== undefined) {
@@ -3543,6 +3854,12 @@ function toolToMldev$1(apiClient, fromObject) {
3543
3854
  if (fromGoogleSearchRetrieval != null) {
3544
3855
  setValueByPath(toObject, ['googleSearchRetrieval'], googleSearchRetrievalToMldev$1(apiClient, fromGoogleSearchRetrieval));
3545
3856
  }
3857
+ if (getValueByPath(fromObject, ['enterpriseWebSearch']) !== undefined) {
3858
+ throw new Error('enterpriseWebSearch parameter is not supported in Gemini API.');
3859
+ }
3860
+ if (getValueByPath(fromObject, ['googleMaps']) !== undefined) {
3861
+ throw new Error('googleMaps parameter is not supported in Gemini API.');
3862
+ }
3546
3863
  const fromCodeExecution = getValueByPath(fromObject, [
3547
3864
  'codeExecution',
3548
3865
  ]);
@@ -3573,6 +3890,16 @@ function toolToVertex$1(apiClient, fromObject) {
3573
3890
  if (fromGoogleSearchRetrieval != null) {
3574
3891
  setValueByPath(toObject, ['googleSearchRetrieval'], googleSearchRetrievalToVertex$1(apiClient, fromGoogleSearchRetrieval));
3575
3892
  }
3893
+ const fromEnterpriseWebSearch = getValueByPath(fromObject, [
3894
+ 'enterpriseWebSearch',
3895
+ ]);
3896
+ if (fromEnterpriseWebSearch != null) {
3897
+ setValueByPath(toObject, ['enterpriseWebSearch'], enterpriseWebSearchToVertex$1());
3898
+ }
3899
+ const fromGoogleMaps = getValueByPath(fromObject, ['googleMaps']);
3900
+ if (fromGoogleMaps != null) {
3901
+ setValueByPath(toObject, ['googleMaps'], googleMapsToVertex$1(apiClient, fromGoogleMaps));
3902
+ }
3576
3903
  const fromCodeExecution = getValueByPath(fromObject, [
3577
3904
  'codeExecution',
3578
3905
  ]);
@@ -3838,8 +4165,11 @@ function liveConnectConfigToMldev(apiClient, fromObject, parentObject) {
3838
4165
  if (parentObject !== undefined && fromSessionResumption != null) {
3839
4166
  setValueByPath(parentObject, ['setup', 'sessionResumption'], sessionResumptionConfigToMldev(apiClient, fromSessionResumption));
3840
4167
  }
3841
- if (getValueByPath(fromObject, ['inputAudioTranscription']) !== undefined) {
3842
- throw new Error('inputAudioTranscription parameter is not supported in Gemini API.');
4168
+ const fromInputAudioTranscription = getValueByPath(fromObject, [
4169
+ 'inputAudioTranscription',
4170
+ ]);
4171
+ if (parentObject !== undefined && fromInputAudioTranscription != null) {
4172
+ setValueByPath(parentObject, ['setup', 'inputAudioTranscription'], audioTranscriptionConfigToMldev());
3843
4173
  }
3844
4174
  const fromOutputAudioTranscription = getValueByPath(fromObject, [
3845
4175
  'outputAudioTranscription',
@@ -4845,6 +5175,12 @@ function toolToMldev(apiClient, fromObject) {
4845
5175
  if (fromGoogleSearchRetrieval != null) {
4846
5176
  setValueByPath(toObject, ['googleSearchRetrieval'], googleSearchRetrievalToMldev(apiClient, fromGoogleSearchRetrieval));
4847
5177
  }
5178
+ if (getValueByPath(fromObject, ['enterpriseWebSearch']) !== undefined) {
5179
+ throw new Error('enterpriseWebSearch parameter is not supported in Gemini API.');
5180
+ }
5181
+ if (getValueByPath(fromObject, ['googleMaps']) !== undefined) {
5182
+ throw new Error('googleMaps parameter is not supported in Gemini API.');
5183
+ }
4848
5184
  const fromCodeExecution = getValueByPath(fromObject, [
4849
5185
  'codeExecution',
4850
5186
  ]);
@@ -4881,6 +5217,9 @@ function toolConfigToMldev(apiClient, fromObject) {
4881
5217
  if (fromFunctionCallingConfig != null) {
4882
5218
  setValueByPath(toObject, ['functionCallingConfig'], functionCallingConfigToMldev(apiClient, fromFunctionCallingConfig));
4883
5219
  }
5220
+ if (getValueByPath(fromObject, ['retrievalConfig']) !== undefined) {
5221
+ throw new Error('retrievalConfig parameter is not supported in Gemini API.');
5222
+ }
4884
5223
  return toObject;
4885
5224
  }
4886
5225
  function prebuiltVoiceConfigToMldev(apiClient, fromObject) {
@@ -5242,6 +5581,34 @@ function getModelParametersToMldev(apiClient, fromObject) {
5242
5581
  }
5243
5582
  return toObject;
5244
5583
  }
5584
+ function listModelsConfigToMldev(apiClient, fromObject, parentObject) {
5585
+ const toObject = {};
5586
+ const fromPageSize = getValueByPath(fromObject, ['pageSize']);
5587
+ if (parentObject !== undefined && fromPageSize != null) {
5588
+ setValueByPath(parentObject, ['_query', 'pageSize'], fromPageSize);
5589
+ }
5590
+ const fromPageToken = getValueByPath(fromObject, ['pageToken']);
5591
+ if (parentObject !== undefined && fromPageToken != null) {
5592
+ setValueByPath(parentObject, ['_query', 'pageToken'], fromPageToken);
5593
+ }
5594
+ const fromFilter = getValueByPath(fromObject, ['filter']);
5595
+ if (parentObject !== undefined && fromFilter != null) {
5596
+ setValueByPath(parentObject, ['_query', 'filter'], fromFilter);
5597
+ }
5598
+ const fromQueryBase = getValueByPath(fromObject, ['queryBase']);
5599
+ if (parentObject !== undefined && fromQueryBase != null) {
5600
+ setValueByPath(parentObject, ['_url', 'models_url'], tModelsUrl(apiClient, fromQueryBase));
5601
+ }
5602
+ return toObject;
5603
+ }
5604
+ function listModelsParametersToMldev(apiClient, fromObject) {
5605
+ const toObject = {};
5606
+ const fromConfig = getValueByPath(fromObject, ['config']);
5607
+ if (fromConfig != null) {
5608
+ setValueByPath(toObject, ['config'], listModelsConfigToMldev(apiClient, fromConfig, toObject));
5609
+ }
5610
+ return toObject;
5611
+ }
5245
5612
  function updateModelConfigToMldev(apiClient, fromObject, parentObject) {
5246
5613
  const toObject = {};
5247
5614
  const fromDisplayName = getValueByPath(fromObject, ['displayName']);
@@ -5518,6 +5885,58 @@ function googleSearchRetrievalToVertex(apiClient, fromObject) {
5518
5885
  }
5519
5886
  return toObject;
5520
5887
  }
5888
+ function enterpriseWebSearchToVertex() {
5889
+ const toObject = {};
5890
+ return toObject;
5891
+ }
5892
+ function apiKeyConfigToVertex(apiClient, fromObject) {
5893
+ const toObject = {};
5894
+ const fromApiKeyString = getValueByPath(fromObject, ['apiKeyString']);
5895
+ if (fromApiKeyString != null) {
5896
+ setValueByPath(toObject, ['apiKeyString'], fromApiKeyString);
5897
+ }
5898
+ return toObject;
5899
+ }
5900
+ function authConfigToVertex(apiClient, fromObject) {
5901
+ const toObject = {};
5902
+ const fromApiKeyConfig = getValueByPath(fromObject, ['apiKeyConfig']);
5903
+ if (fromApiKeyConfig != null) {
5904
+ setValueByPath(toObject, ['apiKeyConfig'], apiKeyConfigToVertex(apiClient, fromApiKeyConfig));
5905
+ }
5906
+ const fromAuthType = getValueByPath(fromObject, ['authType']);
5907
+ if (fromAuthType != null) {
5908
+ setValueByPath(toObject, ['authType'], fromAuthType);
5909
+ }
5910
+ const fromGoogleServiceAccountConfig = getValueByPath(fromObject, [
5911
+ 'googleServiceAccountConfig',
5912
+ ]);
5913
+ if (fromGoogleServiceAccountConfig != null) {
5914
+ setValueByPath(toObject, ['googleServiceAccountConfig'], fromGoogleServiceAccountConfig);
5915
+ }
5916
+ const fromHttpBasicAuthConfig = getValueByPath(fromObject, [
5917
+ 'httpBasicAuthConfig',
5918
+ ]);
5919
+ if (fromHttpBasicAuthConfig != null) {
5920
+ setValueByPath(toObject, ['httpBasicAuthConfig'], fromHttpBasicAuthConfig);
5921
+ }
5922
+ const fromOauthConfig = getValueByPath(fromObject, ['oauthConfig']);
5923
+ if (fromOauthConfig != null) {
5924
+ setValueByPath(toObject, ['oauthConfig'], fromOauthConfig);
5925
+ }
5926
+ const fromOidcConfig = getValueByPath(fromObject, ['oidcConfig']);
5927
+ if (fromOidcConfig != null) {
5928
+ setValueByPath(toObject, ['oidcConfig'], fromOidcConfig);
5929
+ }
5930
+ return toObject;
5931
+ }
5932
+ function googleMapsToVertex(apiClient, fromObject) {
5933
+ const toObject = {};
5934
+ const fromAuthConfig = getValueByPath(fromObject, ['authConfig']);
5935
+ if (fromAuthConfig != null) {
5936
+ setValueByPath(toObject, ['authConfig'], authConfigToVertex(apiClient, fromAuthConfig));
5937
+ }
5938
+ return toObject;
5939
+ }
5521
5940
  function toolToVertex(apiClient, fromObject) {
5522
5941
  const toObject = {};
5523
5942
  const fromRetrieval = getValueByPath(fromObject, ['retrieval']);
@@ -5534,6 +5953,16 @@ function toolToVertex(apiClient, fromObject) {
5534
5953
  if (fromGoogleSearchRetrieval != null) {
5535
5954
  setValueByPath(toObject, ['googleSearchRetrieval'], googleSearchRetrievalToVertex(apiClient, fromGoogleSearchRetrieval));
5536
5955
  }
5956
+ const fromEnterpriseWebSearch = getValueByPath(fromObject, [
5957
+ 'enterpriseWebSearch',
5958
+ ]);
5959
+ if (fromEnterpriseWebSearch != null) {
5960
+ setValueByPath(toObject, ['enterpriseWebSearch'], enterpriseWebSearchToVertex());
5961
+ }
5962
+ const fromGoogleMaps = getValueByPath(fromObject, ['googleMaps']);
5963
+ if (fromGoogleMaps != null) {
5964
+ setValueByPath(toObject, ['googleMaps'], googleMapsToVertex(apiClient, fromGoogleMaps));
5965
+ }
5537
5966
  const fromCodeExecution = getValueByPath(fromObject, [
5538
5967
  'codeExecution',
5539
5968
  ]);
@@ -5562,6 +5991,26 @@ function functionCallingConfigToVertex(apiClient, fromObject) {
5562
5991
  }
5563
5992
  return toObject;
5564
5993
  }
5994
+ function latLngToVertex(apiClient, fromObject) {
5995
+ const toObject = {};
5996
+ const fromLatitude = getValueByPath(fromObject, ['latitude']);
5997
+ if (fromLatitude != null) {
5998
+ setValueByPath(toObject, ['latitude'], fromLatitude);
5999
+ }
6000
+ const fromLongitude = getValueByPath(fromObject, ['longitude']);
6001
+ if (fromLongitude != null) {
6002
+ setValueByPath(toObject, ['longitude'], fromLongitude);
6003
+ }
6004
+ return toObject;
6005
+ }
6006
+ function retrievalConfigToVertex(apiClient, fromObject) {
6007
+ const toObject = {};
6008
+ const fromLatLng = getValueByPath(fromObject, ['latLng']);
6009
+ if (fromLatLng != null) {
6010
+ setValueByPath(toObject, ['latLng'], latLngToVertex(apiClient, fromLatLng));
6011
+ }
6012
+ return toObject;
6013
+ }
5565
6014
  function toolConfigToVertex(apiClient, fromObject) {
5566
6015
  const toObject = {};
5567
6016
  const fromFunctionCallingConfig = getValueByPath(fromObject, [
@@ -5570,6 +6019,12 @@ function toolConfigToVertex(apiClient, fromObject) {
5570
6019
  if (fromFunctionCallingConfig != null) {
5571
6020
  setValueByPath(toObject, ['functionCallingConfig'], functionCallingConfigToVertex(apiClient, fromFunctionCallingConfig));
5572
6021
  }
6022
+ const fromRetrievalConfig = getValueByPath(fromObject, [
6023
+ 'retrievalConfig',
6024
+ ]);
6025
+ if (fromRetrievalConfig != null) {
6026
+ setValueByPath(toObject, ['retrievalConfig'], retrievalConfigToVertex(apiClient, fromRetrievalConfig));
6027
+ }
5573
6028
  return toObject;
5574
6029
  }
5575
6030
  function prebuiltVoiceConfigToVertex(apiClient, fromObject) {
@@ -5948,6 +6403,34 @@ function getModelParametersToVertex(apiClient, fromObject) {
5948
6403
  }
5949
6404
  return toObject;
5950
6405
  }
6406
+ function listModelsConfigToVertex(apiClient, fromObject, parentObject) {
6407
+ const toObject = {};
6408
+ const fromPageSize = getValueByPath(fromObject, ['pageSize']);
6409
+ if (parentObject !== undefined && fromPageSize != null) {
6410
+ setValueByPath(parentObject, ['_query', 'pageSize'], fromPageSize);
6411
+ }
6412
+ const fromPageToken = getValueByPath(fromObject, ['pageToken']);
6413
+ if (parentObject !== undefined && fromPageToken != null) {
6414
+ setValueByPath(parentObject, ['_query', 'pageToken'], fromPageToken);
6415
+ }
6416
+ const fromFilter = getValueByPath(fromObject, ['filter']);
6417
+ if (parentObject !== undefined && fromFilter != null) {
6418
+ setValueByPath(parentObject, ['_query', 'filter'], fromFilter);
6419
+ }
6420
+ const fromQueryBase = getValueByPath(fromObject, ['queryBase']);
6421
+ if (parentObject !== undefined && fromQueryBase != null) {
6422
+ setValueByPath(parentObject, ['_url', 'models_url'], tModelsUrl(apiClient, fromQueryBase));
6423
+ }
6424
+ return toObject;
6425
+ }
6426
+ function listModelsParametersToVertex(apiClient, fromObject) {
6427
+ const toObject = {};
6428
+ const fromConfig = getValueByPath(fromObject, ['config']);
6429
+ if (fromConfig != null) {
6430
+ setValueByPath(toObject, ['config'], listModelsConfigToVertex(apiClient, fromConfig, toObject));
6431
+ }
6432
+ return toObject;
6433
+ }
5951
6434
  function updateModelConfigToVertex(apiClient, fromObject, parentObject) {
5952
6435
  const toObject = {};
5953
6436
  const fromDisplayName = getValueByPath(fromObject, ['displayName']);
@@ -6458,6 +6941,26 @@ function modelFromMldev(apiClient, fromObject) {
6458
6941
  }
6459
6942
  return toObject;
6460
6943
  }
6944
+ function listModelsResponseFromMldev(apiClient, fromObject) {
6945
+ const toObject = {};
6946
+ const fromNextPageToken = getValueByPath(fromObject, [
6947
+ 'nextPageToken',
6948
+ ]);
6949
+ if (fromNextPageToken != null) {
6950
+ setValueByPath(toObject, ['nextPageToken'], fromNextPageToken);
6951
+ }
6952
+ const fromModels = getValueByPath(fromObject, ['_self']);
6953
+ if (fromModels != null) {
6954
+ let transformedList = tExtractModels(apiClient, fromModels);
6955
+ if (Array.isArray(transformedList)) {
6956
+ transformedList = transformedList.map((item) => {
6957
+ return modelFromMldev(apiClient, item);
6958
+ });
6959
+ }
6960
+ setValueByPath(toObject, ['models'], transformedList);
6961
+ }
6962
+ return toObject;
6963
+ }
6461
6964
  function deleteModelResponseFromMldev() {
6462
6965
  const toObject = {};
6463
6966
  return toObject;
@@ -6930,6 +7433,26 @@ function modelFromVertex(apiClient, fromObject) {
6930
7433
  }
6931
7434
  return toObject;
6932
7435
  }
7436
+ function listModelsResponseFromVertex(apiClient, fromObject) {
7437
+ const toObject = {};
7438
+ const fromNextPageToken = getValueByPath(fromObject, [
7439
+ 'nextPageToken',
7440
+ ]);
7441
+ if (fromNextPageToken != null) {
7442
+ setValueByPath(toObject, ['nextPageToken'], fromNextPageToken);
7443
+ }
7444
+ const fromModels = getValueByPath(fromObject, ['_self']);
7445
+ if (fromModels != null) {
7446
+ let transformedList = tExtractModels(apiClient, fromModels);
7447
+ if (Array.isArray(transformedList)) {
7448
+ transformedList = transformedList.map((item) => {
7449
+ return modelFromVertex(apiClient, item);
7450
+ });
7451
+ }
7452
+ setValueByPath(toObject, ['models'], transformedList);
7453
+ }
7454
+ return toObject;
7455
+ }
6933
7456
  function deleteModelResponseFromVertex() {
6934
7457
  const toObject = {};
6935
7458
  return toObject;
@@ -7047,7 +7570,7 @@ const FUNCTION_RESPONSE_REQUIRES_ID = 'FunctionResponse request must have an `id
7047
7570
  * @param event The MessageEvent from the WebSocket.
7048
7571
  */
7049
7572
  async function handleWebSocketMessage(apiClient, onmessage, event) {
7050
- let serverMessage;
7573
+ const serverMessage = new LiveServerMessage();
7051
7574
  let data;
7052
7575
  if (event.data instanceof Blob) {
7053
7576
  data = JSON.parse(await event.data.text());
@@ -7056,10 +7579,12 @@ async function handleWebSocketMessage(apiClient, onmessage, event) {
7056
7579
  data = JSON.parse(event.data);
7057
7580
  }
7058
7581
  if (apiClient.isVertexAI()) {
7059
- serverMessage = liveServerMessageFromVertex(apiClient, data);
7582
+ const resp = liveServerMessageFromVertex(apiClient, data);
7583
+ Object.assign(serverMessage, resp);
7060
7584
  }
7061
7585
  else {
7062
- serverMessage = liveServerMessageFromMldev(apiClient, data);
7586
+ const resp = liveServerMessageFromMldev(apiClient, data);
7587
+ Object.assign(serverMessage, resp);
7063
7588
  }
7064
7589
  onmessage(serverMessage);
7065
7590
  }
@@ -7566,6 +8091,27 @@ class Models extends BaseModule {
7566
8091
  return response;
7567
8092
  });
7568
8093
  };
8094
+ this.list = async (params) => {
8095
+ var _a;
8096
+ const defaultConfig = {
8097
+ queryBase: true,
8098
+ };
8099
+ const actualConfig = Object.assign(Object.assign({}, defaultConfig), params === null || params === void 0 ? void 0 : params.config);
8100
+ const actualParams = {
8101
+ config: actualConfig,
8102
+ };
8103
+ if (this.apiClient.isVertexAI()) {
8104
+ if (!actualParams.config.queryBase) {
8105
+ if ((_a = actualParams.config) === null || _a === void 0 ? void 0 : _a.filter) {
8106
+ throw new Error('Filtering tuned models list for Vertex AI is not currently supported');
8107
+ }
8108
+ else {
8109
+ actualParams.config.filter = 'labels.tune-type:*';
8110
+ }
8111
+ }
8112
+ }
8113
+ return new Pager(PagedItem.PAGED_ITEM_MODELS, (x) => this.listInternal(x), await this.listInternal(actualParams), actualParams);
8114
+ };
7569
8115
  }
7570
8116
  async generateContentInternal(params) {
7571
8117
  var _a, _b, _c, _d;
@@ -7929,6 +8475,64 @@ class Models extends BaseModule {
7929
8475
  });
7930
8476
  }
7931
8477
  }
8478
+ async listInternal(params) {
8479
+ var _a, _b, _c, _d;
8480
+ let response;
8481
+ let path = '';
8482
+ let queryParams = {};
8483
+ if (this.apiClient.isVertexAI()) {
8484
+ const body = listModelsParametersToVertex(this.apiClient, params);
8485
+ path = formatMap('{models_url}', body['_url']);
8486
+ queryParams = body['_query'];
8487
+ delete body['config'];
8488
+ delete body['_url'];
8489
+ delete body['_query'];
8490
+ response = this.apiClient
8491
+ .request({
8492
+ path: path,
8493
+ queryParams: queryParams,
8494
+ body: JSON.stringify(body),
8495
+ httpMethod: 'GET',
8496
+ httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
8497
+ abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
8498
+ })
8499
+ .then((httpResponse) => {
8500
+ return httpResponse.json();
8501
+ });
8502
+ return response.then((apiResponse) => {
8503
+ const resp = listModelsResponseFromVertex(this.apiClient, apiResponse);
8504
+ const typedResp = new ListModelsResponse();
8505
+ Object.assign(typedResp, resp);
8506
+ return typedResp;
8507
+ });
8508
+ }
8509
+ else {
8510
+ const body = listModelsParametersToMldev(this.apiClient, params);
8511
+ path = formatMap('{models_url}', body['_url']);
8512
+ queryParams = body['_query'];
8513
+ delete body['config'];
8514
+ delete body['_url'];
8515
+ delete body['_query'];
8516
+ response = this.apiClient
8517
+ .request({
8518
+ path: path,
8519
+ queryParams: queryParams,
8520
+ body: JSON.stringify(body),
8521
+ httpMethod: 'GET',
8522
+ httpOptions: (_c = params.config) === null || _c === void 0 ? void 0 : _c.httpOptions,
8523
+ abortSignal: (_d = params.config) === null || _d === void 0 ? void 0 : _d.abortSignal,
8524
+ })
8525
+ .then((httpResponse) => {
8526
+ return httpResponse.json();
8527
+ });
8528
+ return response.then((apiResponse) => {
8529
+ const resp = listModelsResponseFromMldev(this.apiClient, apiResponse);
8530
+ const typedResp = new ListModelsResponse();
8531
+ Object.assign(typedResp, resp);
8532
+ return typedResp;
8533
+ });
8534
+ }
8535
+ }
7932
8536
  /**
7933
8537
  * Updates a tuned model by its name.
7934
8538
  *
@@ -8624,7 +9228,7 @@ const CONTENT_TYPE_HEADER = 'Content-Type';
8624
9228
  const SERVER_TIMEOUT_HEADER = 'X-Server-Timeout';
8625
9229
  const USER_AGENT_HEADER = 'User-Agent';
8626
9230
  const GOOGLE_API_CLIENT_HEADER = 'x-goog-api-client';
8627
- const SDK_VERSION = '0.12.0'; // x-release-please-version
9231
+ const SDK_VERSION = '0.13.0'; // x-release-please-version
8628
9232
  const LIBRARY_LABEL = `google-genai-sdk/${SDK_VERSION}`;
8629
9233
  const VERTEX_AI_API_DEFAULT_VERSION = 'v1beta1';
8630
9234
  const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
@@ -8671,18 +9275,11 @@ class ApiClient {
8671
9275
  if (this.clientOptions.vertexai) {
8672
9276
  initHttpOptions.apiVersion =
8673
9277
  (_a = this.clientOptions.apiVersion) !== null && _a !== void 0 ? _a : VERTEX_AI_API_DEFAULT_VERSION;
8674
- // Assume that proj/api key validation occurs before they are passed in.
8675
- if (this.getProject() || this.getLocation()) {
8676
- initHttpOptions.baseUrl = `https://${this.clientOptions.location}-aiplatform.googleapis.com/`;
8677
- this.clientOptions.apiKey = undefined; // unset API key.
8678
- }
8679
- else {
8680
- initHttpOptions.baseUrl = `https://aiplatform.googleapis.com/`;
8681
- this.clientOptions.project = undefined; // unset project.
8682
- this.clientOptions.location = undefined; // unset location.
8683
- }
9278
+ initHttpOptions.baseUrl = this.baseUrlFromProjectLocation();
9279
+ this.normalizeAuthParameters();
8684
9280
  }
8685
9281
  else {
9282
+ // Gemini API
8686
9283
  initHttpOptions.apiVersion =
8687
9284
  (_b = this.clientOptions.apiVersion) !== null && _b !== void 0 ? _b : GOOGLE_AI_API_DEFAULT_VERSION;
8688
9285
  initHttpOptions.baseUrl = `https://generativelanguage.googleapis.com/`;
@@ -8693,6 +9290,39 @@ class ApiClient {
8693
9290
  this.clientOptions.httpOptions = this.patchHttpOptions(initHttpOptions, opts.httpOptions);
8694
9291
  }
8695
9292
  }
9293
+ /**
9294
+ * Determines the base URL for Vertex AI based on project and location.
9295
+ * Uses the global endpoint if location is 'global' or if project/location
9296
+ * are not specified (implying API key usage).
9297
+ * @private
9298
+ */
9299
+ baseUrlFromProjectLocation() {
9300
+ if (this.clientOptions.project &&
9301
+ this.clientOptions.location &&
9302
+ this.clientOptions.location !== 'global') {
9303
+ // Regional endpoint
9304
+ return `https://${this.clientOptions.location}-aiplatform.googleapis.com/`;
9305
+ }
9306
+ // Global endpoint (covers 'global' location and API key usage)
9307
+ return `https://aiplatform.googleapis.com/`;
9308
+ }
9309
+ /**
9310
+ * Normalizes authentication parameters for Vertex AI.
9311
+ * If project and location are provided, API key is cleared.
9312
+ * If project and location are not provided (implying API key usage),
9313
+ * project and location are cleared.
9314
+ * @private
9315
+ */
9316
+ normalizeAuthParameters() {
9317
+ if (this.clientOptions.project && this.clientOptions.location) {
9318
+ // Using project/location for auth, clear potential API key
9319
+ this.clientOptions.apiKey = undefined;
9320
+ return;
9321
+ }
9322
+ // Using API key for auth (or no auth provided yet), clear project/location
9323
+ this.clientOptions.project = undefined;
9324
+ this.clientOptions.location = undefined;
9325
+ }
8696
9326
  isVertexAI() {
8697
9327
  var _a;
8698
9328
  return (_a = this.clientOptions.vertexai) !== null && _a !== void 0 ? _a : false;
@@ -9030,6 +9660,16 @@ class ApiClient {
9030
9660
  const uploadUrl = await this.fetchUploadUrl(fileToUpload, config);
9031
9661
  return uploader.upload(file, uploadUrl, this);
9032
9662
  }
9663
+ /**
9664
+ * Downloads a file asynchronously to the specified path.
9665
+ *
9666
+ * @params params - The parameters for the download request, see {@link
9667
+ * DownloadFileParameters}
9668
+ */
9669
+ async downloadFile(params) {
9670
+ const downloader = this.clientOptions.downloader;
9671
+ await downloader.download(params, this);
9672
+ }
9033
9673
  async fetchUploadUrl(file, config) {
9034
9674
  var _a;
9035
9675
  let httpOptions = {};
@@ -9831,9 +10471,24 @@ class Tunings extends BaseModule {
9831
10471
  }
9832
10472
  }
9833
10473
 
10474
+ /**
10475
+ * @license
10476
+ * Copyright 2025 Google LLC
10477
+ * SPDX-License-Identifier: Apache-2.0
10478
+ */
10479
+ class BrowserDownloader {
10480
+ async download(_params, _apiClient) {
10481
+ throw new Error('Download to file is not supported in the browser, please use a browser compliant download like an <a> tag.');
10482
+ }
10483
+ }
10484
+
9834
10485
  const MAX_CHUNK_SIZE = 1024 * 1024 * 8; // bytes
10486
+ const MAX_RETRY_COUNT = 3;
10487
+ const INITIAL_RETRY_DELAY_MS = 1000;
10488
+ const DELAY_MULTIPLIER = 2;
10489
+ const X_GOOG_UPLOAD_STATUS_HEADER_FIELD = 'x-goog-upload-status';
9835
10490
  async function uploadBlob(file, uploadUrl, apiClient) {
9836
- var _a, _b;
10491
+ var _a, _b, _c;
9837
10492
  let fileSize = 0;
9838
10493
  let offset = 0;
9839
10494
  let response = new HttpResponse(new Response());
@@ -9845,24 +10500,34 @@ async function uploadBlob(file, uploadUrl, apiClient) {
9845
10500
  if (offset + chunkSize >= fileSize) {
9846
10501
  uploadCommand += ', finalize';
9847
10502
  }
9848
- response = await apiClient.request({
9849
- path: '',
9850
- body: chunk,
9851
- httpMethod: 'POST',
9852
- httpOptions: {
9853
- apiVersion: '',
9854
- baseUrl: uploadUrl,
9855
- headers: {
9856
- 'X-Goog-Upload-Command': uploadCommand,
9857
- 'X-Goog-Upload-Offset': String(offset),
9858
- 'Content-Length': String(chunkSize),
10503
+ let retryCount = 0;
10504
+ let currentDelayMs = INITIAL_RETRY_DELAY_MS;
10505
+ while (retryCount < MAX_RETRY_COUNT) {
10506
+ response = await apiClient.request({
10507
+ path: '',
10508
+ body: chunk,
10509
+ httpMethod: 'POST',
10510
+ httpOptions: {
10511
+ apiVersion: '',
10512
+ baseUrl: uploadUrl,
10513
+ headers: {
10514
+ 'X-Goog-Upload-Command': uploadCommand,
10515
+ 'X-Goog-Upload-Offset': String(offset),
10516
+ 'Content-Length': String(chunkSize),
10517
+ },
9859
10518
  },
9860
- },
9861
- });
10519
+ });
10520
+ if ((_a = response === null || response === void 0 ? void 0 : response.headers) === null || _a === void 0 ? void 0 : _a[X_GOOG_UPLOAD_STATUS_HEADER_FIELD]) {
10521
+ break;
10522
+ }
10523
+ retryCount++;
10524
+ await sleep(currentDelayMs);
10525
+ currentDelayMs = currentDelayMs * DELAY_MULTIPLIER;
10526
+ }
9862
10527
  offset += chunkSize;
9863
10528
  // The `x-goog-upload-status` header field can be `active`, `final` and
9864
10529
  //`cancelled` in resposne.
9865
- if (((_a = response === null || response === void 0 ? void 0 : response.headers) === null || _a === void 0 ? void 0 : _a['x-goog-upload-status']) !== 'active') {
10530
+ 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') {
9866
10531
  break;
9867
10532
  }
9868
10533
  // TODO(b/401391430) Investigate why the upload status is not finalized
@@ -9872,7 +10537,7 @@ async function uploadBlob(file, uploadUrl, apiClient) {
9872
10537
  }
9873
10538
  }
9874
10539
  const responseJson = (await (response === null || response === void 0 ? void 0 : response.json()));
9875
- if (((_b = response === null || response === void 0 ? void 0 : response.headers) === null || _b === void 0 ? void 0 : _b['x-goog-upload-status']) !== 'final') {
10540
+ 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') {
9876
10541
  throw new Error('Failed to upload file: Upload status is not finalized.');
9877
10542
  }
9878
10543
  return responseJson['file'];
@@ -9881,6 +10546,9 @@ async function getBlobStat(file) {
9881
10546
  const fileStat = { size: file.size, type: file.type };
9882
10547
  return fileStat;
9883
10548
  }
10549
+ function sleep(ms) {
10550
+ return new Promise((resolvePromise) => setTimeout(resolvePromise, ms));
10551
+ }
9884
10552
 
9885
10553
  class BrowserUploader {
9886
10554
  async upload(file, uploadUrl, apiClient) {
@@ -10033,6 +10701,7 @@ class GoogleGenAI {
10033
10701
  httpOptions: options.httpOptions,
10034
10702
  userAgentExtra: LANGUAGE_LABEL_PREFIX + 'web',
10035
10703
  uploader: new BrowserUploader(),
10704
+ downloader: new BrowserDownloader(),
10036
10705
  });
10037
10706
  this.models = new Models(this.apiClient);
10038
10707
  this.live = new Live(this.apiClient, auth, new BrowserWebSocketFactory());
@@ -10044,5 +10713,5 @@ class GoogleGenAI {
10044
10713
  }
10045
10714
  }
10046
10715
 
10047
- 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 };
10716
+ 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 };
10048
10717
  //# sourceMappingURL=index.mjs.map