@google/genai 1.28.0 → 1.29.1

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.
@@ -5,6 +5,7 @@ import { writeFile } from 'fs/promises';
5
5
  import { Readable } from 'node:stream';
6
6
  import { finished } from 'node:stream/promises';
7
7
  import * as NodeWs from 'ws';
8
+ import * as path from 'path';
8
9
 
9
10
  /**
10
11
  * @license
@@ -468,6 +469,90 @@ function getOperationParametersToVertex(fromObject) {
468
469
  }
469
470
  return toObject;
470
471
  }
472
+ function importFileOperationFromMldev$1(fromObject) {
473
+ const toObject = {};
474
+ const fromName = getValueByPath(fromObject, ['name']);
475
+ if (fromName != null) {
476
+ setValueByPath(toObject, ['name'], fromName);
477
+ }
478
+ const fromMetadata = getValueByPath(fromObject, ['metadata']);
479
+ if (fromMetadata != null) {
480
+ setValueByPath(toObject, ['metadata'], fromMetadata);
481
+ }
482
+ const fromDone = getValueByPath(fromObject, ['done']);
483
+ if (fromDone != null) {
484
+ setValueByPath(toObject, ['done'], fromDone);
485
+ }
486
+ const fromError = getValueByPath(fromObject, ['error']);
487
+ if (fromError != null) {
488
+ setValueByPath(toObject, ['error'], fromError);
489
+ }
490
+ const fromResponse = getValueByPath(fromObject, ['response']);
491
+ if (fromResponse != null) {
492
+ setValueByPath(toObject, ['response'], importFileResponseFromMldev$1(fromResponse));
493
+ }
494
+ return toObject;
495
+ }
496
+ function importFileResponseFromMldev$1(fromObject) {
497
+ const toObject = {};
498
+ const fromSdkHttpResponse = getValueByPath(fromObject, [
499
+ 'sdkHttpResponse',
500
+ ]);
501
+ if (fromSdkHttpResponse != null) {
502
+ setValueByPath(toObject, ['sdkHttpResponse'], fromSdkHttpResponse);
503
+ }
504
+ const fromParent = getValueByPath(fromObject, ['parent']);
505
+ if (fromParent != null) {
506
+ setValueByPath(toObject, ['parent'], fromParent);
507
+ }
508
+ const fromDocumentName = getValueByPath(fromObject, ['documentName']);
509
+ if (fromDocumentName != null) {
510
+ setValueByPath(toObject, ['documentName'], fromDocumentName);
511
+ }
512
+ return toObject;
513
+ }
514
+ function uploadToFileSearchStoreOperationFromMldev(fromObject) {
515
+ const toObject = {};
516
+ const fromName = getValueByPath(fromObject, ['name']);
517
+ if (fromName != null) {
518
+ setValueByPath(toObject, ['name'], fromName);
519
+ }
520
+ const fromMetadata = getValueByPath(fromObject, ['metadata']);
521
+ if (fromMetadata != null) {
522
+ setValueByPath(toObject, ['metadata'], fromMetadata);
523
+ }
524
+ const fromDone = getValueByPath(fromObject, ['done']);
525
+ if (fromDone != null) {
526
+ setValueByPath(toObject, ['done'], fromDone);
527
+ }
528
+ const fromError = getValueByPath(fromObject, ['error']);
529
+ if (fromError != null) {
530
+ setValueByPath(toObject, ['error'], fromError);
531
+ }
532
+ const fromResponse = getValueByPath(fromObject, ['response']);
533
+ if (fromResponse != null) {
534
+ setValueByPath(toObject, ['response'], uploadToFileSearchStoreResponseFromMldev(fromResponse));
535
+ }
536
+ return toObject;
537
+ }
538
+ function uploadToFileSearchStoreResponseFromMldev(fromObject) {
539
+ const toObject = {};
540
+ const fromSdkHttpResponse = getValueByPath(fromObject, [
541
+ 'sdkHttpResponse',
542
+ ]);
543
+ if (fromSdkHttpResponse != null) {
544
+ setValueByPath(toObject, ['sdkHttpResponse'], fromSdkHttpResponse);
545
+ }
546
+ const fromParent = getValueByPath(fromObject, ['parent']);
547
+ if (fromParent != null) {
548
+ setValueByPath(toObject, ['parent'], fromParent);
549
+ }
550
+ const fromDocumentName = getValueByPath(fromObject, ['documentName']);
551
+ if (fromDocumentName != null) {
552
+ setValueByPath(toObject, ['documentName'], fromDocumentName);
553
+ }
554
+ return toObject;
555
+ }
471
556
  function videoFromMldev$1(fromObject) {
472
557
  const toObject = {};
473
558
  const fromUri = getValueByPath(fromObject, ['uri']);
@@ -608,6 +693,22 @@ var Mode;
608
693
  */
609
694
  Mode["MODE_DYNAMIC"] = "MODE_DYNAMIC";
610
695
  })(Mode || (Mode = {}));
696
+ /** The API spec that the external API implements. This enum is not supported in Gemini API. */
697
+ var ApiSpec;
698
+ (function (ApiSpec) {
699
+ /**
700
+ * Unspecified API spec. This value should not be used.
701
+ */
702
+ ApiSpec["API_SPEC_UNSPECIFIED"] = "API_SPEC_UNSPECIFIED";
703
+ /**
704
+ * Simple search API spec.
705
+ */
706
+ ApiSpec["SIMPLE_SEARCH"] = "SIMPLE_SEARCH";
707
+ /**
708
+ * Elastic search API spec.
709
+ */
710
+ ApiSpec["ELASTIC_SEARCH"] = "ELASTIC_SEARCH";
711
+ })(ApiSpec || (ApiSpec = {}));
611
712
  /** Type of auth scheme. This enum is not supported in Gemini API. */
612
713
  var AuthType;
613
714
  (function (AuthType) {
@@ -637,22 +738,63 @@ var AuthType;
637
738
  */
638
739
  AuthType["OIDC_AUTH"] = "OIDC_AUTH";
639
740
  })(AuthType || (AuthType = {}));
640
- /** The API spec that the external API implements. This enum is not supported in Gemini API. */
641
- var ApiSpec;
642
- (function (ApiSpec) {
741
+ /** The location of the API key. This enum is not supported in Gemini API. */
742
+ var HttpElementLocation;
743
+ (function (HttpElementLocation) {
744
+ HttpElementLocation["HTTP_IN_UNSPECIFIED"] = "HTTP_IN_UNSPECIFIED";
643
745
  /**
644
- * Unspecified API spec. This value should not be used.
746
+ * Element is in the HTTP request query.
645
747
  */
646
- ApiSpec["API_SPEC_UNSPECIFIED"] = "API_SPEC_UNSPECIFIED";
748
+ HttpElementLocation["HTTP_IN_QUERY"] = "HTTP_IN_QUERY";
647
749
  /**
648
- * Simple search API spec.
750
+ * Element is in the HTTP request header.
649
751
  */
650
- ApiSpec["SIMPLE_SEARCH"] = "SIMPLE_SEARCH";
752
+ HttpElementLocation["HTTP_IN_HEADER"] = "HTTP_IN_HEADER";
651
753
  /**
652
- * Elastic search API spec.
754
+ * Element is in the HTTP request path.
653
755
  */
654
- ApiSpec["ELASTIC_SEARCH"] = "ELASTIC_SEARCH";
655
- })(ApiSpec || (ApiSpec = {}));
756
+ HttpElementLocation["HTTP_IN_PATH"] = "HTTP_IN_PATH";
757
+ /**
758
+ * Element is in the HTTP request body.
759
+ */
760
+ HttpElementLocation["HTTP_IN_BODY"] = "HTTP_IN_BODY";
761
+ /**
762
+ * Element is in the HTTP request cookie.
763
+ */
764
+ HttpElementLocation["HTTP_IN_COOKIE"] = "HTTP_IN_COOKIE";
765
+ })(HttpElementLocation || (HttpElementLocation = {}));
766
+ /** Sites with confidence level chosen & above this value will be blocked from the search results. This enum is not supported in Gemini API. */
767
+ var PhishBlockThreshold;
768
+ (function (PhishBlockThreshold) {
769
+ /**
770
+ * Defaults to unspecified.
771
+ */
772
+ PhishBlockThreshold["PHISH_BLOCK_THRESHOLD_UNSPECIFIED"] = "PHISH_BLOCK_THRESHOLD_UNSPECIFIED";
773
+ /**
774
+ * Blocks Low and above confidence URL that is risky.
775
+ */
776
+ PhishBlockThreshold["BLOCK_LOW_AND_ABOVE"] = "BLOCK_LOW_AND_ABOVE";
777
+ /**
778
+ * Blocks Medium and above confidence URL that is risky.
779
+ */
780
+ PhishBlockThreshold["BLOCK_MEDIUM_AND_ABOVE"] = "BLOCK_MEDIUM_AND_ABOVE";
781
+ /**
782
+ * Blocks High and above confidence URL that is risky.
783
+ */
784
+ PhishBlockThreshold["BLOCK_HIGH_AND_ABOVE"] = "BLOCK_HIGH_AND_ABOVE";
785
+ /**
786
+ * Blocks Higher and above confidence URL that is risky.
787
+ */
788
+ PhishBlockThreshold["BLOCK_HIGHER_AND_ABOVE"] = "BLOCK_HIGHER_AND_ABOVE";
789
+ /**
790
+ * Blocks Very high and above confidence URL that is risky.
791
+ */
792
+ PhishBlockThreshold["BLOCK_VERY_HIGH_AND_ABOVE"] = "BLOCK_VERY_HIGH_AND_ABOVE";
793
+ /**
794
+ * Blocks Extremely high confidence URL that is risky.
795
+ */
796
+ PhishBlockThreshold["BLOCK_ONLY_EXTREMELY_HIGH"] = "BLOCK_ONLY_EXTREMELY_HIGH";
797
+ })(PhishBlockThreshold || (PhishBlockThreshold = {}));
656
798
  /** Harm category. */
657
799
  var HarmCategory;
658
800
  (function (HarmCategory) {
@@ -919,7 +1061,7 @@ var BlockedReason;
919
1061
  */
920
1062
  BlockedReason["JAILBREAK"] = "JAILBREAK";
921
1063
  })(BlockedReason || (BlockedReason = {}));
922
- /** Output only. Traffic type. This shows whether a request consumes Pay-As-You-Go or Provisioned Throughput quota. This enum is not supported in Gemini API. */
1064
+ /** Output only. The traffic type for this request. This enum is not supported in Gemini API. */
923
1065
  var TrafficType;
924
1066
  (function (TrafficType) {
925
1067
  /**
@@ -927,7 +1069,7 @@ var TrafficType;
927
1069
  */
928
1070
  TrafficType["TRAFFIC_TYPE_UNSPECIFIED"] = "TRAFFIC_TYPE_UNSPECIFIED";
929
1071
  /**
930
- * Type for Pay-As-You-Go traffic.
1072
+ * The request was processed using Pay-As-You-Go quota.
931
1073
  */
932
1074
  TrafficType["ON_DEMAND"] = "ON_DEMAND";
933
1075
  /**
@@ -1090,6 +1232,10 @@ var TuningTask;
1090
1232
  * Tuning task for text to video.
1091
1233
  */
1092
1234
  TuningTask["TUNING_TASK_T2V"] = "TUNING_TASK_T2V";
1235
+ /**
1236
+ * Tuning task for reference to video.
1237
+ */
1238
+ TuningTask["TUNING_TASK_R2V"] = "TUNING_TASK_R2V";
1093
1239
  })(TuningTask || (TuningTask = {}));
1094
1240
  /** Options for feature selection preference. */
1095
1241
  var FeatureSelectionPreference;
@@ -1337,6 +1483,14 @@ var TuningMethod;
1337
1483
  */
1338
1484
  TuningMethod["PREFERENCE_TUNING"] = "PREFERENCE_TUNING";
1339
1485
  })(TuningMethod || (TuningMethod = {}));
1486
+ /** State for the lifecycle of a Document. */
1487
+ var DocumentState;
1488
+ (function (DocumentState) {
1489
+ DocumentState["STATE_UNSPECIFIED"] = "STATE_UNSPECIFIED";
1490
+ DocumentState["STATE_PENDING"] = "STATE_PENDING";
1491
+ DocumentState["STATE_ACTIVE"] = "STATE_ACTIVE";
1492
+ DocumentState["STATE_FAILED"] = "STATE_FAILED";
1493
+ })(DocumentState || (DocumentState = {}));
1340
1494
  /** State for the lifecycle of a File. */
1341
1495
  var FileState;
1342
1496
  (function (FileState) {
@@ -1764,7 +1918,7 @@ class HttpResponse {
1764
1918
  /** Content filter results for a prompt sent in the request. Note: This is sent only in the first stream chunk and only if no candidates were generated due to content violations. */
1765
1919
  class GenerateContentResponsePromptFeedback {
1766
1920
  }
1767
- /** Usage metadata about response(s). This data type is not supported in Gemini API. */
1921
+ /** Usage metadata about the content generation request and response. This message provides a detailed breakdown of token usage and other relevant metrics. This data type is not supported in Gemini API. */
1768
1922
  class GenerateContentResponseUsageMetadata {
1769
1923
  }
1770
1924
  /** Response message for PredictionService.GenerateContent. */
@@ -1806,6 +1960,7 @@ class GenerateContentResponse {
1806
1960
  for (const [fieldName, fieldValue] of Object.entries(part)) {
1807
1961
  if (fieldName !== 'text' &&
1808
1962
  fieldName !== 'thought' &&
1963
+ fieldName !== 'thoughtSignature' &&
1809
1964
  (fieldValue !== null || fieldValue !== undefined)) {
1810
1965
  nonTextParts.push(fieldName);
1811
1966
  }
@@ -2029,11 +2184,11 @@ class GenerateVideosOperation {
2029
2184
  * Instantiates an Operation of the same type as the one being called with the fields set from the API response.
2030
2185
  * @internal
2031
2186
  */
2032
- _fromAPIResponse({ apiResponse, isVertexAI, }) {
2187
+ _fromAPIResponse({ apiResponse, _isVertexAI, }) {
2033
2188
  const operation = new GenerateVideosOperation();
2034
2189
  let response;
2035
2190
  const op = apiResponse;
2036
- if (isVertexAI) {
2191
+ if (_isVertexAI) {
2037
2192
  response = generateVideosOperationFromVertex$1(op);
2038
2193
  }
2039
2194
  else {
@@ -2051,6 +2206,32 @@ class DeleteCachedContentResponse {
2051
2206
  }
2052
2207
  class ListCachedContentsResponse {
2053
2208
  }
2209
+ /** Config for documents.list return value. */
2210
+ class ListDocumentsResponse {
2211
+ }
2212
+ /** Config for file_search_stores.list return value. */
2213
+ class ListFileSearchStoresResponse {
2214
+ }
2215
+ /** Response for the resumable upload method. */
2216
+ class UploadToFileSearchStoreResumableResponse {
2217
+ }
2218
+ /** Response for ImportFile to import a File API file with a file search store. */
2219
+ class ImportFileResponse {
2220
+ }
2221
+ /** Long-running operation for importing a file to a FileSearchStore. */
2222
+ class ImportFileOperation {
2223
+ /**
2224
+ * Instantiates an Operation of the same type as the one being called with the fields set from the API response.
2225
+ * @internal
2226
+ */
2227
+ _fromAPIResponse({ apiResponse, _isVertexAI, }) {
2228
+ const operation = new ImportFileOperation();
2229
+ const op = apiResponse;
2230
+ const response = importFileOperationFromMldev$1(op);
2231
+ Object.assign(operation, response);
2232
+ return operation;
2233
+ }
2234
+ }
2054
2235
  /** Response for the list files method. */
2055
2236
  class ListFilesResponse {
2056
2237
  }
@@ -2286,6 +2467,23 @@ class LiveMusicServerMessage {
2286
2467
  return undefined;
2287
2468
  }
2288
2469
  }
2470
+ /** The response when long-running operation for uploading a file to a FileSearchStore complete. */
2471
+ class UploadToFileSearchStoreResponse {
2472
+ }
2473
+ /** Long-running operation for uploading a file to a FileSearchStore. */
2474
+ class UploadToFileSearchStoreOperation {
2475
+ /**
2476
+ * Instantiates an Operation of the same type as the one being called with the fields set from the API response.
2477
+ * @internal
2478
+ */
2479
+ _fromAPIResponse({ apiResponse, _isVertexAI, }) {
2480
+ const operation = new UploadToFileSearchStoreOperation();
2481
+ const op = apiResponse;
2482
+ const response = uploadToFileSearchStoreOperationFromMldev(op);
2483
+ Object.assign(operation, response);
2484
+ return operation;
2485
+ }
2486
+ }
2289
2487
 
2290
2488
  /**
2291
2489
  * @license
@@ -2296,6 +2494,9 @@ function tModel(apiClient, model) {
2296
2494
  if (!model || typeof model !== 'string') {
2297
2495
  throw new Error('model is required and must be a string');
2298
2496
  }
2497
+ if (model.includes('..') || model.includes('?') || model.includes('&')) {
2498
+ throw new Error('invalid model parameter');
2499
+ }
2299
2500
  if (apiClient.isVertexAI()) {
2300
2501
  if (model.startsWith('publishers/') ||
2301
2502
  model.startsWith('projects/') ||
@@ -3282,6 +3483,12 @@ function batchJobFromVertex(fromObject) {
3282
3483
  if (fromDest != null) {
3283
3484
  setValueByPath(toObject, ['dest'], batchJobDestinationFromVertex(tRecvBatchJobDestination(fromDest)));
3284
3485
  }
3486
+ const fromCompletionStats = getValueByPath(fromObject, [
3487
+ 'completionStats',
3488
+ ]);
3489
+ if (fromCompletionStats != null) {
3490
+ setValueByPath(toObject, ['completionStats'], fromCompletionStats);
3491
+ }
3285
3492
  return toObject;
3286
3493
  }
3287
3494
  function batchJobSourceFromVertex(fromObject) {
@@ -3914,6 +4121,9 @@ function googleSearchToMldev$4(fromObject) {
3914
4121
  if (getValueByPath(fromObject, ['excludeDomains']) !== undefined) {
3915
4122
  throw new Error('excludeDomains parameter is not supported in Gemini API.');
3916
4123
  }
4124
+ if (getValueByPath(fromObject, ['blockingConfidence']) !== undefined) {
4125
+ throw new Error('blockingConfidence parameter is not supported in Gemini API.');
4126
+ }
3917
4127
  const fromTimeRangeFilter = getValueByPath(fromObject, [
3918
4128
  'timeRangeFilter',
3919
4129
  ]);
@@ -4153,14 +4363,14 @@ function toolToMldev$4(fromObject) {
4153
4363
  if (fromGoogleSearchRetrieval != null) {
4154
4364
  setValueByPath(toObject, ['googleSearchRetrieval'], fromGoogleSearchRetrieval);
4155
4365
  }
4156
- const fromGoogleMaps = getValueByPath(fromObject, ['googleMaps']);
4157
- if (fromGoogleMaps != null) {
4158
- setValueByPath(toObject, ['googleMaps'], googleMapsToMldev$4(fromGoogleMaps));
4159
- }
4160
4366
  const fromComputerUse = getValueByPath(fromObject, ['computerUse']);
4161
4367
  if (fromComputerUse != null) {
4162
4368
  setValueByPath(toObject, ['computerUse'], fromComputerUse);
4163
4369
  }
4370
+ const fromFileSearch = getValueByPath(fromObject, ['fileSearch']);
4371
+ if (fromFileSearch != null) {
4372
+ setValueByPath(toObject, ['fileSearch'], fromFileSearch);
4373
+ }
4164
4374
  const fromCodeExecution = getValueByPath(fromObject, [
4165
4375
  'codeExecution',
4166
4376
  ]);
@@ -4170,6 +4380,10 @@ function toolToMldev$4(fromObject) {
4170
4380
  if (getValueByPath(fromObject, ['enterpriseWebSearch']) !== undefined) {
4171
4381
  throw new Error('enterpriseWebSearch parameter is not supported in Gemini API.');
4172
4382
  }
4383
+ const fromGoogleMaps = getValueByPath(fromObject, ['googleMaps']);
4384
+ if (fromGoogleMaps != null) {
4385
+ setValueByPath(toObject, ['googleMaps'], googleMapsToMldev$4(fromGoogleMaps));
4386
+ }
4173
4387
  const fromGoogleSearch = getValueByPath(fromObject, ['googleSearch']);
4174
4388
  if (fromGoogleSearch != null) {
4175
4389
  setValueByPath(toObject, ['googleSearch'], googleSearchToMldev$4(fromGoogleSearch));
@@ -4193,7 +4407,7 @@ var PagedItem;
4193
4407
  PagedItem["PAGED_ITEM_TUNING_JOBS"] = "tuningJobs";
4194
4408
  PagedItem["PAGED_ITEM_FILES"] = "files";
4195
4409
  PagedItem["PAGED_ITEM_CACHED_CONTENTS"] = "cachedContents";
4196
- PagedItem["PAGED_ITEM_RAG_STORES"] = "ragStores";
4410
+ PagedItem["PAGED_ITEM_FILE_SEARCH_STORES"] = "fileSearchStores";
4197
4411
  PagedItem["PAGED_ITEM_DOCUMENTS"] = "documents";
4198
4412
  })(PagedItem || (PagedItem = {}));
4199
4413
  /**
@@ -5147,6 +5361,9 @@ function googleSearchToMldev$3(fromObject) {
5147
5361
  if (getValueByPath(fromObject, ['excludeDomains']) !== undefined) {
5148
5362
  throw new Error('excludeDomains parameter is not supported in Gemini API.');
5149
5363
  }
5364
+ if (getValueByPath(fromObject, ['blockingConfidence']) !== undefined) {
5365
+ throw new Error('blockingConfidence parameter is not supported in Gemini API.');
5366
+ }
5150
5367
  const fromTimeRangeFilter = getValueByPath(fromObject, [
5151
5368
  'timeRangeFilter',
5152
5369
  ]);
@@ -5328,14 +5545,14 @@ function toolToMldev$3(fromObject) {
5328
5545
  if (fromGoogleSearchRetrieval != null) {
5329
5546
  setValueByPath(toObject, ['googleSearchRetrieval'], fromGoogleSearchRetrieval);
5330
5547
  }
5331
- const fromGoogleMaps = getValueByPath(fromObject, ['googleMaps']);
5332
- if (fromGoogleMaps != null) {
5333
- setValueByPath(toObject, ['googleMaps'], googleMapsToMldev$3(fromGoogleMaps));
5334
- }
5335
5548
  const fromComputerUse = getValueByPath(fromObject, ['computerUse']);
5336
5549
  if (fromComputerUse != null) {
5337
5550
  setValueByPath(toObject, ['computerUse'], fromComputerUse);
5338
5551
  }
5552
+ const fromFileSearch = getValueByPath(fromObject, ['fileSearch']);
5553
+ if (fromFileSearch != null) {
5554
+ setValueByPath(toObject, ['fileSearch'], fromFileSearch);
5555
+ }
5339
5556
  const fromCodeExecution = getValueByPath(fromObject, [
5340
5557
  'codeExecution',
5341
5558
  ]);
@@ -5345,6 +5562,10 @@ function toolToMldev$3(fromObject) {
5345
5562
  if (getValueByPath(fromObject, ['enterpriseWebSearch']) !== undefined) {
5346
5563
  throw new Error('enterpriseWebSearch parameter is not supported in Gemini API.');
5347
5564
  }
5565
+ const fromGoogleMaps = getValueByPath(fromObject, ['googleMaps']);
5566
+ if (fromGoogleMaps != null) {
5567
+ setValueByPath(toObject, ['googleMaps'], googleMapsToMldev$3(fromGoogleMaps));
5568
+ }
5348
5569
  const fromGoogleSearch = getValueByPath(fromObject, ['googleSearch']);
5349
5570
  if (fromGoogleSearch != null) {
5350
5571
  setValueByPath(toObject, ['googleSearch'], googleSearchToMldev$3(fromGoogleSearch));
@@ -5379,14 +5600,13 @@ function toolToVertex$2(fromObject) {
5379
5600
  if (fromGoogleSearchRetrieval != null) {
5380
5601
  setValueByPath(toObject, ['googleSearchRetrieval'], fromGoogleSearchRetrieval);
5381
5602
  }
5382
- const fromGoogleMaps = getValueByPath(fromObject, ['googleMaps']);
5383
- if (fromGoogleMaps != null) {
5384
- setValueByPath(toObject, ['googleMaps'], fromGoogleMaps);
5385
- }
5386
5603
  const fromComputerUse = getValueByPath(fromObject, ['computerUse']);
5387
5604
  if (fromComputerUse != null) {
5388
5605
  setValueByPath(toObject, ['computerUse'], fromComputerUse);
5389
5606
  }
5607
+ if (getValueByPath(fromObject, ['fileSearch']) !== undefined) {
5608
+ throw new Error('fileSearch parameter is not supported in Vertex AI.');
5609
+ }
5390
5610
  const fromCodeExecution = getValueByPath(fromObject, [
5391
5611
  'codeExecution',
5392
5612
  ]);
@@ -5399,6 +5619,10 @@ function toolToVertex$2(fromObject) {
5399
5619
  if (fromEnterpriseWebSearch != null) {
5400
5620
  setValueByPath(toObject, ['enterpriseWebSearch'], fromEnterpriseWebSearch);
5401
5621
  }
5622
+ const fromGoogleMaps = getValueByPath(fromObject, ['googleMaps']);
5623
+ if (fromGoogleMaps != null) {
5624
+ setValueByPath(toObject, ['googleMaps'], fromGoogleMaps);
5625
+ }
5402
5626
  const fromGoogleSearch = getValueByPath(fromObject, ['googleSearch']);
5403
5627
  if (fromGoogleSearch != null) {
5404
5628
  setValueByPath(toObject, ['googleSearch'], fromGoogleSearch);
@@ -6704,6 +6928,12 @@ function generationConfigToVertex$1(fromObject) {
6704
6928
  if (fromModelSelectionConfig != null) {
6705
6929
  setValueByPath(toObject, ['modelConfig'], fromModelSelectionConfig);
6706
6930
  }
6931
+ const fromResponseJsonSchema = getValueByPath(fromObject, [
6932
+ 'responseJsonSchema',
6933
+ ]);
6934
+ if (fromResponseJsonSchema != null) {
6935
+ setValueByPath(toObject, ['responseJsonSchema'], fromResponseJsonSchema);
6936
+ }
6707
6937
  const fromAudioTimestamp = getValueByPath(fromObject, [
6708
6938
  'audioTimestamp',
6709
6939
  ]);
@@ -6750,12 +6980,6 @@ function generationConfigToVertex$1(fromObject) {
6750
6980
  if (fromPresencePenalty != null) {
6751
6981
  setValueByPath(toObject, ['presencePenalty'], fromPresencePenalty);
6752
6982
  }
6753
- const fromResponseJsonSchema = getValueByPath(fromObject, [
6754
- 'responseJsonSchema',
6755
- ]);
6756
- if (fromResponseJsonSchema != null) {
6757
- setValueByPath(toObject, ['responseJsonSchema'], fromResponseJsonSchema);
6758
- }
6759
6983
  const fromResponseLogprobs = getValueByPath(fromObject, [
6760
6984
  'responseLogprobs',
6761
6985
  ]);
@@ -6840,6 +7064,9 @@ function googleSearchToMldev$2(fromObject) {
6840
7064
  if (getValueByPath(fromObject, ['excludeDomains']) !== undefined) {
6841
7065
  throw new Error('excludeDomains parameter is not supported in Gemini API.');
6842
7066
  }
7067
+ if (getValueByPath(fromObject, ['blockingConfidence']) !== undefined) {
7068
+ throw new Error('blockingConfidence parameter is not supported in Gemini API.');
7069
+ }
6843
7070
  const fromTimeRangeFilter = getValueByPath(fromObject, [
6844
7071
  'timeRangeFilter',
6845
7072
  ]);
@@ -7347,14 +7574,14 @@ function toolToMldev$2(fromObject) {
7347
7574
  if (fromGoogleSearchRetrieval != null) {
7348
7575
  setValueByPath(toObject, ['googleSearchRetrieval'], fromGoogleSearchRetrieval);
7349
7576
  }
7350
- const fromGoogleMaps = getValueByPath(fromObject, ['googleMaps']);
7351
- if (fromGoogleMaps != null) {
7352
- setValueByPath(toObject, ['googleMaps'], googleMapsToMldev$2(fromGoogleMaps));
7353
- }
7354
7577
  const fromComputerUse = getValueByPath(fromObject, ['computerUse']);
7355
7578
  if (fromComputerUse != null) {
7356
7579
  setValueByPath(toObject, ['computerUse'], fromComputerUse);
7357
7580
  }
7581
+ const fromFileSearch = getValueByPath(fromObject, ['fileSearch']);
7582
+ if (fromFileSearch != null) {
7583
+ setValueByPath(toObject, ['fileSearch'], fromFileSearch);
7584
+ }
7358
7585
  const fromCodeExecution = getValueByPath(fromObject, [
7359
7586
  'codeExecution',
7360
7587
  ]);
@@ -7364,6 +7591,10 @@ function toolToMldev$2(fromObject) {
7364
7591
  if (getValueByPath(fromObject, ['enterpriseWebSearch']) !== undefined) {
7365
7592
  throw new Error('enterpriseWebSearch parameter is not supported in Gemini API.');
7366
7593
  }
7594
+ const fromGoogleMaps = getValueByPath(fromObject, ['googleMaps']);
7595
+ if (fromGoogleMaps != null) {
7596
+ setValueByPath(toObject, ['googleMaps'], googleMapsToMldev$2(fromGoogleMaps));
7597
+ }
7367
7598
  const fromGoogleSearch = getValueByPath(fromObject, ['googleSearch']);
7368
7599
  if (fromGoogleSearch != null) {
7369
7600
  setValueByPath(toObject, ['googleSearch'], googleSearchToMldev$2(fromGoogleSearch));
@@ -7398,14 +7629,13 @@ function toolToVertex$1(fromObject) {
7398
7629
  if (fromGoogleSearchRetrieval != null) {
7399
7630
  setValueByPath(toObject, ['googleSearchRetrieval'], fromGoogleSearchRetrieval);
7400
7631
  }
7401
- const fromGoogleMaps = getValueByPath(fromObject, ['googleMaps']);
7402
- if (fromGoogleMaps != null) {
7403
- setValueByPath(toObject, ['googleMaps'], fromGoogleMaps);
7404
- }
7405
7632
  const fromComputerUse = getValueByPath(fromObject, ['computerUse']);
7406
7633
  if (fromComputerUse != null) {
7407
7634
  setValueByPath(toObject, ['computerUse'], fromComputerUse);
7408
7635
  }
7636
+ if (getValueByPath(fromObject, ['fileSearch']) !== undefined) {
7637
+ throw new Error('fileSearch parameter is not supported in Vertex AI.');
7638
+ }
7409
7639
  const fromCodeExecution = getValueByPath(fromObject, [
7410
7640
  'codeExecution',
7411
7641
  ]);
@@ -7418,6 +7648,10 @@ function toolToVertex$1(fromObject) {
7418
7648
  if (fromEnterpriseWebSearch != null) {
7419
7649
  setValueByPath(toObject, ['enterpriseWebSearch'], fromEnterpriseWebSearch);
7420
7650
  }
7651
+ const fromGoogleMaps = getValueByPath(fromObject, ['googleMaps']);
7652
+ if (fromGoogleMaps != null) {
7653
+ setValueByPath(toObject, ['googleMaps'], fromGoogleMaps);
7654
+ }
7421
7655
  const fromGoogleSearch = getValueByPath(fromObject, ['googleSearch']);
7422
7656
  if (fromGoogleSearch != null) {
7423
7657
  setValueByPath(toObject, ['googleSearch'], fromGoogleSearch);
@@ -9367,6 +9601,12 @@ function generationConfigToVertex(fromObject) {
9367
9601
  if (fromModelSelectionConfig != null) {
9368
9602
  setValueByPath(toObject, ['modelConfig'], fromModelSelectionConfig);
9369
9603
  }
9604
+ const fromResponseJsonSchema = getValueByPath(fromObject, [
9605
+ 'responseJsonSchema',
9606
+ ]);
9607
+ if (fromResponseJsonSchema != null) {
9608
+ setValueByPath(toObject, ['responseJsonSchema'], fromResponseJsonSchema);
9609
+ }
9370
9610
  const fromAudioTimestamp = getValueByPath(fromObject, [
9371
9611
  'audioTimestamp',
9372
9612
  ]);
@@ -9413,12 +9653,6 @@ function generationConfigToVertex(fromObject) {
9413
9653
  if (fromPresencePenalty != null) {
9414
9654
  setValueByPath(toObject, ['presencePenalty'], fromPresencePenalty);
9415
9655
  }
9416
- const fromResponseJsonSchema = getValueByPath(fromObject, [
9417
- 'responseJsonSchema',
9418
- ]);
9419
- if (fromResponseJsonSchema != null) {
9420
- setValueByPath(toObject, ['responseJsonSchema'], fromResponseJsonSchema);
9421
- }
9422
9656
  const fromResponseLogprobs = getValueByPath(fromObject, [
9423
9657
  'responseLogprobs',
9424
9658
  ]);
@@ -9519,6 +9753,9 @@ function googleSearchToMldev$1(fromObject) {
9519
9753
  if (getValueByPath(fromObject, ['excludeDomains']) !== undefined) {
9520
9754
  throw new Error('excludeDomains parameter is not supported in Gemini API.');
9521
9755
  }
9756
+ if (getValueByPath(fromObject, ['blockingConfidence']) !== undefined) {
9757
+ throw new Error('blockingConfidence parameter is not supported in Gemini API.');
9758
+ }
9522
9759
  const fromTimeRangeFilter = getValueByPath(fromObject, [
9523
9760
  'timeRangeFilter',
9524
9761
  ]);
@@ -9756,6 +9993,28 @@ function modelFromMldev(fromObject) {
9756
9993
  if (fromSupportedActions != null) {
9757
9994
  setValueByPath(toObject, ['supportedActions'], fromSupportedActions);
9758
9995
  }
9996
+ const fromTemperature = getValueByPath(fromObject, ['temperature']);
9997
+ if (fromTemperature != null) {
9998
+ setValueByPath(toObject, ['temperature'], fromTemperature);
9999
+ }
10000
+ const fromMaxTemperature = getValueByPath(fromObject, [
10001
+ 'maxTemperature',
10002
+ ]);
10003
+ if (fromMaxTemperature != null) {
10004
+ setValueByPath(toObject, ['maxTemperature'], fromMaxTemperature);
10005
+ }
10006
+ const fromTopP = getValueByPath(fromObject, ['topP']);
10007
+ if (fromTopP != null) {
10008
+ setValueByPath(toObject, ['topP'], fromTopP);
10009
+ }
10010
+ const fromTopK = getValueByPath(fromObject, ['topK']);
10011
+ if (fromTopK != null) {
10012
+ setValueByPath(toObject, ['topK'], fromTopK);
10013
+ }
10014
+ const fromThinking = getValueByPath(fromObject, ['thinking']);
10015
+ if (fromThinking != null) {
10016
+ setValueByPath(toObject, ['thinking'], fromThinking);
10017
+ }
9759
10018
  return toObject;
9760
10019
  }
9761
10020
  function modelFromVertex(fromObject) {
@@ -9884,7 +10143,7 @@ function recontextImageConfigToVertex(fromObject, parentObject) {
9884
10143
  }
9885
10144
  const fromBaseSteps = getValueByPath(fromObject, ['baseSteps']);
9886
10145
  if (parentObject !== undefined && fromBaseSteps != null) {
9887
- setValueByPath(parentObject, ['parameters', 'editConfig', 'baseSteps'], fromBaseSteps);
10146
+ setValueByPath(parentObject, ['parameters', 'baseSteps'], fromBaseSteps);
9888
10147
  }
9889
10148
  const fromOutputGcsUri = getValueByPath(fromObject, ['outputGcsUri']);
9890
10149
  if (parentObject !== undefined && fromOutputGcsUri != null) {
@@ -10221,14 +10480,14 @@ function toolToMldev$1(fromObject) {
10221
10480
  if (fromGoogleSearchRetrieval != null) {
10222
10481
  setValueByPath(toObject, ['googleSearchRetrieval'], fromGoogleSearchRetrieval);
10223
10482
  }
10224
- const fromGoogleMaps = getValueByPath(fromObject, ['googleMaps']);
10225
- if (fromGoogleMaps != null) {
10226
- setValueByPath(toObject, ['googleMaps'], googleMapsToMldev$1(fromGoogleMaps));
10227
- }
10228
10483
  const fromComputerUse = getValueByPath(fromObject, ['computerUse']);
10229
10484
  if (fromComputerUse != null) {
10230
10485
  setValueByPath(toObject, ['computerUse'], fromComputerUse);
10231
10486
  }
10487
+ const fromFileSearch = getValueByPath(fromObject, ['fileSearch']);
10488
+ if (fromFileSearch != null) {
10489
+ setValueByPath(toObject, ['fileSearch'], fromFileSearch);
10490
+ }
10232
10491
  const fromCodeExecution = getValueByPath(fromObject, [
10233
10492
  'codeExecution',
10234
10493
  ]);
@@ -10238,6 +10497,10 @@ function toolToMldev$1(fromObject) {
10238
10497
  if (getValueByPath(fromObject, ['enterpriseWebSearch']) !== undefined) {
10239
10498
  throw new Error('enterpriseWebSearch parameter is not supported in Gemini API.');
10240
10499
  }
10500
+ const fromGoogleMaps = getValueByPath(fromObject, ['googleMaps']);
10501
+ if (fromGoogleMaps != null) {
10502
+ setValueByPath(toObject, ['googleMaps'], googleMapsToMldev$1(fromGoogleMaps));
10503
+ }
10241
10504
  const fromGoogleSearch = getValueByPath(fromObject, ['googleSearch']);
10242
10505
  if (fromGoogleSearch != null) {
10243
10506
  setValueByPath(toObject, ['googleSearch'], googleSearchToMldev$1(fromGoogleSearch));
@@ -10272,14 +10535,13 @@ function toolToVertex(fromObject) {
10272
10535
  if (fromGoogleSearchRetrieval != null) {
10273
10536
  setValueByPath(toObject, ['googleSearchRetrieval'], fromGoogleSearchRetrieval);
10274
10537
  }
10275
- const fromGoogleMaps = getValueByPath(fromObject, ['googleMaps']);
10276
- if (fromGoogleMaps != null) {
10277
- setValueByPath(toObject, ['googleMaps'], fromGoogleMaps);
10278
- }
10279
10538
  const fromComputerUse = getValueByPath(fromObject, ['computerUse']);
10280
10539
  if (fromComputerUse != null) {
10281
10540
  setValueByPath(toObject, ['computerUse'], fromComputerUse);
10282
10541
  }
10542
+ if (getValueByPath(fromObject, ['fileSearch']) !== undefined) {
10543
+ throw new Error('fileSearch parameter is not supported in Vertex AI.');
10544
+ }
10283
10545
  const fromCodeExecution = getValueByPath(fromObject, [
10284
10546
  'codeExecution',
10285
10547
  ]);
@@ -10292,6 +10554,10 @@ function toolToVertex(fromObject) {
10292
10554
  if (fromEnterpriseWebSearch != null) {
10293
10555
  setValueByPath(toObject, ['enterpriseWebSearch'], fromEnterpriseWebSearch);
10294
10556
  }
10557
+ const fromGoogleMaps = getValueByPath(fromObject, ['googleMaps']);
10558
+ if (fromGoogleMaps != null) {
10559
+ setValueByPath(toObject, ['googleMaps'], fromGoogleMaps);
10560
+ }
10295
10561
  const fromGoogleSearch = getValueByPath(fromObject, ['googleSearch']);
10296
10562
  if (fromGoogleSearch != null) {
10297
10563
  setValueByPath(toObject, ['googleSearch'], fromGoogleSearch);
@@ -10621,7 +10887,7 @@ const CONTENT_TYPE_HEADER = 'Content-Type';
10621
10887
  const SERVER_TIMEOUT_HEADER = 'X-Server-Timeout';
10622
10888
  const USER_AGENT_HEADER = 'User-Agent';
10623
10889
  const GOOGLE_API_CLIENT_HEADER = 'x-goog-api-client';
10624
- const SDK_VERSION = '1.28.0'; // x-release-please-version
10890
+ const SDK_VERSION = '1.29.1'; // x-release-please-version
10625
10891
  const LIBRARY_LABEL = `google-genai-sdk/${SDK_VERSION}`;
10626
10892
  const VERTEX_AI_API_DEFAULT_VERSION = 'v1beta1';
10627
10893
  const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
@@ -10999,6 +11265,15 @@ class ApiClient {
10999
11265
  await this.clientOptions.auth.addAuthHeaders(headers, url);
11000
11266
  return headers;
11001
11267
  }
11268
+ getFileName(file) {
11269
+ var _a;
11270
+ let fileName = '';
11271
+ if (typeof file === 'string') {
11272
+ fileName = file.replace(/[/\\]+$/, '');
11273
+ fileName = (_a = fileName.split(/[/\\]/).pop()) !== null && _a !== void 0 ? _a : '';
11274
+ }
11275
+ return fileName;
11276
+ }
11002
11277
  /**
11003
11278
  * Uploads a file asynchronously using Gemini API only, this is not supported
11004
11279
  * in Vertex AI.
@@ -11011,7 +11286,7 @@ class ApiClient {
11011
11286
  * @throws An error if the `mimeType` is not provided and can not be inferred,
11012
11287
  */
11013
11288
  async uploadFile(file, config) {
11014
- var _a, _b;
11289
+ var _a;
11015
11290
  const fileToUpload = {};
11016
11291
  if (config != null) {
11017
11292
  fileToUpload.mimeType = config.mimeType;
@@ -11029,14 +11304,47 @@ class ApiClient {
11029
11304
  throw new Error('Can not determine mimeType. Please provide mimeType in the config.');
11030
11305
  }
11031
11306
  fileToUpload.mimeType = mimeType;
11032
- let fileName = '';
11033
- if (typeof file === 'string') {
11034
- fileName = file.replace(/[/\\]+$/, '');
11035
- fileName = (_b = fileName.split(/[/\\]/).pop()) !== null && _b !== void 0 ? _b : '';
11036
- }
11037
- const uploadUrl = await this.fetchUploadUrl(fileToUpload, fileName, config);
11307
+ const body = {
11308
+ file: fileToUpload,
11309
+ };
11310
+ const fileName = this.getFileName(file);
11311
+ const path = formatMap('upload/v1beta/files', body['_url']);
11312
+ const uploadUrl = await this.fetchUploadUrl(path, fileToUpload.sizeBytes, fileToUpload.mimeType, fileName, body, config === null || config === void 0 ? void 0 : config.httpOptions);
11038
11313
  return uploader.upload(file, uploadUrl, this);
11039
11314
  }
11315
+ /**
11316
+ * Uploads a file to a given file search store asynchronously using Gemini API only, this is not supported
11317
+ * in Vertex AI.
11318
+ *
11319
+ * @param fileSearchStoreName The name of the file search store to upload the file to.
11320
+ * @param file The string path to the file to be uploaded or a Blob object.
11321
+ * @param config Optional parameters specified in the `UploadFileConfig`
11322
+ * interface. @see {@link UploadFileConfig}
11323
+ * @return A promise that resolves to a `File` object.
11324
+ * @throws An error if called on a Vertex AI client.
11325
+ * @throws An error if the `mimeType` is not provided and can not be inferred,
11326
+ */
11327
+ async uploadFileToFileSearchStore(fileSearchStoreName, file, config) {
11328
+ var _a;
11329
+ const uploader = this.clientOptions.uploader;
11330
+ const fileStat = await uploader.stat(file);
11331
+ const sizeBytes = String(fileStat.size);
11332
+ const mimeType = (_a = config === null || config === void 0 ? void 0 : config.mimeType) !== null && _a !== void 0 ? _a : fileStat.type;
11333
+ if (mimeType === undefined || mimeType === '') {
11334
+ throw new Error('Can not determine mimeType. Please provide mimeType in the config.');
11335
+ }
11336
+ const path = `upload/v1beta/${fileSearchStoreName}:uploadToFileSearchStore`;
11337
+ const fileName = this.getFileName(file);
11338
+ const body = {};
11339
+ if (config === null || config === void 0 ? void 0 : config.customMetadata) {
11340
+ body['customMetadata'] = config.customMetadata;
11341
+ }
11342
+ if (config === null || config === void 0 ? void 0 : config.chunkingConfig) {
11343
+ body['chunkingConfig'] = config.chunkingConfig;
11344
+ }
11345
+ const uploadUrl = await this.fetchUploadUrl(path, sizeBytes, mimeType, fileName, body, config === null || config === void 0 ? void 0 : config.httpOptions);
11346
+ return uploader.uploadToFileSearchStore(file, uploadUrl, this);
11347
+ }
11040
11348
  /**
11041
11349
  * Downloads a file asynchronously to the specified path.
11042
11350
  *
@@ -11047,23 +11355,20 @@ class ApiClient {
11047
11355
  const downloader = this.clientOptions.downloader;
11048
11356
  await downloader.download(params, this);
11049
11357
  }
11050
- async fetchUploadUrl(file, fileName, config) {
11358
+ async fetchUploadUrl(path, sizeBytes, mimeType, fileName, body, configHttpOptions) {
11051
11359
  var _a;
11052
11360
  let httpOptions = {};
11053
- if (config === null || config === void 0 ? void 0 : config.httpOptions) {
11054
- httpOptions = config.httpOptions;
11361
+ if (configHttpOptions) {
11362
+ httpOptions = configHttpOptions;
11055
11363
  }
11056
11364
  else {
11057
11365
  httpOptions = {
11058
11366
  apiVersion: '',
11059
- headers: Object.assign({ 'Content-Type': 'application/json', 'X-Goog-Upload-Protocol': 'resumable', 'X-Goog-Upload-Command': 'start', 'X-Goog-Upload-Header-Content-Length': `${file.sizeBytes}`, 'X-Goog-Upload-Header-Content-Type': `${file.mimeType}` }, (fileName ? { 'X-Goog-Upload-File-Name': fileName } : {})),
11367
+ headers: Object.assign({ 'Content-Type': 'application/json', 'X-Goog-Upload-Protocol': 'resumable', 'X-Goog-Upload-Command': 'start', 'X-Goog-Upload-Header-Content-Length': `${sizeBytes}`, 'X-Goog-Upload-Header-Content-Type': `${mimeType}` }, (fileName ? { 'X-Goog-Upload-File-Name': fileName } : {})),
11060
11368
  };
11061
11369
  }
11062
- const body = {
11063
- 'file': file,
11064
- };
11065
11370
  const httpResponse = await this.request({
11066
- path: formatMap('upload/v1beta/files', body['_url']),
11371
+ path,
11067
11372
  body: JSON.stringify(body),
11068
11373
  httpMethod: 'POST',
11069
11374
  httpOptions,
@@ -12067,11 +12372,27 @@ function hasCallableTools(params) {
12067
12372
  var _a, _b, _c;
12068
12373
  return (_c = (_b = (_a = params.config) === null || _a === void 0 ? void 0 : _a.tools) === null || _b === void 0 ? void 0 : _b.some((tool) => isCallableTool(tool))) !== null && _c !== void 0 ? _c : false;
12069
12374
  }
12070
- // Checks whether the list of tools contains any non-callable tools. Will return
12071
- // true if there is at least one non-Callable tool.
12072
- function hasNonCallableTools(params) {
12073
- var _a, _b, _c;
12074
- return (_c = (_b = (_a = params.config) === null || _a === void 0 ? void 0 : _a.tools) === null || _b === void 0 ? void 0 : _b.some((tool) => !isCallableTool(tool))) !== null && _c !== void 0 ? _c : false;
12375
+ /**
12376
+ * Returns the indexes of the tools that are not compatible with AFC.
12377
+ */
12378
+ function findAfcIncompatibleToolIndexes(params) {
12379
+ var _a;
12380
+ // Use number[] for an array of numbers in TypeScript
12381
+ const afcIncompatibleToolIndexes = [];
12382
+ if (!((_a = params === null || params === void 0 ? void 0 : params.config) === null || _a === void 0 ? void 0 : _a.tools)) {
12383
+ return afcIncompatibleToolIndexes;
12384
+ }
12385
+ params.config.tools.forEach((tool, index) => {
12386
+ if (isCallableTool(tool)) {
12387
+ return;
12388
+ }
12389
+ const geminiTool = tool;
12390
+ if (geminiTool.functionDeclarations &&
12391
+ geminiTool.functionDeclarations.length > 0) {
12392
+ afcIncompatibleToolIndexes.push(index);
12393
+ }
12394
+ });
12395
+ return afcIncompatibleToolIndexes;
12075
12396
  }
12076
12397
  /**
12077
12398
  * Returns whether to append automatic function calling history to the
@@ -12136,8 +12457,12 @@ class Models extends BaseModule {
12136
12457
  if (!hasCallableTools(params) || shouldDisableAfc(params.config)) {
12137
12458
  return await this.generateContentInternal(transformedParams);
12138
12459
  }
12139
- if (hasNonCallableTools(params)) {
12140
- throw new Error('Automatic function calling with CallableTools and Tools is not yet supported.');
12460
+ const incompatibleToolIndexes = findAfcIncompatibleToolIndexes(params);
12461
+ if (incompatibleToolIndexes.length > 0) {
12462
+ const formattedIndexes = incompatibleToolIndexes
12463
+ .map((index) => `tools[${index}]`)
12464
+ .join(', ');
12465
+ throw new Error(`Automatic function calling with CallableTools (or MCP objects) and basic FunctionDeclarations is not yet supported. Incompatible tools found at ${formattedIndexes}.`);
12141
12466
  }
12142
12467
  let response;
12143
12468
  let functionResponseContent;
@@ -12224,9 +12549,14 @@ class Models extends BaseModule {
12224
12549
  const transformedParams = await this.processParamsMaybeAddMcpUsage(params);
12225
12550
  return await this.generateContentStreamInternal(transformedParams);
12226
12551
  }
12227
- else {
12228
- return await this.processAfcStream(params);
12552
+ const incompatibleToolIndexes = findAfcIncompatibleToolIndexes(params);
12553
+ if (incompatibleToolIndexes.length > 0) {
12554
+ const formattedIndexes = incompatibleToolIndexes
12555
+ .map((index) => `tools[${index}]`)
12556
+ .join(', ');
12557
+ throw new Error(`Incompatible tools found at ${formattedIndexes}. Automatic function calling with CallableTools (or MCP objects) and basic FunctionDeclarations" is not yet supported.`);
12229
12558
  }
12559
+ return await this.processAfcStream(params);
12230
12560
  };
12231
12561
  /**
12232
12562
  * Generates an image based on a text description and configuration.
@@ -13622,7 +13952,7 @@ class Operations extends BaseModule {
13622
13952
  });
13623
13953
  return operation._fromAPIResponse({
13624
13954
  apiResponse: rawOperation,
13625
- isVertexAI: true,
13955
+ _isVertexAI: true,
13626
13956
  });
13627
13957
  }
13628
13958
  else {
@@ -13632,7 +13962,7 @@ class Operations extends BaseModule {
13632
13962
  });
13633
13963
  return operation._fromAPIResponse({
13634
13964
  apiResponse: rawOperation,
13635
- isVertexAI: false,
13965
+ _isVertexAI: false,
13636
13966
  });
13637
13967
  }
13638
13968
  }
@@ -13661,7 +13991,7 @@ class Operations extends BaseModule {
13661
13991
  });
13662
13992
  return operation._fromAPIResponse({
13663
13993
  apiResponse: rawOperation,
13664
- isVertexAI: true,
13994
+ _isVertexAI: true,
13665
13995
  });
13666
13996
  }
13667
13997
  else {
@@ -13671,7 +14001,7 @@ class Operations extends BaseModule {
13671
14001
  });
13672
14002
  return operation._fromAPIResponse({
13673
14003
  apiResponse: rawOperation,
13674
- isVertexAI: false,
14004
+ _isVertexAI: false,
13675
14005
  });
13676
14006
  }
13677
14007
  }
@@ -13859,6 +14189,9 @@ function googleSearchToMldev(fromObject) {
13859
14189
  if (getValueByPath(fromObject, ['excludeDomains']) !== undefined) {
13860
14190
  throw new Error('excludeDomains parameter is not supported in Gemini API.');
13861
14191
  }
14192
+ if (getValueByPath(fromObject, ['blockingConfidence']) !== undefined) {
14193
+ throw new Error('blockingConfidence parameter is not supported in Gemini API.');
14194
+ }
13862
14195
  const fromTimeRangeFilter = getValueByPath(fromObject, [
13863
14196
  'timeRangeFilter',
13864
14197
  ]);
@@ -14077,14 +14410,14 @@ function toolToMldev(fromObject) {
14077
14410
  if (fromGoogleSearchRetrieval != null) {
14078
14411
  setValueByPath(toObject, ['googleSearchRetrieval'], fromGoogleSearchRetrieval);
14079
14412
  }
14080
- const fromGoogleMaps = getValueByPath(fromObject, ['googleMaps']);
14081
- if (fromGoogleMaps != null) {
14082
- setValueByPath(toObject, ['googleMaps'], googleMapsToMldev(fromGoogleMaps));
14083
- }
14084
14413
  const fromComputerUse = getValueByPath(fromObject, ['computerUse']);
14085
14414
  if (fromComputerUse != null) {
14086
14415
  setValueByPath(toObject, ['computerUse'], fromComputerUse);
14087
14416
  }
14417
+ const fromFileSearch = getValueByPath(fromObject, ['fileSearch']);
14418
+ if (fromFileSearch != null) {
14419
+ setValueByPath(toObject, ['fileSearch'], fromFileSearch);
14420
+ }
14088
14421
  const fromCodeExecution = getValueByPath(fromObject, [
14089
14422
  'codeExecution',
14090
14423
  ]);
@@ -14094,6 +14427,10 @@ function toolToMldev(fromObject) {
14094
14427
  if (getValueByPath(fromObject, ['enterpriseWebSearch']) !== undefined) {
14095
14428
  throw new Error('enterpriseWebSearch parameter is not supported in Gemini API.');
14096
14429
  }
14430
+ const fromGoogleMaps = getValueByPath(fromObject, ['googleMaps']);
14431
+ if (fromGoogleMaps != null) {
14432
+ setValueByPath(toObject, ['googleMaps'], googleMapsToMldev(fromGoogleMaps));
14433
+ }
14097
14434
  const fromGoogleSearch = getValueByPath(fromObject, ['googleSearch']);
14098
14435
  if (fromGoogleSearch != null) {
14099
14436
  setValueByPath(toObject, ['googleSearch'], googleSearchToMldev(fromGoogleSearch));
@@ -14380,195 +14717,44 @@ class Tokens extends BaseModule {
14380
14717
  * Copyright 2025 Google LLC
14381
14718
  * SPDX-License-Identifier: Apache-2.0
14382
14719
  */
14383
- const GOOGLE_API_KEY_HEADER = 'x-goog-api-key';
14384
- const REQUIRED_VERTEX_AI_SCOPE = 'https://www.googleapis.com/auth/cloud-platform';
14385
- class NodeAuth {
14386
- constructor(opts) {
14387
- if (opts.apiKey !== undefined) {
14388
- this.apiKey = opts.apiKey;
14389
- return;
14390
- }
14391
- const vertexAuthOptions = buildGoogleAuthOptions(opts.googleAuthOptions);
14392
- this.googleAuth = new GoogleAuth(vertexAuthOptions);
14393
- }
14394
- async addAuthHeaders(headers, url) {
14395
- if (this.apiKey !== undefined) {
14396
- if (this.apiKey.startsWith('auth_tokens/')) {
14397
- throw new Error('Ephemeral tokens are only supported by the live API.');
14398
- }
14399
- this.addKeyHeader(headers);
14400
- return;
14401
- }
14402
- return this.addGoogleAuthHeaders(headers, url);
14403
- }
14404
- addKeyHeader(headers) {
14405
- if (headers.get(GOOGLE_API_KEY_HEADER) !== null) {
14406
- return;
14407
- }
14408
- if (this.apiKey === undefined) {
14409
- // This should never happen, this method is only called
14410
- // when apiKey is set.
14411
- throw new Error('Trying to set API key header but apiKey is not set');
14412
- }
14413
- headers.append(GOOGLE_API_KEY_HEADER, this.apiKey);
14414
- }
14415
- async addGoogleAuthHeaders(headers, url) {
14416
- if (this.googleAuth === undefined) {
14417
- // This should never happen, addGoogleAuthHeaders should only be
14418
- // called when there is no apiKey set and in these cases googleAuth
14419
- // is set.
14420
- throw new Error('Trying to set google-auth headers but googleAuth is unset');
14421
- }
14422
- const authHeaders = await this.googleAuth.getRequestHeaders(url);
14423
- for (const [key, value] of authHeaders) {
14424
- if (headers.get(key) !== null) {
14425
- continue;
14426
- }
14427
- headers.append(key, value);
14428
- }
14429
- }
14430
- }
14431
- function buildGoogleAuthOptions(googleAuthOptions) {
14432
- let authOptions;
14433
- if (!googleAuthOptions) {
14434
- authOptions = {
14435
- scopes: [REQUIRED_VERTEX_AI_SCOPE],
14436
- };
14437
- return authOptions;
14438
- }
14439
- else {
14440
- authOptions = googleAuthOptions;
14441
- if (!authOptions.scopes) {
14442
- authOptions.scopes = [REQUIRED_VERTEX_AI_SCOPE];
14443
- return authOptions;
14444
- }
14445
- else if ((typeof authOptions.scopes === 'string' &&
14446
- authOptions.scopes !== REQUIRED_VERTEX_AI_SCOPE) ||
14447
- (Array.isArray(authOptions.scopes) &&
14448
- authOptions.scopes.indexOf(REQUIRED_VERTEX_AI_SCOPE) < 0)) {
14449
- throw new Error(`Invalid auth scopes. Scopes must include: ${REQUIRED_VERTEX_AI_SCOPE}`);
14450
- }
14451
- return authOptions;
14452
- }
14453
- }
14454
-
14455
- /**
14456
- * @license
14457
- * Copyright 2025 Google LLC
14458
- * SPDX-License-Identifier: Apache-2.0
14459
- */
14460
- class NodeDownloader {
14461
- async download(params, apiClient) {
14462
- if (params.downloadPath) {
14463
- const response = await downloadFile(params, apiClient);
14464
- if (response instanceof HttpResponse) {
14465
- const writer = createWriteStream(params.downloadPath);
14466
- const body = Readable.fromWeb(response.responseInternal.body);
14467
- body.pipe(writer);
14468
- await finished(writer);
14469
- }
14470
- else {
14471
- try {
14472
- await writeFile(params.downloadPath, response, {
14473
- encoding: 'base64',
14474
- });
14475
- }
14476
- catch (error) {
14477
- throw new Error(`Failed to write file to ${params.downloadPath}: ${error}`);
14478
- }
14479
- }
14480
- }
14481
- }
14482
- }
14483
- async function downloadFile(params, apiClient) {
14484
- var _a, _b, _c;
14485
- const name = tFileName(params.file);
14486
- if (name !== undefined) {
14487
- return await apiClient.request({
14488
- path: `files/${name}:download`,
14489
- httpMethod: 'GET',
14490
- queryParams: {
14491
- 'alt': 'media',
14492
- },
14493
- httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
14494
- abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
14495
- });
14496
- }
14497
- else if (isGeneratedVideo(params.file)) {
14498
- const videoBytes = (_c = params.file.video) === null || _c === void 0 ? void 0 : _c.videoBytes;
14499
- if (typeof videoBytes === 'string') {
14500
- return videoBytes;
14501
- }
14502
- else {
14503
- throw new Error('Failed to download generated video, Uri or videoBytes not found.');
14504
- }
14505
- }
14506
- else if (isVideo(params.file)) {
14507
- const videoBytes = params.file.videoBytes;
14508
- if (typeof videoBytes === 'string') {
14509
- return videoBytes;
14510
- }
14511
- else {
14512
- throw new Error('Failed to download video, Uri or videoBytes not found.');
14513
- }
14514
- }
14515
- else {
14516
- throw new Error('Unsupported file type');
14720
+ // Code generated by the Google Gen AI SDK generator DO NOT EDIT.
14721
+ function createFileSearchStoreConfigToMldev(fromObject, parentObject) {
14722
+ const toObject = {};
14723
+ const fromDisplayName = getValueByPath(fromObject, ['displayName']);
14724
+ if (parentObject !== undefined && fromDisplayName != null) {
14725
+ setValueByPath(parentObject, ['displayName'], fromDisplayName);
14517
14726
  }
14727
+ return toObject;
14518
14728
  }
14519
-
14520
- /**
14521
- * @license
14522
- * Copyright 2025 Google LLC
14523
- * SPDX-License-Identifier: Apache-2.0
14524
- */
14525
- class NodeWebSocketFactory {
14526
- create(url, headers, callbacks) {
14527
- return new NodeWebSocket(url, headers, callbacks);
14729
+ function createFileSearchStoreParametersToMldev(fromObject) {
14730
+ const toObject = {};
14731
+ const fromConfig = getValueByPath(fromObject, ['config']);
14732
+ if (fromConfig != null) {
14733
+ createFileSearchStoreConfigToMldev(fromConfig, toObject);
14528
14734
  }
14735
+ return toObject;
14529
14736
  }
14530
- class NodeWebSocket {
14531
- constructor(url, headers, callbacks) {
14532
- this.url = url;
14533
- this.headers = headers;
14534
- this.callbacks = callbacks;
14535
- }
14536
- connect() {
14537
- this.ws = new NodeWs.WebSocket(this.url, { headers: this.headers });
14538
- this.ws.onopen = this.callbacks.onopen;
14539
- this.ws.onerror = this.callbacks.onerror;
14540
- this.ws.onclose = this.callbacks.onclose;
14541
- this.ws.onmessage = this.callbacks.onmessage;
14542
- }
14543
- send(message) {
14544
- if (this.ws === undefined) {
14545
- throw new Error('WebSocket is not connected');
14546
- }
14547
- this.ws.send(message);
14548
- }
14549
- close() {
14550
- if (this.ws === undefined) {
14551
- throw new Error('WebSocket is not connected');
14552
- }
14553
- this.ws.close();
14737
+ function deleteFileSearchStoreConfigToMldev(fromObject, parentObject) {
14738
+ const toObject = {};
14739
+ const fromForce = getValueByPath(fromObject, ['force']);
14740
+ if (parentObject !== undefined && fromForce != null) {
14741
+ setValueByPath(parentObject, ['_query', 'force'], fromForce);
14554
14742
  }
14743
+ return toObject;
14555
14744
  }
14556
-
14557
- /**
14558
- * @license
14559
- * Copyright 2025 Google LLC
14560
- * SPDX-License-Identifier: Apache-2.0
14561
- */
14562
- // Code generated by the Google Gen AI SDK generator DO NOT EDIT.
14563
- function cancelTuningJobParametersToMldev(fromObject, _rootObject) {
14745
+ function deleteFileSearchStoreParametersToMldev(fromObject) {
14564
14746
  const toObject = {};
14565
14747
  const fromName = getValueByPath(fromObject, ['name']);
14566
14748
  if (fromName != null) {
14567
14749
  setValueByPath(toObject, ['_url', 'name'], fromName);
14568
14750
  }
14751
+ const fromConfig = getValueByPath(fromObject, ['config']);
14752
+ if (fromConfig != null) {
14753
+ deleteFileSearchStoreConfigToMldev(fromConfig, toObject);
14754
+ }
14569
14755
  return toObject;
14570
14756
  }
14571
- function cancelTuningJobParametersToVertex(fromObject, _rootObject) {
14757
+ function getFileSearchStoreParametersToMldev(fromObject) {
14572
14758
  const toObject = {};
14573
14759
  const fromName = getValueByPath(fromObject, ['name']);
14574
14760
  if (fromName != null) {
@@ -14576,23 +14762,921 @@ function cancelTuningJobParametersToVertex(fromObject, _rootObject) {
14576
14762
  }
14577
14763
  return toObject;
14578
14764
  }
14579
- function createTuningJobConfigToMldev(fromObject, parentObject, _rootObject) {
14765
+ function importFileConfigToMldev(fromObject, parentObject) {
14580
14766
  const toObject = {};
14581
- if (getValueByPath(fromObject, ['validationDataset']) !== undefined) {
14582
- throw new Error('validationDataset parameter is not supported in Gemini API.');
14583
- }
14584
- const fromTunedModelDisplayName = getValueByPath(fromObject, [
14585
- 'tunedModelDisplayName',
14767
+ const fromCustomMetadata = getValueByPath(fromObject, [
14768
+ 'customMetadata',
14586
14769
  ]);
14587
- if (parentObject !== undefined && fromTunedModelDisplayName != null) {
14588
- setValueByPath(parentObject, ['displayName'], fromTunedModelDisplayName);
14589
- }
14590
- if (getValueByPath(fromObject, ['description']) !== undefined) {
14591
- throw new Error('description parameter is not supported in Gemini API.');
14770
+ if (parentObject !== undefined && fromCustomMetadata != null) {
14771
+ let transformedList = fromCustomMetadata;
14772
+ if (Array.isArray(transformedList)) {
14773
+ transformedList = transformedList.map((item) => {
14774
+ return item;
14775
+ });
14776
+ }
14777
+ setValueByPath(parentObject, ['customMetadata'], transformedList);
14592
14778
  }
14593
- const fromEpochCount = getValueByPath(fromObject, ['epochCount']);
14594
- if (parentObject !== undefined && fromEpochCount != null) {
14595
- setValueByPath(parentObject, ['tuningTask', 'hyperparameters', 'epochCount'], fromEpochCount);
14779
+ const fromChunkingConfig = getValueByPath(fromObject, [
14780
+ 'chunkingConfig',
14781
+ ]);
14782
+ if (parentObject !== undefined && fromChunkingConfig != null) {
14783
+ setValueByPath(parentObject, ['chunkingConfig'], fromChunkingConfig);
14784
+ }
14785
+ return toObject;
14786
+ }
14787
+ function importFileOperationFromMldev(fromObject) {
14788
+ const toObject = {};
14789
+ const fromName = getValueByPath(fromObject, ['name']);
14790
+ if (fromName != null) {
14791
+ setValueByPath(toObject, ['name'], fromName);
14792
+ }
14793
+ const fromMetadata = getValueByPath(fromObject, ['metadata']);
14794
+ if (fromMetadata != null) {
14795
+ setValueByPath(toObject, ['metadata'], fromMetadata);
14796
+ }
14797
+ const fromDone = getValueByPath(fromObject, ['done']);
14798
+ if (fromDone != null) {
14799
+ setValueByPath(toObject, ['done'], fromDone);
14800
+ }
14801
+ const fromError = getValueByPath(fromObject, ['error']);
14802
+ if (fromError != null) {
14803
+ setValueByPath(toObject, ['error'], fromError);
14804
+ }
14805
+ const fromResponse = getValueByPath(fromObject, ['response']);
14806
+ if (fromResponse != null) {
14807
+ setValueByPath(toObject, ['response'], importFileResponseFromMldev(fromResponse));
14808
+ }
14809
+ return toObject;
14810
+ }
14811
+ function importFileParametersToMldev(fromObject) {
14812
+ const toObject = {};
14813
+ const fromFileSearchStoreName = getValueByPath(fromObject, [
14814
+ 'fileSearchStoreName',
14815
+ ]);
14816
+ if (fromFileSearchStoreName != null) {
14817
+ setValueByPath(toObject, ['_url', 'file_search_store_name'], fromFileSearchStoreName);
14818
+ }
14819
+ const fromFileName = getValueByPath(fromObject, ['fileName']);
14820
+ if (fromFileName != null) {
14821
+ setValueByPath(toObject, ['fileName'], fromFileName);
14822
+ }
14823
+ const fromConfig = getValueByPath(fromObject, ['config']);
14824
+ if (fromConfig != null) {
14825
+ importFileConfigToMldev(fromConfig, toObject);
14826
+ }
14827
+ return toObject;
14828
+ }
14829
+ function importFileResponseFromMldev(fromObject) {
14830
+ const toObject = {};
14831
+ const fromSdkHttpResponse = getValueByPath(fromObject, [
14832
+ 'sdkHttpResponse',
14833
+ ]);
14834
+ if (fromSdkHttpResponse != null) {
14835
+ setValueByPath(toObject, ['sdkHttpResponse'], fromSdkHttpResponse);
14836
+ }
14837
+ const fromParent = getValueByPath(fromObject, ['parent']);
14838
+ if (fromParent != null) {
14839
+ setValueByPath(toObject, ['parent'], fromParent);
14840
+ }
14841
+ const fromDocumentName = getValueByPath(fromObject, ['documentName']);
14842
+ if (fromDocumentName != null) {
14843
+ setValueByPath(toObject, ['documentName'], fromDocumentName);
14844
+ }
14845
+ return toObject;
14846
+ }
14847
+ function listFileSearchStoresConfigToMldev(fromObject, parentObject) {
14848
+ const toObject = {};
14849
+ const fromPageSize = getValueByPath(fromObject, ['pageSize']);
14850
+ if (parentObject !== undefined && fromPageSize != null) {
14851
+ setValueByPath(parentObject, ['_query', 'pageSize'], fromPageSize);
14852
+ }
14853
+ const fromPageToken = getValueByPath(fromObject, ['pageToken']);
14854
+ if (parentObject !== undefined && fromPageToken != null) {
14855
+ setValueByPath(parentObject, ['_query', 'pageToken'], fromPageToken);
14856
+ }
14857
+ return toObject;
14858
+ }
14859
+ function listFileSearchStoresParametersToMldev(fromObject) {
14860
+ const toObject = {};
14861
+ const fromConfig = getValueByPath(fromObject, ['config']);
14862
+ if (fromConfig != null) {
14863
+ listFileSearchStoresConfigToMldev(fromConfig, toObject);
14864
+ }
14865
+ return toObject;
14866
+ }
14867
+ function listFileSearchStoresResponseFromMldev(fromObject) {
14868
+ const toObject = {};
14869
+ const fromSdkHttpResponse = getValueByPath(fromObject, [
14870
+ 'sdkHttpResponse',
14871
+ ]);
14872
+ if (fromSdkHttpResponse != null) {
14873
+ setValueByPath(toObject, ['sdkHttpResponse'], fromSdkHttpResponse);
14874
+ }
14875
+ const fromNextPageToken = getValueByPath(fromObject, [
14876
+ 'nextPageToken',
14877
+ ]);
14878
+ if (fromNextPageToken != null) {
14879
+ setValueByPath(toObject, ['nextPageToken'], fromNextPageToken);
14880
+ }
14881
+ const fromFileSearchStores = getValueByPath(fromObject, [
14882
+ 'fileSearchStores',
14883
+ ]);
14884
+ if (fromFileSearchStores != null) {
14885
+ let transformedList = fromFileSearchStores;
14886
+ if (Array.isArray(transformedList)) {
14887
+ transformedList = transformedList.map((item) => {
14888
+ return item;
14889
+ });
14890
+ }
14891
+ setValueByPath(toObject, ['fileSearchStores'], transformedList);
14892
+ }
14893
+ return toObject;
14894
+ }
14895
+ function uploadToFileSearchStoreConfigToMldev(fromObject, parentObject) {
14896
+ const toObject = {};
14897
+ const fromMimeType = getValueByPath(fromObject, ['mimeType']);
14898
+ if (parentObject !== undefined && fromMimeType != null) {
14899
+ setValueByPath(parentObject, ['mimeType'], fromMimeType);
14900
+ }
14901
+ const fromDisplayName = getValueByPath(fromObject, ['displayName']);
14902
+ if (parentObject !== undefined && fromDisplayName != null) {
14903
+ setValueByPath(parentObject, ['displayName'], fromDisplayName);
14904
+ }
14905
+ const fromCustomMetadata = getValueByPath(fromObject, [
14906
+ 'customMetadata',
14907
+ ]);
14908
+ if (parentObject !== undefined && fromCustomMetadata != null) {
14909
+ let transformedList = fromCustomMetadata;
14910
+ if (Array.isArray(transformedList)) {
14911
+ transformedList = transformedList.map((item) => {
14912
+ return item;
14913
+ });
14914
+ }
14915
+ setValueByPath(parentObject, ['customMetadata'], transformedList);
14916
+ }
14917
+ const fromChunkingConfig = getValueByPath(fromObject, [
14918
+ 'chunkingConfig',
14919
+ ]);
14920
+ if (parentObject !== undefined && fromChunkingConfig != null) {
14921
+ setValueByPath(parentObject, ['chunkingConfig'], fromChunkingConfig);
14922
+ }
14923
+ return toObject;
14924
+ }
14925
+ function uploadToFileSearchStoreParametersToMldev(fromObject) {
14926
+ const toObject = {};
14927
+ const fromFileSearchStoreName = getValueByPath(fromObject, [
14928
+ 'fileSearchStoreName',
14929
+ ]);
14930
+ if (fromFileSearchStoreName != null) {
14931
+ setValueByPath(toObject, ['_url', 'file_search_store_name'], fromFileSearchStoreName);
14932
+ }
14933
+ const fromConfig = getValueByPath(fromObject, ['config']);
14934
+ if (fromConfig != null) {
14935
+ uploadToFileSearchStoreConfigToMldev(fromConfig, toObject);
14936
+ }
14937
+ return toObject;
14938
+ }
14939
+ function uploadToFileSearchStoreResumableResponseFromMldev(fromObject) {
14940
+ const toObject = {};
14941
+ const fromSdkHttpResponse = getValueByPath(fromObject, [
14942
+ 'sdkHttpResponse',
14943
+ ]);
14944
+ if (fromSdkHttpResponse != null) {
14945
+ setValueByPath(toObject, ['sdkHttpResponse'], fromSdkHttpResponse);
14946
+ }
14947
+ return toObject;
14948
+ }
14949
+
14950
+ /**
14951
+ * @license
14952
+ * Copyright 2025 Google LLC
14953
+ * SPDX-License-Identifier: Apache-2.0
14954
+ */
14955
+ // Code generated by the Google Gen AI SDK generator DO NOT EDIT.
14956
+ function deleteDocumentConfigToMldev(fromObject, parentObject) {
14957
+ const toObject = {};
14958
+ const fromForce = getValueByPath(fromObject, ['force']);
14959
+ if (parentObject !== undefined && fromForce != null) {
14960
+ setValueByPath(parentObject, ['_query', 'force'], fromForce);
14961
+ }
14962
+ return toObject;
14963
+ }
14964
+ function deleteDocumentParametersToMldev(fromObject) {
14965
+ const toObject = {};
14966
+ const fromName = getValueByPath(fromObject, ['name']);
14967
+ if (fromName != null) {
14968
+ setValueByPath(toObject, ['_url', 'name'], fromName);
14969
+ }
14970
+ const fromConfig = getValueByPath(fromObject, ['config']);
14971
+ if (fromConfig != null) {
14972
+ deleteDocumentConfigToMldev(fromConfig, toObject);
14973
+ }
14974
+ return toObject;
14975
+ }
14976
+ function getDocumentParametersToMldev(fromObject) {
14977
+ const toObject = {};
14978
+ const fromName = getValueByPath(fromObject, ['name']);
14979
+ if (fromName != null) {
14980
+ setValueByPath(toObject, ['_url', 'name'], fromName);
14981
+ }
14982
+ return toObject;
14983
+ }
14984
+ function listDocumentsConfigToMldev(fromObject, parentObject) {
14985
+ const toObject = {};
14986
+ const fromPageSize = getValueByPath(fromObject, ['pageSize']);
14987
+ if (parentObject !== undefined && fromPageSize != null) {
14988
+ setValueByPath(parentObject, ['_query', 'pageSize'], fromPageSize);
14989
+ }
14990
+ const fromPageToken = getValueByPath(fromObject, ['pageToken']);
14991
+ if (parentObject !== undefined && fromPageToken != null) {
14992
+ setValueByPath(parentObject, ['_query', 'pageToken'], fromPageToken);
14993
+ }
14994
+ return toObject;
14995
+ }
14996
+ function listDocumentsParametersToMldev(fromObject) {
14997
+ const toObject = {};
14998
+ const fromParent = getValueByPath(fromObject, ['parent']);
14999
+ if (fromParent != null) {
15000
+ setValueByPath(toObject, ['_url', 'parent'], fromParent);
15001
+ }
15002
+ const fromConfig = getValueByPath(fromObject, ['config']);
15003
+ if (fromConfig != null) {
15004
+ listDocumentsConfigToMldev(fromConfig, toObject);
15005
+ }
15006
+ return toObject;
15007
+ }
15008
+ function listDocumentsResponseFromMldev(fromObject) {
15009
+ const toObject = {};
15010
+ const fromSdkHttpResponse = getValueByPath(fromObject, [
15011
+ 'sdkHttpResponse',
15012
+ ]);
15013
+ if (fromSdkHttpResponse != null) {
15014
+ setValueByPath(toObject, ['sdkHttpResponse'], fromSdkHttpResponse);
15015
+ }
15016
+ const fromNextPageToken = getValueByPath(fromObject, [
15017
+ 'nextPageToken',
15018
+ ]);
15019
+ if (fromNextPageToken != null) {
15020
+ setValueByPath(toObject, ['nextPageToken'], fromNextPageToken);
15021
+ }
15022
+ const fromDocuments = getValueByPath(fromObject, ['documents']);
15023
+ if (fromDocuments != null) {
15024
+ let transformedList = fromDocuments;
15025
+ if (Array.isArray(transformedList)) {
15026
+ transformedList = transformedList.map((item) => {
15027
+ return item;
15028
+ });
15029
+ }
15030
+ setValueByPath(toObject, ['documents'], transformedList);
15031
+ }
15032
+ return toObject;
15033
+ }
15034
+
15035
+ /**
15036
+ * @license
15037
+ * Copyright 2025 Google LLC
15038
+ * SPDX-License-Identifier: Apache-2.0
15039
+ */
15040
+ class Documents extends BaseModule {
15041
+ constructor(apiClient) {
15042
+ super();
15043
+ this.apiClient = apiClient;
15044
+ /**
15045
+ * Lists documents.
15046
+ *
15047
+ * @param params - The parameters for the list request.
15048
+ * @return - A pager of documents.
15049
+ *
15050
+ * @example
15051
+ * ```ts
15052
+ * const documents = await ai.documents.list({config: {'pageSize': 2}});
15053
+ * for await (const document of documents) {
15054
+ * console.log(document);
15055
+ * }
15056
+ * ```
15057
+ */
15058
+ this.list = async (params) => {
15059
+ return new Pager(PagedItem.PAGED_ITEM_DOCUMENTS, (x) => this.listInternal({
15060
+ parent: params.parent,
15061
+ config: x.config,
15062
+ }), await this.listInternal(params), params);
15063
+ };
15064
+ }
15065
+ /**
15066
+ * Gets a Document.
15067
+ *
15068
+ * @param params - The parameters for getting a document.
15069
+ * @return Document.
15070
+ */
15071
+ async get(params) {
15072
+ var _a, _b;
15073
+ let response;
15074
+ let path = '';
15075
+ let queryParams = {};
15076
+ if (this.apiClient.isVertexAI()) {
15077
+ throw new Error('This method is only supported by the Gemini Developer API.');
15078
+ }
15079
+ else {
15080
+ const body = getDocumentParametersToMldev(params);
15081
+ path = formatMap('{name}', body['_url']);
15082
+ queryParams = body['_query'];
15083
+ delete body['_url'];
15084
+ delete body['_query'];
15085
+ response = this.apiClient
15086
+ .request({
15087
+ path: path,
15088
+ queryParams: queryParams,
15089
+ body: JSON.stringify(body),
15090
+ httpMethod: 'GET',
15091
+ httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
15092
+ abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
15093
+ })
15094
+ .then((httpResponse) => {
15095
+ return httpResponse.json();
15096
+ });
15097
+ return response.then((resp) => {
15098
+ return resp;
15099
+ });
15100
+ }
15101
+ }
15102
+ /**
15103
+ * Deletes a Document.
15104
+ *
15105
+ * @param params - The parameters for deleting a document.
15106
+ */
15107
+ async delete(params) {
15108
+ var _a, _b;
15109
+ let path = '';
15110
+ let queryParams = {};
15111
+ if (this.apiClient.isVertexAI()) {
15112
+ throw new Error('This method is only supported by the Gemini Developer API.');
15113
+ }
15114
+ else {
15115
+ const body = deleteDocumentParametersToMldev(params);
15116
+ path = formatMap('{name}', body['_url']);
15117
+ queryParams = body['_query'];
15118
+ delete body['_url'];
15119
+ delete body['_query'];
15120
+ await this.apiClient.request({
15121
+ path: path,
15122
+ queryParams: queryParams,
15123
+ body: JSON.stringify(body),
15124
+ httpMethod: 'DELETE',
15125
+ httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
15126
+ abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
15127
+ });
15128
+ }
15129
+ }
15130
+ /**
15131
+ * Lists all Documents in a FileSearchStore.
15132
+ *
15133
+ * @param params - The parameters for listing documents.
15134
+ * @return ListDocumentsResponse.
15135
+ */
15136
+ async listInternal(params) {
15137
+ var _a, _b;
15138
+ let response;
15139
+ let path = '';
15140
+ let queryParams = {};
15141
+ if (this.apiClient.isVertexAI()) {
15142
+ throw new Error('This method is only supported by the Gemini Developer API.');
15143
+ }
15144
+ else {
15145
+ const body = listDocumentsParametersToMldev(params);
15146
+ path = formatMap('{parent}/documents', body['_url']);
15147
+ queryParams = body['_query'];
15148
+ delete body['_url'];
15149
+ delete body['_query'];
15150
+ response = this.apiClient
15151
+ .request({
15152
+ path: path,
15153
+ queryParams: queryParams,
15154
+ body: JSON.stringify(body),
15155
+ httpMethod: 'GET',
15156
+ httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
15157
+ abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
15158
+ })
15159
+ .then((httpResponse) => {
15160
+ return httpResponse.json();
15161
+ });
15162
+ return response.then((apiResponse) => {
15163
+ const resp = listDocumentsResponseFromMldev(apiResponse);
15164
+ const typedResp = new ListDocumentsResponse();
15165
+ Object.assign(typedResp, resp);
15166
+ return typedResp;
15167
+ });
15168
+ }
15169
+ }
15170
+ }
15171
+
15172
+ /**
15173
+ * @license
15174
+ * Copyright 2025 Google LLC
15175
+ * SPDX-License-Identifier: Apache-2.0
15176
+ */
15177
+ class FileSearchStores extends BaseModule {
15178
+ constructor(apiClient, documents = new Documents(apiClient)) {
15179
+ super();
15180
+ this.apiClient = apiClient;
15181
+ this.documents = documents;
15182
+ /**
15183
+ * Lists file search stores.
15184
+ *
15185
+ * @param params - The parameters for the list request.
15186
+ * @return - A pager of file search stores.
15187
+ *
15188
+ * @example
15189
+ * ```ts
15190
+ * const fileSearchStores = await ai.fileSearchStores.list({config: {'pageSize': 2}});
15191
+ * for await (const fileSearchStore of fileSearchStores) {
15192
+ * console.log(fileSearchStore);
15193
+ * }
15194
+ * ```
15195
+ */
15196
+ this.list = async (params = {}) => {
15197
+ return new Pager(PagedItem.PAGED_ITEM_FILE_SEARCH_STORES, (x) => this.listInternal(x), await this.listInternal(params), params);
15198
+ };
15199
+ }
15200
+ /**
15201
+ * Uploads a file asynchronously to a given File Search Store.
15202
+ * This method is not available in Vertex AI.
15203
+ * Supported upload sources:
15204
+ * - Node.js: File path (string) or Blob object.
15205
+ * - Browser: Blob object (e.g., File).
15206
+ *
15207
+ * @remarks
15208
+ * The `mimeType` can be specified in the `config` parameter. If omitted:
15209
+ * - For file path (string) inputs, the `mimeType` will be inferred from the
15210
+ * file extension.
15211
+ * - For Blob object inputs, the `mimeType` will be set to the Blob's `type`
15212
+ * property.
15213
+ *
15214
+ * This section can contain multiple paragraphs and code examples.
15215
+ *
15216
+ * @param params - Optional parameters specified in the
15217
+ * `types.UploadToFileSearchStoreParameters` interface.
15218
+ * @see {@link types.UploadToFileSearchStoreParameters#config} for the optional
15219
+ * config in the parameters.
15220
+ * @return A promise that resolves to a long running operation.
15221
+ * @throws An error if called on a Vertex AI client.
15222
+ * @throws An error if the `mimeType` is not provided and can not be inferred,
15223
+ * the `mimeType` can be provided in the `params.config` parameter.
15224
+ * @throws An error occurs if a suitable upload location cannot be established.
15225
+ *
15226
+ * @example
15227
+ * The following code uploads a file to a given file search store.
15228
+ *
15229
+ * ```ts
15230
+ * const operation = await ai.fileSearchStores.upload({fileSearchStoreName: 'fileSearchStores/foo-bar', file: 'file.txt', config: {
15231
+ * mimeType: 'text/plain',
15232
+ * }});
15233
+ * console.log(operation.name);
15234
+ * ```
15235
+ */
15236
+ async uploadToFileSearchStore(params) {
15237
+ if (this.apiClient.isVertexAI()) {
15238
+ throw new Error('Vertex AI does not support uploading files to a file search store.');
15239
+ }
15240
+ return this.apiClient.uploadFileToFileSearchStore(params.fileSearchStoreName, params.file, params.config);
15241
+ }
15242
+ /**
15243
+ * Creates a File Search Store.
15244
+ *
15245
+ * @param params - The parameters for creating a File Search Store.
15246
+ * @return FileSearchStore.
15247
+ */
15248
+ async create(params) {
15249
+ var _a, _b;
15250
+ let response;
15251
+ let path = '';
15252
+ let queryParams = {};
15253
+ if (this.apiClient.isVertexAI()) {
15254
+ throw new Error('This method is only supported by the Gemini Developer API.');
15255
+ }
15256
+ else {
15257
+ const body = createFileSearchStoreParametersToMldev(params);
15258
+ path = formatMap('fileSearchStores', body['_url']);
15259
+ queryParams = body['_query'];
15260
+ delete body['_url'];
15261
+ delete body['_query'];
15262
+ response = this.apiClient
15263
+ .request({
15264
+ path: path,
15265
+ queryParams: queryParams,
15266
+ body: JSON.stringify(body),
15267
+ httpMethod: 'POST',
15268
+ httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
15269
+ abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
15270
+ })
15271
+ .then((httpResponse) => {
15272
+ return httpResponse.json();
15273
+ });
15274
+ return response.then((resp) => {
15275
+ return resp;
15276
+ });
15277
+ }
15278
+ }
15279
+ /**
15280
+ * Gets a File Search Store.
15281
+ *
15282
+ * @param params - The parameters for getting a File Search Store.
15283
+ * @return FileSearchStore.
15284
+ */
15285
+ async get(params) {
15286
+ var _a, _b;
15287
+ let response;
15288
+ let path = '';
15289
+ let queryParams = {};
15290
+ if (this.apiClient.isVertexAI()) {
15291
+ throw new Error('This method is only supported by the Gemini Developer API.');
15292
+ }
15293
+ else {
15294
+ const body = getFileSearchStoreParametersToMldev(params);
15295
+ path = formatMap('{name}', body['_url']);
15296
+ queryParams = body['_query'];
15297
+ delete body['_url'];
15298
+ delete body['_query'];
15299
+ response = this.apiClient
15300
+ .request({
15301
+ path: path,
15302
+ queryParams: queryParams,
15303
+ body: JSON.stringify(body),
15304
+ httpMethod: 'GET',
15305
+ httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
15306
+ abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
15307
+ })
15308
+ .then((httpResponse) => {
15309
+ return httpResponse.json();
15310
+ });
15311
+ return response.then((resp) => {
15312
+ return resp;
15313
+ });
15314
+ }
15315
+ }
15316
+ /**
15317
+ * Deletes a File Search Store.
15318
+ *
15319
+ * @param params - The parameters for deleting a File Search Store.
15320
+ */
15321
+ async delete(params) {
15322
+ var _a, _b;
15323
+ let path = '';
15324
+ let queryParams = {};
15325
+ if (this.apiClient.isVertexAI()) {
15326
+ throw new Error('This method is only supported by the Gemini Developer API.');
15327
+ }
15328
+ else {
15329
+ const body = deleteFileSearchStoreParametersToMldev(params);
15330
+ path = formatMap('{name}', body['_url']);
15331
+ queryParams = body['_query'];
15332
+ delete body['_url'];
15333
+ delete body['_query'];
15334
+ await this.apiClient.request({
15335
+ path: path,
15336
+ queryParams: queryParams,
15337
+ body: JSON.stringify(body),
15338
+ httpMethod: 'DELETE',
15339
+ httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
15340
+ abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
15341
+ });
15342
+ }
15343
+ }
15344
+ /**
15345
+ * Lists all FileSearchStore owned by the user.
15346
+ *
15347
+ * @param params - The parameters for listing file search stores.
15348
+ * @return ListFileSearchStoresResponse.
15349
+ */
15350
+ async listInternal(params) {
15351
+ var _a, _b;
15352
+ let response;
15353
+ let path = '';
15354
+ let queryParams = {};
15355
+ if (this.apiClient.isVertexAI()) {
15356
+ throw new Error('This method is only supported by the Gemini Developer API.');
15357
+ }
15358
+ else {
15359
+ const body = listFileSearchStoresParametersToMldev(params);
15360
+ path = formatMap('fileSearchStores', body['_url']);
15361
+ queryParams = body['_query'];
15362
+ delete body['_url'];
15363
+ delete body['_query'];
15364
+ response = this.apiClient
15365
+ .request({
15366
+ path: path,
15367
+ queryParams: queryParams,
15368
+ body: JSON.stringify(body),
15369
+ httpMethod: 'GET',
15370
+ httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
15371
+ abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
15372
+ })
15373
+ .then((httpResponse) => {
15374
+ return httpResponse.json();
15375
+ });
15376
+ return response.then((apiResponse) => {
15377
+ const resp = listFileSearchStoresResponseFromMldev(apiResponse);
15378
+ const typedResp = new ListFileSearchStoresResponse();
15379
+ Object.assign(typedResp, resp);
15380
+ return typedResp;
15381
+ });
15382
+ }
15383
+ }
15384
+ async uploadToFileSearchStoreInternal(params) {
15385
+ var _a, _b;
15386
+ let response;
15387
+ let path = '';
15388
+ let queryParams = {};
15389
+ if (this.apiClient.isVertexAI()) {
15390
+ throw new Error('This method is only supported by the Gemini Developer API.');
15391
+ }
15392
+ else {
15393
+ const body = uploadToFileSearchStoreParametersToMldev(params);
15394
+ path = formatMap('upload/v1beta/{file_search_store_name}:uploadToFileSearchStore', body['_url']);
15395
+ queryParams = body['_query'];
15396
+ delete body['_url'];
15397
+ delete body['_query'];
15398
+ response = this.apiClient
15399
+ .request({
15400
+ path: path,
15401
+ queryParams: queryParams,
15402
+ body: JSON.stringify(body),
15403
+ httpMethod: 'POST',
15404
+ httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
15405
+ abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
15406
+ })
15407
+ .then((httpResponse) => {
15408
+ return httpResponse.json();
15409
+ });
15410
+ return response.then((apiResponse) => {
15411
+ const resp = uploadToFileSearchStoreResumableResponseFromMldev(apiResponse);
15412
+ const typedResp = new UploadToFileSearchStoreResumableResponse();
15413
+ Object.assign(typedResp, resp);
15414
+ return typedResp;
15415
+ });
15416
+ }
15417
+ }
15418
+ /**
15419
+ * Imports a File from File Service to a FileSearchStore.
15420
+ *
15421
+ * This is a long-running operation, see aip.dev/151
15422
+ *
15423
+ * @param params - The parameters for importing a file to a file search store.
15424
+ * @return ImportFileOperation.
15425
+ */
15426
+ async importFile(params) {
15427
+ var _a, _b;
15428
+ let response;
15429
+ let path = '';
15430
+ let queryParams = {};
15431
+ if (this.apiClient.isVertexAI()) {
15432
+ throw new Error('This method is only supported by the Gemini Developer API.');
15433
+ }
15434
+ else {
15435
+ const body = importFileParametersToMldev(params);
15436
+ path = formatMap('{file_search_store_name}:importFile', body['_url']);
15437
+ queryParams = body['_query'];
15438
+ delete body['_url'];
15439
+ delete body['_query'];
15440
+ response = this.apiClient
15441
+ .request({
15442
+ path: path,
15443
+ queryParams: queryParams,
15444
+ body: JSON.stringify(body),
15445
+ httpMethod: 'POST',
15446
+ httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
15447
+ abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
15448
+ })
15449
+ .then((httpResponse) => {
15450
+ return httpResponse.json();
15451
+ });
15452
+ return response.then((apiResponse) => {
15453
+ const resp = importFileOperationFromMldev(apiResponse);
15454
+ const typedResp = new ImportFileOperation();
15455
+ Object.assign(typedResp, resp);
15456
+ return typedResp;
15457
+ });
15458
+ }
15459
+ }
15460
+ }
15461
+
15462
+ /**
15463
+ * @license
15464
+ * Copyright 2025 Google LLC
15465
+ * SPDX-License-Identifier: Apache-2.0
15466
+ */
15467
+ const GOOGLE_API_KEY_HEADER = 'x-goog-api-key';
15468
+ const REQUIRED_VERTEX_AI_SCOPE = 'https://www.googleapis.com/auth/cloud-platform';
15469
+ class NodeAuth {
15470
+ constructor(opts) {
15471
+ if (opts.apiKey !== undefined) {
15472
+ this.apiKey = opts.apiKey;
15473
+ return;
15474
+ }
15475
+ const vertexAuthOptions = buildGoogleAuthOptions(opts.googleAuthOptions);
15476
+ this.googleAuth = new GoogleAuth(vertexAuthOptions);
15477
+ }
15478
+ async addAuthHeaders(headers, url) {
15479
+ if (this.apiKey !== undefined) {
15480
+ if (this.apiKey.startsWith('auth_tokens/')) {
15481
+ throw new Error('Ephemeral tokens are only supported by the live API.');
15482
+ }
15483
+ this.addKeyHeader(headers);
15484
+ return;
15485
+ }
15486
+ return this.addGoogleAuthHeaders(headers, url);
15487
+ }
15488
+ addKeyHeader(headers) {
15489
+ if (headers.get(GOOGLE_API_KEY_HEADER) !== null) {
15490
+ return;
15491
+ }
15492
+ if (this.apiKey === undefined) {
15493
+ // This should never happen, this method is only called
15494
+ // when apiKey is set.
15495
+ throw new Error('Trying to set API key header but apiKey is not set');
15496
+ }
15497
+ headers.append(GOOGLE_API_KEY_HEADER, this.apiKey);
15498
+ }
15499
+ async addGoogleAuthHeaders(headers, url) {
15500
+ if (this.googleAuth === undefined) {
15501
+ // This should never happen, addGoogleAuthHeaders should only be
15502
+ // called when there is no apiKey set and in these cases googleAuth
15503
+ // is set.
15504
+ throw new Error('Trying to set google-auth headers but googleAuth is unset');
15505
+ }
15506
+ const authHeaders = await this.googleAuth.getRequestHeaders(url);
15507
+ for (const [key, value] of authHeaders) {
15508
+ if (headers.get(key) !== null) {
15509
+ continue;
15510
+ }
15511
+ headers.append(key, value);
15512
+ }
15513
+ }
15514
+ }
15515
+ function buildGoogleAuthOptions(googleAuthOptions) {
15516
+ let authOptions;
15517
+ if (!googleAuthOptions) {
15518
+ authOptions = {
15519
+ scopes: [REQUIRED_VERTEX_AI_SCOPE],
15520
+ };
15521
+ return authOptions;
15522
+ }
15523
+ else {
15524
+ authOptions = googleAuthOptions;
15525
+ if (!authOptions.scopes) {
15526
+ authOptions.scopes = [REQUIRED_VERTEX_AI_SCOPE];
15527
+ return authOptions;
15528
+ }
15529
+ else if ((typeof authOptions.scopes === 'string' &&
15530
+ authOptions.scopes !== REQUIRED_VERTEX_AI_SCOPE) ||
15531
+ (Array.isArray(authOptions.scopes) &&
15532
+ authOptions.scopes.indexOf(REQUIRED_VERTEX_AI_SCOPE) < 0)) {
15533
+ throw new Error(`Invalid auth scopes. Scopes must include: ${REQUIRED_VERTEX_AI_SCOPE}`);
15534
+ }
15535
+ return authOptions;
15536
+ }
15537
+ }
15538
+
15539
+ /**
15540
+ * @license
15541
+ * Copyright 2025 Google LLC
15542
+ * SPDX-License-Identifier: Apache-2.0
15543
+ */
15544
+ class NodeDownloader {
15545
+ async download(params, apiClient) {
15546
+ if (params.downloadPath) {
15547
+ const response = await downloadFile(params, apiClient);
15548
+ if (response instanceof HttpResponse) {
15549
+ const writer = createWriteStream(params.downloadPath);
15550
+ const body = Readable.fromWeb(response.responseInternal.body);
15551
+ body.pipe(writer);
15552
+ await finished(writer);
15553
+ }
15554
+ else {
15555
+ try {
15556
+ await writeFile(params.downloadPath, response, {
15557
+ encoding: 'base64',
15558
+ });
15559
+ }
15560
+ catch (error) {
15561
+ throw new Error(`Failed to write file to ${params.downloadPath}: ${error}`);
15562
+ }
15563
+ }
15564
+ }
15565
+ }
15566
+ }
15567
+ async function downloadFile(params, apiClient) {
15568
+ var _a, _b, _c;
15569
+ const name = tFileName(params.file);
15570
+ if (name !== undefined) {
15571
+ return await apiClient.request({
15572
+ path: `files/${name}:download`,
15573
+ httpMethod: 'GET',
15574
+ queryParams: {
15575
+ 'alt': 'media',
15576
+ },
15577
+ httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
15578
+ abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
15579
+ });
15580
+ }
15581
+ else if (isGeneratedVideo(params.file)) {
15582
+ const videoBytes = (_c = params.file.video) === null || _c === void 0 ? void 0 : _c.videoBytes;
15583
+ if (typeof videoBytes === 'string') {
15584
+ return videoBytes;
15585
+ }
15586
+ else {
15587
+ throw new Error('Failed to download generated video, Uri or videoBytes not found.');
15588
+ }
15589
+ }
15590
+ else if (isVideo(params.file)) {
15591
+ const videoBytes = params.file.videoBytes;
15592
+ if (typeof videoBytes === 'string') {
15593
+ return videoBytes;
15594
+ }
15595
+ else {
15596
+ throw new Error('Failed to download video, Uri or videoBytes not found.');
15597
+ }
15598
+ }
15599
+ else {
15600
+ throw new Error('Unsupported file type');
15601
+ }
15602
+ }
15603
+
15604
+ /**
15605
+ * @license
15606
+ * Copyright 2025 Google LLC
15607
+ * SPDX-License-Identifier: Apache-2.0
15608
+ */
15609
+ class NodeWebSocketFactory {
15610
+ create(url, headers, callbacks) {
15611
+ return new NodeWebSocket(url, headers, callbacks);
15612
+ }
15613
+ }
15614
+ class NodeWebSocket {
15615
+ constructor(url, headers, callbacks) {
15616
+ this.url = url;
15617
+ this.headers = headers;
15618
+ this.callbacks = callbacks;
15619
+ }
15620
+ connect() {
15621
+ this.ws = new NodeWs.WebSocket(this.url, { headers: this.headers });
15622
+ this.ws.onopen = this.callbacks.onopen;
15623
+ this.ws.onerror = this.callbacks.onerror;
15624
+ this.ws.onclose = this.callbacks.onclose;
15625
+ this.ws.onmessage = this.callbacks.onmessage;
15626
+ }
15627
+ send(message) {
15628
+ if (this.ws === undefined) {
15629
+ throw new Error('WebSocket is not connected');
15630
+ }
15631
+ this.ws.send(message);
15632
+ }
15633
+ close() {
15634
+ if (this.ws === undefined) {
15635
+ throw new Error('WebSocket is not connected');
15636
+ }
15637
+ this.ws.close();
15638
+ }
15639
+ }
15640
+
15641
+ /**
15642
+ * @license
15643
+ * Copyright 2025 Google LLC
15644
+ * SPDX-License-Identifier: Apache-2.0
15645
+ */
15646
+ // Code generated by the Google Gen AI SDK generator DO NOT EDIT.
15647
+ function cancelTuningJobParametersToMldev(fromObject, _rootObject) {
15648
+ const toObject = {};
15649
+ const fromName = getValueByPath(fromObject, ['name']);
15650
+ if (fromName != null) {
15651
+ setValueByPath(toObject, ['_url', 'name'], fromName);
15652
+ }
15653
+ return toObject;
15654
+ }
15655
+ function cancelTuningJobParametersToVertex(fromObject, _rootObject) {
15656
+ const toObject = {};
15657
+ const fromName = getValueByPath(fromObject, ['name']);
15658
+ if (fromName != null) {
15659
+ setValueByPath(toObject, ['_url', 'name'], fromName);
15660
+ }
15661
+ return toObject;
15662
+ }
15663
+ function createTuningJobConfigToMldev(fromObject, parentObject, _rootObject) {
15664
+ const toObject = {};
15665
+ if (getValueByPath(fromObject, ['validationDataset']) !== undefined) {
15666
+ throw new Error('validationDataset parameter is not supported in Gemini API.');
15667
+ }
15668
+ const fromTunedModelDisplayName = getValueByPath(fromObject, [
15669
+ 'tunedModelDisplayName',
15670
+ ]);
15671
+ if (parentObject !== undefined && fromTunedModelDisplayName != null) {
15672
+ setValueByPath(parentObject, ['displayName'], fromTunedModelDisplayName);
15673
+ }
15674
+ if (getValueByPath(fromObject, ['description']) !== undefined) {
15675
+ throw new Error('description parameter is not supported in Gemini API.');
15676
+ }
15677
+ const fromEpochCount = getValueByPath(fromObject, ['epochCount']);
15678
+ if (parentObject !== undefined && fromEpochCount != null) {
15679
+ setValueByPath(parentObject, ['tuningTask', 'hyperparameters', 'epochCount'], fromEpochCount);
14596
15680
  }
14597
15681
  const fromLearningRateMultiplier = getValueByPath(fromObject, [
14598
15682
  'learningRateMultiplier',
@@ -15570,7 +16654,28 @@ const INITIAL_RETRY_DELAY_MS = 1000;
15570
16654
  const DELAY_MULTIPLIER = 2;
15571
16655
  const X_GOOG_UPLOAD_STATUS_HEADER_FIELD = 'x-goog-upload-status';
15572
16656
  async function uploadBlob(file, uploadUrl, apiClient) {
15573
- var _a, _b, _c;
16657
+ var _a;
16658
+ const response = await uploadBlobInternal(file, uploadUrl, apiClient);
16659
+ const responseJson = (await (response === null || response === void 0 ? void 0 : response.json()));
16660
+ 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') {
16661
+ throw new Error('Failed to upload file: Upload status is not finalized.');
16662
+ }
16663
+ return responseJson['file'];
16664
+ }
16665
+ async function uploadBlobToFileSearchStore(file, uploadUrl, apiClient) {
16666
+ var _a;
16667
+ const response = await uploadBlobInternal(file, uploadUrl, apiClient);
16668
+ const responseJson = (await (response === null || response === void 0 ? void 0 : response.json()));
16669
+ 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') {
16670
+ throw new Error('Failed to upload file: Upload status is not finalized.');
16671
+ }
16672
+ const resp = uploadToFileSearchStoreOperationFromMldev(responseJson);
16673
+ const typedResp = new UploadToFileSearchStoreOperation();
16674
+ Object.assign(typedResp, resp);
16675
+ return typedResp;
16676
+ }
16677
+ async function uploadBlobInternal(file, uploadUrl, apiClient) {
16678
+ var _a, _b;
15574
16679
  let fileSize = 0;
15575
16680
  let offset = 0;
15576
16681
  let response = new HttpResponse(new Response());
@@ -15618,11 +16723,7 @@ async function uploadBlob(file, uploadUrl, apiClient) {
15618
16723
  throw new Error('All content has been uploaded, but the upload status is not finalized.');
15619
16724
  }
15620
16725
  }
15621
- const responseJson = (await (response === null || response === void 0 ? void 0 : response.json()));
15622
- 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') {
15623
- throw new Error('Failed to upload file: Upload status is not finalized.');
15624
- }
15625
- return responseJson['file'];
16726
+ return response;
15626
16727
  }
15627
16728
  async function getBlobStat(file) {
15628
16729
  const fileStat = { size: file.size, type: file.type };
@@ -15658,6 +16759,14 @@ class NodeUploader {
15658
16759
  return uploadBlob(file, uploadUrl, apiClient);
15659
16760
  }
15660
16761
  }
16762
+ async uploadToFileSearchStore(file, uploadUrl, apiClient) {
16763
+ if (typeof file === 'string') {
16764
+ return await this.uploadFileToFileSearchStoreFromPath(file, uploadUrl, apiClient);
16765
+ }
16766
+ else {
16767
+ return uploadBlobToFileSearchStore(file, uploadUrl, apiClient);
16768
+ }
16769
+ }
15661
16770
  /**
15662
16771
  * Infers the MIME type of a file based on its extension.
15663
16772
  *
@@ -15749,12 +16858,34 @@ class NodeUploader {
15749
16858
  return mimeType;
15750
16859
  }
15751
16860
  async uploadFileFromPath(file, uploadUrl, apiClient) {
15752
- var _a, _b, _c;
16861
+ var _a;
16862
+ const response = await this.uploadFileFromPathInternal(file, uploadUrl, apiClient);
16863
+ const responseJson = (await (response === null || response === void 0 ? void 0 : response.json()));
16864
+ 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') {
16865
+ throw new Error('Failed to upload file: Upload status is not finalized.');
16866
+ }
16867
+ return responseJson['file'];
16868
+ }
16869
+ async uploadFileToFileSearchStoreFromPath(file, uploadUrl, apiClient) {
16870
+ var _a;
16871
+ const response = await this.uploadFileFromPathInternal(file, uploadUrl, apiClient);
16872
+ const responseJson = (await (response === null || response === void 0 ? void 0 : response.json()));
16873
+ 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') {
16874
+ throw new Error('Failed to upload file: Upload status is not finalized.');
16875
+ }
16876
+ const resp = uploadToFileSearchStoreOperationFromMldev(responseJson);
16877
+ const typedResp = new UploadToFileSearchStoreOperation();
16878
+ Object.assign(typedResp, resp);
16879
+ return typedResp;
16880
+ }
16881
+ async uploadFileFromPathInternal(file, uploadUrl, apiClient) {
16882
+ var _a, _b;
15753
16883
  let fileSize = 0;
15754
16884
  let offset = 0;
15755
16885
  let response = new HttpResponse(new Response());
15756
16886
  let uploadCommand = 'upload';
15757
16887
  let fileHandle;
16888
+ const fileName = path.basename(file);
15758
16889
  try {
15759
16890
  fileHandle = await fs.open(file, 'r');
15760
16891
  if (!fileHandle) {
@@ -15786,6 +16917,7 @@ class NodeUploader {
15786
16917
  'X-Goog-Upload-Command': uploadCommand,
15787
16918
  'X-Goog-Upload-Offset': String(offset),
15788
16919
  'Content-Length': String(bytesRead),
16920
+ 'X-Goog-Upload-File-Name': fileName,
15789
16921
  },
15790
16922
  },
15791
16923
  });
@@ -15806,11 +16938,7 @@ class NodeUploader {
15806
16938
  throw new Error('All content has been uploaded, but the upload status is not finalized.');
15807
16939
  }
15808
16940
  }
15809
- const responseJson = (await (response === null || response === void 0 ? void 0 : response.json()));
15810
- 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') {
15811
- throw new Error('Failed to upload file: Upload status is not finalized.');
15812
- }
15813
- return responseJson['file'];
16941
+ return response;
15814
16942
  }
15815
16943
  finally {
15816
16944
  // Ensure the file handle is always closed
@@ -15949,6 +17077,7 @@ class GoogleGenAI {
15949
17077
  this.operations = new Operations(this.apiClient);
15950
17078
  this.authTokens = new Tokens(this.apiClient);
15951
17079
  this.tunings = new Tunings(this.apiClient);
17080
+ this.fileSearchStores = new FileSearchStores(this.apiClient);
15952
17081
  }
15953
17082
  }
15954
17083
  function getEnv(env) {
@@ -15973,5 +17102,5 @@ function getApiKeyFromEnv() {
15973
17102
  return envGoogleApiKey || envGeminiApiKey || undefined;
15974
17103
  }
15975
17104
 
15976
- export { ActivityHandling, AdapterSize, ApiError, ApiSpec, AuthType, Batches, Behavior, BlockedReason, Caches, Chat, Chats, ComputeTokensResponse, ContentReferenceImage, ControlReferenceImage, ControlReferenceType, CountTokensResponse, CreateFileResponse, DeleteCachedContentResponse, DeleteFileResponse, DeleteModelResponse, DynamicRetrievalConfigMode, EditImageResponse, EditMode, EmbedContentResponse, EndSensitivity, Environment, FeatureSelectionPreference, FileSource, FileState, Files, FinishReason, FunctionCallingConfigMode, FunctionResponse, FunctionResponseBlob, FunctionResponseFileData, FunctionResponsePart, FunctionResponseScheduling, GenerateContentResponse, GenerateContentResponsePromptFeedback, GenerateContentResponseUsageMetadata, GenerateImagesResponse, GenerateVideosOperation, GenerateVideosResponse, GoogleGenAI, HarmBlockMethod, HarmBlockThreshold, HarmCategory, HarmProbability, HarmSeverity, HttpResponse, ImagePromptLanguage, InlinedEmbedContentResponse, InlinedResponse, JobState, Language, ListBatchJobsResponse, ListCachedContentsResponse, ListFilesResponse, ListModelsResponse, ListTuningJobsResponse, Live, LiveClientToolResponse, LiveMusicPlaybackControl, LiveMusicServerMessage, LiveSendToolResponseParameters, LiveServerMessage, MaskReferenceImage, MaskReferenceMode, MediaModality, MediaResolution, Modality, Mode, Models, MusicGenerationMode, Operations, Outcome, PagedItem, Pager, PersonGeneration, RawReferenceImage, RecontextImageResponse, ReplayResponse, SafetyFilterLevel, Scale, SegmentImageResponse, SegmentMode, Session, SingleEmbedContentResponse, StartSensitivity, StyleReferenceImage, SubjectReferenceImage, SubjectReferenceType, Tokens, TrafficType, TuningMethod, TuningMode, TuningTask, TurnCompleteReason, TurnCoverage, Type, UpscaleImageResponse, UrlRetrievalStatus, VideoCompressionQuality, VideoGenerationMaskMode, VideoGenerationReferenceType, createFunctionResponsePartFromBase64, createFunctionResponsePartFromUri, createModelContent, createPartFromBase64, createPartFromCodeExecutionResult, createPartFromExecutableCode, createPartFromFunctionCall, createPartFromFunctionResponse, createPartFromText, createPartFromUri, createUserContent, mcpToTool, setDefaultBaseUrls };
17105
+ export { ActivityHandling, AdapterSize, ApiError, ApiSpec, AuthType, Batches, Behavior, BlockedReason, Caches, Chat, Chats, ComputeTokensResponse, ContentReferenceImage, ControlReferenceImage, ControlReferenceType, CountTokensResponse, CreateFileResponse, DeleteCachedContentResponse, DeleteFileResponse, DeleteModelResponse, DocumentState, DynamicRetrievalConfigMode, EditImageResponse, EditMode, EmbedContentResponse, EndSensitivity, Environment, FeatureSelectionPreference, FileSource, FileState, Files, FinishReason, FunctionCallingConfigMode, FunctionResponse, FunctionResponseBlob, FunctionResponseFileData, FunctionResponsePart, FunctionResponseScheduling, GenerateContentResponse, GenerateContentResponsePromptFeedback, GenerateContentResponseUsageMetadata, GenerateImagesResponse, GenerateVideosOperation, GenerateVideosResponse, GoogleGenAI, HarmBlockMethod, HarmBlockThreshold, HarmCategory, HarmProbability, HarmSeverity, HttpElementLocation, HttpResponse, ImagePromptLanguage, ImportFileOperation, ImportFileResponse, InlinedEmbedContentResponse, InlinedResponse, JobState, Language, ListBatchJobsResponse, ListCachedContentsResponse, ListDocumentsResponse, ListFileSearchStoresResponse, ListFilesResponse, ListModelsResponse, ListTuningJobsResponse, Live, LiveClientToolResponse, LiveMusicPlaybackControl, LiveMusicServerMessage, LiveSendToolResponseParameters, LiveServerMessage, MaskReferenceImage, MaskReferenceMode, MediaModality, MediaResolution, Modality, Mode, Models, MusicGenerationMode, Operations, Outcome, PagedItem, Pager, PersonGeneration, PhishBlockThreshold, RawReferenceImage, RecontextImageResponse, ReplayResponse, SafetyFilterLevel, Scale, SegmentImageResponse, SegmentMode, Session, SingleEmbedContentResponse, StartSensitivity, StyleReferenceImage, SubjectReferenceImage, SubjectReferenceType, Tokens, TrafficType, TuningMethod, TuningMode, TuningTask, TurnCompleteReason, TurnCoverage, Type, UploadToFileSearchStoreOperation, UploadToFileSearchStoreResponse, UploadToFileSearchStoreResumableResponse, UpscaleImageResponse, UrlRetrievalStatus, VideoCompressionQuality, VideoGenerationMaskMode, VideoGenerationReferenceType, createFunctionResponsePartFromBase64, createFunctionResponsePartFromUri, createModelContent, createPartFromBase64, createPartFromCodeExecutionResult, createPartFromExecutableCode, createPartFromFunctionCall, createPartFromFunctionResponse, createPartFromText, createPartFromUri, createUserContent, mcpToTool, setDefaultBaseUrls };
15977
17106
  //# sourceMappingURL=index.mjs.map