@google/genai 1.45.0 → 1.47.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.
@@ -382,6 +382,18 @@ function uploadToFileSearchStoreResponseFromMldev(fromObject) {
382
382
  * Copyright 2025 Google LLC
383
383
  * SPDX-License-Identifier: Apache-2.0
384
384
  */
385
+ /** Programming language of the `code`. */
386
+ var Language;
387
+ (function (Language) {
388
+ /**
389
+ * Unspecified language. This value should not be used.
390
+ */
391
+ Language["LANGUAGE_UNSPECIFIED"] = "LANGUAGE_UNSPECIFIED";
392
+ /**
393
+ * Python >= 3.10, with numpy and simpy available.
394
+ */
395
+ Language["PYTHON"] = "PYTHON";
396
+ })(Language || (Language = {}));
385
397
  /** Outcome of the code execution. */
386
398
  var Outcome;
387
399
  (function (Outcome) {
@@ -402,18 +414,6 @@ var Outcome;
402
414
  */
403
415
  Outcome["OUTCOME_DEADLINE_EXCEEDED"] = "OUTCOME_DEADLINE_EXCEEDED";
404
416
  })(Outcome || (Outcome = {}));
405
- /** Programming language of the `code`. */
406
- var Language;
407
- (function (Language) {
408
- /**
409
- * Unspecified language. This value should not be used.
410
- */
411
- Language["LANGUAGE_UNSPECIFIED"] = "LANGUAGE_UNSPECIFIED";
412
- /**
413
- * Python >= 3.10, with numpy and simpy available.
414
- */
415
- Language["PYTHON"] = "PYTHON";
416
- })(Language || (Language = {}));
417
417
  /** Specifies how the response should be scheduled in the conversation. */
418
418
  var FunctionResponseScheduling;
419
419
  (function (FunctionResponseScheduling) {
@@ -470,38 +470,18 @@ var Type;
470
470
  */
471
471
  Type["NULL"] = "NULL";
472
472
  })(Type || (Type = {}));
473
- /** Sites with confidence level chosen & above this value will be blocked from the search results. This enum is not supported in Gemini API. */
474
- var PhishBlockThreshold;
475
- (function (PhishBlockThreshold) {
476
- /**
477
- * Defaults to unspecified.
478
- */
479
- PhishBlockThreshold["PHISH_BLOCK_THRESHOLD_UNSPECIFIED"] = "PHISH_BLOCK_THRESHOLD_UNSPECIFIED";
480
- /**
481
- * Blocks Low and above confidence URL that is risky.
482
- */
483
- PhishBlockThreshold["BLOCK_LOW_AND_ABOVE"] = "BLOCK_LOW_AND_ABOVE";
484
- /**
485
- * Blocks Medium and above confidence URL that is risky.
486
- */
487
- PhishBlockThreshold["BLOCK_MEDIUM_AND_ABOVE"] = "BLOCK_MEDIUM_AND_ABOVE";
488
- /**
489
- * Blocks High and above confidence URL that is risky.
490
- */
491
- PhishBlockThreshold["BLOCK_HIGH_AND_ABOVE"] = "BLOCK_HIGH_AND_ABOVE";
492
- /**
493
- * Blocks Higher and above confidence URL that is risky.
494
- */
495
- PhishBlockThreshold["BLOCK_HIGHER_AND_ABOVE"] = "BLOCK_HIGHER_AND_ABOVE";
473
+ /** The environment being operated. */
474
+ var Environment;
475
+ (function (Environment) {
496
476
  /**
497
- * Blocks Very high and above confidence URL that is risky.
477
+ * Defaults to browser.
498
478
  */
499
- PhishBlockThreshold["BLOCK_VERY_HIGH_AND_ABOVE"] = "BLOCK_VERY_HIGH_AND_ABOVE";
479
+ Environment["ENVIRONMENT_UNSPECIFIED"] = "ENVIRONMENT_UNSPECIFIED";
500
480
  /**
501
- * Blocks Extremely high confidence URL that is risky.
481
+ * Operates in a web browser.
502
482
  */
503
- PhishBlockThreshold["BLOCK_ONLY_EXTREMELY_HIGH"] = "BLOCK_ONLY_EXTREMELY_HIGH";
504
- })(PhishBlockThreshold || (PhishBlockThreshold = {}));
483
+ Environment["ENVIRONMENT_BROWSER"] = "ENVIRONMENT_BROWSER";
484
+ })(Environment || (Environment = {}));
505
485
  /** Type of auth scheme. This enum is not supported in Gemini API. */
506
486
  var AuthType;
507
487
  (function (AuthType) {
@@ -572,6 +552,38 @@ var ApiSpec;
572
552
  */
573
553
  ApiSpec["ELASTIC_SEARCH"] = "ELASTIC_SEARCH";
574
554
  })(ApiSpec || (ApiSpec = {}));
555
+ /** Sites with confidence level chosen & above this value will be blocked from the search results. This enum is not supported in Gemini API. */
556
+ var PhishBlockThreshold;
557
+ (function (PhishBlockThreshold) {
558
+ /**
559
+ * Defaults to unspecified.
560
+ */
561
+ PhishBlockThreshold["PHISH_BLOCK_THRESHOLD_UNSPECIFIED"] = "PHISH_BLOCK_THRESHOLD_UNSPECIFIED";
562
+ /**
563
+ * Blocks Low and above confidence URL that is risky.
564
+ */
565
+ PhishBlockThreshold["BLOCK_LOW_AND_ABOVE"] = "BLOCK_LOW_AND_ABOVE";
566
+ /**
567
+ * Blocks Medium and above confidence URL that is risky.
568
+ */
569
+ PhishBlockThreshold["BLOCK_MEDIUM_AND_ABOVE"] = "BLOCK_MEDIUM_AND_ABOVE";
570
+ /**
571
+ * Blocks High and above confidence URL that is risky.
572
+ */
573
+ PhishBlockThreshold["BLOCK_HIGH_AND_ABOVE"] = "BLOCK_HIGH_AND_ABOVE";
574
+ /**
575
+ * Blocks Higher and above confidence URL that is risky.
576
+ */
577
+ PhishBlockThreshold["BLOCK_HIGHER_AND_ABOVE"] = "BLOCK_HIGHER_AND_ABOVE";
578
+ /**
579
+ * Blocks Very high and above confidence URL that is risky.
580
+ */
581
+ PhishBlockThreshold["BLOCK_VERY_HIGH_AND_ABOVE"] = "BLOCK_VERY_HIGH_AND_ABOVE";
582
+ /**
583
+ * Blocks Extremely high confidence URL that is risky.
584
+ */
585
+ PhishBlockThreshold["BLOCK_ONLY_EXTREMELY_HIGH"] = "BLOCK_ONLY_EXTREMELY_HIGH";
586
+ })(PhishBlockThreshold || (PhishBlockThreshold = {}));
575
587
  /** Specifies the function Behavior. Currently only supported by the BidiGenerateContent method. This enum is not supported in Vertex AI. */
576
588
  var Behavior;
577
589
  (function (Behavior) {
@@ -631,6 +643,10 @@ var ThinkingLevel;
631
643
  * Unspecified thinking level.
632
644
  */
633
645
  ThinkingLevel["THINKING_LEVEL_UNSPECIFIED"] = "THINKING_LEVEL_UNSPECIFIED";
646
+ /**
647
+ * MINIMAL thinking level.
648
+ */
649
+ ThinkingLevel["MINIMAL"] = "MINIMAL";
634
650
  /**
635
651
  * Low thinking level.
636
652
  */
@@ -643,10 +659,6 @@ var ThinkingLevel;
643
659
  * High thinking level.
644
660
  */
645
661
  ThinkingLevel["HIGH"] = "HIGH";
646
- /**
647
- * MINIMAL thinking level.
648
- */
649
- ThinkingLevel["MINIMAL"] = "MINIMAL";
650
662
  })(ThinkingLevel || (ThinkingLevel = {}));
651
663
  /** Enum that controls the generation of people. */
652
664
  var PersonGeneration;
@@ -664,6 +676,22 @@ var PersonGeneration;
664
676
  */
665
677
  PersonGeneration["ALLOW_ALL"] = "ALLOW_ALL";
666
678
  })(PersonGeneration || (PersonGeneration = {}));
679
+ /** Controls whether prominent people (celebrities) generation is allowed. If used with personGeneration, personGeneration enum would take precedence. For instance, if ALLOW_NONE is set, all person generation would be blocked. If this field is unspecified, the default behavior is to allow prominent people. This enum is not supported in Gemini API. */
680
+ var ProminentPeople;
681
+ (function (ProminentPeople) {
682
+ /**
683
+ * Unspecified value. The model will proceed with the default behavior, which is to allow generation of prominent people.
684
+ */
685
+ ProminentPeople["PROMINENT_PEOPLE_UNSPECIFIED"] = "PROMINENT_PEOPLE_UNSPECIFIED";
686
+ /**
687
+ * Allows the model to generate images of prominent people.
688
+ */
689
+ ProminentPeople["ALLOW_PROMINENT_PEOPLE"] = "ALLOW_PROMINENT_PEOPLE";
690
+ /**
691
+ * Prevents the model from generating images of prominent people.
692
+ */
693
+ ProminentPeople["BLOCK_PROMINENT_PEOPLE"] = "BLOCK_PROMINENT_PEOPLE";
694
+ })(ProminentPeople || (ProminentPeople = {}));
667
695
  /** The harm category to be blocked. */
668
696
  var HarmCategory;
669
697
  (function (HarmCategory) {
@@ -982,6 +1010,42 @@ var Modality;
982
1010
  */
983
1011
  Modality["AUDIO"] = "AUDIO";
984
1012
  })(Modality || (Modality = {}));
1013
+ /** The stage of the underlying model. This enum is not supported in Vertex AI. */
1014
+ var ModelStage;
1015
+ (function (ModelStage) {
1016
+ /**
1017
+ * Unspecified model stage.
1018
+ */
1019
+ ModelStage["MODEL_STAGE_UNSPECIFIED"] = "MODEL_STAGE_UNSPECIFIED";
1020
+ /**
1021
+ * The underlying model is subject to lots of tunings.
1022
+ */
1023
+ ModelStage["UNSTABLE_EXPERIMENTAL"] = "UNSTABLE_EXPERIMENTAL";
1024
+ /**
1025
+ * Models in this stage are for experimental purposes only.
1026
+ */
1027
+ ModelStage["EXPERIMENTAL"] = "EXPERIMENTAL";
1028
+ /**
1029
+ * Models in this stage are more mature than experimental models.
1030
+ */
1031
+ ModelStage["PREVIEW"] = "PREVIEW";
1032
+ /**
1033
+ * Models in this stage are considered stable and ready for production use.
1034
+ */
1035
+ ModelStage["STABLE"] = "STABLE";
1036
+ /**
1037
+ * If the model is on this stage, it means that this model is on the path to deprecation in near future. Only existing customers can use this model.
1038
+ */
1039
+ ModelStage["LEGACY"] = "LEGACY";
1040
+ /**
1041
+ * Models in this stage are deprecated. These models cannot be used.
1042
+ */
1043
+ ModelStage["DEPRECATED"] = "DEPRECATED";
1044
+ /**
1045
+ * Models in this stage are retired. These models cannot be used.
1046
+ */
1047
+ ModelStage["RETIRED"] = "RETIRED";
1048
+ })(ModelStage || (ModelStage = {}));
985
1049
  /** The media resolution to use. */
986
1050
  var MediaResolution;
987
1051
  (function (MediaResolution) {
@@ -1218,6 +1282,26 @@ var TuningTask;
1218
1282
  */
1219
1283
  TuningTask["TUNING_TASK_R2V"] = "TUNING_TASK_R2V";
1220
1284
  })(TuningTask || (TuningTask = {}));
1285
+ /** Output only. Current state of the `Document`. This enum is not supported in Vertex AI. */
1286
+ var DocumentState;
1287
+ (function (DocumentState) {
1288
+ /**
1289
+ * The default value. This value is used if the state is omitted.
1290
+ */
1291
+ DocumentState["STATE_UNSPECIFIED"] = "STATE_UNSPECIFIED";
1292
+ /**
1293
+ * Some `Chunks` of the `Document` are being processed (embedding and vector storage).
1294
+ */
1295
+ DocumentState["STATE_PENDING"] = "STATE_PENDING";
1296
+ /**
1297
+ * All `Chunks` of the `Document` is processed and available for querying.
1298
+ */
1299
+ DocumentState["STATE_ACTIVE"] = "STATE_ACTIVE";
1300
+ /**
1301
+ * Some `Chunks` of the `Document` failed processing.
1302
+ */
1303
+ DocumentState["STATE_FAILED"] = "STATE_FAILED";
1304
+ })(DocumentState || (DocumentState = {}));
1221
1305
  /** The tokenization quality used for given media. */
1222
1306
  var PartMediaResolutionLevel;
1223
1307
  (function (PartMediaResolutionLevel) {
@@ -1242,6 +1326,34 @@ var PartMediaResolutionLevel;
1242
1326
  */
1243
1327
  PartMediaResolutionLevel["MEDIA_RESOLUTION_ULTRA_HIGH"] = "MEDIA_RESOLUTION_ULTRA_HIGH";
1244
1328
  })(PartMediaResolutionLevel || (PartMediaResolutionLevel = {}));
1329
+ /** The type of tool in the function call. */
1330
+ var ToolType;
1331
+ (function (ToolType) {
1332
+ /**
1333
+ * Unspecified tool type.
1334
+ */
1335
+ ToolType["TOOL_TYPE_UNSPECIFIED"] = "TOOL_TYPE_UNSPECIFIED";
1336
+ /**
1337
+ * Google search tool, maps to Tool.google_search.search_types.web_search.
1338
+ */
1339
+ ToolType["GOOGLE_SEARCH_WEB"] = "GOOGLE_SEARCH_WEB";
1340
+ /**
1341
+ * Image search tool, maps to Tool.google_search.search_types.image_search.
1342
+ */
1343
+ ToolType["GOOGLE_SEARCH_IMAGE"] = "GOOGLE_SEARCH_IMAGE";
1344
+ /**
1345
+ * URL context tool, maps to Tool.url_context.
1346
+ */
1347
+ ToolType["URL_CONTEXT"] = "URL_CONTEXT";
1348
+ /**
1349
+ * Google maps tool, maps to Tool.google_maps.
1350
+ */
1351
+ ToolType["GOOGLE_MAPS"] = "GOOGLE_MAPS";
1352
+ /**
1353
+ * File search tool, maps to Tool.file_search.
1354
+ */
1355
+ ToolType["FILE_SEARCH"] = "FILE_SEARCH";
1356
+ })(ToolType || (ToolType = {}));
1245
1357
  /** Resource scope. */
1246
1358
  var ResourceScope;
1247
1359
  (function (ResourceScope) {
@@ -1254,42 +1366,34 @@ var ResourceScope;
1254
1366
  */
1255
1367
  ResourceScope["COLLECTION"] = "COLLECTION";
1256
1368
  })(ResourceScope || (ResourceScope = {}));
1257
- /** Options for feature selection preference. */
1258
- var FeatureSelectionPreference;
1259
- (function (FeatureSelectionPreference) {
1260
- FeatureSelectionPreference["FEATURE_SELECTION_PREFERENCE_UNSPECIFIED"] = "FEATURE_SELECTION_PREFERENCE_UNSPECIFIED";
1261
- FeatureSelectionPreference["PRIORITIZE_QUALITY"] = "PRIORITIZE_QUALITY";
1262
- FeatureSelectionPreference["BALANCED"] = "BALANCED";
1263
- FeatureSelectionPreference["PRIORITIZE_COST"] = "PRIORITIZE_COST";
1264
- })(FeatureSelectionPreference || (FeatureSelectionPreference = {}));
1265
- /** The environment being operated. */
1266
- var Environment;
1267
- (function (Environment) {
1369
+ /** Pricing and performance service tier. */
1370
+ var ServiceTier;
1371
+ (function (ServiceTier) {
1268
1372
  /**
1269
- * Defaults to browser.
1373
+ * Default service tier, which is standard.
1270
1374
  */
1271
- Environment["ENVIRONMENT_UNSPECIFIED"] = "ENVIRONMENT_UNSPECIFIED";
1375
+ ServiceTier["SERVICE_TIER_UNSPECIFIED"] = "SERVICE_TIER_UNSPECIFIED";
1272
1376
  /**
1273
- * Operates in a web browser.
1377
+ * Flex service tier.
1274
1378
  */
1275
- Environment["ENVIRONMENT_BROWSER"] = "ENVIRONMENT_BROWSER";
1276
- })(Environment || (Environment = {}));
1277
- /** Enum for controlling whether the model can generate images of prominent people (celebrities). */
1278
- var ProminentPeople;
1279
- (function (ProminentPeople) {
1379
+ ServiceTier["SERVICE_TIER_FLEX"] = "SERVICE_TIER_FLEX";
1280
1380
  /**
1281
- * Unspecified value. The model will proceed with the default behavior, which is to allow generation of prominent people.
1282
- */
1283
- ProminentPeople["PROMINENT_PEOPLE_UNSPECIFIED"] = "PROMINENT_PEOPLE_UNSPECIFIED";
1284
- /**
1285
- * Allows the model to generate images of prominent people.
1381
+ * Standard service tier.
1286
1382
  */
1287
- ProminentPeople["ALLOW_PROMINENT_PEOPLE"] = "ALLOW_PROMINENT_PEOPLE";
1383
+ ServiceTier["SERVICE_TIER_STANDARD"] = "SERVICE_TIER_STANDARD";
1288
1384
  /**
1289
- * Prevents the model from generating images of prominent people.
1385
+ * Priority service tier.
1290
1386
  */
1291
- ProminentPeople["BLOCK_PROMINENT_PEOPLE"] = "BLOCK_PROMINENT_PEOPLE";
1292
- })(ProminentPeople || (ProminentPeople = {}));
1387
+ ServiceTier["SERVICE_TIER_PRIORITY"] = "SERVICE_TIER_PRIORITY";
1388
+ })(ServiceTier || (ServiceTier = {}));
1389
+ /** Options for feature selection preference. */
1390
+ var FeatureSelectionPreference;
1391
+ (function (FeatureSelectionPreference) {
1392
+ FeatureSelectionPreference["FEATURE_SELECTION_PREFERENCE_UNSPECIFIED"] = "FEATURE_SELECTION_PREFERENCE_UNSPECIFIED";
1393
+ FeatureSelectionPreference["PRIORITIZE_QUALITY"] = "PRIORITIZE_QUALITY";
1394
+ FeatureSelectionPreference["BALANCED"] = "BALANCED";
1395
+ FeatureSelectionPreference["PRIORITIZE_COST"] = "PRIORITIZE_COST";
1396
+ })(FeatureSelectionPreference || (FeatureSelectionPreference = {}));
1293
1397
  /** Enum representing the Vertex embedding API to use. */
1294
1398
  var EmbeddingApiType;
1295
1399
  (function (EmbeddingApiType) {
@@ -1464,14 +1568,6 @@ var TuningMethod;
1464
1568
  */
1465
1569
  TuningMethod["DISTILLATION"] = "DISTILLATION";
1466
1570
  })(TuningMethod || (TuningMethod = {}));
1467
- /** State for the lifecycle of a Document. */
1468
- var DocumentState;
1469
- (function (DocumentState) {
1470
- DocumentState["STATE_UNSPECIFIED"] = "STATE_UNSPECIFIED";
1471
- DocumentState["STATE_PENDING"] = "STATE_PENDING";
1472
- DocumentState["STATE_ACTIVE"] = "STATE_ACTIVE";
1473
- DocumentState["STATE_FAILED"] = "STATE_FAILED";
1474
- })(DocumentState || (DocumentState = {}));
1475
1571
  /** State for the lifecycle of a File. */
1476
1572
  var FileState;
1477
1573
  (function (FileState) {
@@ -1631,6 +1727,10 @@ var TurnCoverage;
1631
1727
  * The users turn includes all realtime input since the last turn, including inactivity (e.g. silence on the audio stream).
1632
1728
  */
1633
1729
  TurnCoverage["TURN_INCLUDES_ALL_INPUT"] = "TURN_INCLUDES_ALL_INPUT";
1730
+ /**
1731
+ * Includes audio activity and all video since the last turn. With automatic activity detection, audio activity means speech and excludes silence.
1732
+ */
1733
+ TurnCoverage["TURN_INCLUDES_AUDIO_ACTIVITY_AND_ALL_VIDEO"] = "TURN_INCLUDES_AUDIO_ACTIVITY_AND_ALL_VIDEO";
1634
1734
  })(TurnCoverage || (TurnCoverage = {}));
1635
1735
  /** Scale of the generated music. */
1636
1736
  var Scale;
@@ -1757,7 +1857,6 @@ class HttpResponse {
1757
1857
  class UploadToFileSearchStoreOperation {
1758
1858
  /**
1759
1859
  * Instantiates an Operation of the same type as the one being called with the fields set from the API response.
1760
- * @internal
1761
1860
  */
1762
1861
  _fromAPIResponse({ apiResponse, _isVertexAI, }) {
1763
1862
  const operation = new UploadToFileSearchStoreOperation();
@@ -1777,7 +1876,7 @@ const CONTENT_TYPE_HEADER = 'Content-Type';
1777
1876
  const SERVER_TIMEOUT_HEADER = 'X-Server-Timeout';
1778
1877
  const USER_AGENT_HEADER = 'User-Agent';
1779
1878
  const GOOGLE_API_CLIENT_HEADER = 'x-goog-api-client';
1780
- const SDK_VERSION = '1.45.0'; // x-release-please-version
1879
+ const SDK_VERSION = '1.47.0'; // x-release-please-version
1781
1880
  const LIBRARY_LABEL = `google-genai-sdk/${SDK_VERSION}`;
1782
1881
  const VERTEX_AI_API_DEFAULT_VERSION = 'v1beta1';
1783
1882
  const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
@@ -1837,6 +1936,11 @@ class ApiClient {
1837
1936
  // Vertex Express or global endpoint case.
1838
1937
  initHttpOptions.baseUrl = 'https://aiplatform.googleapis.com/';
1839
1938
  }
1939
+ else if (this.clientOptions.project &&
1940
+ this.clientOptions.location &&
1941
+ this.clientOptions.location === 'us') {
1942
+ initHttpOptions.baseUrl = `https://aiplatform.${this.clientOptions.location}.rep.googleapis.com/`;
1943
+ }
1840
1944
  else if (this.clientOptions.project && this.clientOptions.location) {
1841
1945
  initHttpOptions.baseUrl = `https://${this.clientOptions.location}-aiplatform.googleapis.com/`;
1842
1946
  }
@@ -2651,18 +2755,18 @@ const MAX_RETRY_COUNT = 3;
2651
2755
  const INITIAL_RETRY_DELAY_MS = 1000;
2652
2756
  const DELAY_MULTIPLIER = 2;
2653
2757
  const X_GOOG_UPLOAD_STATUS_HEADER_FIELD = 'x-goog-upload-status';
2654
- async function uploadBlob(file, uploadUrl, apiClient) {
2758
+ async function uploadBlob(file, uploadUrl, apiClient, httpOptions) {
2655
2759
  var _a;
2656
- const response = await uploadBlobInternal(file, uploadUrl, apiClient);
2760
+ const response = await uploadBlobInternal(file, uploadUrl, apiClient, httpOptions);
2657
2761
  const responseJson = (await (response === null || response === void 0 ? void 0 : response.json()));
2658
2762
  if (((_a = response === null || response === void 0 ? void 0 : response.headers) === null || _a === void 0 ? void 0 : _a[X_GOOG_UPLOAD_STATUS_HEADER_FIELD]) !== 'final') {
2659
2763
  throw new Error('Failed to upload file: Upload status is not finalized.');
2660
2764
  }
2661
2765
  return responseJson['file'];
2662
2766
  }
2663
- async function uploadBlobToFileSearchStore(file, uploadUrl, apiClient) {
2767
+ async function uploadBlobToFileSearchStore(file, uploadUrl, apiClient, httpOptions) {
2664
2768
  var _a;
2665
- const response = await uploadBlobInternal(file, uploadUrl, apiClient);
2769
+ const response = await uploadBlobInternal(file, uploadUrl, apiClient, httpOptions);
2666
2770
  const responseJson = (await (response === null || response === void 0 ? void 0 : response.json()));
2667
2771
  if (((_a = response === null || response === void 0 ? void 0 : response.headers) === null || _a === void 0 ? void 0 : _a[X_GOOG_UPLOAD_STATUS_HEADER_FIELD]) !== 'final') {
2668
2772
  throw new Error('Failed to upload file: Upload status is not finalized.');
@@ -2672,8 +2776,18 @@ async function uploadBlobToFileSearchStore(file, uploadUrl, apiClient) {
2672
2776
  Object.assign(typedResp, resp);
2673
2777
  return typedResp;
2674
2778
  }
2675
- async function uploadBlobInternal(file, uploadUrl, apiClient) {
2676
- var _a, _b;
2779
+ async function uploadBlobInternal(file, uploadUrl, apiClient, httpOptions) {
2780
+ var _a, _b, _c;
2781
+ let finalUrl = uploadUrl;
2782
+ const effectiveBaseUrl = (httpOptions === null || httpOptions === void 0 ? void 0 : httpOptions.baseUrl) || ((_a = apiClient.clientOptions.httpOptions) === null || _a === void 0 ? void 0 : _a.baseUrl);
2783
+ if (effectiveBaseUrl) {
2784
+ const baseUri = new URL(effectiveBaseUrl);
2785
+ const uploadUri = new URL(uploadUrl);
2786
+ uploadUri.protocol = baseUri.protocol;
2787
+ uploadUri.host = baseUri.host;
2788
+ uploadUri.port = baseUri.port;
2789
+ finalUrl = uploadUri.toString();
2790
+ }
2677
2791
  let fileSize = 0;
2678
2792
  let offset = 0;
2679
2793
  let response = new HttpResponse(new Response());
@@ -2688,21 +2802,14 @@ async function uploadBlobInternal(file, uploadUrl, apiClient) {
2688
2802
  let retryCount = 0;
2689
2803
  let currentDelayMs = INITIAL_RETRY_DELAY_MS;
2690
2804
  while (retryCount < MAX_RETRY_COUNT) {
2805
+ const mergedHeaders = Object.assign(Object.assign({}, ((httpOptions === null || httpOptions === void 0 ? void 0 : httpOptions.headers) || {})), { 'X-Goog-Upload-Command': uploadCommand, 'X-Goog-Upload-Offset': String(offset), 'Content-Length': String(chunkSize) });
2691
2806
  response = await apiClient.request({
2692
2807
  path: '',
2693
2808
  body: chunk,
2694
2809
  httpMethod: 'POST',
2695
- httpOptions: {
2696
- apiVersion: '',
2697
- baseUrl: uploadUrl,
2698
- headers: {
2699
- 'X-Goog-Upload-Command': uploadCommand,
2700
- 'X-Goog-Upload-Offset': String(offset),
2701
- 'Content-Length': String(chunkSize),
2702
- },
2703
- },
2810
+ httpOptions: Object.assign(Object.assign({}, httpOptions), { apiVersion: '', baseUrl: finalUrl, headers: mergedHeaders }),
2704
2811
  });
2705
- if ((_a = response === null || response === void 0 ? void 0 : response.headers) === null || _a === void 0 ? void 0 : _a[X_GOOG_UPLOAD_STATUS_HEADER_FIELD]) {
2812
+ if ((_b = response === null || response === void 0 ? void 0 : response.headers) === null || _b === void 0 ? void 0 : _b[X_GOOG_UPLOAD_STATUS_HEADER_FIELD]) {
2706
2813
  break;
2707
2814
  }
2708
2815
  retryCount++;
@@ -2712,7 +2819,7 @@ async function uploadBlobInternal(file, uploadUrl, apiClient) {
2712
2819
  offset += chunkSize;
2713
2820
  // The `x-goog-upload-status` header field can be `active`, `final` and
2714
2821
  //`cancelled` in resposne.
2715
- 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') {
2822
+ if (((_c = response === null || response === void 0 ? void 0 : response.headers) === null || _c === void 0 ? void 0 : _c[X_GOOG_UPLOAD_STATUS_HEADER_FIELD]) !== 'active') {
2716
2823
  break;
2717
2824
  }
2718
2825
  // TODO(b/401391430) Investigate why the upload status is not finalized
@@ -2749,20 +2856,20 @@ class NodeUploader {
2749
2856
  return await getBlobStat(file);
2750
2857
  }
2751
2858
  }
2752
- async upload(file, uploadUrl, apiClient) {
2859
+ async upload(file, uploadUrl, apiClient, httpOptions) {
2753
2860
  if (typeof file === 'string') {
2754
- return await this.uploadFileFromPath(file, uploadUrl, apiClient);
2861
+ return await this.uploadFileFromPath(file, uploadUrl, apiClient, httpOptions);
2755
2862
  }
2756
2863
  else {
2757
- return uploadBlob(file, uploadUrl, apiClient);
2864
+ return uploadBlob(file, uploadUrl, apiClient, httpOptions);
2758
2865
  }
2759
2866
  }
2760
- async uploadToFileSearchStore(file, uploadUrl, apiClient) {
2867
+ async uploadToFileSearchStore(file, uploadUrl, apiClient, httpOptions) {
2761
2868
  if (typeof file === 'string') {
2762
- return await this.uploadFileToFileSearchStoreFromPath(file, uploadUrl, apiClient);
2869
+ return await this.uploadFileToFileSearchStoreFromPath(file, uploadUrl, apiClient, httpOptions);
2763
2870
  }
2764
2871
  else {
2765
- return uploadBlobToFileSearchStore(file, uploadUrl, apiClient);
2872
+ return uploadBlobToFileSearchStore(file, uploadUrl, apiClient, httpOptions);
2766
2873
  }
2767
2874
  }
2768
2875
  /**
@@ -2855,18 +2962,18 @@ class NodeUploader {
2855
2962
  // Return the MIME type.
2856
2963
  return mimeType;
2857
2964
  }
2858
- async uploadFileFromPath(file, uploadUrl, apiClient) {
2965
+ async uploadFileFromPath(file, uploadUrl, apiClient, httpOptions) {
2859
2966
  var _a;
2860
- const response = await this.uploadFileFromPathInternal(file, uploadUrl, apiClient);
2967
+ const response = await this.uploadFileFromPathInternal(file, uploadUrl, apiClient, httpOptions);
2861
2968
  const responseJson = (await (response === null || response === void 0 ? void 0 : response.json()));
2862
2969
  if (((_a = response === null || response === void 0 ? void 0 : response.headers) === null || _a === void 0 ? void 0 : _a[X_GOOG_UPLOAD_STATUS_HEADER_FIELD]) !== 'final') {
2863
2970
  throw new Error('Failed to upload file: Upload status is not finalized.');
2864
2971
  }
2865
2972
  return responseJson['file'];
2866
2973
  }
2867
- async uploadFileToFileSearchStoreFromPath(file, uploadUrl, apiClient) {
2974
+ async uploadFileToFileSearchStoreFromPath(file, uploadUrl, apiClient, httpOptions) {
2868
2975
  var _a;
2869
- const response = await this.uploadFileFromPathInternal(file, uploadUrl, apiClient);
2976
+ const response = await this.uploadFileFromPathInternal(file, uploadUrl, apiClient, httpOptions);
2870
2977
  const responseJson = (await (response === null || response === void 0 ? void 0 : response.json()));
2871
2978
  if (((_a = response === null || response === void 0 ? void 0 : response.headers) === null || _a === void 0 ? void 0 : _a[X_GOOG_UPLOAD_STATUS_HEADER_FIELD]) !== 'final') {
2872
2979
  throw new Error('Failed to upload file: Upload status is not finalized.');
@@ -2876,8 +2983,18 @@ class NodeUploader {
2876
2983
  Object.assign(typedResp, resp);
2877
2984
  return typedResp;
2878
2985
  }
2879
- async uploadFileFromPathInternal(file, uploadUrl, apiClient) {
2880
- var _a, _b;
2986
+ async uploadFileFromPathInternal(file, uploadUrl, apiClient, httpOptions) {
2987
+ var _a, _b, _c;
2988
+ let finalUrl = uploadUrl;
2989
+ const effectiveBaseUrl = (httpOptions === null || httpOptions === void 0 ? void 0 : httpOptions.baseUrl) || ((_a = apiClient.clientOptions.httpOptions) === null || _a === void 0 ? void 0 : _a.baseUrl);
2990
+ if (effectiveBaseUrl) {
2991
+ const baseUri = new URL(effectiveBaseUrl);
2992
+ const uploadUri = new URL(uploadUrl);
2993
+ uploadUri.protocol = baseUri.protocol;
2994
+ uploadUri.host = baseUri.host;
2995
+ uploadUri.port = baseUri.port;
2996
+ finalUrl = uploadUri.toString();
2997
+ }
2881
2998
  let fileSize = 0;
2882
2999
  let offset = 0;
2883
3000
  let response = new HttpResponse(new Response());
@@ -2904,22 +3021,14 @@ class NodeUploader {
2904
3021
  let retryCount = 0;
2905
3022
  let currentDelayMs = INITIAL_RETRY_DELAY_MS;
2906
3023
  while (retryCount < MAX_RETRY_COUNT) {
3024
+ const mergedHeaders = Object.assign(Object.assign({}, ((httpOptions === null || httpOptions === void 0 ? void 0 : httpOptions.headers) || {})), { 'X-Goog-Upload-Command': uploadCommand, 'X-Goog-Upload-Offset': String(offset), 'Content-Length': String(bytesRead), 'X-Goog-Upload-File-Name': fileName });
2907
3025
  response = await apiClient.request({
2908
3026
  path: '',
2909
3027
  body: chunk,
2910
3028
  httpMethod: 'POST',
2911
- httpOptions: {
2912
- apiVersion: '',
2913
- baseUrl: uploadUrl,
2914
- headers: {
2915
- 'X-Goog-Upload-Command': uploadCommand,
2916
- 'X-Goog-Upload-Offset': String(offset),
2917
- 'Content-Length': String(bytesRead),
2918
- 'X-Goog-Upload-File-Name': fileName,
2919
- },
2920
- },
3029
+ httpOptions: Object.assign(Object.assign({}, httpOptions), { apiVersion: '', baseUrl: finalUrl, headers: mergedHeaders }),
2921
3030
  });
2922
- if ((_a = response === null || response === void 0 ? void 0 : response.headers) === null || _a === void 0 ? void 0 : _a[X_GOOG_UPLOAD_STATUS_HEADER_FIELD]) {
3031
+ if ((_b = response === null || response === void 0 ? void 0 : response.headers) === null || _b === void 0 ? void 0 : _b[X_GOOG_UPLOAD_STATUS_HEADER_FIELD]) {
2923
3032
  break;
2924
3033
  }
2925
3034
  retryCount++;
@@ -2929,7 +3038,7 @@ class NodeUploader {
2929
3038
  offset += bytesRead;
2930
3039
  // The `x-goog-upload-status` header field can be `active`, `final` and
2931
3040
  //`cancelled` in resposne.
2932
- 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') {
3041
+ if (((_c = response === null || response === void 0 ? void 0 : response.headers) === null || _c === void 0 ? void 0 : _c[X_GOOG_UPLOAD_STATUS_HEADER_FIELD]) !== 'active') {
2933
3042
  break;
2934
3043
  }
2935
3044
  if (fileSize <= offset) {