@google/genai 1.28.0 → 1.29.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- package/dist/genai.d.ts +747 -47
- package/dist/index.cjs +1286 -196
- package/dist/index.mjs +1280 -197
- package/dist/index.mjs.map +1 -1
- package/dist/node/index.cjs +1405 -294
- package/dist/node/index.mjs +1398 -295
- package/dist/node/index.mjs.map +1 -1
- package/dist/node/node.d.ts +747 -47
- package/dist/web/index.mjs +1291 -210
- package/dist/web/index.mjs.map +1 -1
- package/dist/web/web.d.ts +747 -47
- package/package.json +11 -6
package/dist/node/index.cjs
CHANGED
|
@@ -6,6 +6,7 @@ var fs$1 = require('fs/promises');
|
|
|
6
6
|
var node_stream = require('node:stream');
|
|
7
7
|
var promises = require('node:stream/promises');
|
|
8
8
|
var NodeWs = require('ws');
|
|
9
|
+
var path = require('path');
|
|
9
10
|
|
|
10
11
|
function _interopNamespaceDefault(e) {
|
|
11
12
|
var n = Object.create(null);
|
|
@@ -26,6 +27,7 @@ function _interopNamespaceDefault(e) {
|
|
|
26
27
|
|
|
27
28
|
var fs__namespace = /*#__PURE__*/_interopNamespaceDefault(fs$1);
|
|
28
29
|
var NodeWs__namespace = /*#__PURE__*/_interopNamespaceDefault(NodeWs);
|
|
30
|
+
var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
|
|
29
31
|
|
|
30
32
|
/**
|
|
31
33
|
* @license
|
|
@@ -489,6 +491,90 @@ function getOperationParametersToVertex(fromObject) {
|
|
|
489
491
|
}
|
|
490
492
|
return toObject;
|
|
491
493
|
}
|
|
494
|
+
function importFileOperationFromMldev$1(fromObject) {
|
|
495
|
+
const toObject = {};
|
|
496
|
+
const fromName = getValueByPath(fromObject, ['name']);
|
|
497
|
+
if (fromName != null) {
|
|
498
|
+
setValueByPath(toObject, ['name'], fromName);
|
|
499
|
+
}
|
|
500
|
+
const fromMetadata = getValueByPath(fromObject, ['metadata']);
|
|
501
|
+
if (fromMetadata != null) {
|
|
502
|
+
setValueByPath(toObject, ['metadata'], fromMetadata);
|
|
503
|
+
}
|
|
504
|
+
const fromDone = getValueByPath(fromObject, ['done']);
|
|
505
|
+
if (fromDone != null) {
|
|
506
|
+
setValueByPath(toObject, ['done'], fromDone);
|
|
507
|
+
}
|
|
508
|
+
const fromError = getValueByPath(fromObject, ['error']);
|
|
509
|
+
if (fromError != null) {
|
|
510
|
+
setValueByPath(toObject, ['error'], fromError);
|
|
511
|
+
}
|
|
512
|
+
const fromResponse = getValueByPath(fromObject, ['response']);
|
|
513
|
+
if (fromResponse != null) {
|
|
514
|
+
setValueByPath(toObject, ['response'], importFileResponseFromMldev$1(fromResponse));
|
|
515
|
+
}
|
|
516
|
+
return toObject;
|
|
517
|
+
}
|
|
518
|
+
function importFileResponseFromMldev$1(fromObject) {
|
|
519
|
+
const toObject = {};
|
|
520
|
+
const fromSdkHttpResponse = getValueByPath(fromObject, [
|
|
521
|
+
'sdkHttpResponse',
|
|
522
|
+
]);
|
|
523
|
+
if (fromSdkHttpResponse != null) {
|
|
524
|
+
setValueByPath(toObject, ['sdkHttpResponse'], fromSdkHttpResponse);
|
|
525
|
+
}
|
|
526
|
+
const fromParent = getValueByPath(fromObject, ['parent']);
|
|
527
|
+
if (fromParent != null) {
|
|
528
|
+
setValueByPath(toObject, ['parent'], fromParent);
|
|
529
|
+
}
|
|
530
|
+
const fromDocumentName = getValueByPath(fromObject, ['documentName']);
|
|
531
|
+
if (fromDocumentName != null) {
|
|
532
|
+
setValueByPath(toObject, ['documentName'], fromDocumentName);
|
|
533
|
+
}
|
|
534
|
+
return toObject;
|
|
535
|
+
}
|
|
536
|
+
function uploadToFileSearchStoreOperationFromMldev(fromObject) {
|
|
537
|
+
const toObject = {};
|
|
538
|
+
const fromName = getValueByPath(fromObject, ['name']);
|
|
539
|
+
if (fromName != null) {
|
|
540
|
+
setValueByPath(toObject, ['name'], fromName);
|
|
541
|
+
}
|
|
542
|
+
const fromMetadata = getValueByPath(fromObject, ['metadata']);
|
|
543
|
+
if (fromMetadata != null) {
|
|
544
|
+
setValueByPath(toObject, ['metadata'], fromMetadata);
|
|
545
|
+
}
|
|
546
|
+
const fromDone = getValueByPath(fromObject, ['done']);
|
|
547
|
+
if (fromDone != null) {
|
|
548
|
+
setValueByPath(toObject, ['done'], fromDone);
|
|
549
|
+
}
|
|
550
|
+
const fromError = getValueByPath(fromObject, ['error']);
|
|
551
|
+
if (fromError != null) {
|
|
552
|
+
setValueByPath(toObject, ['error'], fromError);
|
|
553
|
+
}
|
|
554
|
+
const fromResponse = getValueByPath(fromObject, ['response']);
|
|
555
|
+
if (fromResponse != null) {
|
|
556
|
+
setValueByPath(toObject, ['response'], uploadToFileSearchStoreResponseFromMldev(fromResponse));
|
|
557
|
+
}
|
|
558
|
+
return toObject;
|
|
559
|
+
}
|
|
560
|
+
function uploadToFileSearchStoreResponseFromMldev(fromObject) {
|
|
561
|
+
const toObject = {};
|
|
562
|
+
const fromSdkHttpResponse = getValueByPath(fromObject, [
|
|
563
|
+
'sdkHttpResponse',
|
|
564
|
+
]);
|
|
565
|
+
if (fromSdkHttpResponse != null) {
|
|
566
|
+
setValueByPath(toObject, ['sdkHttpResponse'], fromSdkHttpResponse);
|
|
567
|
+
}
|
|
568
|
+
const fromParent = getValueByPath(fromObject, ['parent']);
|
|
569
|
+
if (fromParent != null) {
|
|
570
|
+
setValueByPath(toObject, ['parent'], fromParent);
|
|
571
|
+
}
|
|
572
|
+
const fromDocumentName = getValueByPath(fromObject, ['documentName']);
|
|
573
|
+
if (fromDocumentName != null) {
|
|
574
|
+
setValueByPath(toObject, ['documentName'], fromDocumentName);
|
|
575
|
+
}
|
|
576
|
+
return toObject;
|
|
577
|
+
}
|
|
492
578
|
function videoFromMldev$1(fromObject) {
|
|
493
579
|
const toObject = {};
|
|
494
580
|
const fromUri = getValueByPath(fromObject, ['uri']);
|
|
@@ -629,6 +715,22 @@ exports.Mode = void 0;
|
|
|
629
715
|
*/
|
|
630
716
|
Mode["MODE_DYNAMIC"] = "MODE_DYNAMIC";
|
|
631
717
|
})(exports.Mode || (exports.Mode = {}));
|
|
718
|
+
/** The API spec that the external API implements. This enum is not supported in Gemini API. */
|
|
719
|
+
exports.ApiSpec = void 0;
|
|
720
|
+
(function (ApiSpec) {
|
|
721
|
+
/**
|
|
722
|
+
* Unspecified API spec. This value should not be used.
|
|
723
|
+
*/
|
|
724
|
+
ApiSpec["API_SPEC_UNSPECIFIED"] = "API_SPEC_UNSPECIFIED";
|
|
725
|
+
/**
|
|
726
|
+
* Simple search API spec.
|
|
727
|
+
*/
|
|
728
|
+
ApiSpec["SIMPLE_SEARCH"] = "SIMPLE_SEARCH";
|
|
729
|
+
/**
|
|
730
|
+
* Elastic search API spec.
|
|
731
|
+
*/
|
|
732
|
+
ApiSpec["ELASTIC_SEARCH"] = "ELASTIC_SEARCH";
|
|
733
|
+
})(exports.ApiSpec || (exports.ApiSpec = {}));
|
|
632
734
|
/** Type of auth scheme. This enum is not supported in Gemini API. */
|
|
633
735
|
exports.AuthType = void 0;
|
|
634
736
|
(function (AuthType) {
|
|
@@ -658,22 +760,63 @@ exports.AuthType = void 0;
|
|
|
658
760
|
*/
|
|
659
761
|
AuthType["OIDC_AUTH"] = "OIDC_AUTH";
|
|
660
762
|
})(exports.AuthType || (exports.AuthType = {}));
|
|
661
|
-
/** The
|
|
662
|
-
exports.
|
|
663
|
-
(function (
|
|
763
|
+
/** The location of the API key. This enum is not supported in Gemini API. */
|
|
764
|
+
exports.HttpElementLocation = void 0;
|
|
765
|
+
(function (HttpElementLocation) {
|
|
766
|
+
HttpElementLocation["HTTP_IN_UNSPECIFIED"] = "HTTP_IN_UNSPECIFIED";
|
|
664
767
|
/**
|
|
665
|
-
*
|
|
768
|
+
* Element is in the HTTP request query.
|
|
666
769
|
*/
|
|
667
|
-
|
|
770
|
+
HttpElementLocation["HTTP_IN_QUERY"] = "HTTP_IN_QUERY";
|
|
668
771
|
/**
|
|
669
|
-
*
|
|
772
|
+
* Element is in the HTTP request header.
|
|
670
773
|
*/
|
|
671
|
-
|
|
774
|
+
HttpElementLocation["HTTP_IN_HEADER"] = "HTTP_IN_HEADER";
|
|
672
775
|
/**
|
|
673
|
-
*
|
|
776
|
+
* Element is in the HTTP request path.
|
|
674
777
|
*/
|
|
675
|
-
|
|
676
|
-
|
|
778
|
+
HttpElementLocation["HTTP_IN_PATH"] = "HTTP_IN_PATH";
|
|
779
|
+
/**
|
|
780
|
+
* Element is in the HTTP request body.
|
|
781
|
+
*/
|
|
782
|
+
HttpElementLocation["HTTP_IN_BODY"] = "HTTP_IN_BODY";
|
|
783
|
+
/**
|
|
784
|
+
* Element is in the HTTP request cookie.
|
|
785
|
+
*/
|
|
786
|
+
HttpElementLocation["HTTP_IN_COOKIE"] = "HTTP_IN_COOKIE";
|
|
787
|
+
})(exports.HttpElementLocation || (exports.HttpElementLocation = {}));
|
|
788
|
+
/** Sites with confidence level chosen & above this value will be blocked from the search results. This enum is not supported in Gemini API. */
|
|
789
|
+
exports.PhishBlockThreshold = void 0;
|
|
790
|
+
(function (PhishBlockThreshold) {
|
|
791
|
+
/**
|
|
792
|
+
* Defaults to unspecified.
|
|
793
|
+
*/
|
|
794
|
+
PhishBlockThreshold["PHISH_BLOCK_THRESHOLD_UNSPECIFIED"] = "PHISH_BLOCK_THRESHOLD_UNSPECIFIED";
|
|
795
|
+
/**
|
|
796
|
+
* Blocks Low and above confidence URL that is risky.
|
|
797
|
+
*/
|
|
798
|
+
PhishBlockThreshold["BLOCK_LOW_AND_ABOVE"] = "BLOCK_LOW_AND_ABOVE";
|
|
799
|
+
/**
|
|
800
|
+
* Blocks Medium and above confidence URL that is risky.
|
|
801
|
+
*/
|
|
802
|
+
PhishBlockThreshold["BLOCK_MEDIUM_AND_ABOVE"] = "BLOCK_MEDIUM_AND_ABOVE";
|
|
803
|
+
/**
|
|
804
|
+
* Blocks High and above confidence URL that is risky.
|
|
805
|
+
*/
|
|
806
|
+
PhishBlockThreshold["BLOCK_HIGH_AND_ABOVE"] = "BLOCK_HIGH_AND_ABOVE";
|
|
807
|
+
/**
|
|
808
|
+
* Blocks Higher and above confidence URL that is risky.
|
|
809
|
+
*/
|
|
810
|
+
PhishBlockThreshold["BLOCK_HIGHER_AND_ABOVE"] = "BLOCK_HIGHER_AND_ABOVE";
|
|
811
|
+
/**
|
|
812
|
+
* Blocks Very high and above confidence URL that is risky.
|
|
813
|
+
*/
|
|
814
|
+
PhishBlockThreshold["BLOCK_VERY_HIGH_AND_ABOVE"] = "BLOCK_VERY_HIGH_AND_ABOVE";
|
|
815
|
+
/**
|
|
816
|
+
* Blocks Extremely high confidence URL that is risky.
|
|
817
|
+
*/
|
|
818
|
+
PhishBlockThreshold["BLOCK_ONLY_EXTREMELY_HIGH"] = "BLOCK_ONLY_EXTREMELY_HIGH";
|
|
819
|
+
})(exports.PhishBlockThreshold || (exports.PhishBlockThreshold = {}));
|
|
677
820
|
/** Harm category. */
|
|
678
821
|
exports.HarmCategory = void 0;
|
|
679
822
|
(function (HarmCategory) {
|
|
@@ -940,7 +1083,7 @@ exports.BlockedReason = void 0;
|
|
|
940
1083
|
*/
|
|
941
1084
|
BlockedReason["JAILBREAK"] = "JAILBREAK";
|
|
942
1085
|
})(exports.BlockedReason || (exports.BlockedReason = {}));
|
|
943
|
-
/** Output only.
|
|
1086
|
+
/** Output only. The traffic type for this request. This enum is not supported in Gemini API. */
|
|
944
1087
|
exports.TrafficType = void 0;
|
|
945
1088
|
(function (TrafficType) {
|
|
946
1089
|
/**
|
|
@@ -948,7 +1091,7 @@ exports.TrafficType = void 0;
|
|
|
948
1091
|
*/
|
|
949
1092
|
TrafficType["TRAFFIC_TYPE_UNSPECIFIED"] = "TRAFFIC_TYPE_UNSPECIFIED";
|
|
950
1093
|
/**
|
|
951
|
-
*
|
|
1094
|
+
* The request was processed using Pay-As-You-Go quota.
|
|
952
1095
|
*/
|
|
953
1096
|
TrafficType["ON_DEMAND"] = "ON_DEMAND";
|
|
954
1097
|
/**
|
|
@@ -1111,6 +1254,10 @@ exports.TuningTask = void 0;
|
|
|
1111
1254
|
* Tuning task for text to video.
|
|
1112
1255
|
*/
|
|
1113
1256
|
TuningTask["TUNING_TASK_T2V"] = "TUNING_TASK_T2V";
|
|
1257
|
+
/**
|
|
1258
|
+
* Tuning task for reference to video.
|
|
1259
|
+
*/
|
|
1260
|
+
TuningTask["TUNING_TASK_R2V"] = "TUNING_TASK_R2V";
|
|
1114
1261
|
})(exports.TuningTask || (exports.TuningTask = {}));
|
|
1115
1262
|
/** Options for feature selection preference. */
|
|
1116
1263
|
exports.FeatureSelectionPreference = void 0;
|
|
@@ -1358,6 +1505,14 @@ exports.TuningMethod = void 0;
|
|
|
1358
1505
|
*/
|
|
1359
1506
|
TuningMethod["PREFERENCE_TUNING"] = "PREFERENCE_TUNING";
|
|
1360
1507
|
})(exports.TuningMethod || (exports.TuningMethod = {}));
|
|
1508
|
+
/** State for the lifecycle of a Document. */
|
|
1509
|
+
exports.DocumentState = void 0;
|
|
1510
|
+
(function (DocumentState) {
|
|
1511
|
+
DocumentState["STATE_UNSPECIFIED"] = "STATE_UNSPECIFIED";
|
|
1512
|
+
DocumentState["STATE_PENDING"] = "STATE_PENDING";
|
|
1513
|
+
DocumentState["STATE_ACTIVE"] = "STATE_ACTIVE";
|
|
1514
|
+
DocumentState["STATE_FAILED"] = "STATE_FAILED";
|
|
1515
|
+
})(exports.DocumentState || (exports.DocumentState = {}));
|
|
1361
1516
|
/** State for the lifecycle of a File. */
|
|
1362
1517
|
exports.FileState = void 0;
|
|
1363
1518
|
(function (FileState) {
|
|
@@ -1785,7 +1940,7 @@ class HttpResponse {
|
|
|
1785
1940
|
/** 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. */
|
|
1786
1941
|
class GenerateContentResponsePromptFeedback {
|
|
1787
1942
|
}
|
|
1788
|
-
/** Usage metadata about response
|
|
1943
|
+
/** 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. */
|
|
1789
1944
|
class GenerateContentResponseUsageMetadata {
|
|
1790
1945
|
}
|
|
1791
1946
|
/** Response message for PredictionService.GenerateContent. */
|
|
@@ -2050,11 +2205,11 @@ class GenerateVideosOperation {
|
|
|
2050
2205
|
* Instantiates an Operation of the same type as the one being called with the fields set from the API response.
|
|
2051
2206
|
* @internal
|
|
2052
2207
|
*/
|
|
2053
|
-
_fromAPIResponse({ apiResponse,
|
|
2208
|
+
_fromAPIResponse({ apiResponse, _isVertexAI, }) {
|
|
2054
2209
|
const operation = new GenerateVideosOperation();
|
|
2055
2210
|
let response;
|
|
2056
2211
|
const op = apiResponse;
|
|
2057
|
-
if (
|
|
2212
|
+
if (_isVertexAI) {
|
|
2058
2213
|
response = generateVideosOperationFromVertex$1(op);
|
|
2059
2214
|
}
|
|
2060
2215
|
else {
|
|
@@ -2072,6 +2227,32 @@ class DeleteCachedContentResponse {
|
|
|
2072
2227
|
}
|
|
2073
2228
|
class ListCachedContentsResponse {
|
|
2074
2229
|
}
|
|
2230
|
+
/** Config for documents.list return value. */
|
|
2231
|
+
class ListDocumentsResponse {
|
|
2232
|
+
}
|
|
2233
|
+
/** Config for file_search_stores.list return value. */
|
|
2234
|
+
class ListFileSearchStoresResponse {
|
|
2235
|
+
}
|
|
2236
|
+
/** Response for the resumable upload method. */
|
|
2237
|
+
class UploadToFileSearchStoreResumableResponse {
|
|
2238
|
+
}
|
|
2239
|
+
/** Response for ImportFile to import a File API file with a file search store. */
|
|
2240
|
+
class ImportFileResponse {
|
|
2241
|
+
}
|
|
2242
|
+
/** Long-running operation for importing a file to a FileSearchStore. */
|
|
2243
|
+
class ImportFileOperation {
|
|
2244
|
+
/**
|
|
2245
|
+
* Instantiates an Operation of the same type as the one being called with the fields set from the API response.
|
|
2246
|
+
* @internal
|
|
2247
|
+
*/
|
|
2248
|
+
_fromAPIResponse({ apiResponse, _isVertexAI, }) {
|
|
2249
|
+
const operation = new ImportFileOperation();
|
|
2250
|
+
const op = apiResponse;
|
|
2251
|
+
const response = importFileOperationFromMldev$1(op);
|
|
2252
|
+
Object.assign(operation, response);
|
|
2253
|
+
return operation;
|
|
2254
|
+
}
|
|
2255
|
+
}
|
|
2075
2256
|
/** Response for the list files method. */
|
|
2076
2257
|
class ListFilesResponse {
|
|
2077
2258
|
}
|
|
@@ -2307,6 +2488,23 @@ class LiveMusicServerMessage {
|
|
|
2307
2488
|
return undefined;
|
|
2308
2489
|
}
|
|
2309
2490
|
}
|
|
2491
|
+
/** The response when long-running operation for uploading a file to a FileSearchStore complete. */
|
|
2492
|
+
class UploadToFileSearchStoreResponse {
|
|
2493
|
+
}
|
|
2494
|
+
/** Long-running operation for uploading a file to a FileSearchStore. */
|
|
2495
|
+
class UploadToFileSearchStoreOperation {
|
|
2496
|
+
/**
|
|
2497
|
+
* Instantiates an Operation of the same type as the one being called with the fields set from the API response.
|
|
2498
|
+
* @internal
|
|
2499
|
+
*/
|
|
2500
|
+
_fromAPIResponse({ apiResponse, _isVertexAI, }) {
|
|
2501
|
+
const operation = new UploadToFileSearchStoreOperation();
|
|
2502
|
+
const op = apiResponse;
|
|
2503
|
+
const response = uploadToFileSearchStoreOperationFromMldev(op);
|
|
2504
|
+
Object.assign(operation, response);
|
|
2505
|
+
return operation;
|
|
2506
|
+
}
|
|
2507
|
+
}
|
|
2310
2508
|
|
|
2311
2509
|
/**
|
|
2312
2510
|
* @license
|
|
@@ -3303,6 +3501,12 @@ function batchJobFromVertex(fromObject) {
|
|
|
3303
3501
|
if (fromDest != null) {
|
|
3304
3502
|
setValueByPath(toObject, ['dest'], batchJobDestinationFromVertex(tRecvBatchJobDestination(fromDest)));
|
|
3305
3503
|
}
|
|
3504
|
+
const fromCompletionStats = getValueByPath(fromObject, [
|
|
3505
|
+
'completionStats',
|
|
3506
|
+
]);
|
|
3507
|
+
if (fromCompletionStats != null) {
|
|
3508
|
+
setValueByPath(toObject, ['completionStats'], fromCompletionStats);
|
|
3509
|
+
}
|
|
3306
3510
|
return toObject;
|
|
3307
3511
|
}
|
|
3308
3512
|
function batchJobSourceFromVertex(fromObject) {
|
|
@@ -3935,6 +4139,9 @@ function googleSearchToMldev$4(fromObject) {
|
|
|
3935
4139
|
if (getValueByPath(fromObject, ['excludeDomains']) !== undefined) {
|
|
3936
4140
|
throw new Error('excludeDomains parameter is not supported in Gemini API.');
|
|
3937
4141
|
}
|
|
4142
|
+
if (getValueByPath(fromObject, ['blockingConfidence']) !== undefined) {
|
|
4143
|
+
throw new Error('blockingConfidence parameter is not supported in Gemini API.');
|
|
4144
|
+
}
|
|
3938
4145
|
const fromTimeRangeFilter = getValueByPath(fromObject, [
|
|
3939
4146
|
'timeRangeFilter',
|
|
3940
4147
|
]);
|
|
@@ -4174,14 +4381,14 @@ function toolToMldev$4(fromObject) {
|
|
|
4174
4381
|
if (fromGoogleSearchRetrieval != null) {
|
|
4175
4382
|
setValueByPath(toObject, ['googleSearchRetrieval'], fromGoogleSearchRetrieval);
|
|
4176
4383
|
}
|
|
4177
|
-
const fromGoogleMaps = getValueByPath(fromObject, ['googleMaps']);
|
|
4178
|
-
if (fromGoogleMaps != null) {
|
|
4179
|
-
setValueByPath(toObject, ['googleMaps'], googleMapsToMldev$4(fromGoogleMaps));
|
|
4180
|
-
}
|
|
4181
4384
|
const fromComputerUse = getValueByPath(fromObject, ['computerUse']);
|
|
4182
4385
|
if (fromComputerUse != null) {
|
|
4183
4386
|
setValueByPath(toObject, ['computerUse'], fromComputerUse);
|
|
4184
4387
|
}
|
|
4388
|
+
const fromFileSearch = getValueByPath(fromObject, ['fileSearch']);
|
|
4389
|
+
if (fromFileSearch != null) {
|
|
4390
|
+
setValueByPath(toObject, ['fileSearch'], fromFileSearch);
|
|
4391
|
+
}
|
|
4185
4392
|
const fromCodeExecution = getValueByPath(fromObject, [
|
|
4186
4393
|
'codeExecution',
|
|
4187
4394
|
]);
|
|
@@ -4191,6 +4398,10 @@ function toolToMldev$4(fromObject) {
|
|
|
4191
4398
|
if (getValueByPath(fromObject, ['enterpriseWebSearch']) !== undefined) {
|
|
4192
4399
|
throw new Error('enterpriseWebSearch parameter is not supported in Gemini API.');
|
|
4193
4400
|
}
|
|
4401
|
+
const fromGoogleMaps = getValueByPath(fromObject, ['googleMaps']);
|
|
4402
|
+
if (fromGoogleMaps != null) {
|
|
4403
|
+
setValueByPath(toObject, ['googleMaps'], googleMapsToMldev$4(fromGoogleMaps));
|
|
4404
|
+
}
|
|
4194
4405
|
const fromGoogleSearch = getValueByPath(fromObject, ['googleSearch']);
|
|
4195
4406
|
if (fromGoogleSearch != null) {
|
|
4196
4407
|
setValueByPath(toObject, ['googleSearch'], googleSearchToMldev$4(fromGoogleSearch));
|
|
@@ -4214,7 +4425,7 @@ exports.PagedItem = void 0;
|
|
|
4214
4425
|
PagedItem["PAGED_ITEM_TUNING_JOBS"] = "tuningJobs";
|
|
4215
4426
|
PagedItem["PAGED_ITEM_FILES"] = "files";
|
|
4216
4427
|
PagedItem["PAGED_ITEM_CACHED_CONTENTS"] = "cachedContents";
|
|
4217
|
-
PagedItem["
|
|
4428
|
+
PagedItem["PAGED_ITEM_FILE_SEARCH_STORES"] = "fileSearchStores";
|
|
4218
4429
|
PagedItem["PAGED_ITEM_DOCUMENTS"] = "documents";
|
|
4219
4430
|
})(exports.PagedItem || (exports.PagedItem = {}));
|
|
4220
4431
|
/**
|
|
@@ -5168,6 +5379,9 @@ function googleSearchToMldev$3(fromObject) {
|
|
|
5168
5379
|
if (getValueByPath(fromObject, ['excludeDomains']) !== undefined) {
|
|
5169
5380
|
throw new Error('excludeDomains parameter is not supported in Gemini API.');
|
|
5170
5381
|
}
|
|
5382
|
+
if (getValueByPath(fromObject, ['blockingConfidence']) !== undefined) {
|
|
5383
|
+
throw new Error('blockingConfidence parameter is not supported in Gemini API.');
|
|
5384
|
+
}
|
|
5171
5385
|
const fromTimeRangeFilter = getValueByPath(fromObject, [
|
|
5172
5386
|
'timeRangeFilter',
|
|
5173
5387
|
]);
|
|
@@ -5349,14 +5563,14 @@ function toolToMldev$3(fromObject) {
|
|
|
5349
5563
|
if (fromGoogleSearchRetrieval != null) {
|
|
5350
5564
|
setValueByPath(toObject, ['googleSearchRetrieval'], fromGoogleSearchRetrieval);
|
|
5351
5565
|
}
|
|
5352
|
-
const fromGoogleMaps = getValueByPath(fromObject, ['googleMaps']);
|
|
5353
|
-
if (fromGoogleMaps != null) {
|
|
5354
|
-
setValueByPath(toObject, ['googleMaps'], googleMapsToMldev$3(fromGoogleMaps));
|
|
5355
|
-
}
|
|
5356
5566
|
const fromComputerUse = getValueByPath(fromObject, ['computerUse']);
|
|
5357
5567
|
if (fromComputerUse != null) {
|
|
5358
5568
|
setValueByPath(toObject, ['computerUse'], fromComputerUse);
|
|
5359
5569
|
}
|
|
5570
|
+
const fromFileSearch = getValueByPath(fromObject, ['fileSearch']);
|
|
5571
|
+
if (fromFileSearch != null) {
|
|
5572
|
+
setValueByPath(toObject, ['fileSearch'], fromFileSearch);
|
|
5573
|
+
}
|
|
5360
5574
|
const fromCodeExecution = getValueByPath(fromObject, [
|
|
5361
5575
|
'codeExecution',
|
|
5362
5576
|
]);
|
|
@@ -5366,6 +5580,10 @@ function toolToMldev$3(fromObject) {
|
|
|
5366
5580
|
if (getValueByPath(fromObject, ['enterpriseWebSearch']) !== undefined) {
|
|
5367
5581
|
throw new Error('enterpriseWebSearch parameter is not supported in Gemini API.');
|
|
5368
5582
|
}
|
|
5583
|
+
const fromGoogleMaps = getValueByPath(fromObject, ['googleMaps']);
|
|
5584
|
+
if (fromGoogleMaps != null) {
|
|
5585
|
+
setValueByPath(toObject, ['googleMaps'], googleMapsToMldev$3(fromGoogleMaps));
|
|
5586
|
+
}
|
|
5369
5587
|
const fromGoogleSearch = getValueByPath(fromObject, ['googleSearch']);
|
|
5370
5588
|
if (fromGoogleSearch != null) {
|
|
5371
5589
|
setValueByPath(toObject, ['googleSearch'], googleSearchToMldev$3(fromGoogleSearch));
|
|
@@ -5400,14 +5618,13 @@ function toolToVertex$2(fromObject) {
|
|
|
5400
5618
|
if (fromGoogleSearchRetrieval != null) {
|
|
5401
5619
|
setValueByPath(toObject, ['googleSearchRetrieval'], fromGoogleSearchRetrieval);
|
|
5402
5620
|
}
|
|
5403
|
-
const fromGoogleMaps = getValueByPath(fromObject, ['googleMaps']);
|
|
5404
|
-
if (fromGoogleMaps != null) {
|
|
5405
|
-
setValueByPath(toObject, ['googleMaps'], fromGoogleMaps);
|
|
5406
|
-
}
|
|
5407
5621
|
const fromComputerUse = getValueByPath(fromObject, ['computerUse']);
|
|
5408
5622
|
if (fromComputerUse != null) {
|
|
5409
5623
|
setValueByPath(toObject, ['computerUse'], fromComputerUse);
|
|
5410
5624
|
}
|
|
5625
|
+
if (getValueByPath(fromObject, ['fileSearch']) !== undefined) {
|
|
5626
|
+
throw new Error('fileSearch parameter is not supported in Vertex AI.');
|
|
5627
|
+
}
|
|
5411
5628
|
const fromCodeExecution = getValueByPath(fromObject, [
|
|
5412
5629
|
'codeExecution',
|
|
5413
5630
|
]);
|
|
@@ -5420,6 +5637,10 @@ function toolToVertex$2(fromObject) {
|
|
|
5420
5637
|
if (fromEnterpriseWebSearch != null) {
|
|
5421
5638
|
setValueByPath(toObject, ['enterpriseWebSearch'], fromEnterpriseWebSearch);
|
|
5422
5639
|
}
|
|
5640
|
+
const fromGoogleMaps = getValueByPath(fromObject, ['googleMaps']);
|
|
5641
|
+
if (fromGoogleMaps != null) {
|
|
5642
|
+
setValueByPath(toObject, ['googleMaps'], fromGoogleMaps);
|
|
5643
|
+
}
|
|
5423
5644
|
const fromGoogleSearch = getValueByPath(fromObject, ['googleSearch']);
|
|
5424
5645
|
if (fromGoogleSearch != null) {
|
|
5425
5646
|
setValueByPath(toObject, ['googleSearch'], fromGoogleSearch);
|
|
@@ -6725,6 +6946,12 @@ function generationConfigToVertex$1(fromObject) {
|
|
|
6725
6946
|
if (fromModelSelectionConfig != null) {
|
|
6726
6947
|
setValueByPath(toObject, ['modelConfig'], fromModelSelectionConfig);
|
|
6727
6948
|
}
|
|
6949
|
+
const fromResponseJsonSchema = getValueByPath(fromObject, [
|
|
6950
|
+
'responseJsonSchema',
|
|
6951
|
+
]);
|
|
6952
|
+
if (fromResponseJsonSchema != null) {
|
|
6953
|
+
setValueByPath(toObject, ['responseJsonSchema'], fromResponseJsonSchema);
|
|
6954
|
+
}
|
|
6728
6955
|
const fromAudioTimestamp = getValueByPath(fromObject, [
|
|
6729
6956
|
'audioTimestamp',
|
|
6730
6957
|
]);
|
|
@@ -6771,12 +6998,6 @@ function generationConfigToVertex$1(fromObject) {
|
|
|
6771
6998
|
if (fromPresencePenalty != null) {
|
|
6772
6999
|
setValueByPath(toObject, ['presencePenalty'], fromPresencePenalty);
|
|
6773
7000
|
}
|
|
6774
|
-
const fromResponseJsonSchema = getValueByPath(fromObject, [
|
|
6775
|
-
'responseJsonSchema',
|
|
6776
|
-
]);
|
|
6777
|
-
if (fromResponseJsonSchema != null) {
|
|
6778
|
-
setValueByPath(toObject, ['responseJsonSchema'], fromResponseJsonSchema);
|
|
6779
|
-
}
|
|
6780
7001
|
const fromResponseLogprobs = getValueByPath(fromObject, [
|
|
6781
7002
|
'responseLogprobs',
|
|
6782
7003
|
]);
|
|
@@ -6861,6 +7082,9 @@ function googleSearchToMldev$2(fromObject) {
|
|
|
6861
7082
|
if (getValueByPath(fromObject, ['excludeDomains']) !== undefined) {
|
|
6862
7083
|
throw new Error('excludeDomains parameter is not supported in Gemini API.');
|
|
6863
7084
|
}
|
|
7085
|
+
if (getValueByPath(fromObject, ['blockingConfidence']) !== undefined) {
|
|
7086
|
+
throw new Error('blockingConfidence parameter is not supported in Gemini API.');
|
|
7087
|
+
}
|
|
6864
7088
|
const fromTimeRangeFilter = getValueByPath(fromObject, [
|
|
6865
7089
|
'timeRangeFilter',
|
|
6866
7090
|
]);
|
|
@@ -7368,14 +7592,14 @@ function toolToMldev$2(fromObject) {
|
|
|
7368
7592
|
if (fromGoogleSearchRetrieval != null) {
|
|
7369
7593
|
setValueByPath(toObject, ['googleSearchRetrieval'], fromGoogleSearchRetrieval);
|
|
7370
7594
|
}
|
|
7371
|
-
const fromGoogleMaps = getValueByPath(fromObject, ['googleMaps']);
|
|
7372
|
-
if (fromGoogleMaps != null) {
|
|
7373
|
-
setValueByPath(toObject, ['googleMaps'], googleMapsToMldev$2(fromGoogleMaps));
|
|
7374
|
-
}
|
|
7375
7595
|
const fromComputerUse = getValueByPath(fromObject, ['computerUse']);
|
|
7376
7596
|
if (fromComputerUse != null) {
|
|
7377
7597
|
setValueByPath(toObject, ['computerUse'], fromComputerUse);
|
|
7378
7598
|
}
|
|
7599
|
+
const fromFileSearch = getValueByPath(fromObject, ['fileSearch']);
|
|
7600
|
+
if (fromFileSearch != null) {
|
|
7601
|
+
setValueByPath(toObject, ['fileSearch'], fromFileSearch);
|
|
7602
|
+
}
|
|
7379
7603
|
const fromCodeExecution = getValueByPath(fromObject, [
|
|
7380
7604
|
'codeExecution',
|
|
7381
7605
|
]);
|
|
@@ -7385,6 +7609,10 @@ function toolToMldev$2(fromObject) {
|
|
|
7385
7609
|
if (getValueByPath(fromObject, ['enterpriseWebSearch']) !== undefined) {
|
|
7386
7610
|
throw new Error('enterpriseWebSearch parameter is not supported in Gemini API.');
|
|
7387
7611
|
}
|
|
7612
|
+
const fromGoogleMaps = getValueByPath(fromObject, ['googleMaps']);
|
|
7613
|
+
if (fromGoogleMaps != null) {
|
|
7614
|
+
setValueByPath(toObject, ['googleMaps'], googleMapsToMldev$2(fromGoogleMaps));
|
|
7615
|
+
}
|
|
7388
7616
|
const fromGoogleSearch = getValueByPath(fromObject, ['googleSearch']);
|
|
7389
7617
|
if (fromGoogleSearch != null) {
|
|
7390
7618
|
setValueByPath(toObject, ['googleSearch'], googleSearchToMldev$2(fromGoogleSearch));
|
|
@@ -7419,14 +7647,13 @@ function toolToVertex$1(fromObject) {
|
|
|
7419
7647
|
if (fromGoogleSearchRetrieval != null) {
|
|
7420
7648
|
setValueByPath(toObject, ['googleSearchRetrieval'], fromGoogleSearchRetrieval);
|
|
7421
7649
|
}
|
|
7422
|
-
const fromGoogleMaps = getValueByPath(fromObject, ['googleMaps']);
|
|
7423
|
-
if (fromGoogleMaps != null) {
|
|
7424
|
-
setValueByPath(toObject, ['googleMaps'], fromGoogleMaps);
|
|
7425
|
-
}
|
|
7426
7650
|
const fromComputerUse = getValueByPath(fromObject, ['computerUse']);
|
|
7427
7651
|
if (fromComputerUse != null) {
|
|
7428
7652
|
setValueByPath(toObject, ['computerUse'], fromComputerUse);
|
|
7429
7653
|
}
|
|
7654
|
+
if (getValueByPath(fromObject, ['fileSearch']) !== undefined) {
|
|
7655
|
+
throw new Error('fileSearch parameter is not supported in Vertex AI.');
|
|
7656
|
+
}
|
|
7430
7657
|
const fromCodeExecution = getValueByPath(fromObject, [
|
|
7431
7658
|
'codeExecution',
|
|
7432
7659
|
]);
|
|
@@ -7439,6 +7666,10 @@ function toolToVertex$1(fromObject) {
|
|
|
7439
7666
|
if (fromEnterpriseWebSearch != null) {
|
|
7440
7667
|
setValueByPath(toObject, ['enterpriseWebSearch'], fromEnterpriseWebSearch);
|
|
7441
7668
|
}
|
|
7669
|
+
const fromGoogleMaps = getValueByPath(fromObject, ['googleMaps']);
|
|
7670
|
+
if (fromGoogleMaps != null) {
|
|
7671
|
+
setValueByPath(toObject, ['googleMaps'], fromGoogleMaps);
|
|
7672
|
+
}
|
|
7442
7673
|
const fromGoogleSearch = getValueByPath(fromObject, ['googleSearch']);
|
|
7443
7674
|
if (fromGoogleSearch != null) {
|
|
7444
7675
|
setValueByPath(toObject, ['googleSearch'], fromGoogleSearch);
|
|
@@ -9388,6 +9619,12 @@ function generationConfigToVertex(fromObject) {
|
|
|
9388
9619
|
if (fromModelSelectionConfig != null) {
|
|
9389
9620
|
setValueByPath(toObject, ['modelConfig'], fromModelSelectionConfig);
|
|
9390
9621
|
}
|
|
9622
|
+
const fromResponseJsonSchema = getValueByPath(fromObject, [
|
|
9623
|
+
'responseJsonSchema',
|
|
9624
|
+
]);
|
|
9625
|
+
if (fromResponseJsonSchema != null) {
|
|
9626
|
+
setValueByPath(toObject, ['responseJsonSchema'], fromResponseJsonSchema);
|
|
9627
|
+
}
|
|
9391
9628
|
const fromAudioTimestamp = getValueByPath(fromObject, [
|
|
9392
9629
|
'audioTimestamp',
|
|
9393
9630
|
]);
|
|
@@ -9434,12 +9671,6 @@ function generationConfigToVertex(fromObject) {
|
|
|
9434
9671
|
if (fromPresencePenalty != null) {
|
|
9435
9672
|
setValueByPath(toObject, ['presencePenalty'], fromPresencePenalty);
|
|
9436
9673
|
}
|
|
9437
|
-
const fromResponseJsonSchema = getValueByPath(fromObject, [
|
|
9438
|
-
'responseJsonSchema',
|
|
9439
|
-
]);
|
|
9440
|
-
if (fromResponseJsonSchema != null) {
|
|
9441
|
-
setValueByPath(toObject, ['responseJsonSchema'], fromResponseJsonSchema);
|
|
9442
|
-
}
|
|
9443
9674
|
const fromResponseLogprobs = getValueByPath(fromObject, [
|
|
9444
9675
|
'responseLogprobs',
|
|
9445
9676
|
]);
|
|
@@ -9540,6 +9771,9 @@ function googleSearchToMldev$1(fromObject) {
|
|
|
9540
9771
|
if (getValueByPath(fromObject, ['excludeDomains']) !== undefined) {
|
|
9541
9772
|
throw new Error('excludeDomains parameter is not supported in Gemini API.');
|
|
9542
9773
|
}
|
|
9774
|
+
if (getValueByPath(fromObject, ['blockingConfidence']) !== undefined) {
|
|
9775
|
+
throw new Error('blockingConfidence parameter is not supported in Gemini API.');
|
|
9776
|
+
}
|
|
9543
9777
|
const fromTimeRangeFilter = getValueByPath(fromObject, [
|
|
9544
9778
|
'timeRangeFilter',
|
|
9545
9779
|
]);
|
|
@@ -10242,14 +10476,14 @@ function toolToMldev$1(fromObject) {
|
|
|
10242
10476
|
if (fromGoogleSearchRetrieval != null) {
|
|
10243
10477
|
setValueByPath(toObject, ['googleSearchRetrieval'], fromGoogleSearchRetrieval);
|
|
10244
10478
|
}
|
|
10245
|
-
const fromGoogleMaps = getValueByPath(fromObject, ['googleMaps']);
|
|
10246
|
-
if (fromGoogleMaps != null) {
|
|
10247
|
-
setValueByPath(toObject, ['googleMaps'], googleMapsToMldev$1(fromGoogleMaps));
|
|
10248
|
-
}
|
|
10249
10479
|
const fromComputerUse = getValueByPath(fromObject, ['computerUse']);
|
|
10250
10480
|
if (fromComputerUse != null) {
|
|
10251
10481
|
setValueByPath(toObject, ['computerUse'], fromComputerUse);
|
|
10252
10482
|
}
|
|
10483
|
+
const fromFileSearch = getValueByPath(fromObject, ['fileSearch']);
|
|
10484
|
+
if (fromFileSearch != null) {
|
|
10485
|
+
setValueByPath(toObject, ['fileSearch'], fromFileSearch);
|
|
10486
|
+
}
|
|
10253
10487
|
const fromCodeExecution = getValueByPath(fromObject, [
|
|
10254
10488
|
'codeExecution',
|
|
10255
10489
|
]);
|
|
@@ -10259,6 +10493,10 @@ function toolToMldev$1(fromObject) {
|
|
|
10259
10493
|
if (getValueByPath(fromObject, ['enterpriseWebSearch']) !== undefined) {
|
|
10260
10494
|
throw new Error('enterpriseWebSearch parameter is not supported in Gemini API.');
|
|
10261
10495
|
}
|
|
10496
|
+
const fromGoogleMaps = getValueByPath(fromObject, ['googleMaps']);
|
|
10497
|
+
if (fromGoogleMaps != null) {
|
|
10498
|
+
setValueByPath(toObject, ['googleMaps'], googleMapsToMldev$1(fromGoogleMaps));
|
|
10499
|
+
}
|
|
10262
10500
|
const fromGoogleSearch = getValueByPath(fromObject, ['googleSearch']);
|
|
10263
10501
|
if (fromGoogleSearch != null) {
|
|
10264
10502
|
setValueByPath(toObject, ['googleSearch'], googleSearchToMldev$1(fromGoogleSearch));
|
|
@@ -10293,14 +10531,13 @@ function toolToVertex(fromObject) {
|
|
|
10293
10531
|
if (fromGoogleSearchRetrieval != null) {
|
|
10294
10532
|
setValueByPath(toObject, ['googleSearchRetrieval'], fromGoogleSearchRetrieval);
|
|
10295
10533
|
}
|
|
10296
|
-
const fromGoogleMaps = getValueByPath(fromObject, ['googleMaps']);
|
|
10297
|
-
if (fromGoogleMaps != null) {
|
|
10298
|
-
setValueByPath(toObject, ['googleMaps'], fromGoogleMaps);
|
|
10299
|
-
}
|
|
10300
10534
|
const fromComputerUse = getValueByPath(fromObject, ['computerUse']);
|
|
10301
10535
|
if (fromComputerUse != null) {
|
|
10302
10536
|
setValueByPath(toObject, ['computerUse'], fromComputerUse);
|
|
10303
10537
|
}
|
|
10538
|
+
if (getValueByPath(fromObject, ['fileSearch']) !== undefined) {
|
|
10539
|
+
throw new Error('fileSearch parameter is not supported in Vertex AI.');
|
|
10540
|
+
}
|
|
10304
10541
|
const fromCodeExecution = getValueByPath(fromObject, [
|
|
10305
10542
|
'codeExecution',
|
|
10306
10543
|
]);
|
|
@@ -10313,6 +10550,10 @@ function toolToVertex(fromObject) {
|
|
|
10313
10550
|
if (fromEnterpriseWebSearch != null) {
|
|
10314
10551
|
setValueByPath(toObject, ['enterpriseWebSearch'], fromEnterpriseWebSearch);
|
|
10315
10552
|
}
|
|
10553
|
+
const fromGoogleMaps = getValueByPath(fromObject, ['googleMaps']);
|
|
10554
|
+
if (fromGoogleMaps != null) {
|
|
10555
|
+
setValueByPath(toObject, ['googleMaps'], fromGoogleMaps);
|
|
10556
|
+
}
|
|
10316
10557
|
const fromGoogleSearch = getValueByPath(fromObject, ['googleSearch']);
|
|
10317
10558
|
if (fromGoogleSearch != null) {
|
|
10318
10559
|
setValueByPath(toObject, ['googleSearch'], fromGoogleSearch);
|
|
@@ -10642,7 +10883,7 @@ const CONTENT_TYPE_HEADER = 'Content-Type';
|
|
|
10642
10883
|
const SERVER_TIMEOUT_HEADER = 'X-Server-Timeout';
|
|
10643
10884
|
const USER_AGENT_HEADER = 'User-Agent';
|
|
10644
10885
|
const GOOGLE_API_CLIENT_HEADER = 'x-goog-api-client';
|
|
10645
|
-
const SDK_VERSION = '1.
|
|
10886
|
+
const SDK_VERSION = '1.29.0'; // x-release-please-version
|
|
10646
10887
|
const LIBRARY_LABEL = `google-genai-sdk/${SDK_VERSION}`;
|
|
10647
10888
|
const VERTEX_AI_API_DEFAULT_VERSION = 'v1beta1';
|
|
10648
10889
|
const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
|
|
@@ -11020,6 +11261,15 @@ class ApiClient {
|
|
|
11020
11261
|
await this.clientOptions.auth.addAuthHeaders(headers, url);
|
|
11021
11262
|
return headers;
|
|
11022
11263
|
}
|
|
11264
|
+
getFileName(file) {
|
|
11265
|
+
var _a;
|
|
11266
|
+
let fileName = '';
|
|
11267
|
+
if (typeof file === 'string') {
|
|
11268
|
+
fileName = file.replace(/[/\\]+$/, '');
|
|
11269
|
+
fileName = (_a = fileName.split(/[/\\]/).pop()) !== null && _a !== void 0 ? _a : '';
|
|
11270
|
+
}
|
|
11271
|
+
return fileName;
|
|
11272
|
+
}
|
|
11023
11273
|
/**
|
|
11024
11274
|
* Uploads a file asynchronously using Gemini API only, this is not supported
|
|
11025
11275
|
* in Vertex AI.
|
|
@@ -11032,7 +11282,7 @@ class ApiClient {
|
|
|
11032
11282
|
* @throws An error if the `mimeType` is not provided and can not be inferred,
|
|
11033
11283
|
*/
|
|
11034
11284
|
async uploadFile(file, config) {
|
|
11035
|
-
var _a
|
|
11285
|
+
var _a;
|
|
11036
11286
|
const fileToUpload = {};
|
|
11037
11287
|
if (config != null) {
|
|
11038
11288
|
fileToUpload.mimeType = config.mimeType;
|
|
@@ -11050,41 +11300,71 @@ class ApiClient {
|
|
|
11050
11300
|
throw new Error('Can not determine mimeType. Please provide mimeType in the config.');
|
|
11051
11301
|
}
|
|
11052
11302
|
fileToUpload.mimeType = mimeType;
|
|
11053
|
-
|
|
11054
|
-
|
|
11055
|
-
|
|
11056
|
-
|
|
11057
|
-
|
|
11058
|
-
const uploadUrl = await this.fetchUploadUrl(fileToUpload, fileName, config);
|
|
11303
|
+
const body = {
|
|
11304
|
+
file: fileToUpload,
|
|
11305
|
+
};
|
|
11306
|
+
const fileName = this.getFileName(file);
|
|
11307
|
+
const path = formatMap('upload/v1beta/files', body['_url']);
|
|
11308
|
+
const uploadUrl = await this.fetchUploadUrl(path, fileToUpload.sizeBytes, fileToUpload.mimeType, fileName, body, config === null || config === void 0 ? void 0 : config.httpOptions);
|
|
11059
11309
|
return uploader.upload(file, uploadUrl, this);
|
|
11060
11310
|
}
|
|
11061
11311
|
/**
|
|
11062
|
-
*
|
|
11312
|
+
* Uploads a file to a given file search store asynchronously using Gemini API only, this is not supported
|
|
11313
|
+
* in Vertex AI.
|
|
11063
11314
|
*
|
|
11064
|
-
* @
|
|
11065
|
-
*
|
|
11315
|
+
* @param fileSearchStoreName The name of the file search store to upload the file to.
|
|
11316
|
+
* @param file The string path to the file to be uploaded or a Blob object.
|
|
11317
|
+
* @param config Optional parameters specified in the `UploadFileConfig`
|
|
11318
|
+
* interface. @see {@link UploadFileConfig}
|
|
11319
|
+
* @return A promise that resolves to a `File` object.
|
|
11320
|
+
* @throws An error if called on a Vertex AI client.
|
|
11321
|
+
* @throws An error if the `mimeType` is not provided and can not be inferred,
|
|
11066
11322
|
*/
|
|
11067
|
-
async
|
|
11068
|
-
const downloader = this.clientOptions.downloader;
|
|
11069
|
-
await downloader.download(params, this);
|
|
11070
|
-
}
|
|
11071
|
-
async fetchUploadUrl(file, fileName, config) {
|
|
11323
|
+
async uploadFileToFileSearchStore(fileSearchStoreName, file, config) {
|
|
11072
11324
|
var _a;
|
|
11073
|
-
|
|
11074
|
-
|
|
11075
|
-
|
|
11325
|
+
const uploader = this.clientOptions.uploader;
|
|
11326
|
+
const fileStat = await uploader.stat(file);
|
|
11327
|
+
const sizeBytes = String(fileStat.size);
|
|
11328
|
+
const mimeType = (_a = config === null || config === void 0 ? void 0 : config.mimeType) !== null && _a !== void 0 ? _a : fileStat.type;
|
|
11329
|
+
if (mimeType === undefined || mimeType === '') {
|
|
11330
|
+
throw new Error('Can not determine mimeType. Please provide mimeType in the config.');
|
|
11331
|
+
}
|
|
11332
|
+
const path = `upload/v1beta/${fileSearchStoreName}:uploadToFileSearchStore`;
|
|
11333
|
+
const fileName = this.getFileName(file);
|
|
11334
|
+
const body = {};
|
|
11335
|
+
if (config === null || config === void 0 ? void 0 : config.customMetadata) {
|
|
11336
|
+
body['customMetadata'] = config.customMetadata;
|
|
11337
|
+
}
|
|
11338
|
+
if (config === null || config === void 0 ? void 0 : config.chunkingConfig) {
|
|
11339
|
+
body['chunkingConfig'] = config.chunkingConfig;
|
|
11340
|
+
}
|
|
11341
|
+
const uploadUrl = await this.fetchUploadUrl(path, sizeBytes, mimeType, fileName, body, config === null || config === void 0 ? void 0 : config.httpOptions);
|
|
11342
|
+
return uploader.uploadToFileSearchStore(file, uploadUrl, this);
|
|
11343
|
+
}
|
|
11344
|
+
/**
|
|
11345
|
+
* Downloads a file asynchronously to the specified path.
|
|
11346
|
+
*
|
|
11347
|
+
* @params params - The parameters for the download request, see {@link
|
|
11348
|
+
* types.DownloadFileParameters}
|
|
11349
|
+
*/
|
|
11350
|
+
async downloadFile(params) {
|
|
11351
|
+
const downloader = this.clientOptions.downloader;
|
|
11352
|
+
await downloader.download(params, this);
|
|
11353
|
+
}
|
|
11354
|
+
async fetchUploadUrl(path, sizeBytes, mimeType, fileName, body, configHttpOptions) {
|
|
11355
|
+
var _a;
|
|
11356
|
+
let httpOptions = {};
|
|
11357
|
+
if (configHttpOptions) {
|
|
11358
|
+
httpOptions = configHttpOptions;
|
|
11076
11359
|
}
|
|
11077
11360
|
else {
|
|
11078
11361
|
httpOptions = {
|
|
11079
11362
|
apiVersion: '',
|
|
11080
|
-
headers: Object.assign({ 'Content-Type': 'application/json', 'X-Goog-Upload-Protocol': 'resumable', 'X-Goog-Upload-Command': 'start', 'X-Goog-Upload-Header-Content-Length': `${
|
|
11363
|
+
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 } : {})),
|
|
11081
11364
|
};
|
|
11082
11365
|
}
|
|
11083
|
-
const body = {
|
|
11084
|
-
'file': file,
|
|
11085
|
-
};
|
|
11086
11366
|
const httpResponse = await this.request({
|
|
11087
|
-
path
|
|
11367
|
+
path,
|
|
11088
11368
|
body: JSON.stringify(body),
|
|
11089
11369
|
httpMethod: 'POST',
|
|
11090
11370
|
httpOptions,
|
|
@@ -12088,11 +12368,27 @@ function hasCallableTools(params) {
|
|
|
12088
12368
|
var _a, _b, _c;
|
|
12089
12369
|
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;
|
|
12090
12370
|
}
|
|
12091
|
-
|
|
12092
|
-
|
|
12093
|
-
|
|
12094
|
-
|
|
12095
|
-
|
|
12371
|
+
/**
|
|
12372
|
+
* Returns the indexes of the tools that are not compatible with AFC.
|
|
12373
|
+
*/
|
|
12374
|
+
function findAfcIncompatibleToolIndexes(params) {
|
|
12375
|
+
var _a;
|
|
12376
|
+
// Use number[] for an array of numbers in TypeScript
|
|
12377
|
+
const afcIncompatibleToolIndexes = [];
|
|
12378
|
+
if (!((_a = params === null || params === void 0 ? void 0 : params.config) === null || _a === void 0 ? void 0 : _a.tools)) {
|
|
12379
|
+
return afcIncompatibleToolIndexes;
|
|
12380
|
+
}
|
|
12381
|
+
params.config.tools.forEach((tool, index) => {
|
|
12382
|
+
if (isCallableTool(tool)) {
|
|
12383
|
+
return;
|
|
12384
|
+
}
|
|
12385
|
+
const geminiTool = tool;
|
|
12386
|
+
if (geminiTool.functionDeclarations &&
|
|
12387
|
+
geminiTool.functionDeclarations.length > 0) {
|
|
12388
|
+
afcIncompatibleToolIndexes.push(index);
|
|
12389
|
+
}
|
|
12390
|
+
});
|
|
12391
|
+
return afcIncompatibleToolIndexes;
|
|
12096
12392
|
}
|
|
12097
12393
|
/**
|
|
12098
12394
|
* Returns whether to append automatic function calling history to the
|
|
@@ -12157,8 +12453,12 @@ class Models extends BaseModule {
|
|
|
12157
12453
|
if (!hasCallableTools(params) || shouldDisableAfc(params.config)) {
|
|
12158
12454
|
return await this.generateContentInternal(transformedParams);
|
|
12159
12455
|
}
|
|
12160
|
-
|
|
12161
|
-
|
|
12456
|
+
const incompatibleToolIndexes = findAfcIncompatibleToolIndexes(params);
|
|
12457
|
+
if (incompatibleToolIndexes.length > 0) {
|
|
12458
|
+
const formattedIndexes = incompatibleToolIndexes
|
|
12459
|
+
.map((index) => `tools[${index}]`)
|
|
12460
|
+
.join(', ');
|
|
12461
|
+
throw new Error(`Automatic function calling with CallableTools (or MCP objects) and basic FunctionDeclarations is not yet supported. Incompatible tools found at ${formattedIndexes}.`);
|
|
12162
12462
|
}
|
|
12163
12463
|
let response;
|
|
12164
12464
|
let functionResponseContent;
|
|
@@ -12245,9 +12545,14 @@ class Models extends BaseModule {
|
|
|
12245
12545
|
const transformedParams = await this.processParamsMaybeAddMcpUsage(params);
|
|
12246
12546
|
return await this.generateContentStreamInternal(transformedParams);
|
|
12247
12547
|
}
|
|
12248
|
-
|
|
12249
|
-
|
|
12548
|
+
const incompatibleToolIndexes = findAfcIncompatibleToolIndexes(params);
|
|
12549
|
+
if (incompatibleToolIndexes.length > 0) {
|
|
12550
|
+
const formattedIndexes = incompatibleToolIndexes
|
|
12551
|
+
.map((index) => `tools[${index}]`)
|
|
12552
|
+
.join(', ');
|
|
12553
|
+
throw new Error(`Incompatible tools found at ${formattedIndexes}. Automatic function calling with CallableTools (or MCP objects) and basic FunctionDeclarations" is not yet supported.`);
|
|
12250
12554
|
}
|
|
12555
|
+
return await this.processAfcStream(params);
|
|
12251
12556
|
};
|
|
12252
12557
|
/**
|
|
12253
12558
|
* Generates an image based on a text description and configuration.
|
|
@@ -13643,7 +13948,7 @@ class Operations extends BaseModule {
|
|
|
13643
13948
|
});
|
|
13644
13949
|
return operation._fromAPIResponse({
|
|
13645
13950
|
apiResponse: rawOperation,
|
|
13646
|
-
|
|
13951
|
+
_isVertexAI: true,
|
|
13647
13952
|
});
|
|
13648
13953
|
}
|
|
13649
13954
|
else {
|
|
@@ -13653,7 +13958,7 @@ class Operations extends BaseModule {
|
|
|
13653
13958
|
});
|
|
13654
13959
|
return operation._fromAPIResponse({
|
|
13655
13960
|
apiResponse: rawOperation,
|
|
13656
|
-
|
|
13961
|
+
_isVertexAI: false,
|
|
13657
13962
|
});
|
|
13658
13963
|
}
|
|
13659
13964
|
}
|
|
@@ -13682,7 +13987,7 @@ class Operations extends BaseModule {
|
|
|
13682
13987
|
});
|
|
13683
13988
|
return operation._fromAPIResponse({
|
|
13684
13989
|
apiResponse: rawOperation,
|
|
13685
|
-
|
|
13990
|
+
_isVertexAI: true,
|
|
13686
13991
|
});
|
|
13687
13992
|
}
|
|
13688
13993
|
else {
|
|
@@ -13692,7 +13997,7 @@ class Operations extends BaseModule {
|
|
|
13692
13997
|
});
|
|
13693
13998
|
return operation._fromAPIResponse({
|
|
13694
13999
|
apiResponse: rawOperation,
|
|
13695
|
-
|
|
14000
|
+
_isVertexAI: false,
|
|
13696
14001
|
});
|
|
13697
14002
|
}
|
|
13698
14003
|
}
|
|
@@ -13880,6 +14185,9 @@ function googleSearchToMldev(fromObject) {
|
|
|
13880
14185
|
if (getValueByPath(fromObject, ['excludeDomains']) !== undefined) {
|
|
13881
14186
|
throw new Error('excludeDomains parameter is not supported in Gemini API.');
|
|
13882
14187
|
}
|
|
14188
|
+
if (getValueByPath(fromObject, ['blockingConfidence']) !== undefined) {
|
|
14189
|
+
throw new Error('blockingConfidence parameter is not supported in Gemini API.');
|
|
14190
|
+
}
|
|
13883
14191
|
const fromTimeRangeFilter = getValueByPath(fromObject, [
|
|
13884
14192
|
'timeRangeFilter',
|
|
13885
14193
|
]);
|
|
@@ -14098,14 +14406,14 @@ function toolToMldev(fromObject) {
|
|
|
14098
14406
|
if (fromGoogleSearchRetrieval != null) {
|
|
14099
14407
|
setValueByPath(toObject, ['googleSearchRetrieval'], fromGoogleSearchRetrieval);
|
|
14100
14408
|
}
|
|
14101
|
-
const fromGoogleMaps = getValueByPath(fromObject, ['googleMaps']);
|
|
14102
|
-
if (fromGoogleMaps != null) {
|
|
14103
|
-
setValueByPath(toObject, ['googleMaps'], googleMapsToMldev(fromGoogleMaps));
|
|
14104
|
-
}
|
|
14105
14409
|
const fromComputerUse = getValueByPath(fromObject, ['computerUse']);
|
|
14106
14410
|
if (fromComputerUse != null) {
|
|
14107
14411
|
setValueByPath(toObject, ['computerUse'], fromComputerUse);
|
|
14108
14412
|
}
|
|
14413
|
+
const fromFileSearch = getValueByPath(fromObject, ['fileSearch']);
|
|
14414
|
+
if (fromFileSearch != null) {
|
|
14415
|
+
setValueByPath(toObject, ['fileSearch'], fromFileSearch);
|
|
14416
|
+
}
|
|
14109
14417
|
const fromCodeExecution = getValueByPath(fromObject, [
|
|
14110
14418
|
'codeExecution',
|
|
14111
14419
|
]);
|
|
@@ -14115,6 +14423,10 @@ function toolToMldev(fromObject) {
|
|
|
14115
14423
|
if (getValueByPath(fromObject, ['enterpriseWebSearch']) !== undefined) {
|
|
14116
14424
|
throw new Error('enterpriseWebSearch parameter is not supported in Gemini API.');
|
|
14117
14425
|
}
|
|
14426
|
+
const fromGoogleMaps = getValueByPath(fromObject, ['googleMaps']);
|
|
14427
|
+
if (fromGoogleMaps != null) {
|
|
14428
|
+
setValueByPath(toObject, ['googleMaps'], googleMapsToMldev(fromGoogleMaps));
|
|
14429
|
+
}
|
|
14118
14430
|
const fromGoogleSearch = getValueByPath(fromObject, ['googleSearch']);
|
|
14119
14431
|
if (fromGoogleSearch != null) {
|
|
14120
14432
|
setValueByPath(toObject, ['googleSearch'], googleSearchToMldev(fromGoogleSearch));
|
|
@@ -14401,195 +14713,44 @@ class Tokens extends BaseModule {
|
|
|
14401
14713
|
* Copyright 2025 Google LLC
|
|
14402
14714
|
* SPDX-License-Identifier: Apache-2.0
|
|
14403
14715
|
*/
|
|
14404
|
-
|
|
14405
|
-
|
|
14406
|
-
|
|
14407
|
-
|
|
14408
|
-
|
|
14409
|
-
|
|
14410
|
-
return;
|
|
14411
|
-
}
|
|
14412
|
-
const vertexAuthOptions = buildGoogleAuthOptions(opts.googleAuthOptions);
|
|
14413
|
-
this.googleAuth = new googleAuthLibrary.GoogleAuth(vertexAuthOptions);
|
|
14414
|
-
}
|
|
14415
|
-
async addAuthHeaders(headers, url) {
|
|
14416
|
-
if (this.apiKey !== undefined) {
|
|
14417
|
-
if (this.apiKey.startsWith('auth_tokens/')) {
|
|
14418
|
-
throw new Error('Ephemeral tokens are only supported by the live API.');
|
|
14419
|
-
}
|
|
14420
|
-
this.addKeyHeader(headers);
|
|
14421
|
-
return;
|
|
14422
|
-
}
|
|
14423
|
-
return this.addGoogleAuthHeaders(headers, url);
|
|
14424
|
-
}
|
|
14425
|
-
addKeyHeader(headers) {
|
|
14426
|
-
if (headers.get(GOOGLE_API_KEY_HEADER) !== null) {
|
|
14427
|
-
return;
|
|
14428
|
-
}
|
|
14429
|
-
if (this.apiKey === undefined) {
|
|
14430
|
-
// This should never happen, this method is only called
|
|
14431
|
-
// when apiKey is set.
|
|
14432
|
-
throw new Error('Trying to set API key header but apiKey is not set');
|
|
14433
|
-
}
|
|
14434
|
-
headers.append(GOOGLE_API_KEY_HEADER, this.apiKey);
|
|
14435
|
-
}
|
|
14436
|
-
async addGoogleAuthHeaders(headers, url) {
|
|
14437
|
-
if (this.googleAuth === undefined) {
|
|
14438
|
-
// This should never happen, addGoogleAuthHeaders should only be
|
|
14439
|
-
// called when there is no apiKey set and in these cases googleAuth
|
|
14440
|
-
// is set.
|
|
14441
|
-
throw new Error('Trying to set google-auth headers but googleAuth is unset');
|
|
14442
|
-
}
|
|
14443
|
-
const authHeaders = await this.googleAuth.getRequestHeaders(url);
|
|
14444
|
-
for (const [key, value] of authHeaders) {
|
|
14445
|
-
if (headers.get(key) !== null) {
|
|
14446
|
-
continue;
|
|
14447
|
-
}
|
|
14448
|
-
headers.append(key, value);
|
|
14449
|
-
}
|
|
14450
|
-
}
|
|
14451
|
-
}
|
|
14452
|
-
function buildGoogleAuthOptions(googleAuthOptions) {
|
|
14453
|
-
let authOptions;
|
|
14454
|
-
if (!googleAuthOptions) {
|
|
14455
|
-
authOptions = {
|
|
14456
|
-
scopes: [REQUIRED_VERTEX_AI_SCOPE],
|
|
14457
|
-
};
|
|
14458
|
-
return authOptions;
|
|
14459
|
-
}
|
|
14460
|
-
else {
|
|
14461
|
-
authOptions = googleAuthOptions;
|
|
14462
|
-
if (!authOptions.scopes) {
|
|
14463
|
-
authOptions.scopes = [REQUIRED_VERTEX_AI_SCOPE];
|
|
14464
|
-
return authOptions;
|
|
14465
|
-
}
|
|
14466
|
-
else if ((typeof authOptions.scopes === 'string' &&
|
|
14467
|
-
authOptions.scopes !== REQUIRED_VERTEX_AI_SCOPE) ||
|
|
14468
|
-
(Array.isArray(authOptions.scopes) &&
|
|
14469
|
-
authOptions.scopes.indexOf(REQUIRED_VERTEX_AI_SCOPE) < 0)) {
|
|
14470
|
-
throw new Error(`Invalid auth scopes. Scopes must include: ${REQUIRED_VERTEX_AI_SCOPE}`);
|
|
14471
|
-
}
|
|
14472
|
-
return authOptions;
|
|
14473
|
-
}
|
|
14474
|
-
}
|
|
14475
|
-
|
|
14476
|
-
/**
|
|
14477
|
-
* @license
|
|
14478
|
-
* Copyright 2025 Google LLC
|
|
14479
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
14480
|
-
*/
|
|
14481
|
-
class NodeDownloader {
|
|
14482
|
-
async download(params, apiClient) {
|
|
14483
|
-
if (params.downloadPath) {
|
|
14484
|
-
const response = await downloadFile(params, apiClient);
|
|
14485
|
-
if (response instanceof HttpResponse) {
|
|
14486
|
-
const writer = fs.createWriteStream(params.downloadPath);
|
|
14487
|
-
const body = node_stream.Readable.fromWeb(response.responseInternal.body);
|
|
14488
|
-
body.pipe(writer);
|
|
14489
|
-
await promises.finished(writer);
|
|
14490
|
-
}
|
|
14491
|
-
else {
|
|
14492
|
-
try {
|
|
14493
|
-
await fs$1.writeFile(params.downloadPath, response, {
|
|
14494
|
-
encoding: 'base64',
|
|
14495
|
-
});
|
|
14496
|
-
}
|
|
14497
|
-
catch (error) {
|
|
14498
|
-
throw new Error(`Failed to write file to ${params.downloadPath}: ${error}`);
|
|
14499
|
-
}
|
|
14500
|
-
}
|
|
14501
|
-
}
|
|
14502
|
-
}
|
|
14503
|
-
}
|
|
14504
|
-
async function downloadFile(params, apiClient) {
|
|
14505
|
-
var _a, _b, _c;
|
|
14506
|
-
const name = tFileName(params.file);
|
|
14507
|
-
if (name !== undefined) {
|
|
14508
|
-
return await apiClient.request({
|
|
14509
|
-
path: `files/${name}:download`,
|
|
14510
|
-
httpMethod: 'GET',
|
|
14511
|
-
queryParams: {
|
|
14512
|
-
'alt': 'media',
|
|
14513
|
-
},
|
|
14514
|
-
httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
|
|
14515
|
-
abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
|
|
14516
|
-
});
|
|
14517
|
-
}
|
|
14518
|
-
else if (isGeneratedVideo(params.file)) {
|
|
14519
|
-
const videoBytes = (_c = params.file.video) === null || _c === void 0 ? void 0 : _c.videoBytes;
|
|
14520
|
-
if (typeof videoBytes === 'string') {
|
|
14521
|
-
return videoBytes;
|
|
14522
|
-
}
|
|
14523
|
-
else {
|
|
14524
|
-
throw new Error('Failed to download generated video, Uri or videoBytes not found.');
|
|
14525
|
-
}
|
|
14526
|
-
}
|
|
14527
|
-
else if (isVideo(params.file)) {
|
|
14528
|
-
const videoBytes = params.file.videoBytes;
|
|
14529
|
-
if (typeof videoBytes === 'string') {
|
|
14530
|
-
return videoBytes;
|
|
14531
|
-
}
|
|
14532
|
-
else {
|
|
14533
|
-
throw new Error('Failed to download video, Uri or videoBytes not found.');
|
|
14534
|
-
}
|
|
14535
|
-
}
|
|
14536
|
-
else {
|
|
14537
|
-
throw new Error('Unsupported file type');
|
|
14716
|
+
// Code generated by the Google Gen AI SDK generator DO NOT EDIT.
|
|
14717
|
+
function createFileSearchStoreConfigToMldev(fromObject, parentObject) {
|
|
14718
|
+
const toObject = {};
|
|
14719
|
+
const fromDisplayName = getValueByPath(fromObject, ['displayName']);
|
|
14720
|
+
if (parentObject !== undefined && fromDisplayName != null) {
|
|
14721
|
+
setValueByPath(parentObject, ['displayName'], fromDisplayName);
|
|
14538
14722
|
}
|
|
14723
|
+
return toObject;
|
|
14539
14724
|
}
|
|
14540
|
-
|
|
14541
|
-
|
|
14542
|
-
|
|
14543
|
-
|
|
14544
|
-
|
|
14545
|
-
*/
|
|
14546
|
-
class NodeWebSocketFactory {
|
|
14547
|
-
create(url, headers, callbacks) {
|
|
14548
|
-
return new NodeWebSocket(url, headers, callbacks);
|
|
14725
|
+
function createFileSearchStoreParametersToMldev(fromObject) {
|
|
14726
|
+
const toObject = {};
|
|
14727
|
+
const fromConfig = getValueByPath(fromObject, ['config']);
|
|
14728
|
+
if (fromConfig != null) {
|
|
14729
|
+
createFileSearchStoreConfigToMldev(fromConfig, toObject);
|
|
14549
14730
|
}
|
|
14731
|
+
return toObject;
|
|
14550
14732
|
}
|
|
14551
|
-
|
|
14552
|
-
|
|
14553
|
-
|
|
14554
|
-
|
|
14555
|
-
|
|
14556
|
-
}
|
|
14557
|
-
connect() {
|
|
14558
|
-
this.ws = new NodeWs__namespace.WebSocket(this.url, { headers: this.headers });
|
|
14559
|
-
this.ws.onopen = this.callbacks.onopen;
|
|
14560
|
-
this.ws.onerror = this.callbacks.onerror;
|
|
14561
|
-
this.ws.onclose = this.callbacks.onclose;
|
|
14562
|
-
this.ws.onmessage = this.callbacks.onmessage;
|
|
14563
|
-
}
|
|
14564
|
-
send(message) {
|
|
14565
|
-
if (this.ws === undefined) {
|
|
14566
|
-
throw new Error('WebSocket is not connected');
|
|
14567
|
-
}
|
|
14568
|
-
this.ws.send(message);
|
|
14569
|
-
}
|
|
14570
|
-
close() {
|
|
14571
|
-
if (this.ws === undefined) {
|
|
14572
|
-
throw new Error('WebSocket is not connected');
|
|
14573
|
-
}
|
|
14574
|
-
this.ws.close();
|
|
14733
|
+
function deleteFileSearchStoreConfigToMldev(fromObject, parentObject) {
|
|
14734
|
+
const toObject = {};
|
|
14735
|
+
const fromForce = getValueByPath(fromObject, ['force']);
|
|
14736
|
+
if (parentObject !== undefined && fromForce != null) {
|
|
14737
|
+
setValueByPath(parentObject, ['_query', 'force'], fromForce);
|
|
14575
14738
|
}
|
|
14739
|
+
return toObject;
|
|
14576
14740
|
}
|
|
14577
|
-
|
|
14578
|
-
/**
|
|
14579
|
-
* @license
|
|
14580
|
-
* Copyright 2025 Google LLC
|
|
14581
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
14582
|
-
*/
|
|
14583
|
-
// Code generated by the Google Gen AI SDK generator DO NOT EDIT.
|
|
14584
|
-
function cancelTuningJobParametersToMldev(fromObject, _rootObject) {
|
|
14741
|
+
function deleteFileSearchStoreParametersToMldev(fromObject) {
|
|
14585
14742
|
const toObject = {};
|
|
14586
14743
|
const fromName = getValueByPath(fromObject, ['name']);
|
|
14587
14744
|
if (fromName != null) {
|
|
14588
14745
|
setValueByPath(toObject, ['_url', 'name'], fromName);
|
|
14589
14746
|
}
|
|
14747
|
+
const fromConfig = getValueByPath(fromObject, ['config']);
|
|
14748
|
+
if (fromConfig != null) {
|
|
14749
|
+
deleteFileSearchStoreConfigToMldev(fromConfig, toObject);
|
|
14750
|
+
}
|
|
14590
14751
|
return toObject;
|
|
14591
14752
|
}
|
|
14592
|
-
function
|
|
14753
|
+
function getFileSearchStoreParametersToMldev(fromObject) {
|
|
14593
14754
|
const toObject = {};
|
|
14594
14755
|
const fromName = getValueByPath(fromObject, ['name']);
|
|
14595
14756
|
if (fromName != null) {
|
|
@@ -14597,19 +14758,917 @@ function cancelTuningJobParametersToVertex(fromObject, _rootObject) {
|
|
|
14597
14758
|
}
|
|
14598
14759
|
return toObject;
|
|
14599
14760
|
}
|
|
14600
|
-
function
|
|
14761
|
+
function importFileConfigToMldev(fromObject, parentObject) {
|
|
14601
14762
|
const toObject = {};
|
|
14602
|
-
|
|
14603
|
-
|
|
14763
|
+
const fromCustomMetadata = getValueByPath(fromObject, [
|
|
14764
|
+
'customMetadata',
|
|
14765
|
+
]);
|
|
14766
|
+
if (parentObject !== undefined && fromCustomMetadata != null) {
|
|
14767
|
+
let transformedList = fromCustomMetadata;
|
|
14768
|
+
if (Array.isArray(transformedList)) {
|
|
14769
|
+
transformedList = transformedList.map((item) => {
|
|
14770
|
+
return item;
|
|
14771
|
+
});
|
|
14772
|
+
}
|
|
14773
|
+
setValueByPath(parentObject, ['customMetadata'], transformedList);
|
|
14604
14774
|
}
|
|
14605
|
-
const
|
|
14606
|
-
'
|
|
14775
|
+
const fromChunkingConfig = getValueByPath(fromObject, [
|
|
14776
|
+
'chunkingConfig',
|
|
14607
14777
|
]);
|
|
14608
|
-
if (parentObject !== undefined &&
|
|
14609
|
-
setValueByPath(parentObject, ['
|
|
14778
|
+
if (parentObject !== undefined && fromChunkingConfig != null) {
|
|
14779
|
+
setValueByPath(parentObject, ['chunkingConfig'], fromChunkingConfig);
|
|
14610
14780
|
}
|
|
14611
|
-
|
|
14612
|
-
|
|
14781
|
+
return toObject;
|
|
14782
|
+
}
|
|
14783
|
+
function importFileOperationFromMldev(fromObject) {
|
|
14784
|
+
const toObject = {};
|
|
14785
|
+
const fromName = getValueByPath(fromObject, ['name']);
|
|
14786
|
+
if (fromName != null) {
|
|
14787
|
+
setValueByPath(toObject, ['name'], fromName);
|
|
14788
|
+
}
|
|
14789
|
+
const fromMetadata = getValueByPath(fromObject, ['metadata']);
|
|
14790
|
+
if (fromMetadata != null) {
|
|
14791
|
+
setValueByPath(toObject, ['metadata'], fromMetadata);
|
|
14792
|
+
}
|
|
14793
|
+
const fromDone = getValueByPath(fromObject, ['done']);
|
|
14794
|
+
if (fromDone != null) {
|
|
14795
|
+
setValueByPath(toObject, ['done'], fromDone);
|
|
14796
|
+
}
|
|
14797
|
+
const fromError = getValueByPath(fromObject, ['error']);
|
|
14798
|
+
if (fromError != null) {
|
|
14799
|
+
setValueByPath(toObject, ['error'], fromError);
|
|
14800
|
+
}
|
|
14801
|
+
const fromResponse = getValueByPath(fromObject, ['response']);
|
|
14802
|
+
if (fromResponse != null) {
|
|
14803
|
+
setValueByPath(toObject, ['response'], importFileResponseFromMldev(fromResponse));
|
|
14804
|
+
}
|
|
14805
|
+
return toObject;
|
|
14806
|
+
}
|
|
14807
|
+
function importFileParametersToMldev(fromObject) {
|
|
14808
|
+
const toObject = {};
|
|
14809
|
+
const fromFileSearchStoreName = getValueByPath(fromObject, [
|
|
14810
|
+
'fileSearchStoreName',
|
|
14811
|
+
]);
|
|
14812
|
+
if (fromFileSearchStoreName != null) {
|
|
14813
|
+
setValueByPath(toObject, ['_url', 'file_search_store_name'], fromFileSearchStoreName);
|
|
14814
|
+
}
|
|
14815
|
+
const fromFileName = getValueByPath(fromObject, ['fileName']);
|
|
14816
|
+
if (fromFileName != null) {
|
|
14817
|
+
setValueByPath(toObject, ['fileName'], fromFileName);
|
|
14818
|
+
}
|
|
14819
|
+
const fromConfig = getValueByPath(fromObject, ['config']);
|
|
14820
|
+
if (fromConfig != null) {
|
|
14821
|
+
importFileConfigToMldev(fromConfig, toObject);
|
|
14822
|
+
}
|
|
14823
|
+
return toObject;
|
|
14824
|
+
}
|
|
14825
|
+
function importFileResponseFromMldev(fromObject) {
|
|
14826
|
+
const toObject = {};
|
|
14827
|
+
const fromSdkHttpResponse = getValueByPath(fromObject, [
|
|
14828
|
+
'sdkHttpResponse',
|
|
14829
|
+
]);
|
|
14830
|
+
if (fromSdkHttpResponse != null) {
|
|
14831
|
+
setValueByPath(toObject, ['sdkHttpResponse'], fromSdkHttpResponse);
|
|
14832
|
+
}
|
|
14833
|
+
const fromParent = getValueByPath(fromObject, ['parent']);
|
|
14834
|
+
if (fromParent != null) {
|
|
14835
|
+
setValueByPath(toObject, ['parent'], fromParent);
|
|
14836
|
+
}
|
|
14837
|
+
const fromDocumentName = getValueByPath(fromObject, ['documentName']);
|
|
14838
|
+
if (fromDocumentName != null) {
|
|
14839
|
+
setValueByPath(toObject, ['documentName'], fromDocumentName);
|
|
14840
|
+
}
|
|
14841
|
+
return toObject;
|
|
14842
|
+
}
|
|
14843
|
+
function listFileSearchStoresConfigToMldev(fromObject, parentObject) {
|
|
14844
|
+
const toObject = {};
|
|
14845
|
+
const fromPageSize = getValueByPath(fromObject, ['pageSize']);
|
|
14846
|
+
if (parentObject !== undefined && fromPageSize != null) {
|
|
14847
|
+
setValueByPath(parentObject, ['_query', 'pageSize'], fromPageSize);
|
|
14848
|
+
}
|
|
14849
|
+
const fromPageToken = getValueByPath(fromObject, ['pageToken']);
|
|
14850
|
+
if (parentObject !== undefined && fromPageToken != null) {
|
|
14851
|
+
setValueByPath(parentObject, ['_query', 'pageToken'], fromPageToken);
|
|
14852
|
+
}
|
|
14853
|
+
return toObject;
|
|
14854
|
+
}
|
|
14855
|
+
function listFileSearchStoresParametersToMldev(fromObject) {
|
|
14856
|
+
const toObject = {};
|
|
14857
|
+
const fromConfig = getValueByPath(fromObject, ['config']);
|
|
14858
|
+
if (fromConfig != null) {
|
|
14859
|
+
listFileSearchStoresConfigToMldev(fromConfig, toObject);
|
|
14860
|
+
}
|
|
14861
|
+
return toObject;
|
|
14862
|
+
}
|
|
14863
|
+
function listFileSearchStoresResponseFromMldev(fromObject) {
|
|
14864
|
+
const toObject = {};
|
|
14865
|
+
const fromSdkHttpResponse = getValueByPath(fromObject, [
|
|
14866
|
+
'sdkHttpResponse',
|
|
14867
|
+
]);
|
|
14868
|
+
if (fromSdkHttpResponse != null) {
|
|
14869
|
+
setValueByPath(toObject, ['sdkHttpResponse'], fromSdkHttpResponse);
|
|
14870
|
+
}
|
|
14871
|
+
const fromNextPageToken = getValueByPath(fromObject, [
|
|
14872
|
+
'nextPageToken',
|
|
14873
|
+
]);
|
|
14874
|
+
if (fromNextPageToken != null) {
|
|
14875
|
+
setValueByPath(toObject, ['nextPageToken'], fromNextPageToken);
|
|
14876
|
+
}
|
|
14877
|
+
const fromFileSearchStores = getValueByPath(fromObject, [
|
|
14878
|
+
'fileSearchStores',
|
|
14879
|
+
]);
|
|
14880
|
+
if (fromFileSearchStores != null) {
|
|
14881
|
+
let transformedList = fromFileSearchStores;
|
|
14882
|
+
if (Array.isArray(transformedList)) {
|
|
14883
|
+
transformedList = transformedList.map((item) => {
|
|
14884
|
+
return item;
|
|
14885
|
+
});
|
|
14886
|
+
}
|
|
14887
|
+
setValueByPath(toObject, ['fileSearchStores'], transformedList);
|
|
14888
|
+
}
|
|
14889
|
+
return toObject;
|
|
14890
|
+
}
|
|
14891
|
+
function uploadToFileSearchStoreConfigToMldev(fromObject, parentObject) {
|
|
14892
|
+
const toObject = {};
|
|
14893
|
+
const fromMimeType = getValueByPath(fromObject, ['mimeType']);
|
|
14894
|
+
if (parentObject !== undefined && fromMimeType != null) {
|
|
14895
|
+
setValueByPath(parentObject, ['mimeType'], fromMimeType);
|
|
14896
|
+
}
|
|
14897
|
+
const fromDisplayName = getValueByPath(fromObject, ['displayName']);
|
|
14898
|
+
if (parentObject !== undefined && fromDisplayName != null) {
|
|
14899
|
+
setValueByPath(parentObject, ['displayName'], fromDisplayName);
|
|
14900
|
+
}
|
|
14901
|
+
const fromCustomMetadata = getValueByPath(fromObject, [
|
|
14902
|
+
'customMetadata',
|
|
14903
|
+
]);
|
|
14904
|
+
if (parentObject !== undefined && fromCustomMetadata != null) {
|
|
14905
|
+
let transformedList = fromCustomMetadata;
|
|
14906
|
+
if (Array.isArray(transformedList)) {
|
|
14907
|
+
transformedList = transformedList.map((item) => {
|
|
14908
|
+
return item;
|
|
14909
|
+
});
|
|
14910
|
+
}
|
|
14911
|
+
setValueByPath(parentObject, ['customMetadata'], transformedList);
|
|
14912
|
+
}
|
|
14913
|
+
const fromChunkingConfig = getValueByPath(fromObject, [
|
|
14914
|
+
'chunkingConfig',
|
|
14915
|
+
]);
|
|
14916
|
+
if (parentObject !== undefined && fromChunkingConfig != null) {
|
|
14917
|
+
setValueByPath(parentObject, ['chunkingConfig'], fromChunkingConfig);
|
|
14918
|
+
}
|
|
14919
|
+
return toObject;
|
|
14920
|
+
}
|
|
14921
|
+
function uploadToFileSearchStoreParametersToMldev(fromObject) {
|
|
14922
|
+
const toObject = {};
|
|
14923
|
+
const fromFileSearchStoreName = getValueByPath(fromObject, [
|
|
14924
|
+
'fileSearchStoreName',
|
|
14925
|
+
]);
|
|
14926
|
+
if (fromFileSearchStoreName != null) {
|
|
14927
|
+
setValueByPath(toObject, ['_url', 'file_search_store_name'], fromFileSearchStoreName);
|
|
14928
|
+
}
|
|
14929
|
+
const fromConfig = getValueByPath(fromObject, ['config']);
|
|
14930
|
+
if (fromConfig != null) {
|
|
14931
|
+
uploadToFileSearchStoreConfigToMldev(fromConfig, toObject);
|
|
14932
|
+
}
|
|
14933
|
+
return toObject;
|
|
14934
|
+
}
|
|
14935
|
+
function uploadToFileSearchStoreResumableResponseFromMldev(fromObject) {
|
|
14936
|
+
const toObject = {};
|
|
14937
|
+
const fromSdkHttpResponse = getValueByPath(fromObject, [
|
|
14938
|
+
'sdkHttpResponse',
|
|
14939
|
+
]);
|
|
14940
|
+
if (fromSdkHttpResponse != null) {
|
|
14941
|
+
setValueByPath(toObject, ['sdkHttpResponse'], fromSdkHttpResponse);
|
|
14942
|
+
}
|
|
14943
|
+
return toObject;
|
|
14944
|
+
}
|
|
14945
|
+
|
|
14946
|
+
/**
|
|
14947
|
+
* @license
|
|
14948
|
+
* Copyright 2025 Google LLC
|
|
14949
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
14950
|
+
*/
|
|
14951
|
+
// Code generated by the Google Gen AI SDK generator DO NOT EDIT.
|
|
14952
|
+
function deleteDocumentConfigToMldev(fromObject, parentObject) {
|
|
14953
|
+
const toObject = {};
|
|
14954
|
+
const fromForce = getValueByPath(fromObject, ['force']);
|
|
14955
|
+
if (parentObject !== undefined && fromForce != null) {
|
|
14956
|
+
setValueByPath(parentObject, ['_query', 'force'], fromForce);
|
|
14957
|
+
}
|
|
14958
|
+
return toObject;
|
|
14959
|
+
}
|
|
14960
|
+
function deleteDocumentParametersToMldev(fromObject) {
|
|
14961
|
+
const toObject = {};
|
|
14962
|
+
const fromName = getValueByPath(fromObject, ['name']);
|
|
14963
|
+
if (fromName != null) {
|
|
14964
|
+
setValueByPath(toObject, ['_url', 'name'], fromName);
|
|
14965
|
+
}
|
|
14966
|
+
const fromConfig = getValueByPath(fromObject, ['config']);
|
|
14967
|
+
if (fromConfig != null) {
|
|
14968
|
+
deleteDocumentConfigToMldev(fromConfig, toObject);
|
|
14969
|
+
}
|
|
14970
|
+
return toObject;
|
|
14971
|
+
}
|
|
14972
|
+
function getDocumentParametersToMldev(fromObject) {
|
|
14973
|
+
const toObject = {};
|
|
14974
|
+
const fromName = getValueByPath(fromObject, ['name']);
|
|
14975
|
+
if (fromName != null) {
|
|
14976
|
+
setValueByPath(toObject, ['_url', 'name'], fromName);
|
|
14977
|
+
}
|
|
14978
|
+
return toObject;
|
|
14979
|
+
}
|
|
14980
|
+
function listDocumentsConfigToMldev(fromObject, parentObject) {
|
|
14981
|
+
const toObject = {};
|
|
14982
|
+
const fromPageSize = getValueByPath(fromObject, ['pageSize']);
|
|
14983
|
+
if (parentObject !== undefined && fromPageSize != null) {
|
|
14984
|
+
setValueByPath(parentObject, ['_query', 'pageSize'], fromPageSize);
|
|
14985
|
+
}
|
|
14986
|
+
const fromPageToken = getValueByPath(fromObject, ['pageToken']);
|
|
14987
|
+
if (parentObject !== undefined && fromPageToken != null) {
|
|
14988
|
+
setValueByPath(parentObject, ['_query', 'pageToken'], fromPageToken);
|
|
14989
|
+
}
|
|
14990
|
+
return toObject;
|
|
14991
|
+
}
|
|
14992
|
+
function listDocumentsParametersToMldev(fromObject) {
|
|
14993
|
+
const toObject = {};
|
|
14994
|
+
const fromParent = getValueByPath(fromObject, ['parent']);
|
|
14995
|
+
if (fromParent != null) {
|
|
14996
|
+
setValueByPath(toObject, ['_url', 'parent'], fromParent);
|
|
14997
|
+
}
|
|
14998
|
+
const fromConfig = getValueByPath(fromObject, ['config']);
|
|
14999
|
+
if (fromConfig != null) {
|
|
15000
|
+
listDocumentsConfigToMldev(fromConfig, toObject);
|
|
15001
|
+
}
|
|
15002
|
+
return toObject;
|
|
15003
|
+
}
|
|
15004
|
+
function listDocumentsResponseFromMldev(fromObject) {
|
|
15005
|
+
const toObject = {};
|
|
15006
|
+
const fromSdkHttpResponse = getValueByPath(fromObject, [
|
|
15007
|
+
'sdkHttpResponse',
|
|
15008
|
+
]);
|
|
15009
|
+
if (fromSdkHttpResponse != null) {
|
|
15010
|
+
setValueByPath(toObject, ['sdkHttpResponse'], fromSdkHttpResponse);
|
|
15011
|
+
}
|
|
15012
|
+
const fromNextPageToken = getValueByPath(fromObject, [
|
|
15013
|
+
'nextPageToken',
|
|
15014
|
+
]);
|
|
15015
|
+
if (fromNextPageToken != null) {
|
|
15016
|
+
setValueByPath(toObject, ['nextPageToken'], fromNextPageToken);
|
|
15017
|
+
}
|
|
15018
|
+
const fromDocuments = getValueByPath(fromObject, ['documents']);
|
|
15019
|
+
if (fromDocuments != null) {
|
|
15020
|
+
let transformedList = fromDocuments;
|
|
15021
|
+
if (Array.isArray(transformedList)) {
|
|
15022
|
+
transformedList = transformedList.map((item) => {
|
|
15023
|
+
return item;
|
|
15024
|
+
});
|
|
15025
|
+
}
|
|
15026
|
+
setValueByPath(toObject, ['documents'], transformedList);
|
|
15027
|
+
}
|
|
15028
|
+
return toObject;
|
|
15029
|
+
}
|
|
15030
|
+
|
|
15031
|
+
/**
|
|
15032
|
+
* @license
|
|
15033
|
+
* Copyright 2025 Google LLC
|
|
15034
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
15035
|
+
*/
|
|
15036
|
+
class Documents extends BaseModule {
|
|
15037
|
+
constructor(apiClient) {
|
|
15038
|
+
super();
|
|
15039
|
+
this.apiClient = apiClient;
|
|
15040
|
+
/**
|
|
15041
|
+
* Lists documents.
|
|
15042
|
+
*
|
|
15043
|
+
* @param params - The parameters for the list request.
|
|
15044
|
+
* @return - A pager of documents.
|
|
15045
|
+
*
|
|
15046
|
+
* @example
|
|
15047
|
+
* ```ts
|
|
15048
|
+
* const documents = await ai.documents.list({config: {'pageSize': 2}});
|
|
15049
|
+
* for await (const document of documents) {
|
|
15050
|
+
* console.log(document);
|
|
15051
|
+
* }
|
|
15052
|
+
* ```
|
|
15053
|
+
*/
|
|
15054
|
+
this.list = async (params) => {
|
|
15055
|
+
return new Pager(exports.PagedItem.PAGED_ITEM_DOCUMENTS, (x) => this.listInternal({
|
|
15056
|
+
parent: params.parent,
|
|
15057
|
+
config: x.config,
|
|
15058
|
+
}), await this.listInternal(params), params);
|
|
15059
|
+
};
|
|
15060
|
+
}
|
|
15061
|
+
/**
|
|
15062
|
+
* Gets a Document.
|
|
15063
|
+
*
|
|
15064
|
+
* @param params - The parameters for getting a document.
|
|
15065
|
+
* @return Document.
|
|
15066
|
+
*/
|
|
15067
|
+
async get(params) {
|
|
15068
|
+
var _a, _b;
|
|
15069
|
+
let response;
|
|
15070
|
+
let path = '';
|
|
15071
|
+
let queryParams = {};
|
|
15072
|
+
if (this.apiClient.isVertexAI()) {
|
|
15073
|
+
throw new Error('This method is only supported by the Gemini Developer API.');
|
|
15074
|
+
}
|
|
15075
|
+
else {
|
|
15076
|
+
const body = getDocumentParametersToMldev(params);
|
|
15077
|
+
path = formatMap('{name}', body['_url']);
|
|
15078
|
+
queryParams = body['_query'];
|
|
15079
|
+
delete body['_url'];
|
|
15080
|
+
delete body['_query'];
|
|
15081
|
+
response = this.apiClient
|
|
15082
|
+
.request({
|
|
15083
|
+
path: path,
|
|
15084
|
+
queryParams: queryParams,
|
|
15085
|
+
body: JSON.stringify(body),
|
|
15086
|
+
httpMethod: 'GET',
|
|
15087
|
+
httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
|
|
15088
|
+
abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
|
|
15089
|
+
})
|
|
15090
|
+
.then((httpResponse) => {
|
|
15091
|
+
return httpResponse.json();
|
|
15092
|
+
});
|
|
15093
|
+
return response.then((resp) => {
|
|
15094
|
+
return resp;
|
|
15095
|
+
});
|
|
15096
|
+
}
|
|
15097
|
+
}
|
|
15098
|
+
/**
|
|
15099
|
+
* Deletes a Document.
|
|
15100
|
+
*
|
|
15101
|
+
* @param params - The parameters for deleting a document.
|
|
15102
|
+
*/
|
|
15103
|
+
async delete(params) {
|
|
15104
|
+
var _a, _b;
|
|
15105
|
+
let path = '';
|
|
15106
|
+
let queryParams = {};
|
|
15107
|
+
if (this.apiClient.isVertexAI()) {
|
|
15108
|
+
throw new Error('This method is only supported by the Gemini Developer API.');
|
|
15109
|
+
}
|
|
15110
|
+
else {
|
|
15111
|
+
const body = deleteDocumentParametersToMldev(params);
|
|
15112
|
+
path = formatMap('{name}', body['_url']);
|
|
15113
|
+
queryParams = body['_query'];
|
|
15114
|
+
delete body['_url'];
|
|
15115
|
+
delete body['_query'];
|
|
15116
|
+
await this.apiClient.request({
|
|
15117
|
+
path: path,
|
|
15118
|
+
queryParams: queryParams,
|
|
15119
|
+
body: JSON.stringify(body),
|
|
15120
|
+
httpMethod: 'DELETE',
|
|
15121
|
+
httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
|
|
15122
|
+
abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
|
|
15123
|
+
});
|
|
15124
|
+
}
|
|
15125
|
+
}
|
|
15126
|
+
/**
|
|
15127
|
+
* Lists all Documents in a FileSearchStore.
|
|
15128
|
+
*
|
|
15129
|
+
* @param params - The parameters for listing documents.
|
|
15130
|
+
* @return ListDocumentsResponse.
|
|
15131
|
+
*/
|
|
15132
|
+
async listInternal(params) {
|
|
15133
|
+
var _a, _b;
|
|
15134
|
+
let response;
|
|
15135
|
+
let path = '';
|
|
15136
|
+
let queryParams = {};
|
|
15137
|
+
if (this.apiClient.isVertexAI()) {
|
|
15138
|
+
throw new Error('This method is only supported by the Gemini Developer API.');
|
|
15139
|
+
}
|
|
15140
|
+
else {
|
|
15141
|
+
const body = listDocumentsParametersToMldev(params);
|
|
15142
|
+
path = formatMap('{parent}/documents', body['_url']);
|
|
15143
|
+
queryParams = body['_query'];
|
|
15144
|
+
delete body['_url'];
|
|
15145
|
+
delete body['_query'];
|
|
15146
|
+
response = this.apiClient
|
|
15147
|
+
.request({
|
|
15148
|
+
path: path,
|
|
15149
|
+
queryParams: queryParams,
|
|
15150
|
+
body: JSON.stringify(body),
|
|
15151
|
+
httpMethod: 'GET',
|
|
15152
|
+
httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
|
|
15153
|
+
abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
|
|
15154
|
+
})
|
|
15155
|
+
.then((httpResponse) => {
|
|
15156
|
+
return httpResponse.json();
|
|
15157
|
+
});
|
|
15158
|
+
return response.then((apiResponse) => {
|
|
15159
|
+
const resp = listDocumentsResponseFromMldev(apiResponse);
|
|
15160
|
+
const typedResp = new ListDocumentsResponse();
|
|
15161
|
+
Object.assign(typedResp, resp);
|
|
15162
|
+
return typedResp;
|
|
15163
|
+
});
|
|
15164
|
+
}
|
|
15165
|
+
}
|
|
15166
|
+
}
|
|
15167
|
+
|
|
15168
|
+
/**
|
|
15169
|
+
* @license
|
|
15170
|
+
* Copyright 2025 Google LLC
|
|
15171
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
15172
|
+
*/
|
|
15173
|
+
class FileSearchStores extends BaseModule {
|
|
15174
|
+
constructor(apiClient, documents = new Documents(apiClient)) {
|
|
15175
|
+
super();
|
|
15176
|
+
this.apiClient = apiClient;
|
|
15177
|
+
this.documents = documents;
|
|
15178
|
+
/**
|
|
15179
|
+
* Lists file search stores.
|
|
15180
|
+
*
|
|
15181
|
+
* @param params - The parameters for the list request.
|
|
15182
|
+
* @return - A pager of file search stores.
|
|
15183
|
+
*
|
|
15184
|
+
* @example
|
|
15185
|
+
* ```ts
|
|
15186
|
+
* const fileSearchStores = await ai.fileSearchStores.list({config: {'pageSize': 2}});
|
|
15187
|
+
* for await (const fileSearchStore of fileSearchStores) {
|
|
15188
|
+
* console.log(fileSearchStore);
|
|
15189
|
+
* }
|
|
15190
|
+
* ```
|
|
15191
|
+
*/
|
|
15192
|
+
this.list = async (params = {}) => {
|
|
15193
|
+
return new Pager(exports.PagedItem.PAGED_ITEM_FILE_SEARCH_STORES, (x) => this.listInternal(x), await this.listInternal(params), params);
|
|
15194
|
+
};
|
|
15195
|
+
}
|
|
15196
|
+
/**
|
|
15197
|
+
* Uploads a file asynchronously to a given File Search Store.
|
|
15198
|
+
* This method is not available in Vertex AI.
|
|
15199
|
+
* Supported upload sources:
|
|
15200
|
+
* - Node.js: File path (string) or Blob object.
|
|
15201
|
+
* - Browser: Blob object (e.g., File).
|
|
15202
|
+
*
|
|
15203
|
+
* @remarks
|
|
15204
|
+
* The `mimeType` can be specified in the `config` parameter. If omitted:
|
|
15205
|
+
* - For file path (string) inputs, the `mimeType` will be inferred from the
|
|
15206
|
+
* file extension.
|
|
15207
|
+
* - For Blob object inputs, the `mimeType` will be set to the Blob's `type`
|
|
15208
|
+
* property.
|
|
15209
|
+
*
|
|
15210
|
+
* This section can contain multiple paragraphs and code examples.
|
|
15211
|
+
*
|
|
15212
|
+
* @param params - Optional parameters specified in the
|
|
15213
|
+
* `types.UploadToFileSearchStoreParameters` interface.
|
|
15214
|
+
* @see {@link types.UploadToFileSearchStoreParameters#config} for the optional
|
|
15215
|
+
* config in the parameters.
|
|
15216
|
+
* @return A promise that resolves to a long running operation.
|
|
15217
|
+
* @throws An error if called on a Vertex AI client.
|
|
15218
|
+
* @throws An error if the `mimeType` is not provided and can not be inferred,
|
|
15219
|
+
* the `mimeType` can be provided in the `params.config` parameter.
|
|
15220
|
+
* @throws An error occurs if a suitable upload location cannot be established.
|
|
15221
|
+
*
|
|
15222
|
+
* @example
|
|
15223
|
+
* The following code uploads a file to a given file search store.
|
|
15224
|
+
*
|
|
15225
|
+
* ```ts
|
|
15226
|
+
* const operation = await ai.fileSearchStores.upload({fileSearchStoreName: 'fileSearchStores/foo-bar', file: 'file.txt', config: {
|
|
15227
|
+
* mimeType: 'text/plain',
|
|
15228
|
+
* }});
|
|
15229
|
+
* console.log(operation.name);
|
|
15230
|
+
* ```
|
|
15231
|
+
*/
|
|
15232
|
+
async uploadToFileSearchStore(params) {
|
|
15233
|
+
if (this.apiClient.isVertexAI()) {
|
|
15234
|
+
throw new Error('Vertex AI does not support uploading files to a file search store.');
|
|
15235
|
+
}
|
|
15236
|
+
return this.apiClient.uploadFileToFileSearchStore(params.fileSearchStoreName, params.file, params.config);
|
|
15237
|
+
}
|
|
15238
|
+
/**
|
|
15239
|
+
* Creates a File Search Store.
|
|
15240
|
+
*
|
|
15241
|
+
* @param params - The parameters for creating a File Search Store.
|
|
15242
|
+
* @return FileSearchStore.
|
|
15243
|
+
*/
|
|
15244
|
+
async create(params) {
|
|
15245
|
+
var _a, _b;
|
|
15246
|
+
let response;
|
|
15247
|
+
let path = '';
|
|
15248
|
+
let queryParams = {};
|
|
15249
|
+
if (this.apiClient.isVertexAI()) {
|
|
15250
|
+
throw new Error('This method is only supported by the Gemini Developer API.');
|
|
15251
|
+
}
|
|
15252
|
+
else {
|
|
15253
|
+
const body = createFileSearchStoreParametersToMldev(params);
|
|
15254
|
+
path = formatMap('fileSearchStores', body['_url']);
|
|
15255
|
+
queryParams = body['_query'];
|
|
15256
|
+
delete body['_url'];
|
|
15257
|
+
delete body['_query'];
|
|
15258
|
+
response = this.apiClient
|
|
15259
|
+
.request({
|
|
15260
|
+
path: path,
|
|
15261
|
+
queryParams: queryParams,
|
|
15262
|
+
body: JSON.stringify(body),
|
|
15263
|
+
httpMethod: 'POST',
|
|
15264
|
+
httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
|
|
15265
|
+
abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
|
|
15266
|
+
})
|
|
15267
|
+
.then((httpResponse) => {
|
|
15268
|
+
return httpResponse.json();
|
|
15269
|
+
});
|
|
15270
|
+
return response.then((resp) => {
|
|
15271
|
+
return resp;
|
|
15272
|
+
});
|
|
15273
|
+
}
|
|
15274
|
+
}
|
|
15275
|
+
/**
|
|
15276
|
+
* Gets a File Search Store.
|
|
15277
|
+
*
|
|
15278
|
+
* @param params - The parameters for getting a File Search Store.
|
|
15279
|
+
* @return FileSearchStore.
|
|
15280
|
+
*/
|
|
15281
|
+
async get(params) {
|
|
15282
|
+
var _a, _b;
|
|
15283
|
+
let response;
|
|
15284
|
+
let path = '';
|
|
15285
|
+
let queryParams = {};
|
|
15286
|
+
if (this.apiClient.isVertexAI()) {
|
|
15287
|
+
throw new Error('This method is only supported by the Gemini Developer API.');
|
|
15288
|
+
}
|
|
15289
|
+
else {
|
|
15290
|
+
const body = getFileSearchStoreParametersToMldev(params);
|
|
15291
|
+
path = formatMap('{name}', body['_url']);
|
|
15292
|
+
queryParams = body['_query'];
|
|
15293
|
+
delete body['_url'];
|
|
15294
|
+
delete body['_query'];
|
|
15295
|
+
response = this.apiClient
|
|
15296
|
+
.request({
|
|
15297
|
+
path: path,
|
|
15298
|
+
queryParams: queryParams,
|
|
15299
|
+
body: JSON.stringify(body),
|
|
15300
|
+
httpMethod: 'GET',
|
|
15301
|
+
httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
|
|
15302
|
+
abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
|
|
15303
|
+
})
|
|
15304
|
+
.then((httpResponse) => {
|
|
15305
|
+
return httpResponse.json();
|
|
15306
|
+
});
|
|
15307
|
+
return response.then((resp) => {
|
|
15308
|
+
return resp;
|
|
15309
|
+
});
|
|
15310
|
+
}
|
|
15311
|
+
}
|
|
15312
|
+
/**
|
|
15313
|
+
* Deletes a File Search Store.
|
|
15314
|
+
*
|
|
15315
|
+
* @param params - The parameters for deleting a File Search Store.
|
|
15316
|
+
*/
|
|
15317
|
+
async delete(params) {
|
|
15318
|
+
var _a, _b;
|
|
15319
|
+
let path = '';
|
|
15320
|
+
let queryParams = {};
|
|
15321
|
+
if (this.apiClient.isVertexAI()) {
|
|
15322
|
+
throw new Error('This method is only supported by the Gemini Developer API.');
|
|
15323
|
+
}
|
|
15324
|
+
else {
|
|
15325
|
+
const body = deleteFileSearchStoreParametersToMldev(params);
|
|
15326
|
+
path = formatMap('{name}', body['_url']);
|
|
15327
|
+
queryParams = body['_query'];
|
|
15328
|
+
delete body['_url'];
|
|
15329
|
+
delete body['_query'];
|
|
15330
|
+
await this.apiClient.request({
|
|
15331
|
+
path: path,
|
|
15332
|
+
queryParams: queryParams,
|
|
15333
|
+
body: JSON.stringify(body),
|
|
15334
|
+
httpMethod: 'DELETE',
|
|
15335
|
+
httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
|
|
15336
|
+
abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
|
|
15337
|
+
});
|
|
15338
|
+
}
|
|
15339
|
+
}
|
|
15340
|
+
/**
|
|
15341
|
+
* Lists all FileSearchStore owned by the user.
|
|
15342
|
+
*
|
|
15343
|
+
* @param params - The parameters for listing file search stores.
|
|
15344
|
+
* @return ListFileSearchStoresResponse.
|
|
15345
|
+
*/
|
|
15346
|
+
async listInternal(params) {
|
|
15347
|
+
var _a, _b;
|
|
15348
|
+
let response;
|
|
15349
|
+
let path = '';
|
|
15350
|
+
let queryParams = {};
|
|
15351
|
+
if (this.apiClient.isVertexAI()) {
|
|
15352
|
+
throw new Error('This method is only supported by the Gemini Developer API.');
|
|
15353
|
+
}
|
|
15354
|
+
else {
|
|
15355
|
+
const body = listFileSearchStoresParametersToMldev(params);
|
|
15356
|
+
path = formatMap('fileSearchStores', body['_url']);
|
|
15357
|
+
queryParams = body['_query'];
|
|
15358
|
+
delete body['_url'];
|
|
15359
|
+
delete body['_query'];
|
|
15360
|
+
response = this.apiClient
|
|
15361
|
+
.request({
|
|
15362
|
+
path: path,
|
|
15363
|
+
queryParams: queryParams,
|
|
15364
|
+
body: JSON.stringify(body),
|
|
15365
|
+
httpMethod: 'GET',
|
|
15366
|
+
httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
|
|
15367
|
+
abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
|
|
15368
|
+
})
|
|
15369
|
+
.then((httpResponse) => {
|
|
15370
|
+
return httpResponse.json();
|
|
15371
|
+
});
|
|
15372
|
+
return response.then((apiResponse) => {
|
|
15373
|
+
const resp = listFileSearchStoresResponseFromMldev(apiResponse);
|
|
15374
|
+
const typedResp = new ListFileSearchStoresResponse();
|
|
15375
|
+
Object.assign(typedResp, resp);
|
|
15376
|
+
return typedResp;
|
|
15377
|
+
});
|
|
15378
|
+
}
|
|
15379
|
+
}
|
|
15380
|
+
async uploadToFileSearchStoreInternal(params) {
|
|
15381
|
+
var _a, _b;
|
|
15382
|
+
let response;
|
|
15383
|
+
let path = '';
|
|
15384
|
+
let queryParams = {};
|
|
15385
|
+
if (this.apiClient.isVertexAI()) {
|
|
15386
|
+
throw new Error('This method is only supported by the Gemini Developer API.');
|
|
15387
|
+
}
|
|
15388
|
+
else {
|
|
15389
|
+
const body = uploadToFileSearchStoreParametersToMldev(params);
|
|
15390
|
+
path = formatMap('upload/v1beta/{file_search_store_name}:uploadToFileSearchStore', body['_url']);
|
|
15391
|
+
queryParams = body['_query'];
|
|
15392
|
+
delete body['_url'];
|
|
15393
|
+
delete body['_query'];
|
|
15394
|
+
response = this.apiClient
|
|
15395
|
+
.request({
|
|
15396
|
+
path: path,
|
|
15397
|
+
queryParams: queryParams,
|
|
15398
|
+
body: JSON.stringify(body),
|
|
15399
|
+
httpMethod: 'POST',
|
|
15400
|
+
httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
|
|
15401
|
+
abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
|
|
15402
|
+
})
|
|
15403
|
+
.then((httpResponse) => {
|
|
15404
|
+
return httpResponse.json();
|
|
15405
|
+
});
|
|
15406
|
+
return response.then((apiResponse) => {
|
|
15407
|
+
const resp = uploadToFileSearchStoreResumableResponseFromMldev(apiResponse);
|
|
15408
|
+
const typedResp = new UploadToFileSearchStoreResumableResponse();
|
|
15409
|
+
Object.assign(typedResp, resp);
|
|
15410
|
+
return typedResp;
|
|
15411
|
+
});
|
|
15412
|
+
}
|
|
15413
|
+
}
|
|
15414
|
+
/**
|
|
15415
|
+
* Imports a File from File Service to a FileSearchStore.
|
|
15416
|
+
*
|
|
15417
|
+
* This is a long-running operation, see aip.dev/151
|
|
15418
|
+
*
|
|
15419
|
+
* @param params - The parameters for importing a file to a file search store.
|
|
15420
|
+
* @return ImportFileOperation.
|
|
15421
|
+
*/
|
|
15422
|
+
async importFile(params) {
|
|
15423
|
+
var _a, _b;
|
|
15424
|
+
let response;
|
|
15425
|
+
let path = '';
|
|
15426
|
+
let queryParams = {};
|
|
15427
|
+
if (this.apiClient.isVertexAI()) {
|
|
15428
|
+
throw new Error('This method is only supported by the Gemini Developer API.');
|
|
15429
|
+
}
|
|
15430
|
+
else {
|
|
15431
|
+
const body = importFileParametersToMldev(params);
|
|
15432
|
+
path = formatMap('{file_search_store_name}:importFile', body['_url']);
|
|
15433
|
+
queryParams = body['_query'];
|
|
15434
|
+
delete body['_url'];
|
|
15435
|
+
delete body['_query'];
|
|
15436
|
+
response = this.apiClient
|
|
15437
|
+
.request({
|
|
15438
|
+
path: path,
|
|
15439
|
+
queryParams: queryParams,
|
|
15440
|
+
body: JSON.stringify(body),
|
|
15441
|
+
httpMethod: 'POST',
|
|
15442
|
+
httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
|
|
15443
|
+
abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
|
|
15444
|
+
})
|
|
15445
|
+
.then((httpResponse) => {
|
|
15446
|
+
return httpResponse.json();
|
|
15447
|
+
});
|
|
15448
|
+
return response.then((apiResponse) => {
|
|
15449
|
+
const resp = importFileOperationFromMldev(apiResponse);
|
|
15450
|
+
const typedResp = new ImportFileOperation();
|
|
15451
|
+
Object.assign(typedResp, resp);
|
|
15452
|
+
return typedResp;
|
|
15453
|
+
});
|
|
15454
|
+
}
|
|
15455
|
+
}
|
|
15456
|
+
}
|
|
15457
|
+
|
|
15458
|
+
/**
|
|
15459
|
+
* @license
|
|
15460
|
+
* Copyright 2025 Google LLC
|
|
15461
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
15462
|
+
*/
|
|
15463
|
+
const GOOGLE_API_KEY_HEADER = 'x-goog-api-key';
|
|
15464
|
+
const REQUIRED_VERTEX_AI_SCOPE = 'https://www.googleapis.com/auth/cloud-platform';
|
|
15465
|
+
class NodeAuth {
|
|
15466
|
+
constructor(opts) {
|
|
15467
|
+
if (opts.apiKey !== undefined) {
|
|
15468
|
+
this.apiKey = opts.apiKey;
|
|
15469
|
+
return;
|
|
15470
|
+
}
|
|
15471
|
+
const vertexAuthOptions = buildGoogleAuthOptions(opts.googleAuthOptions);
|
|
15472
|
+
this.googleAuth = new googleAuthLibrary.GoogleAuth(vertexAuthOptions);
|
|
15473
|
+
}
|
|
15474
|
+
async addAuthHeaders(headers, url) {
|
|
15475
|
+
if (this.apiKey !== undefined) {
|
|
15476
|
+
if (this.apiKey.startsWith('auth_tokens/')) {
|
|
15477
|
+
throw new Error('Ephemeral tokens are only supported by the live API.');
|
|
15478
|
+
}
|
|
15479
|
+
this.addKeyHeader(headers);
|
|
15480
|
+
return;
|
|
15481
|
+
}
|
|
15482
|
+
return this.addGoogleAuthHeaders(headers, url);
|
|
15483
|
+
}
|
|
15484
|
+
addKeyHeader(headers) {
|
|
15485
|
+
if (headers.get(GOOGLE_API_KEY_HEADER) !== null) {
|
|
15486
|
+
return;
|
|
15487
|
+
}
|
|
15488
|
+
if (this.apiKey === undefined) {
|
|
15489
|
+
// This should never happen, this method is only called
|
|
15490
|
+
// when apiKey is set.
|
|
15491
|
+
throw new Error('Trying to set API key header but apiKey is not set');
|
|
15492
|
+
}
|
|
15493
|
+
headers.append(GOOGLE_API_KEY_HEADER, this.apiKey);
|
|
15494
|
+
}
|
|
15495
|
+
async addGoogleAuthHeaders(headers, url) {
|
|
15496
|
+
if (this.googleAuth === undefined) {
|
|
15497
|
+
// This should never happen, addGoogleAuthHeaders should only be
|
|
15498
|
+
// called when there is no apiKey set and in these cases googleAuth
|
|
15499
|
+
// is set.
|
|
15500
|
+
throw new Error('Trying to set google-auth headers but googleAuth is unset');
|
|
15501
|
+
}
|
|
15502
|
+
const authHeaders = await this.googleAuth.getRequestHeaders(url);
|
|
15503
|
+
for (const [key, value] of authHeaders) {
|
|
15504
|
+
if (headers.get(key) !== null) {
|
|
15505
|
+
continue;
|
|
15506
|
+
}
|
|
15507
|
+
headers.append(key, value);
|
|
15508
|
+
}
|
|
15509
|
+
}
|
|
15510
|
+
}
|
|
15511
|
+
function buildGoogleAuthOptions(googleAuthOptions) {
|
|
15512
|
+
let authOptions;
|
|
15513
|
+
if (!googleAuthOptions) {
|
|
15514
|
+
authOptions = {
|
|
15515
|
+
scopes: [REQUIRED_VERTEX_AI_SCOPE],
|
|
15516
|
+
};
|
|
15517
|
+
return authOptions;
|
|
15518
|
+
}
|
|
15519
|
+
else {
|
|
15520
|
+
authOptions = googleAuthOptions;
|
|
15521
|
+
if (!authOptions.scopes) {
|
|
15522
|
+
authOptions.scopes = [REQUIRED_VERTEX_AI_SCOPE];
|
|
15523
|
+
return authOptions;
|
|
15524
|
+
}
|
|
15525
|
+
else if ((typeof authOptions.scopes === 'string' &&
|
|
15526
|
+
authOptions.scopes !== REQUIRED_VERTEX_AI_SCOPE) ||
|
|
15527
|
+
(Array.isArray(authOptions.scopes) &&
|
|
15528
|
+
authOptions.scopes.indexOf(REQUIRED_VERTEX_AI_SCOPE) < 0)) {
|
|
15529
|
+
throw new Error(`Invalid auth scopes. Scopes must include: ${REQUIRED_VERTEX_AI_SCOPE}`);
|
|
15530
|
+
}
|
|
15531
|
+
return authOptions;
|
|
15532
|
+
}
|
|
15533
|
+
}
|
|
15534
|
+
|
|
15535
|
+
/**
|
|
15536
|
+
* @license
|
|
15537
|
+
* Copyright 2025 Google LLC
|
|
15538
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
15539
|
+
*/
|
|
15540
|
+
class NodeDownloader {
|
|
15541
|
+
async download(params, apiClient) {
|
|
15542
|
+
if (params.downloadPath) {
|
|
15543
|
+
const response = await downloadFile(params, apiClient);
|
|
15544
|
+
if (response instanceof HttpResponse) {
|
|
15545
|
+
const writer = fs.createWriteStream(params.downloadPath);
|
|
15546
|
+
const body = node_stream.Readable.fromWeb(response.responseInternal.body);
|
|
15547
|
+
body.pipe(writer);
|
|
15548
|
+
await promises.finished(writer);
|
|
15549
|
+
}
|
|
15550
|
+
else {
|
|
15551
|
+
try {
|
|
15552
|
+
await fs$1.writeFile(params.downloadPath, response, {
|
|
15553
|
+
encoding: 'base64',
|
|
15554
|
+
});
|
|
15555
|
+
}
|
|
15556
|
+
catch (error) {
|
|
15557
|
+
throw new Error(`Failed to write file to ${params.downloadPath}: ${error}`);
|
|
15558
|
+
}
|
|
15559
|
+
}
|
|
15560
|
+
}
|
|
15561
|
+
}
|
|
15562
|
+
}
|
|
15563
|
+
async function downloadFile(params, apiClient) {
|
|
15564
|
+
var _a, _b, _c;
|
|
15565
|
+
const name = tFileName(params.file);
|
|
15566
|
+
if (name !== undefined) {
|
|
15567
|
+
return await apiClient.request({
|
|
15568
|
+
path: `files/${name}:download`,
|
|
15569
|
+
httpMethod: 'GET',
|
|
15570
|
+
queryParams: {
|
|
15571
|
+
'alt': 'media',
|
|
15572
|
+
},
|
|
15573
|
+
httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
|
|
15574
|
+
abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
|
|
15575
|
+
});
|
|
15576
|
+
}
|
|
15577
|
+
else if (isGeneratedVideo(params.file)) {
|
|
15578
|
+
const videoBytes = (_c = params.file.video) === null || _c === void 0 ? void 0 : _c.videoBytes;
|
|
15579
|
+
if (typeof videoBytes === 'string') {
|
|
15580
|
+
return videoBytes;
|
|
15581
|
+
}
|
|
15582
|
+
else {
|
|
15583
|
+
throw new Error('Failed to download generated video, Uri or videoBytes not found.');
|
|
15584
|
+
}
|
|
15585
|
+
}
|
|
15586
|
+
else if (isVideo(params.file)) {
|
|
15587
|
+
const videoBytes = params.file.videoBytes;
|
|
15588
|
+
if (typeof videoBytes === 'string') {
|
|
15589
|
+
return videoBytes;
|
|
15590
|
+
}
|
|
15591
|
+
else {
|
|
15592
|
+
throw new Error('Failed to download video, Uri or videoBytes not found.');
|
|
15593
|
+
}
|
|
15594
|
+
}
|
|
15595
|
+
else {
|
|
15596
|
+
throw new Error('Unsupported file type');
|
|
15597
|
+
}
|
|
15598
|
+
}
|
|
15599
|
+
|
|
15600
|
+
/**
|
|
15601
|
+
* @license
|
|
15602
|
+
* Copyright 2025 Google LLC
|
|
15603
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
15604
|
+
*/
|
|
15605
|
+
class NodeWebSocketFactory {
|
|
15606
|
+
create(url, headers, callbacks) {
|
|
15607
|
+
return new NodeWebSocket(url, headers, callbacks);
|
|
15608
|
+
}
|
|
15609
|
+
}
|
|
15610
|
+
class NodeWebSocket {
|
|
15611
|
+
constructor(url, headers, callbacks) {
|
|
15612
|
+
this.url = url;
|
|
15613
|
+
this.headers = headers;
|
|
15614
|
+
this.callbacks = callbacks;
|
|
15615
|
+
}
|
|
15616
|
+
connect() {
|
|
15617
|
+
this.ws = new NodeWs__namespace.WebSocket(this.url, { headers: this.headers });
|
|
15618
|
+
this.ws.onopen = this.callbacks.onopen;
|
|
15619
|
+
this.ws.onerror = this.callbacks.onerror;
|
|
15620
|
+
this.ws.onclose = this.callbacks.onclose;
|
|
15621
|
+
this.ws.onmessage = this.callbacks.onmessage;
|
|
15622
|
+
}
|
|
15623
|
+
send(message) {
|
|
15624
|
+
if (this.ws === undefined) {
|
|
15625
|
+
throw new Error('WebSocket is not connected');
|
|
15626
|
+
}
|
|
15627
|
+
this.ws.send(message);
|
|
15628
|
+
}
|
|
15629
|
+
close() {
|
|
15630
|
+
if (this.ws === undefined) {
|
|
15631
|
+
throw new Error('WebSocket is not connected');
|
|
15632
|
+
}
|
|
15633
|
+
this.ws.close();
|
|
15634
|
+
}
|
|
15635
|
+
}
|
|
15636
|
+
|
|
15637
|
+
/**
|
|
15638
|
+
* @license
|
|
15639
|
+
* Copyright 2025 Google LLC
|
|
15640
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
15641
|
+
*/
|
|
15642
|
+
// Code generated by the Google Gen AI SDK generator DO NOT EDIT.
|
|
15643
|
+
function cancelTuningJobParametersToMldev(fromObject, _rootObject) {
|
|
15644
|
+
const toObject = {};
|
|
15645
|
+
const fromName = getValueByPath(fromObject, ['name']);
|
|
15646
|
+
if (fromName != null) {
|
|
15647
|
+
setValueByPath(toObject, ['_url', 'name'], fromName);
|
|
15648
|
+
}
|
|
15649
|
+
return toObject;
|
|
15650
|
+
}
|
|
15651
|
+
function cancelTuningJobParametersToVertex(fromObject, _rootObject) {
|
|
15652
|
+
const toObject = {};
|
|
15653
|
+
const fromName = getValueByPath(fromObject, ['name']);
|
|
15654
|
+
if (fromName != null) {
|
|
15655
|
+
setValueByPath(toObject, ['_url', 'name'], fromName);
|
|
15656
|
+
}
|
|
15657
|
+
return toObject;
|
|
15658
|
+
}
|
|
15659
|
+
function createTuningJobConfigToMldev(fromObject, parentObject, _rootObject) {
|
|
15660
|
+
const toObject = {};
|
|
15661
|
+
if (getValueByPath(fromObject, ['validationDataset']) !== undefined) {
|
|
15662
|
+
throw new Error('validationDataset parameter is not supported in Gemini API.');
|
|
15663
|
+
}
|
|
15664
|
+
const fromTunedModelDisplayName = getValueByPath(fromObject, [
|
|
15665
|
+
'tunedModelDisplayName',
|
|
15666
|
+
]);
|
|
15667
|
+
if (parentObject !== undefined && fromTunedModelDisplayName != null) {
|
|
15668
|
+
setValueByPath(parentObject, ['displayName'], fromTunedModelDisplayName);
|
|
15669
|
+
}
|
|
15670
|
+
if (getValueByPath(fromObject, ['description']) !== undefined) {
|
|
15671
|
+
throw new Error('description parameter is not supported in Gemini API.');
|
|
14613
15672
|
}
|
|
14614
15673
|
const fromEpochCount = getValueByPath(fromObject, ['epochCount']);
|
|
14615
15674
|
if (parentObject !== undefined && fromEpochCount != null) {
|
|
@@ -15591,7 +16650,28 @@ const INITIAL_RETRY_DELAY_MS = 1000;
|
|
|
15591
16650
|
const DELAY_MULTIPLIER = 2;
|
|
15592
16651
|
const X_GOOG_UPLOAD_STATUS_HEADER_FIELD = 'x-goog-upload-status';
|
|
15593
16652
|
async function uploadBlob(file, uploadUrl, apiClient) {
|
|
15594
|
-
var _a
|
|
16653
|
+
var _a;
|
|
16654
|
+
const response = await uploadBlobInternal(file, uploadUrl, apiClient);
|
|
16655
|
+
const responseJson = (await (response === null || response === void 0 ? void 0 : response.json()));
|
|
16656
|
+
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') {
|
|
16657
|
+
throw new Error('Failed to upload file: Upload status is not finalized.');
|
|
16658
|
+
}
|
|
16659
|
+
return responseJson['file'];
|
|
16660
|
+
}
|
|
16661
|
+
async function uploadBlobToFileSearchStore(file, uploadUrl, apiClient) {
|
|
16662
|
+
var _a;
|
|
16663
|
+
const response = await uploadBlobInternal(file, uploadUrl, apiClient);
|
|
16664
|
+
const responseJson = (await (response === null || response === void 0 ? void 0 : response.json()));
|
|
16665
|
+
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') {
|
|
16666
|
+
throw new Error('Failed to upload file: Upload status is not finalized.');
|
|
16667
|
+
}
|
|
16668
|
+
const resp = uploadToFileSearchStoreOperationFromMldev(responseJson);
|
|
16669
|
+
const typedResp = new UploadToFileSearchStoreOperation();
|
|
16670
|
+
Object.assign(typedResp, resp);
|
|
16671
|
+
return typedResp;
|
|
16672
|
+
}
|
|
16673
|
+
async function uploadBlobInternal(file, uploadUrl, apiClient) {
|
|
16674
|
+
var _a, _b;
|
|
15595
16675
|
let fileSize = 0;
|
|
15596
16676
|
let offset = 0;
|
|
15597
16677
|
let response = new HttpResponse(new Response());
|
|
@@ -15639,11 +16719,7 @@ async function uploadBlob(file, uploadUrl, apiClient) {
|
|
|
15639
16719
|
throw new Error('All content has been uploaded, but the upload status is not finalized.');
|
|
15640
16720
|
}
|
|
15641
16721
|
}
|
|
15642
|
-
|
|
15643
|
-
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') {
|
|
15644
|
-
throw new Error('Failed to upload file: Upload status is not finalized.');
|
|
15645
|
-
}
|
|
15646
|
-
return responseJson['file'];
|
|
16722
|
+
return response;
|
|
15647
16723
|
}
|
|
15648
16724
|
async function getBlobStat(file) {
|
|
15649
16725
|
const fileStat = { size: file.size, type: file.type };
|
|
@@ -15679,6 +16755,14 @@ class NodeUploader {
|
|
|
15679
16755
|
return uploadBlob(file, uploadUrl, apiClient);
|
|
15680
16756
|
}
|
|
15681
16757
|
}
|
|
16758
|
+
async uploadToFileSearchStore(file, uploadUrl, apiClient) {
|
|
16759
|
+
if (typeof file === 'string') {
|
|
16760
|
+
return await this.uploadFileToFileSearchStoreFromPath(file, uploadUrl, apiClient);
|
|
16761
|
+
}
|
|
16762
|
+
else {
|
|
16763
|
+
return uploadBlobToFileSearchStore(file, uploadUrl, apiClient);
|
|
16764
|
+
}
|
|
16765
|
+
}
|
|
15682
16766
|
/**
|
|
15683
16767
|
* Infers the MIME type of a file based on its extension.
|
|
15684
16768
|
*
|
|
@@ -15770,12 +16854,34 @@ class NodeUploader {
|
|
|
15770
16854
|
return mimeType;
|
|
15771
16855
|
}
|
|
15772
16856
|
async uploadFileFromPath(file, uploadUrl, apiClient) {
|
|
15773
|
-
var _a
|
|
16857
|
+
var _a;
|
|
16858
|
+
const response = await this.uploadFileFromPathInternal(file, uploadUrl, apiClient);
|
|
16859
|
+
const responseJson = (await (response === null || response === void 0 ? void 0 : response.json()));
|
|
16860
|
+
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') {
|
|
16861
|
+
throw new Error('Failed to upload file: Upload status is not finalized.');
|
|
16862
|
+
}
|
|
16863
|
+
return responseJson['file'];
|
|
16864
|
+
}
|
|
16865
|
+
async uploadFileToFileSearchStoreFromPath(file, uploadUrl, apiClient) {
|
|
16866
|
+
var _a;
|
|
16867
|
+
const response = await this.uploadFileFromPathInternal(file, uploadUrl, apiClient);
|
|
16868
|
+
const responseJson = (await (response === null || response === void 0 ? void 0 : response.json()));
|
|
16869
|
+
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') {
|
|
16870
|
+
throw new Error('Failed to upload file: Upload status is not finalized.');
|
|
16871
|
+
}
|
|
16872
|
+
const resp = uploadToFileSearchStoreOperationFromMldev(responseJson);
|
|
16873
|
+
const typedResp = new UploadToFileSearchStoreOperation();
|
|
16874
|
+
Object.assign(typedResp, resp);
|
|
16875
|
+
return typedResp;
|
|
16876
|
+
}
|
|
16877
|
+
async uploadFileFromPathInternal(file, uploadUrl, apiClient) {
|
|
16878
|
+
var _a, _b;
|
|
15774
16879
|
let fileSize = 0;
|
|
15775
16880
|
let offset = 0;
|
|
15776
16881
|
let response = new HttpResponse(new Response());
|
|
15777
16882
|
let uploadCommand = 'upload';
|
|
15778
16883
|
let fileHandle;
|
|
16884
|
+
const fileName = path__namespace.basename(file);
|
|
15779
16885
|
try {
|
|
15780
16886
|
fileHandle = await fs__namespace.open(file, 'r');
|
|
15781
16887
|
if (!fileHandle) {
|
|
@@ -15807,6 +16913,7 @@ class NodeUploader {
|
|
|
15807
16913
|
'X-Goog-Upload-Command': uploadCommand,
|
|
15808
16914
|
'X-Goog-Upload-Offset': String(offset),
|
|
15809
16915
|
'Content-Length': String(bytesRead),
|
|
16916
|
+
'X-Goog-Upload-File-Name': fileName,
|
|
15810
16917
|
},
|
|
15811
16918
|
},
|
|
15812
16919
|
});
|
|
@@ -15827,11 +16934,7 @@ class NodeUploader {
|
|
|
15827
16934
|
throw new Error('All content has been uploaded, but the upload status is not finalized.');
|
|
15828
16935
|
}
|
|
15829
16936
|
}
|
|
15830
|
-
|
|
15831
|
-
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') {
|
|
15832
|
-
throw new Error('Failed to upload file: Upload status is not finalized.');
|
|
15833
|
-
}
|
|
15834
|
-
return responseJson['file'];
|
|
16937
|
+
return response;
|
|
15835
16938
|
}
|
|
15836
16939
|
finally {
|
|
15837
16940
|
// Ensure the file handle is always closed
|
|
@@ -15970,6 +17073,7 @@ class GoogleGenAI {
|
|
|
15970
17073
|
this.operations = new Operations(this.apiClient);
|
|
15971
17074
|
this.authTokens = new Tokens(this.apiClient);
|
|
15972
17075
|
this.tunings = new Tunings(this.apiClient);
|
|
17076
|
+
this.fileSearchStores = new FileSearchStores(this.apiClient);
|
|
15973
17077
|
}
|
|
15974
17078
|
}
|
|
15975
17079
|
function getEnv(env) {
|
|
@@ -16022,10 +17126,14 @@ exports.GenerateVideosOperation = GenerateVideosOperation;
|
|
|
16022
17126
|
exports.GenerateVideosResponse = GenerateVideosResponse;
|
|
16023
17127
|
exports.GoogleGenAI = GoogleGenAI;
|
|
16024
17128
|
exports.HttpResponse = HttpResponse;
|
|
17129
|
+
exports.ImportFileOperation = ImportFileOperation;
|
|
17130
|
+
exports.ImportFileResponse = ImportFileResponse;
|
|
16025
17131
|
exports.InlinedEmbedContentResponse = InlinedEmbedContentResponse;
|
|
16026
17132
|
exports.InlinedResponse = InlinedResponse;
|
|
16027
17133
|
exports.ListBatchJobsResponse = ListBatchJobsResponse;
|
|
16028
17134
|
exports.ListCachedContentsResponse = ListCachedContentsResponse;
|
|
17135
|
+
exports.ListDocumentsResponse = ListDocumentsResponse;
|
|
17136
|
+
exports.ListFileSearchStoresResponse = ListFileSearchStoresResponse;
|
|
16029
17137
|
exports.ListFilesResponse = ListFilesResponse;
|
|
16030
17138
|
exports.ListModelsResponse = ListModelsResponse;
|
|
16031
17139
|
exports.ListTuningJobsResponse = ListTuningJobsResponse;
|
|
@@ -16047,6 +17155,9 @@ exports.SingleEmbedContentResponse = SingleEmbedContentResponse;
|
|
|
16047
17155
|
exports.StyleReferenceImage = StyleReferenceImage;
|
|
16048
17156
|
exports.SubjectReferenceImage = SubjectReferenceImage;
|
|
16049
17157
|
exports.Tokens = Tokens;
|
|
17158
|
+
exports.UploadToFileSearchStoreOperation = UploadToFileSearchStoreOperation;
|
|
17159
|
+
exports.UploadToFileSearchStoreResponse = UploadToFileSearchStoreResponse;
|
|
17160
|
+
exports.UploadToFileSearchStoreResumableResponse = UploadToFileSearchStoreResumableResponse;
|
|
16050
17161
|
exports.UpscaleImageResponse = UpscaleImageResponse;
|
|
16051
17162
|
exports.createFunctionResponsePartFromBase64 = createFunctionResponsePartFromBase64;
|
|
16052
17163
|
exports.createFunctionResponsePartFromUri = createFunctionResponsePartFromUri;
|