@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.mjs
CHANGED
|
@@ -5,6 +5,7 @@ import { writeFile } from 'fs/promises';
|
|
|
5
5
|
import { Readable } from 'node:stream';
|
|
6
6
|
import { finished } from 'node:stream/promises';
|
|
7
7
|
import * as NodeWs from 'ws';
|
|
8
|
+
import * as path from 'path';
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* @license
|
|
@@ -468,6 +469,90 @@ function getOperationParametersToVertex(fromObject) {
|
|
|
468
469
|
}
|
|
469
470
|
return toObject;
|
|
470
471
|
}
|
|
472
|
+
function importFileOperationFromMldev$1(fromObject) {
|
|
473
|
+
const toObject = {};
|
|
474
|
+
const fromName = getValueByPath(fromObject, ['name']);
|
|
475
|
+
if (fromName != null) {
|
|
476
|
+
setValueByPath(toObject, ['name'], fromName);
|
|
477
|
+
}
|
|
478
|
+
const fromMetadata = getValueByPath(fromObject, ['metadata']);
|
|
479
|
+
if (fromMetadata != null) {
|
|
480
|
+
setValueByPath(toObject, ['metadata'], fromMetadata);
|
|
481
|
+
}
|
|
482
|
+
const fromDone = getValueByPath(fromObject, ['done']);
|
|
483
|
+
if (fromDone != null) {
|
|
484
|
+
setValueByPath(toObject, ['done'], fromDone);
|
|
485
|
+
}
|
|
486
|
+
const fromError = getValueByPath(fromObject, ['error']);
|
|
487
|
+
if (fromError != null) {
|
|
488
|
+
setValueByPath(toObject, ['error'], fromError);
|
|
489
|
+
}
|
|
490
|
+
const fromResponse = getValueByPath(fromObject, ['response']);
|
|
491
|
+
if (fromResponse != null) {
|
|
492
|
+
setValueByPath(toObject, ['response'], importFileResponseFromMldev$1(fromResponse));
|
|
493
|
+
}
|
|
494
|
+
return toObject;
|
|
495
|
+
}
|
|
496
|
+
function importFileResponseFromMldev$1(fromObject) {
|
|
497
|
+
const toObject = {};
|
|
498
|
+
const fromSdkHttpResponse = getValueByPath(fromObject, [
|
|
499
|
+
'sdkHttpResponse',
|
|
500
|
+
]);
|
|
501
|
+
if (fromSdkHttpResponse != null) {
|
|
502
|
+
setValueByPath(toObject, ['sdkHttpResponse'], fromSdkHttpResponse);
|
|
503
|
+
}
|
|
504
|
+
const fromParent = getValueByPath(fromObject, ['parent']);
|
|
505
|
+
if (fromParent != null) {
|
|
506
|
+
setValueByPath(toObject, ['parent'], fromParent);
|
|
507
|
+
}
|
|
508
|
+
const fromDocumentName = getValueByPath(fromObject, ['documentName']);
|
|
509
|
+
if (fromDocumentName != null) {
|
|
510
|
+
setValueByPath(toObject, ['documentName'], fromDocumentName);
|
|
511
|
+
}
|
|
512
|
+
return toObject;
|
|
513
|
+
}
|
|
514
|
+
function uploadToFileSearchStoreOperationFromMldev(fromObject) {
|
|
515
|
+
const toObject = {};
|
|
516
|
+
const fromName = getValueByPath(fromObject, ['name']);
|
|
517
|
+
if (fromName != null) {
|
|
518
|
+
setValueByPath(toObject, ['name'], fromName);
|
|
519
|
+
}
|
|
520
|
+
const fromMetadata = getValueByPath(fromObject, ['metadata']);
|
|
521
|
+
if (fromMetadata != null) {
|
|
522
|
+
setValueByPath(toObject, ['metadata'], fromMetadata);
|
|
523
|
+
}
|
|
524
|
+
const fromDone = getValueByPath(fromObject, ['done']);
|
|
525
|
+
if (fromDone != null) {
|
|
526
|
+
setValueByPath(toObject, ['done'], fromDone);
|
|
527
|
+
}
|
|
528
|
+
const fromError = getValueByPath(fromObject, ['error']);
|
|
529
|
+
if (fromError != null) {
|
|
530
|
+
setValueByPath(toObject, ['error'], fromError);
|
|
531
|
+
}
|
|
532
|
+
const fromResponse = getValueByPath(fromObject, ['response']);
|
|
533
|
+
if (fromResponse != null) {
|
|
534
|
+
setValueByPath(toObject, ['response'], uploadToFileSearchStoreResponseFromMldev(fromResponse));
|
|
535
|
+
}
|
|
536
|
+
return toObject;
|
|
537
|
+
}
|
|
538
|
+
function uploadToFileSearchStoreResponseFromMldev(fromObject) {
|
|
539
|
+
const toObject = {};
|
|
540
|
+
const fromSdkHttpResponse = getValueByPath(fromObject, [
|
|
541
|
+
'sdkHttpResponse',
|
|
542
|
+
]);
|
|
543
|
+
if (fromSdkHttpResponse != null) {
|
|
544
|
+
setValueByPath(toObject, ['sdkHttpResponse'], fromSdkHttpResponse);
|
|
545
|
+
}
|
|
546
|
+
const fromParent = getValueByPath(fromObject, ['parent']);
|
|
547
|
+
if (fromParent != null) {
|
|
548
|
+
setValueByPath(toObject, ['parent'], fromParent);
|
|
549
|
+
}
|
|
550
|
+
const fromDocumentName = getValueByPath(fromObject, ['documentName']);
|
|
551
|
+
if (fromDocumentName != null) {
|
|
552
|
+
setValueByPath(toObject, ['documentName'], fromDocumentName);
|
|
553
|
+
}
|
|
554
|
+
return toObject;
|
|
555
|
+
}
|
|
471
556
|
function videoFromMldev$1(fromObject) {
|
|
472
557
|
const toObject = {};
|
|
473
558
|
const fromUri = getValueByPath(fromObject, ['uri']);
|
|
@@ -608,6 +693,22 @@ var Mode;
|
|
|
608
693
|
*/
|
|
609
694
|
Mode["MODE_DYNAMIC"] = "MODE_DYNAMIC";
|
|
610
695
|
})(Mode || (Mode = {}));
|
|
696
|
+
/** The API spec that the external API implements. This enum is not supported in Gemini API. */
|
|
697
|
+
var ApiSpec;
|
|
698
|
+
(function (ApiSpec) {
|
|
699
|
+
/**
|
|
700
|
+
* Unspecified API spec. This value should not be used.
|
|
701
|
+
*/
|
|
702
|
+
ApiSpec["API_SPEC_UNSPECIFIED"] = "API_SPEC_UNSPECIFIED";
|
|
703
|
+
/**
|
|
704
|
+
* Simple search API spec.
|
|
705
|
+
*/
|
|
706
|
+
ApiSpec["SIMPLE_SEARCH"] = "SIMPLE_SEARCH";
|
|
707
|
+
/**
|
|
708
|
+
* Elastic search API spec.
|
|
709
|
+
*/
|
|
710
|
+
ApiSpec["ELASTIC_SEARCH"] = "ELASTIC_SEARCH";
|
|
711
|
+
})(ApiSpec || (ApiSpec = {}));
|
|
611
712
|
/** Type of auth scheme. This enum is not supported in Gemini API. */
|
|
612
713
|
var AuthType;
|
|
613
714
|
(function (AuthType) {
|
|
@@ -637,22 +738,63 @@ var AuthType;
|
|
|
637
738
|
*/
|
|
638
739
|
AuthType["OIDC_AUTH"] = "OIDC_AUTH";
|
|
639
740
|
})(AuthType || (AuthType = {}));
|
|
640
|
-
/** The
|
|
641
|
-
var
|
|
642
|
-
(function (
|
|
741
|
+
/** The location of the API key. This enum is not supported in Gemini API. */
|
|
742
|
+
var HttpElementLocation;
|
|
743
|
+
(function (HttpElementLocation) {
|
|
744
|
+
HttpElementLocation["HTTP_IN_UNSPECIFIED"] = "HTTP_IN_UNSPECIFIED";
|
|
643
745
|
/**
|
|
644
|
-
*
|
|
746
|
+
* Element is in the HTTP request query.
|
|
645
747
|
*/
|
|
646
|
-
|
|
748
|
+
HttpElementLocation["HTTP_IN_QUERY"] = "HTTP_IN_QUERY";
|
|
647
749
|
/**
|
|
648
|
-
*
|
|
750
|
+
* Element is in the HTTP request header.
|
|
649
751
|
*/
|
|
650
|
-
|
|
752
|
+
HttpElementLocation["HTTP_IN_HEADER"] = "HTTP_IN_HEADER";
|
|
651
753
|
/**
|
|
652
|
-
*
|
|
754
|
+
* Element is in the HTTP request path.
|
|
653
755
|
*/
|
|
654
|
-
|
|
655
|
-
|
|
756
|
+
HttpElementLocation["HTTP_IN_PATH"] = "HTTP_IN_PATH";
|
|
757
|
+
/**
|
|
758
|
+
* Element is in the HTTP request body.
|
|
759
|
+
*/
|
|
760
|
+
HttpElementLocation["HTTP_IN_BODY"] = "HTTP_IN_BODY";
|
|
761
|
+
/**
|
|
762
|
+
* Element is in the HTTP request cookie.
|
|
763
|
+
*/
|
|
764
|
+
HttpElementLocation["HTTP_IN_COOKIE"] = "HTTP_IN_COOKIE";
|
|
765
|
+
})(HttpElementLocation || (HttpElementLocation = {}));
|
|
766
|
+
/** Sites with confidence level chosen & above this value will be blocked from the search results. This enum is not supported in Gemini API. */
|
|
767
|
+
var PhishBlockThreshold;
|
|
768
|
+
(function (PhishBlockThreshold) {
|
|
769
|
+
/**
|
|
770
|
+
* Defaults to unspecified.
|
|
771
|
+
*/
|
|
772
|
+
PhishBlockThreshold["PHISH_BLOCK_THRESHOLD_UNSPECIFIED"] = "PHISH_BLOCK_THRESHOLD_UNSPECIFIED";
|
|
773
|
+
/**
|
|
774
|
+
* Blocks Low and above confidence URL that is risky.
|
|
775
|
+
*/
|
|
776
|
+
PhishBlockThreshold["BLOCK_LOW_AND_ABOVE"] = "BLOCK_LOW_AND_ABOVE";
|
|
777
|
+
/**
|
|
778
|
+
* Blocks Medium and above confidence URL that is risky.
|
|
779
|
+
*/
|
|
780
|
+
PhishBlockThreshold["BLOCK_MEDIUM_AND_ABOVE"] = "BLOCK_MEDIUM_AND_ABOVE";
|
|
781
|
+
/**
|
|
782
|
+
* Blocks High and above confidence URL that is risky.
|
|
783
|
+
*/
|
|
784
|
+
PhishBlockThreshold["BLOCK_HIGH_AND_ABOVE"] = "BLOCK_HIGH_AND_ABOVE";
|
|
785
|
+
/**
|
|
786
|
+
* Blocks Higher and above confidence URL that is risky.
|
|
787
|
+
*/
|
|
788
|
+
PhishBlockThreshold["BLOCK_HIGHER_AND_ABOVE"] = "BLOCK_HIGHER_AND_ABOVE";
|
|
789
|
+
/**
|
|
790
|
+
* Blocks Very high and above confidence URL that is risky.
|
|
791
|
+
*/
|
|
792
|
+
PhishBlockThreshold["BLOCK_VERY_HIGH_AND_ABOVE"] = "BLOCK_VERY_HIGH_AND_ABOVE";
|
|
793
|
+
/**
|
|
794
|
+
* Blocks Extremely high confidence URL that is risky.
|
|
795
|
+
*/
|
|
796
|
+
PhishBlockThreshold["BLOCK_ONLY_EXTREMELY_HIGH"] = "BLOCK_ONLY_EXTREMELY_HIGH";
|
|
797
|
+
})(PhishBlockThreshold || (PhishBlockThreshold = {}));
|
|
656
798
|
/** Harm category. */
|
|
657
799
|
var HarmCategory;
|
|
658
800
|
(function (HarmCategory) {
|
|
@@ -919,7 +1061,7 @@ var BlockedReason;
|
|
|
919
1061
|
*/
|
|
920
1062
|
BlockedReason["JAILBREAK"] = "JAILBREAK";
|
|
921
1063
|
})(BlockedReason || (BlockedReason = {}));
|
|
922
|
-
/** Output only.
|
|
1064
|
+
/** Output only. The traffic type for this request. This enum is not supported in Gemini API. */
|
|
923
1065
|
var TrafficType;
|
|
924
1066
|
(function (TrafficType) {
|
|
925
1067
|
/**
|
|
@@ -927,7 +1069,7 @@ var TrafficType;
|
|
|
927
1069
|
*/
|
|
928
1070
|
TrafficType["TRAFFIC_TYPE_UNSPECIFIED"] = "TRAFFIC_TYPE_UNSPECIFIED";
|
|
929
1071
|
/**
|
|
930
|
-
*
|
|
1072
|
+
* The request was processed using Pay-As-You-Go quota.
|
|
931
1073
|
*/
|
|
932
1074
|
TrafficType["ON_DEMAND"] = "ON_DEMAND";
|
|
933
1075
|
/**
|
|
@@ -1090,6 +1232,10 @@ var TuningTask;
|
|
|
1090
1232
|
* Tuning task for text to video.
|
|
1091
1233
|
*/
|
|
1092
1234
|
TuningTask["TUNING_TASK_T2V"] = "TUNING_TASK_T2V";
|
|
1235
|
+
/**
|
|
1236
|
+
* Tuning task for reference to video.
|
|
1237
|
+
*/
|
|
1238
|
+
TuningTask["TUNING_TASK_R2V"] = "TUNING_TASK_R2V";
|
|
1093
1239
|
})(TuningTask || (TuningTask = {}));
|
|
1094
1240
|
/** Options for feature selection preference. */
|
|
1095
1241
|
var FeatureSelectionPreference;
|
|
@@ -1337,6 +1483,14 @@ var TuningMethod;
|
|
|
1337
1483
|
*/
|
|
1338
1484
|
TuningMethod["PREFERENCE_TUNING"] = "PREFERENCE_TUNING";
|
|
1339
1485
|
})(TuningMethod || (TuningMethod = {}));
|
|
1486
|
+
/** State for the lifecycle of a Document. */
|
|
1487
|
+
var DocumentState;
|
|
1488
|
+
(function (DocumentState) {
|
|
1489
|
+
DocumentState["STATE_UNSPECIFIED"] = "STATE_UNSPECIFIED";
|
|
1490
|
+
DocumentState["STATE_PENDING"] = "STATE_PENDING";
|
|
1491
|
+
DocumentState["STATE_ACTIVE"] = "STATE_ACTIVE";
|
|
1492
|
+
DocumentState["STATE_FAILED"] = "STATE_FAILED";
|
|
1493
|
+
})(DocumentState || (DocumentState = {}));
|
|
1340
1494
|
/** State for the lifecycle of a File. */
|
|
1341
1495
|
var FileState;
|
|
1342
1496
|
(function (FileState) {
|
|
@@ -1764,7 +1918,7 @@ class HttpResponse {
|
|
|
1764
1918
|
/** Content filter results for a prompt sent in the request. Note: This is sent only in the first stream chunk and only if no candidates were generated due to content violations. */
|
|
1765
1919
|
class GenerateContentResponsePromptFeedback {
|
|
1766
1920
|
}
|
|
1767
|
-
/** Usage metadata about response
|
|
1921
|
+
/** Usage metadata about the content generation request and response. This message provides a detailed breakdown of token usage and other relevant metrics. This data type is not supported in Gemini API. */
|
|
1768
1922
|
class GenerateContentResponseUsageMetadata {
|
|
1769
1923
|
}
|
|
1770
1924
|
/** Response message for PredictionService.GenerateContent. */
|
|
@@ -2029,11 +2183,11 @@ class GenerateVideosOperation {
|
|
|
2029
2183
|
* Instantiates an Operation of the same type as the one being called with the fields set from the API response.
|
|
2030
2184
|
* @internal
|
|
2031
2185
|
*/
|
|
2032
|
-
_fromAPIResponse({ apiResponse,
|
|
2186
|
+
_fromAPIResponse({ apiResponse, _isVertexAI, }) {
|
|
2033
2187
|
const operation = new GenerateVideosOperation();
|
|
2034
2188
|
let response;
|
|
2035
2189
|
const op = apiResponse;
|
|
2036
|
-
if (
|
|
2190
|
+
if (_isVertexAI) {
|
|
2037
2191
|
response = generateVideosOperationFromVertex$1(op);
|
|
2038
2192
|
}
|
|
2039
2193
|
else {
|
|
@@ -2051,6 +2205,32 @@ class DeleteCachedContentResponse {
|
|
|
2051
2205
|
}
|
|
2052
2206
|
class ListCachedContentsResponse {
|
|
2053
2207
|
}
|
|
2208
|
+
/** Config for documents.list return value. */
|
|
2209
|
+
class ListDocumentsResponse {
|
|
2210
|
+
}
|
|
2211
|
+
/** Config for file_search_stores.list return value. */
|
|
2212
|
+
class ListFileSearchStoresResponse {
|
|
2213
|
+
}
|
|
2214
|
+
/** Response for the resumable upload method. */
|
|
2215
|
+
class UploadToFileSearchStoreResumableResponse {
|
|
2216
|
+
}
|
|
2217
|
+
/** Response for ImportFile to import a File API file with a file search store. */
|
|
2218
|
+
class ImportFileResponse {
|
|
2219
|
+
}
|
|
2220
|
+
/** Long-running operation for importing a file to a FileSearchStore. */
|
|
2221
|
+
class ImportFileOperation {
|
|
2222
|
+
/**
|
|
2223
|
+
* Instantiates an Operation of the same type as the one being called with the fields set from the API response.
|
|
2224
|
+
* @internal
|
|
2225
|
+
*/
|
|
2226
|
+
_fromAPIResponse({ apiResponse, _isVertexAI, }) {
|
|
2227
|
+
const operation = new ImportFileOperation();
|
|
2228
|
+
const op = apiResponse;
|
|
2229
|
+
const response = importFileOperationFromMldev$1(op);
|
|
2230
|
+
Object.assign(operation, response);
|
|
2231
|
+
return operation;
|
|
2232
|
+
}
|
|
2233
|
+
}
|
|
2054
2234
|
/** Response for the list files method. */
|
|
2055
2235
|
class ListFilesResponse {
|
|
2056
2236
|
}
|
|
@@ -2286,6 +2466,23 @@ class LiveMusicServerMessage {
|
|
|
2286
2466
|
return undefined;
|
|
2287
2467
|
}
|
|
2288
2468
|
}
|
|
2469
|
+
/** The response when long-running operation for uploading a file to a FileSearchStore complete. */
|
|
2470
|
+
class UploadToFileSearchStoreResponse {
|
|
2471
|
+
}
|
|
2472
|
+
/** Long-running operation for uploading a file to a FileSearchStore. */
|
|
2473
|
+
class UploadToFileSearchStoreOperation {
|
|
2474
|
+
/**
|
|
2475
|
+
* Instantiates an Operation of the same type as the one being called with the fields set from the API response.
|
|
2476
|
+
* @internal
|
|
2477
|
+
*/
|
|
2478
|
+
_fromAPIResponse({ apiResponse, _isVertexAI, }) {
|
|
2479
|
+
const operation = new UploadToFileSearchStoreOperation();
|
|
2480
|
+
const op = apiResponse;
|
|
2481
|
+
const response = uploadToFileSearchStoreOperationFromMldev(op);
|
|
2482
|
+
Object.assign(operation, response);
|
|
2483
|
+
return operation;
|
|
2484
|
+
}
|
|
2485
|
+
}
|
|
2289
2486
|
|
|
2290
2487
|
/**
|
|
2291
2488
|
* @license
|
|
@@ -3282,6 +3479,12 @@ function batchJobFromVertex(fromObject) {
|
|
|
3282
3479
|
if (fromDest != null) {
|
|
3283
3480
|
setValueByPath(toObject, ['dest'], batchJobDestinationFromVertex(tRecvBatchJobDestination(fromDest)));
|
|
3284
3481
|
}
|
|
3482
|
+
const fromCompletionStats = getValueByPath(fromObject, [
|
|
3483
|
+
'completionStats',
|
|
3484
|
+
]);
|
|
3485
|
+
if (fromCompletionStats != null) {
|
|
3486
|
+
setValueByPath(toObject, ['completionStats'], fromCompletionStats);
|
|
3487
|
+
}
|
|
3285
3488
|
return toObject;
|
|
3286
3489
|
}
|
|
3287
3490
|
function batchJobSourceFromVertex(fromObject) {
|
|
@@ -3914,6 +4117,9 @@ function googleSearchToMldev$4(fromObject) {
|
|
|
3914
4117
|
if (getValueByPath(fromObject, ['excludeDomains']) !== undefined) {
|
|
3915
4118
|
throw new Error('excludeDomains parameter is not supported in Gemini API.');
|
|
3916
4119
|
}
|
|
4120
|
+
if (getValueByPath(fromObject, ['blockingConfidence']) !== undefined) {
|
|
4121
|
+
throw new Error('blockingConfidence parameter is not supported in Gemini API.');
|
|
4122
|
+
}
|
|
3917
4123
|
const fromTimeRangeFilter = getValueByPath(fromObject, [
|
|
3918
4124
|
'timeRangeFilter',
|
|
3919
4125
|
]);
|
|
@@ -4153,14 +4359,14 @@ function toolToMldev$4(fromObject) {
|
|
|
4153
4359
|
if (fromGoogleSearchRetrieval != null) {
|
|
4154
4360
|
setValueByPath(toObject, ['googleSearchRetrieval'], fromGoogleSearchRetrieval);
|
|
4155
4361
|
}
|
|
4156
|
-
const fromGoogleMaps = getValueByPath(fromObject, ['googleMaps']);
|
|
4157
|
-
if (fromGoogleMaps != null) {
|
|
4158
|
-
setValueByPath(toObject, ['googleMaps'], googleMapsToMldev$4(fromGoogleMaps));
|
|
4159
|
-
}
|
|
4160
4362
|
const fromComputerUse = getValueByPath(fromObject, ['computerUse']);
|
|
4161
4363
|
if (fromComputerUse != null) {
|
|
4162
4364
|
setValueByPath(toObject, ['computerUse'], fromComputerUse);
|
|
4163
4365
|
}
|
|
4366
|
+
const fromFileSearch = getValueByPath(fromObject, ['fileSearch']);
|
|
4367
|
+
if (fromFileSearch != null) {
|
|
4368
|
+
setValueByPath(toObject, ['fileSearch'], fromFileSearch);
|
|
4369
|
+
}
|
|
4164
4370
|
const fromCodeExecution = getValueByPath(fromObject, [
|
|
4165
4371
|
'codeExecution',
|
|
4166
4372
|
]);
|
|
@@ -4170,6 +4376,10 @@ function toolToMldev$4(fromObject) {
|
|
|
4170
4376
|
if (getValueByPath(fromObject, ['enterpriseWebSearch']) !== undefined) {
|
|
4171
4377
|
throw new Error('enterpriseWebSearch parameter is not supported in Gemini API.');
|
|
4172
4378
|
}
|
|
4379
|
+
const fromGoogleMaps = getValueByPath(fromObject, ['googleMaps']);
|
|
4380
|
+
if (fromGoogleMaps != null) {
|
|
4381
|
+
setValueByPath(toObject, ['googleMaps'], googleMapsToMldev$4(fromGoogleMaps));
|
|
4382
|
+
}
|
|
4173
4383
|
const fromGoogleSearch = getValueByPath(fromObject, ['googleSearch']);
|
|
4174
4384
|
if (fromGoogleSearch != null) {
|
|
4175
4385
|
setValueByPath(toObject, ['googleSearch'], googleSearchToMldev$4(fromGoogleSearch));
|
|
@@ -4193,7 +4403,7 @@ var PagedItem;
|
|
|
4193
4403
|
PagedItem["PAGED_ITEM_TUNING_JOBS"] = "tuningJobs";
|
|
4194
4404
|
PagedItem["PAGED_ITEM_FILES"] = "files";
|
|
4195
4405
|
PagedItem["PAGED_ITEM_CACHED_CONTENTS"] = "cachedContents";
|
|
4196
|
-
PagedItem["
|
|
4406
|
+
PagedItem["PAGED_ITEM_FILE_SEARCH_STORES"] = "fileSearchStores";
|
|
4197
4407
|
PagedItem["PAGED_ITEM_DOCUMENTS"] = "documents";
|
|
4198
4408
|
})(PagedItem || (PagedItem = {}));
|
|
4199
4409
|
/**
|
|
@@ -5147,6 +5357,9 @@ function googleSearchToMldev$3(fromObject) {
|
|
|
5147
5357
|
if (getValueByPath(fromObject, ['excludeDomains']) !== undefined) {
|
|
5148
5358
|
throw new Error('excludeDomains parameter is not supported in Gemini API.');
|
|
5149
5359
|
}
|
|
5360
|
+
if (getValueByPath(fromObject, ['blockingConfidence']) !== undefined) {
|
|
5361
|
+
throw new Error('blockingConfidence parameter is not supported in Gemini API.');
|
|
5362
|
+
}
|
|
5150
5363
|
const fromTimeRangeFilter = getValueByPath(fromObject, [
|
|
5151
5364
|
'timeRangeFilter',
|
|
5152
5365
|
]);
|
|
@@ -5328,14 +5541,14 @@ function toolToMldev$3(fromObject) {
|
|
|
5328
5541
|
if (fromGoogleSearchRetrieval != null) {
|
|
5329
5542
|
setValueByPath(toObject, ['googleSearchRetrieval'], fromGoogleSearchRetrieval);
|
|
5330
5543
|
}
|
|
5331
|
-
const fromGoogleMaps = getValueByPath(fromObject, ['googleMaps']);
|
|
5332
|
-
if (fromGoogleMaps != null) {
|
|
5333
|
-
setValueByPath(toObject, ['googleMaps'], googleMapsToMldev$3(fromGoogleMaps));
|
|
5334
|
-
}
|
|
5335
5544
|
const fromComputerUse = getValueByPath(fromObject, ['computerUse']);
|
|
5336
5545
|
if (fromComputerUse != null) {
|
|
5337
5546
|
setValueByPath(toObject, ['computerUse'], fromComputerUse);
|
|
5338
5547
|
}
|
|
5548
|
+
const fromFileSearch = getValueByPath(fromObject, ['fileSearch']);
|
|
5549
|
+
if (fromFileSearch != null) {
|
|
5550
|
+
setValueByPath(toObject, ['fileSearch'], fromFileSearch);
|
|
5551
|
+
}
|
|
5339
5552
|
const fromCodeExecution = getValueByPath(fromObject, [
|
|
5340
5553
|
'codeExecution',
|
|
5341
5554
|
]);
|
|
@@ -5345,6 +5558,10 @@ function toolToMldev$3(fromObject) {
|
|
|
5345
5558
|
if (getValueByPath(fromObject, ['enterpriseWebSearch']) !== undefined) {
|
|
5346
5559
|
throw new Error('enterpriseWebSearch parameter is not supported in Gemini API.');
|
|
5347
5560
|
}
|
|
5561
|
+
const fromGoogleMaps = getValueByPath(fromObject, ['googleMaps']);
|
|
5562
|
+
if (fromGoogleMaps != null) {
|
|
5563
|
+
setValueByPath(toObject, ['googleMaps'], googleMapsToMldev$3(fromGoogleMaps));
|
|
5564
|
+
}
|
|
5348
5565
|
const fromGoogleSearch = getValueByPath(fromObject, ['googleSearch']);
|
|
5349
5566
|
if (fromGoogleSearch != null) {
|
|
5350
5567
|
setValueByPath(toObject, ['googleSearch'], googleSearchToMldev$3(fromGoogleSearch));
|
|
@@ -5379,14 +5596,13 @@ function toolToVertex$2(fromObject) {
|
|
|
5379
5596
|
if (fromGoogleSearchRetrieval != null) {
|
|
5380
5597
|
setValueByPath(toObject, ['googleSearchRetrieval'], fromGoogleSearchRetrieval);
|
|
5381
5598
|
}
|
|
5382
|
-
const fromGoogleMaps = getValueByPath(fromObject, ['googleMaps']);
|
|
5383
|
-
if (fromGoogleMaps != null) {
|
|
5384
|
-
setValueByPath(toObject, ['googleMaps'], fromGoogleMaps);
|
|
5385
|
-
}
|
|
5386
5599
|
const fromComputerUse = getValueByPath(fromObject, ['computerUse']);
|
|
5387
5600
|
if (fromComputerUse != null) {
|
|
5388
5601
|
setValueByPath(toObject, ['computerUse'], fromComputerUse);
|
|
5389
5602
|
}
|
|
5603
|
+
if (getValueByPath(fromObject, ['fileSearch']) !== undefined) {
|
|
5604
|
+
throw new Error('fileSearch parameter is not supported in Vertex AI.');
|
|
5605
|
+
}
|
|
5390
5606
|
const fromCodeExecution = getValueByPath(fromObject, [
|
|
5391
5607
|
'codeExecution',
|
|
5392
5608
|
]);
|
|
@@ -5399,6 +5615,10 @@ function toolToVertex$2(fromObject) {
|
|
|
5399
5615
|
if (fromEnterpriseWebSearch != null) {
|
|
5400
5616
|
setValueByPath(toObject, ['enterpriseWebSearch'], fromEnterpriseWebSearch);
|
|
5401
5617
|
}
|
|
5618
|
+
const fromGoogleMaps = getValueByPath(fromObject, ['googleMaps']);
|
|
5619
|
+
if (fromGoogleMaps != null) {
|
|
5620
|
+
setValueByPath(toObject, ['googleMaps'], fromGoogleMaps);
|
|
5621
|
+
}
|
|
5402
5622
|
const fromGoogleSearch = getValueByPath(fromObject, ['googleSearch']);
|
|
5403
5623
|
if (fromGoogleSearch != null) {
|
|
5404
5624
|
setValueByPath(toObject, ['googleSearch'], fromGoogleSearch);
|
|
@@ -6704,6 +6924,12 @@ function generationConfigToVertex$1(fromObject) {
|
|
|
6704
6924
|
if (fromModelSelectionConfig != null) {
|
|
6705
6925
|
setValueByPath(toObject, ['modelConfig'], fromModelSelectionConfig);
|
|
6706
6926
|
}
|
|
6927
|
+
const fromResponseJsonSchema = getValueByPath(fromObject, [
|
|
6928
|
+
'responseJsonSchema',
|
|
6929
|
+
]);
|
|
6930
|
+
if (fromResponseJsonSchema != null) {
|
|
6931
|
+
setValueByPath(toObject, ['responseJsonSchema'], fromResponseJsonSchema);
|
|
6932
|
+
}
|
|
6707
6933
|
const fromAudioTimestamp = getValueByPath(fromObject, [
|
|
6708
6934
|
'audioTimestamp',
|
|
6709
6935
|
]);
|
|
@@ -6750,12 +6976,6 @@ function generationConfigToVertex$1(fromObject) {
|
|
|
6750
6976
|
if (fromPresencePenalty != null) {
|
|
6751
6977
|
setValueByPath(toObject, ['presencePenalty'], fromPresencePenalty);
|
|
6752
6978
|
}
|
|
6753
|
-
const fromResponseJsonSchema = getValueByPath(fromObject, [
|
|
6754
|
-
'responseJsonSchema',
|
|
6755
|
-
]);
|
|
6756
|
-
if (fromResponseJsonSchema != null) {
|
|
6757
|
-
setValueByPath(toObject, ['responseJsonSchema'], fromResponseJsonSchema);
|
|
6758
|
-
}
|
|
6759
6979
|
const fromResponseLogprobs = getValueByPath(fromObject, [
|
|
6760
6980
|
'responseLogprobs',
|
|
6761
6981
|
]);
|
|
@@ -6840,6 +7060,9 @@ function googleSearchToMldev$2(fromObject) {
|
|
|
6840
7060
|
if (getValueByPath(fromObject, ['excludeDomains']) !== undefined) {
|
|
6841
7061
|
throw new Error('excludeDomains parameter is not supported in Gemini API.');
|
|
6842
7062
|
}
|
|
7063
|
+
if (getValueByPath(fromObject, ['blockingConfidence']) !== undefined) {
|
|
7064
|
+
throw new Error('blockingConfidence parameter is not supported in Gemini API.');
|
|
7065
|
+
}
|
|
6843
7066
|
const fromTimeRangeFilter = getValueByPath(fromObject, [
|
|
6844
7067
|
'timeRangeFilter',
|
|
6845
7068
|
]);
|
|
@@ -7347,14 +7570,14 @@ function toolToMldev$2(fromObject) {
|
|
|
7347
7570
|
if (fromGoogleSearchRetrieval != null) {
|
|
7348
7571
|
setValueByPath(toObject, ['googleSearchRetrieval'], fromGoogleSearchRetrieval);
|
|
7349
7572
|
}
|
|
7350
|
-
const fromGoogleMaps = getValueByPath(fromObject, ['googleMaps']);
|
|
7351
|
-
if (fromGoogleMaps != null) {
|
|
7352
|
-
setValueByPath(toObject, ['googleMaps'], googleMapsToMldev$2(fromGoogleMaps));
|
|
7353
|
-
}
|
|
7354
7573
|
const fromComputerUse = getValueByPath(fromObject, ['computerUse']);
|
|
7355
7574
|
if (fromComputerUse != null) {
|
|
7356
7575
|
setValueByPath(toObject, ['computerUse'], fromComputerUse);
|
|
7357
7576
|
}
|
|
7577
|
+
const fromFileSearch = getValueByPath(fromObject, ['fileSearch']);
|
|
7578
|
+
if (fromFileSearch != null) {
|
|
7579
|
+
setValueByPath(toObject, ['fileSearch'], fromFileSearch);
|
|
7580
|
+
}
|
|
7358
7581
|
const fromCodeExecution = getValueByPath(fromObject, [
|
|
7359
7582
|
'codeExecution',
|
|
7360
7583
|
]);
|
|
@@ -7364,6 +7587,10 @@ function toolToMldev$2(fromObject) {
|
|
|
7364
7587
|
if (getValueByPath(fromObject, ['enterpriseWebSearch']) !== undefined) {
|
|
7365
7588
|
throw new Error('enterpriseWebSearch parameter is not supported in Gemini API.');
|
|
7366
7589
|
}
|
|
7590
|
+
const fromGoogleMaps = getValueByPath(fromObject, ['googleMaps']);
|
|
7591
|
+
if (fromGoogleMaps != null) {
|
|
7592
|
+
setValueByPath(toObject, ['googleMaps'], googleMapsToMldev$2(fromGoogleMaps));
|
|
7593
|
+
}
|
|
7367
7594
|
const fromGoogleSearch = getValueByPath(fromObject, ['googleSearch']);
|
|
7368
7595
|
if (fromGoogleSearch != null) {
|
|
7369
7596
|
setValueByPath(toObject, ['googleSearch'], googleSearchToMldev$2(fromGoogleSearch));
|
|
@@ -7398,14 +7625,13 @@ function toolToVertex$1(fromObject) {
|
|
|
7398
7625
|
if (fromGoogleSearchRetrieval != null) {
|
|
7399
7626
|
setValueByPath(toObject, ['googleSearchRetrieval'], fromGoogleSearchRetrieval);
|
|
7400
7627
|
}
|
|
7401
|
-
const fromGoogleMaps = getValueByPath(fromObject, ['googleMaps']);
|
|
7402
|
-
if (fromGoogleMaps != null) {
|
|
7403
|
-
setValueByPath(toObject, ['googleMaps'], fromGoogleMaps);
|
|
7404
|
-
}
|
|
7405
7628
|
const fromComputerUse = getValueByPath(fromObject, ['computerUse']);
|
|
7406
7629
|
if (fromComputerUse != null) {
|
|
7407
7630
|
setValueByPath(toObject, ['computerUse'], fromComputerUse);
|
|
7408
7631
|
}
|
|
7632
|
+
if (getValueByPath(fromObject, ['fileSearch']) !== undefined) {
|
|
7633
|
+
throw new Error('fileSearch parameter is not supported in Vertex AI.');
|
|
7634
|
+
}
|
|
7409
7635
|
const fromCodeExecution = getValueByPath(fromObject, [
|
|
7410
7636
|
'codeExecution',
|
|
7411
7637
|
]);
|
|
@@ -7418,6 +7644,10 @@ function toolToVertex$1(fromObject) {
|
|
|
7418
7644
|
if (fromEnterpriseWebSearch != null) {
|
|
7419
7645
|
setValueByPath(toObject, ['enterpriseWebSearch'], fromEnterpriseWebSearch);
|
|
7420
7646
|
}
|
|
7647
|
+
const fromGoogleMaps = getValueByPath(fromObject, ['googleMaps']);
|
|
7648
|
+
if (fromGoogleMaps != null) {
|
|
7649
|
+
setValueByPath(toObject, ['googleMaps'], fromGoogleMaps);
|
|
7650
|
+
}
|
|
7421
7651
|
const fromGoogleSearch = getValueByPath(fromObject, ['googleSearch']);
|
|
7422
7652
|
if (fromGoogleSearch != null) {
|
|
7423
7653
|
setValueByPath(toObject, ['googleSearch'], fromGoogleSearch);
|
|
@@ -9367,6 +9597,12 @@ function generationConfigToVertex(fromObject) {
|
|
|
9367
9597
|
if (fromModelSelectionConfig != null) {
|
|
9368
9598
|
setValueByPath(toObject, ['modelConfig'], fromModelSelectionConfig);
|
|
9369
9599
|
}
|
|
9600
|
+
const fromResponseJsonSchema = getValueByPath(fromObject, [
|
|
9601
|
+
'responseJsonSchema',
|
|
9602
|
+
]);
|
|
9603
|
+
if (fromResponseJsonSchema != null) {
|
|
9604
|
+
setValueByPath(toObject, ['responseJsonSchema'], fromResponseJsonSchema);
|
|
9605
|
+
}
|
|
9370
9606
|
const fromAudioTimestamp = getValueByPath(fromObject, [
|
|
9371
9607
|
'audioTimestamp',
|
|
9372
9608
|
]);
|
|
@@ -9413,12 +9649,6 @@ function generationConfigToVertex(fromObject) {
|
|
|
9413
9649
|
if (fromPresencePenalty != null) {
|
|
9414
9650
|
setValueByPath(toObject, ['presencePenalty'], fromPresencePenalty);
|
|
9415
9651
|
}
|
|
9416
|
-
const fromResponseJsonSchema = getValueByPath(fromObject, [
|
|
9417
|
-
'responseJsonSchema',
|
|
9418
|
-
]);
|
|
9419
|
-
if (fromResponseJsonSchema != null) {
|
|
9420
|
-
setValueByPath(toObject, ['responseJsonSchema'], fromResponseJsonSchema);
|
|
9421
|
-
}
|
|
9422
9652
|
const fromResponseLogprobs = getValueByPath(fromObject, [
|
|
9423
9653
|
'responseLogprobs',
|
|
9424
9654
|
]);
|
|
@@ -9519,6 +9749,9 @@ function googleSearchToMldev$1(fromObject) {
|
|
|
9519
9749
|
if (getValueByPath(fromObject, ['excludeDomains']) !== undefined) {
|
|
9520
9750
|
throw new Error('excludeDomains parameter is not supported in Gemini API.');
|
|
9521
9751
|
}
|
|
9752
|
+
if (getValueByPath(fromObject, ['blockingConfidence']) !== undefined) {
|
|
9753
|
+
throw new Error('blockingConfidence parameter is not supported in Gemini API.');
|
|
9754
|
+
}
|
|
9522
9755
|
const fromTimeRangeFilter = getValueByPath(fromObject, [
|
|
9523
9756
|
'timeRangeFilter',
|
|
9524
9757
|
]);
|
|
@@ -10221,14 +10454,14 @@ function toolToMldev$1(fromObject) {
|
|
|
10221
10454
|
if (fromGoogleSearchRetrieval != null) {
|
|
10222
10455
|
setValueByPath(toObject, ['googleSearchRetrieval'], fromGoogleSearchRetrieval);
|
|
10223
10456
|
}
|
|
10224
|
-
const fromGoogleMaps = getValueByPath(fromObject, ['googleMaps']);
|
|
10225
|
-
if (fromGoogleMaps != null) {
|
|
10226
|
-
setValueByPath(toObject, ['googleMaps'], googleMapsToMldev$1(fromGoogleMaps));
|
|
10227
|
-
}
|
|
10228
10457
|
const fromComputerUse = getValueByPath(fromObject, ['computerUse']);
|
|
10229
10458
|
if (fromComputerUse != null) {
|
|
10230
10459
|
setValueByPath(toObject, ['computerUse'], fromComputerUse);
|
|
10231
10460
|
}
|
|
10461
|
+
const fromFileSearch = getValueByPath(fromObject, ['fileSearch']);
|
|
10462
|
+
if (fromFileSearch != null) {
|
|
10463
|
+
setValueByPath(toObject, ['fileSearch'], fromFileSearch);
|
|
10464
|
+
}
|
|
10232
10465
|
const fromCodeExecution = getValueByPath(fromObject, [
|
|
10233
10466
|
'codeExecution',
|
|
10234
10467
|
]);
|
|
@@ -10238,6 +10471,10 @@ function toolToMldev$1(fromObject) {
|
|
|
10238
10471
|
if (getValueByPath(fromObject, ['enterpriseWebSearch']) !== undefined) {
|
|
10239
10472
|
throw new Error('enterpriseWebSearch parameter is not supported in Gemini API.');
|
|
10240
10473
|
}
|
|
10474
|
+
const fromGoogleMaps = getValueByPath(fromObject, ['googleMaps']);
|
|
10475
|
+
if (fromGoogleMaps != null) {
|
|
10476
|
+
setValueByPath(toObject, ['googleMaps'], googleMapsToMldev$1(fromGoogleMaps));
|
|
10477
|
+
}
|
|
10241
10478
|
const fromGoogleSearch = getValueByPath(fromObject, ['googleSearch']);
|
|
10242
10479
|
if (fromGoogleSearch != null) {
|
|
10243
10480
|
setValueByPath(toObject, ['googleSearch'], googleSearchToMldev$1(fromGoogleSearch));
|
|
@@ -10272,14 +10509,13 @@ function toolToVertex(fromObject) {
|
|
|
10272
10509
|
if (fromGoogleSearchRetrieval != null) {
|
|
10273
10510
|
setValueByPath(toObject, ['googleSearchRetrieval'], fromGoogleSearchRetrieval);
|
|
10274
10511
|
}
|
|
10275
|
-
const fromGoogleMaps = getValueByPath(fromObject, ['googleMaps']);
|
|
10276
|
-
if (fromGoogleMaps != null) {
|
|
10277
|
-
setValueByPath(toObject, ['googleMaps'], fromGoogleMaps);
|
|
10278
|
-
}
|
|
10279
10512
|
const fromComputerUse = getValueByPath(fromObject, ['computerUse']);
|
|
10280
10513
|
if (fromComputerUse != null) {
|
|
10281
10514
|
setValueByPath(toObject, ['computerUse'], fromComputerUse);
|
|
10282
10515
|
}
|
|
10516
|
+
if (getValueByPath(fromObject, ['fileSearch']) !== undefined) {
|
|
10517
|
+
throw new Error('fileSearch parameter is not supported in Vertex AI.');
|
|
10518
|
+
}
|
|
10283
10519
|
const fromCodeExecution = getValueByPath(fromObject, [
|
|
10284
10520
|
'codeExecution',
|
|
10285
10521
|
]);
|
|
@@ -10292,6 +10528,10 @@ function toolToVertex(fromObject) {
|
|
|
10292
10528
|
if (fromEnterpriseWebSearch != null) {
|
|
10293
10529
|
setValueByPath(toObject, ['enterpriseWebSearch'], fromEnterpriseWebSearch);
|
|
10294
10530
|
}
|
|
10531
|
+
const fromGoogleMaps = getValueByPath(fromObject, ['googleMaps']);
|
|
10532
|
+
if (fromGoogleMaps != null) {
|
|
10533
|
+
setValueByPath(toObject, ['googleMaps'], fromGoogleMaps);
|
|
10534
|
+
}
|
|
10295
10535
|
const fromGoogleSearch = getValueByPath(fromObject, ['googleSearch']);
|
|
10296
10536
|
if (fromGoogleSearch != null) {
|
|
10297
10537
|
setValueByPath(toObject, ['googleSearch'], fromGoogleSearch);
|
|
@@ -10621,7 +10861,7 @@ const CONTENT_TYPE_HEADER = 'Content-Type';
|
|
|
10621
10861
|
const SERVER_TIMEOUT_HEADER = 'X-Server-Timeout';
|
|
10622
10862
|
const USER_AGENT_HEADER = 'User-Agent';
|
|
10623
10863
|
const GOOGLE_API_CLIENT_HEADER = 'x-goog-api-client';
|
|
10624
|
-
const SDK_VERSION = '1.
|
|
10864
|
+
const SDK_VERSION = '1.29.0'; // x-release-please-version
|
|
10625
10865
|
const LIBRARY_LABEL = `google-genai-sdk/${SDK_VERSION}`;
|
|
10626
10866
|
const VERTEX_AI_API_DEFAULT_VERSION = 'v1beta1';
|
|
10627
10867
|
const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
|
|
@@ -10999,6 +11239,15 @@ class ApiClient {
|
|
|
10999
11239
|
await this.clientOptions.auth.addAuthHeaders(headers, url);
|
|
11000
11240
|
return headers;
|
|
11001
11241
|
}
|
|
11242
|
+
getFileName(file) {
|
|
11243
|
+
var _a;
|
|
11244
|
+
let fileName = '';
|
|
11245
|
+
if (typeof file === 'string') {
|
|
11246
|
+
fileName = file.replace(/[/\\]+$/, '');
|
|
11247
|
+
fileName = (_a = fileName.split(/[/\\]/).pop()) !== null && _a !== void 0 ? _a : '';
|
|
11248
|
+
}
|
|
11249
|
+
return fileName;
|
|
11250
|
+
}
|
|
11002
11251
|
/**
|
|
11003
11252
|
* Uploads a file asynchronously using Gemini API only, this is not supported
|
|
11004
11253
|
* in Vertex AI.
|
|
@@ -11011,7 +11260,7 @@ class ApiClient {
|
|
|
11011
11260
|
* @throws An error if the `mimeType` is not provided and can not be inferred,
|
|
11012
11261
|
*/
|
|
11013
11262
|
async uploadFile(file, config) {
|
|
11014
|
-
var _a
|
|
11263
|
+
var _a;
|
|
11015
11264
|
const fileToUpload = {};
|
|
11016
11265
|
if (config != null) {
|
|
11017
11266
|
fileToUpload.mimeType = config.mimeType;
|
|
@@ -11029,41 +11278,71 @@ class ApiClient {
|
|
|
11029
11278
|
throw new Error('Can not determine mimeType. Please provide mimeType in the config.');
|
|
11030
11279
|
}
|
|
11031
11280
|
fileToUpload.mimeType = mimeType;
|
|
11032
|
-
|
|
11033
|
-
|
|
11034
|
-
|
|
11035
|
-
|
|
11036
|
-
|
|
11037
|
-
const uploadUrl = await this.fetchUploadUrl(fileToUpload, fileName, config);
|
|
11281
|
+
const body = {
|
|
11282
|
+
file: fileToUpload,
|
|
11283
|
+
};
|
|
11284
|
+
const fileName = this.getFileName(file);
|
|
11285
|
+
const path = formatMap('upload/v1beta/files', body['_url']);
|
|
11286
|
+
const uploadUrl = await this.fetchUploadUrl(path, fileToUpload.sizeBytes, fileToUpload.mimeType, fileName, body, config === null || config === void 0 ? void 0 : config.httpOptions);
|
|
11038
11287
|
return uploader.upload(file, uploadUrl, this);
|
|
11039
11288
|
}
|
|
11040
11289
|
/**
|
|
11041
|
-
*
|
|
11290
|
+
* Uploads a file to a given file search store asynchronously using Gemini API only, this is not supported
|
|
11291
|
+
* in Vertex AI.
|
|
11042
11292
|
*
|
|
11043
|
-
* @
|
|
11044
|
-
*
|
|
11293
|
+
* @param fileSearchStoreName The name of the file search store to upload the file to.
|
|
11294
|
+
* @param file The string path to the file to be uploaded or a Blob object.
|
|
11295
|
+
* @param config Optional parameters specified in the `UploadFileConfig`
|
|
11296
|
+
* interface. @see {@link UploadFileConfig}
|
|
11297
|
+
* @return A promise that resolves to a `File` object.
|
|
11298
|
+
* @throws An error if called on a Vertex AI client.
|
|
11299
|
+
* @throws An error if the `mimeType` is not provided and can not be inferred,
|
|
11045
11300
|
*/
|
|
11046
|
-
async
|
|
11047
|
-
const downloader = this.clientOptions.downloader;
|
|
11048
|
-
await downloader.download(params, this);
|
|
11049
|
-
}
|
|
11050
|
-
async fetchUploadUrl(file, fileName, config) {
|
|
11301
|
+
async uploadFileToFileSearchStore(fileSearchStoreName, file, config) {
|
|
11051
11302
|
var _a;
|
|
11052
|
-
|
|
11053
|
-
|
|
11054
|
-
|
|
11303
|
+
const uploader = this.clientOptions.uploader;
|
|
11304
|
+
const fileStat = await uploader.stat(file);
|
|
11305
|
+
const sizeBytes = String(fileStat.size);
|
|
11306
|
+
const mimeType = (_a = config === null || config === void 0 ? void 0 : config.mimeType) !== null && _a !== void 0 ? _a : fileStat.type;
|
|
11307
|
+
if (mimeType === undefined || mimeType === '') {
|
|
11308
|
+
throw new Error('Can not determine mimeType. Please provide mimeType in the config.');
|
|
11309
|
+
}
|
|
11310
|
+
const path = `upload/v1beta/${fileSearchStoreName}:uploadToFileSearchStore`;
|
|
11311
|
+
const fileName = this.getFileName(file);
|
|
11312
|
+
const body = {};
|
|
11313
|
+
if (config === null || config === void 0 ? void 0 : config.customMetadata) {
|
|
11314
|
+
body['customMetadata'] = config.customMetadata;
|
|
11315
|
+
}
|
|
11316
|
+
if (config === null || config === void 0 ? void 0 : config.chunkingConfig) {
|
|
11317
|
+
body['chunkingConfig'] = config.chunkingConfig;
|
|
11318
|
+
}
|
|
11319
|
+
const uploadUrl = await this.fetchUploadUrl(path, sizeBytes, mimeType, fileName, body, config === null || config === void 0 ? void 0 : config.httpOptions);
|
|
11320
|
+
return uploader.uploadToFileSearchStore(file, uploadUrl, this);
|
|
11321
|
+
}
|
|
11322
|
+
/**
|
|
11323
|
+
* Downloads a file asynchronously to the specified path.
|
|
11324
|
+
*
|
|
11325
|
+
* @params params - The parameters for the download request, see {@link
|
|
11326
|
+
* types.DownloadFileParameters}
|
|
11327
|
+
*/
|
|
11328
|
+
async downloadFile(params) {
|
|
11329
|
+
const downloader = this.clientOptions.downloader;
|
|
11330
|
+
await downloader.download(params, this);
|
|
11331
|
+
}
|
|
11332
|
+
async fetchUploadUrl(path, sizeBytes, mimeType, fileName, body, configHttpOptions) {
|
|
11333
|
+
var _a;
|
|
11334
|
+
let httpOptions = {};
|
|
11335
|
+
if (configHttpOptions) {
|
|
11336
|
+
httpOptions = configHttpOptions;
|
|
11055
11337
|
}
|
|
11056
11338
|
else {
|
|
11057
11339
|
httpOptions = {
|
|
11058
11340
|
apiVersion: '',
|
|
11059
|
-
headers: Object.assign({ 'Content-Type': 'application/json', 'X-Goog-Upload-Protocol': 'resumable', 'X-Goog-Upload-Command': 'start', 'X-Goog-Upload-Header-Content-Length': `${
|
|
11341
|
+
headers: Object.assign({ 'Content-Type': 'application/json', 'X-Goog-Upload-Protocol': 'resumable', 'X-Goog-Upload-Command': 'start', 'X-Goog-Upload-Header-Content-Length': `${sizeBytes}`, 'X-Goog-Upload-Header-Content-Type': `${mimeType}` }, (fileName ? { 'X-Goog-Upload-File-Name': fileName } : {})),
|
|
11060
11342
|
};
|
|
11061
11343
|
}
|
|
11062
|
-
const body = {
|
|
11063
|
-
'file': file,
|
|
11064
|
-
};
|
|
11065
11344
|
const httpResponse = await this.request({
|
|
11066
|
-
path
|
|
11345
|
+
path,
|
|
11067
11346
|
body: JSON.stringify(body),
|
|
11068
11347
|
httpMethod: 'POST',
|
|
11069
11348
|
httpOptions,
|
|
@@ -12067,11 +12346,27 @@ function hasCallableTools(params) {
|
|
|
12067
12346
|
var _a, _b, _c;
|
|
12068
12347
|
return (_c = (_b = (_a = params.config) === null || _a === void 0 ? void 0 : _a.tools) === null || _b === void 0 ? void 0 : _b.some((tool) => isCallableTool(tool))) !== null && _c !== void 0 ? _c : false;
|
|
12069
12348
|
}
|
|
12070
|
-
|
|
12071
|
-
|
|
12072
|
-
|
|
12073
|
-
|
|
12074
|
-
|
|
12349
|
+
/**
|
|
12350
|
+
* Returns the indexes of the tools that are not compatible with AFC.
|
|
12351
|
+
*/
|
|
12352
|
+
function findAfcIncompatibleToolIndexes(params) {
|
|
12353
|
+
var _a;
|
|
12354
|
+
// Use number[] for an array of numbers in TypeScript
|
|
12355
|
+
const afcIncompatibleToolIndexes = [];
|
|
12356
|
+
if (!((_a = params === null || params === void 0 ? void 0 : params.config) === null || _a === void 0 ? void 0 : _a.tools)) {
|
|
12357
|
+
return afcIncompatibleToolIndexes;
|
|
12358
|
+
}
|
|
12359
|
+
params.config.tools.forEach((tool, index) => {
|
|
12360
|
+
if (isCallableTool(tool)) {
|
|
12361
|
+
return;
|
|
12362
|
+
}
|
|
12363
|
+
const geminiTool = tool;
|
|
12364
|
+
if (geminiTool.functionDeclarations &&
|
|
12365
|
+
geminiTool.functionDeclarations.length > 0) {
|
|
12366
|
+
afcIncompatibleToolIndexes.push(index);
|
|
12367
|
+
}
|
|
12368
|
+
});
|
|
12369
|
+
return afcIncompatibleToolIndexes;
|
|
12075
12370
|
}
|
|
12076
12371
|
/**
|
|
12077
12372
|
* Returns whether to append automatic function calling history to the
|
|
@@ -12136,8 +12431,12 @@ class Models extends BaseModule {
|
|
|
12136
12431
|
if (!hasCallableTools(params) || shouldDisableAfc(params.config)) {
|
|
12137
12432
|
return await this.generateContentInternal(transformedParams);
|
|
12138
12433
|
}
|
|
12139
|
-
|
|
12140
|
-
|
|
12434
|
+
const incompatibleToolIndexes = findAfcIncompatibleToolIndexes(params);
|
|
12435
|
+
if (incompatibleToolIndexes.length > 0) {
|
|
12436
|
+
const formattedIndexes = incompatibleToolIndexes
|
|
12437
|
+
.map((index) => `tools[${index}]`)
|
|
12438
|
+
.join(', ');
|
|
12439
|
+
throw new Error(`Automatic function calling with CallableTools (or MCP objects) and basic FunctionDeclarations is not yet supported. Incompatible tools found at ${formattedIndexes}.`);
|
|
12141
12440
|
}
|
|
12142
12441
|
let response;
|
|
12143
12442
|
let functionResponseContent;
|
|
@@ -12224,9 +12523,14 @@ class Models extends BaseModule {
|
|
|
12224
12523
|
const transformedParams = await this.processParamsMaybeAddMcpUsage(params);
|
|
12225
12524
|
return await this.generateContentStreamInternal(transformedParams);
|
|
12226
12525
|
}
|
|
12227
|
-
|
|
12228
|
-
|
|
12526
|
+
const incompatibleToolIndexes = findAfcIncompatibleToolIndexes(params);
|
|
12527
|
+
if (incompatibleToolIndexes.length > 0) {
|
|
12528
|
+
const formattedIndexes = incompatibleToolIndexes
|
|
12529
|
+
.map((index) => `tools[${index}]`)
|
|
12530
|
+
.join(', ');
|
|
12531
|
+
throw new Error(`Incompatible tools found at ${formattedIndexes}. Automatic function calling with CallableTools (or MCP objects) and basic FunctionDeclarations" is not yet supported.`);
|
|
12229
12532
|
}
|
|
12533
|
+
return await this.processAfcStream(params);
|
|
12230
12534
|
};
|
|
12231
12535
|
/**
|
|
12232
12536
|
* Generates an image based on a text description and configuration.
|
|
@@ -13622,7 +13926,7 @@ class Operations extends BaseModule {
|
|
|
13622
13926
|
});
|
|
13623
13927
|
return operation._fromAPIResponse({
|
|
13624
13928
|
apiResponse: rawOperation,
|
|
13625
|
-
|
|
13929
|
+
_isVertexAI: true,
|
|
13626
13930
|
});
|
|
13627
13931
|
}
|
|
13628
13932
|
else {
|
|
@@ -13632,7 +13936,7 @@ class Operations extends BaseModule {
|
|
|
13632
13936
|
});
|
|
13633
13937
|
return operation._fromAPIResponse({
|
|
13634
13938
|
apiResponse: rawOperation,
|
|
13635
|
-
|
|
13939
|
+
_isVertexAI: false,
|
|
13636
13940
|
});
|
|
13637
13941
|
}
|
|
13638
13942
|
}
|
|
@@ -13661,7 +13965,7 @@ class Operations extends BaseModule {
|
|
|
13661
13965
|
});
|
|
13662
13966
|
return operation._fromAPIResponse({
|
|
13663
13967
|
apiResponse: rawOperation,
|
|
13664
|
-
|
|
13968
|
+
_isVertexAI: true,
|
|
13665
13969
|
});
|
|
13666
13970
|
}
|
|
13667
13971
|
else {
|
|
@@ -13671,7 +13975,7 @@ class Operations extends BaseModule {
|
|
|
13671
13975
|
});
|
|
13672
13976
|
return operation._fromAPIResponse({
|
|
13673
13977
|
apiResponse: rawOperation,
|
|
13674
|
-
|
|
13978
|
+
_isVertexAI: false,
|
|
13675
13979
|
});
|
|
13676
13980
|
}
|
|
13677
13981
|
}
|
|
@@ -13859,6 +14163,9 @@ function googleSearchToMldev(fromObject) {
|
|
|
13859
14163
|
if (getValueByPath(fromObject, ['excludeDomains']) !== undefined) {
|
|
13860
14164
|
throw new Error('excludeDomains parameter is not supported in Gemini API.');
|
|
13861
14165
|
}
|
|
14166
|
+
if (getValueByPath(fromObject, ['blockingConfidence']) !== undefined) {
|
|
14167
|
+
throw new Error('blockingConfidence parameter is not supported in Gemini API.');
|
|
14168
|
+
}
|
|
13862
14169
|
const fromTimeRangeFilter = getValueByPath(fromObject, [
|
|
13863
14170
|
'timeRangeFilter',
|
|
13864
14171
|
]);
|
|
@@ -14077,14 +14384,14 @@ function toolToMldev(fromObject) {
|
|
|
14077
14384
|
if (fromGoogleSearchRetrieval != null) {
|
|
14078
14385
|
setValueByPath(toObject, ['googleSearchRetrieval'], fromGoogleSearchRetrieval);
|
|
14079
14386
|
}
|
|
14080
|
-
const fromGoogleMaps = getValueByPath(fromObject, ['googleMaps']);
|
|
14081
|
-
if (fromGoogleMaps != null) {
|
|
14082
|
-
setValueByPath(toObject, ['googleMaps'], googleMapsToMldev(fromGoogleMaps));
|
|
14083
|
-
}
|
|
14084
14387
|
const fromComputerUse = getValueByPath(fromObject, ['computerUse']);
|
|
14085
14388
|
if (fromComputerUse != null) {
|
|
14086
14389
|
setValueByPath(toObject, ['computerUse'], fromComputerUse);
|
|
14087
14390
|
}
|
|
14391
|
+
const fromFileSearch = getValueByPath(fromObject, ['fileSearch']);
|
|
14392
|
+
if (fromFileSearch != null) {
|
|
14393
|
+
setValueByPath(toObject, ['fileSearch'], fromFileSearch);
|
|
14394
|
+
}
|
|
14088
14395
|
const fromCodeExecution = getValueByPath(fromObject, [
|
|
14089
14396
|
'codeExecution',
|
|
14090
14397
|
]);
|
|
@@ -14094,6 +14401,10 @@ function toolToMldev(fromObject) {
|
|
|
14094
14401
|
if (getValueByPath(fromObject, ['enterpriseWebSearch']) !== undefined) {
|
|
14095
14402
|
throw new Error('enterpriseWebSearch parameter is not supported in Gemini API.');
|
|
14096
14403
|
}
|
|
14404
|
+
const fromGoogleMaps = getValueByPath(fromObject, ['googleMaps']);
|
|
14405
|
+
if (fromGoogleMaps != null) {
|
|
14406
|
+
setValueByPath(toObject, ['googleMaps'], googleMapsToMldev(fromGoogleMaps));
|
|
14407
|
+
}
|
|
14097
14408
|
const fromGoogleSearch = getValueByPath(fromObject, ['googleSearch']);
|
|
14098
14409
|
if (fromGoogleSearch != null) {
|
|
14099
14410
|
setValueByPath(toObject, ['googleSearch'], googleSearchToMldev(fromGoogleSearch));
|
|
@@ -14380,195 +14691,44 @@ class Tokens extends BaseModule {
|
|
|
14380
14691
|
* Copyright 2025 Google LLC
|
|
14381
14692
|
* SPDX-License-Identifier: Apache-2.0
|
|
14382
14693
|
*/
|
|
14383
|
-
|
|
14384
|
-
|
|
14385
|
-
|
|
14386
|
-
|
|
14387
|
-
|
|
14388
|
-
|
|
14389
|
-
return;
|
|
14390
|
-
}
|
|
14391
|
-
const vertexAuthOptions = buildGoogleAuthOptions(opts.googleAuthOptions);
|
|
14392
|
-
this.googleAuth = new GoogleAuth(vertexAuthOptions);
|
|
14393
|
-
}
|
|
14394
|
-
async addAuthHeaders(headers, url) {
|
|
14395
|
-
if (this.apiKey !== undefined) {
|
|
14396
|
-
if (this.apiKey.startsWith('auth_tokens/')) {
|
|
14397
|
-
throw new Error('Ephemeral tokens are only supported by the live API.');
|
|
14398
|
-
}
|
|
14399
|
-
this.addKeyHeader(headers);
|
|
14400
|
-
return;
|
|
14401
|
-
}
|
|
14402
|
-
return this.addGoogleAuthHeaders(headers, url);
|
|
14403
|
-
}
|
|
14404
|
-
addKeyHeader(headers) {
|
|
14405
|
-
if (headers.get(GOOGLE_API_KEY_HEADER) !== null) {
|
|
14406
|
-
return;
|
|
14407
|
-
}
|
|
14408
|
-
if (this.apiKey === undefined) {
|
|
14409
|
-
// This should never happen, this method is only called
|
|
14410
|
-
// when apiKey is set.
|
|
14411
|
-
throw new Error('Trying to set API key header but apiKey is not set');
|
|
14412
|
-
}
|
|
14413
|
-
headers.append(GOOGLE_API_KEY_HEADER, this.apiKey);
|
|
14414
|
-
}
|
|
14415
|
-
async addGoogleAuthHeaders(headers, url) {
|
|
14416
|
-
if (this.googleAuth === undefined) {
|
|
14417
|
-
// This should never happen, addGoogleAuthHeaders should only be
|
|
14418
|
-
// called when there is no apiKey set and in these cases googleAuth
|
|
14419
|
-
// is set.
|
|
14420
|
-
throw new Error('Trying to set google-auth headers but googleAuth is unset');
|
|
14421
|
-
}
|
|
14422
|
-
const authHeaders = await this.googleAuth.getRequestHeaders(url);
|
|
14423
|
-
for (const [key, value] of authHeaders) {
|
|
14424
|
-
if (headers.get(key) !== null) {
|
|
14425
|
-
continue;
|
|
14426
|
-
}
|
|
14427
|
-
headers.append(key, value);
|
|
14428
|
-
}
|
|
14429
|
-
}
|
|
14430
|
-
}
|
|
14431
|
-
function buildGoogleAuthOptions(googleAuthOptions) {
|
|
14432
|
-
let authOptions;
|
|
14433
|
-
if (!googleAuthOptions) {
|
|
14434
|
-
authOptions = {
|
|
14435
|
-
scopes: [REQUIRED_VERTEX_AI_SCOPE],
|
|
14436
|
-
};
|
|
14437
|
-
return authOptions;
|
|
14438
|
-
}
|
|
14439
|
-
else {
|
|
14440
|
-
authOptions = googleAuthOptions;
|
|
14441
|
-
if (!authOptions.scopes) {
|
|
14442
|
-
authOptions.scopes = [REQUIRED_VERTEX_AI_SCOPE];
|
|
14443
|
-
return authOptions;
|
|
14444
|
-
}
|
|
14445
|
-
else if ((typeof authOptions.scopes === 'string' &&
|
|
14446
|
-
authOptions.scopes !== REQUIRED_VERTEX_AI_SCOPE) ||
|
|
14447
|
-
(Array.isArray(authOptions.scopes) &&
|
|
14448
|
-
authOptions.scopes.indexOf(REQUIRED_VERTEX_AI_SCOPE) < 0)) {
|
|
14449
|
-
throw new Error(`Invalid auth scopes. Scopes must include: ${REQUIRED_VERTEX_AI_SCOPE}`);
|
|
14450
|
-
}
|
|
14451
|
-
return authOptions;
|
|
14452
|
-
}
|
|
14453
|
-
}
|
|
14454
|
-
|
|
14455
|
-
/**
|
|
14456
|
-
* @license
|
|
14457
|
-
* Copyright 2025 Google LLC
|
|
14458
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
14459
|
-
*/
|
|
14460
|
-
class NodeDownloader {
|
|
14461
|
-
async download(params, apiClient) {
|
|
14462
|
-
if (params.downloadPath) {
|
|
14463
|
-
const response = await downloadFile(params, apiClient);
|
|
14464
|
-
if (response instanceof HttpResponse) {
|
|
14465
|
-
const writer = createWriteStream(params.downloadPath);
|
|
14466
|
-
const body = Readable.fromWeb(response.responseInternal.body);
|
|
14467
|
-
body.pipe(writer);
|
|
14468
|
-
await finished(writer);
|
|
14469
|
-
}
|
|
14470
|
-
else {
|
|
14471
|
-
try {
|
|
14472
|
-
await writeFile(params.downloadPath, response, {
|
|
14473
|
-
encoding: 'base64',
|
|
14474
|
-
});
|
|
14475
|
-
}
|
|
14476
|
-
catch (error) {
|
|
14477
|
-
throw new Error(`Failed to write file to ${params.downloadPath}: ${error}`);
|
|
14478
|
-
}
|
|
14479
|
-
}
|
|
14480
|
-
}
|
|
14481
|
-
}
|
|
14482
|
-
}
|
|
14483
|
-
async function downloadFile(params, apiClient) {
|
|
14484
|
-
var _a, _b, _c;
|
|
14485
|
-
const name = tFileName(params.file);
|
|
14486
|
-
if (name !== undefined) {
|
|
14487
|
-
return await apiClient.request({
|
|
14488
|
-
path: `files/${name}:download`,
|
|
14489
|
-
httpMethod: 'GET',
|
|
14490
|
-
queryParams: {
|
|
14491
|
-
'alt': 'media',
|
|
14492
|
-
},
|
|
14493
|
-
httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
|
|
14494
|
-
abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
|
|
14495
|
-
});
|
|
14496
|
-
}
|
|
14497
|
-
else if (isGeneratedVideo(params.file)) {
|
|
14498
|
-
const videoBytes = (_c = params.file.video) === null || _c === void 0 ? void 0 : _c.videoBytes;
|
|
14499
|
-
if (typeof videoBytes === 'string') {
|
|
14500
|
-
return videoBytes;
|
|
14501
|
-
}
|
|
14502
|
-
else {
|
|
14503
|
-
throw new Error('Failed to download generated video, Uri or videoBytes not found.');
|
|
14504
|
-
}
|
|
14505
|
-
}
|
|
14506
|
-
else if (isVideo(params.file)) {
|
|
14507
|
-
const videoBytes = params.file.videoBytes;
|
|
14508
|
-
if (typeof videoBytes === 'string') {
|
|
14509
|
-
return videoBytes;
|
|
14510
|
-
}
|
|
14511
|
-
else {
|
|
14512
|
-
throw new Error('Failed to download video, Uri or videoBytes not found.');
|
|
14513
|
-
}
|
|
14514
|
-
}
|
|
14515
|
-
else {
|
|
14516
|
-
throw new Error('Unsupported file type');
|
|
14694
|
+
// Code generated by the Google Gen AI SDK generator DO NOT EDIT.
|
|
14695
|
+
function createFileSearchStoreConfigToMldev(fromObject, parentObject) {
|
|
14696
|
+
const toObject = {};
|
|
14697
|
+
const fromDisplayName = getValueByPath(fromObject, ['displayName']);
|
|
14698
|
+
if (parentObject !== undefined && fromDisplayName != null) {
|
|
14699
|
+
setValueByPath(parentObject, ['displayName'], fromDisplayName);
|
|
14517
14700
|
}
|
|
14701
|
+
return toObject;
|
|
14518
14702
|
}
|
|
14519
|
-
|
|
14520
|
-
|
|
14521
|
-
|
|
14522
|
-
|
|
14523
|
-
|
|
14524
|
-
*/
|
|
14525
|
-
class NodeWebSocketFactory {
|
|
14526
|
-
create(url, headers, callbacks) {
|
|
14527
|
-
return new NodeWebSocket(url, headers, callbacks);
|
|
14703
|
+
function createFileSearchStoreParametersToMldev(fromObject) {
|
|
14704
|
+
const toObject = {};
|
|
14705
|
+
const fromConfig = getValueByPath(fromObject, ['config']);
|
|
14706
|
+
if (fromConfig != null) {
|
|
14707
|
+
createFileSearchStoreConfigToMldev(fromConfig, toObject);
|
|
14528
14708
|
}
|
|
14709
|
+
return toObject;
|
|
14529
14710
|
}
|
|
14530
|
-
|
|
14531
|
-
|
|
14532
|
-
|
|
14533
|
-
|
|
14534
|
-
|
|
14535
|
-
}
|
|
14536
|
-
connect() {
|
|
14537
|
-
this.ws = new NodeWs.WebSocket(this.url, { headers: this.headers });
|
|
14538
|
-
this.ws.onopen = this.callbacks.onopen;
|
|
14539
|
-
this.ws.onerror = this.callbacks.onerror;
|
|
14540
|
-
this.ws.onclose = this.callbacks.onclose;
|
|
14541
|
-
this.ws.onmessage = this.callbacks.onmessage;
|
|
14542
|
-
}
|
|
14543
|
-
send(message) {
|
|
14544
|
-
if (this.ws === undefined) {
|
|
14545
|
-
throw new Error('WebSocket is not connected');
|
|
14546
|
-
}
|
|
14547
|
-
this.ws.send(message);
|
|
14548
|
-
}
|
|
14549
|
-
close() {
|
|
14550
|
-
if (this.ws === undefined) {
|
|
14551
|
-
throw new Error('WebSocket is not connected');
|
|
14552
|
-
}
|
|
14553
|
-
this.ws.close();
|
|
14711
|
+
function deleteFileSearchStoreConfigToMldev(fromObject, parentObject) {
|
|
14712
|
+
const toObject = {};
|
|
14713
|
+
const fromForce = getValueByPath(fromObject, ['force']);
|
|
14714
|
+
if (parentObject !== undefined && fromForce != null) {
|
|
14715
|
+
setValueByPath(parentObject, ['_query', 'force'], fromForce);
|
|
14554
14716
|
}
|
|
14717
|
+
return toObject;
|
|
14555
14718
|
}
|
|
14556
|
-
|
|
14557
|
-
/**
|
|
14558
|
-
* @license
|
|
14559
|
-
* Copyright 2025 Google LLC
|
|
14560
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
14561
|
-
*/
|
|
14562
|
-
// Code generated by the Google Gen AI SDK generator DO NOT EDIT.
|
|
14563
|
-
function cancelTuningJobParametersToMldev(fromObject, _rootObject) {
|
|
14719
|
+
function deleteFileSearchStoreParametersToMldev(fromObject) {
|
|
14564
14720
|
const toObject = {};
|
|
14565
14721
|
const fromName = getValueByPath(fromObject, ['name']);
|
|
14566
14722
|
if (fromName != null) {
|
|
14567
14723
|
setValueByPath(toObject, ['_url', 'name'], fromName);
|
|
14568
14724
|
}
|
|
14725
|
+
const fromConfig = getValueByPath(fromObject, ['config']);
|
|
14726
|
+
if (fromConfig != null) {
|
|
14727
|
+
deleteFileSearchStoreConfigToMldev(fromConfig, toObject);
|
|
14728
|
+
}
|
|
14569
14729
|
return toObject;
|
|
14570
14730
|
}
|
|
14571
|
-
function
|
|
14731
|
+
function getFileSearchStoreParametersToMldev(fromObject) {
|
|
14572
14732
|
const toObject = {};
|
|
14573
14733
|
const fromName = getValueByPath(fromObject, ['name']);
|
|
14574
14734
|
if (fromName != null) {
|
|
@@ -14576,19 +14736,917 @@ function cancelTuningJobParametersToVertex(fromObject, _rootObject) {
|
|
|
14576
14736
|
}
|
|
14577
14737
|
return toObject;
|
|
14578
14738
|
}
|
|
14579
|
-
function
|
|
14739
|
+
function importFileConfigToMldev(fromObject, parentObject) {
|
|
14580
14740
|
const toObject = {};
|
|
14581
|
-
|
|
14582
|
-
|
|
14741
|
+
const fromCustomMetadata = getValueByPath(fromObject, [
|
|
14742
|
+
'customMetadata',
|
|
14743
|
+
]);
|
|
14744
|
+
if (parentObject !== undefined && fromCustomMetadata != null) {
|
|
14745
|
+
let transformedList = fromCustomMetadata;
|
|
14746
|
+
if (Array.isArray(transformedList)) {
|
|
14747
|
+
transformedList = transformedList.map((item) => {
|
|
14748
|
+
return item;
|
|
14749
|
+
});
|
|
14750
|
+
}
|
|
14751
|
+
setValueByPath(parentObject, ['customMetadata'], transformedList);
|
|
14583
14752
|
}
|
|
14584
|
-
const
|
|
14585
|
-
'
|
|
14753
|
+
const fromChunkingConfig = getValueByPath(fromObject, [
|
|
14754
|
+
'chunkingConfig',
|
|
14586
14755
|
]);
|
|
14587
|
-
if (parentObject !== undefined &&
|
|
14588
|
-
setValueByPath(parentObject, ['
|
|
14756
|
+
if (parentObject !== undefined && fromChunkingConfig != null) {
|
|
14757
|
+
setValueByPath(parentObject, ['chunkingConfig'], fromChunkingConfig);
|
|
14589
14758
|
}
|
|
14590
|
-
|
|
14591
|
-
|
|
14759
|
+
return toObject;
|
|
14760
|
+
}
|
|
14761
|
+
function importFileOperationFromMldev(fromObject) {
|
|
14762
|
+
const toObject = {};
|
|
14763
|
+
const fromName = getValueByPath(fromObject, ['name']);
|
|
14764
|
+
if (fromName != null) {
|
|
14765
|
+
setValueByPath(toObject, ['name'], fromName);
|
|
14766
|
+
}
|
|
14767
|
+
const fromMetadata = getValueByPath(fromObject, ['metadata']);
|
|
14768
|
+
if (fromMetadata != null) {
|
|
14769
|
+
setValueByPath(toObject, ['metadata'], fromMetadata);
|
|
14770
|
+
}
|
|
14771
|
+
const fromDone = getValueByPath(fromObject, ['done']);
|
|
14772
|
+
if (fromDone != null) {
|
|
14773
|
+
setValueByPath(toObject, ['done'], fromDone);
|
|
14774
|
+
}
|
|
14775
|
+
const fromError = getValueByPath(fromObject, ['error']);
|
|
14776
|
+
if (fromError != null) {
|
|
14777
|
+
setValueByPath(toObject, ['error'], fromError);
|
|
14778
|
+
}
|
|
14779
|
+
const fromResponse = getValueByPath(fromObject, ['response']);
|
|
14780
|
+
if (fromResponse != null) {
|
|
14781
|
+
setValueByPath(toObject, ['response'], importFileResponseFromMldev(fromResponse));
|
|
14782
|
+
}
|
|
14783
|
+
return toObject;
|
|
14784
|
+
}
|
|
14785
|
+
function importFileParametersToMldev(fromObject) {
|
|
14786
|
+
const toObject = {};
|
|
14787
|
+
const fromFileSearchStoreName = getValueByPath(fromObject, [
|
|
14788
|
+
'fileSearchStoreName',
|
|
14789
|
+
]);
|
|
14790
|
+
if (fromFileSearchStoreName != null) {
|
|
14791
|
+
setValueByPath(toObject, ['_url', 'file_search_store_name'], fromFileSearchStoreName);
|
|
14792
|
+
}
|
|
14793
|
+
const fromFileName = getValueByPath(fromObject, ['fileName']);
|
|
14794
|
+
if (fromFileName != null) {
|
|
14795
|
+
setValueByPath(toObject, ['fileName'], fromFileName);
|
|
14796
|
+
}
|
|
14797
|
+
const fromConfig = getValueByPath(fromObject, ['config']);
|
|
14798
|
+
if (fromConfig != null) {
|
|
14799
|
+
importFileConfigToMldev(fromConfig, toObject);
|
|
14800
|
+
}
|
|
14801
|
+
return toObject;
|
|
14802
|
+
}
|
|
14803
|
+
function importFileResponseFromMldev(fromObject) {
|
|
14804
|
+
const toObject = {};
|
|
14805
|
+
const fromSdkHttpResponse = getValueByPath(fromObject, [
|
|
14806
|
+
'sdkHttpResponse',
|
|
14807
|
+
]);
|
|
14808
|
+
if (fromSdkHttpResponse != null) {
|
|
14809
|
+
setValueByPath(toObject, ['sdkHttpResponse'], fromSdkHttpResponse);
|
|
14810
|
+
}
|
|
14811
|
+
const fromParent = getValueByPath(fromObject, ['parent']);
|
|
14812
|
+
if (fromParent != null) {
|
|
14813
|
+
setValueByPath(toObject, ['parent'], fromParent);
|
|
14814
|
+
}
|
|
14815
|
+
const fromDocumentName = getValueByPath(fromObject, ['documentName']);
|
|
14816
|
+
if (fromDocumentName != null) {
|
|
14817
|
+
setValueByPath(toObject, ['documentName'], fromDocumentName);
|
|
14818
|
+
}
|
|
14819
|
+
return toObject;
|
|
14820
|
+
}
|
|
14821
|
+
function listFileSearchStoresConfigToMldev(fromObject, parentObject) {
|
|
14822
|
+
const toObject = {};
|
|
14823
|
+
const fromPageSize = getValueByPath(fromObject, ['pageSize']);
|
|
14824
|
+
if (parentObject !== undefined && fromPageSize != null) {
|
|
14825
|
+
setValueByPath(parentObject, ['_query', 'pageSize'], fromPageSize);
|
|
14826
|
+
}
|
|
14827
|
+
const fromPageToken = getValueByPath(fromObject, ['pageToken']);
|
|
14828
|
+
if (parentObject !== undefined && fromPageToken != null) {
|
|
14829
|
+
setValueByPath(parentObject, ['_query', 'pageToken'], fromPageToken);
|
|
14830
|
+
}
|
|
14831
|
+
return toObject;
|
|
14832
|
+
}
|
|
14833
|
+
function listFileSearchStoresParametersToMldev(fromObject) {
|
|
14834
|
+
const toObject = {};
|
|
14835
|
+
const fromConfig = getValueByPath(fromObject, ['config']);
|
|
14836
|
+
if (fromConfig != null) {
|
|
14837
|
+
listFileSearchStoresConfigToMldev(fromConfig, toObject);
|
|
14838
|
+
}
|
|
14839
|
+
return toObject;
|
|
14840
|
+
}
|
|
14841
|
+
function listFileSearchStoresResponseFromMldev(fromObject) {
|
|
14842
|
+
const toObject = {};
|
|
14843
|
+
const fromSdkHttpResponse = getValueByPath(fromObject, [
|
|
14844
|
+
'sdkHttpResponse',
|
|
14845
|
+
]);
|
|
14846
|
+
if (fromSdkHttpResponse != null) {
|
|
14847
|
+
setValueByPath(toObject, ['sdkHttpResponse'], fromSdkHttpResponse);
|
|
14848
|
+
}
|
|
14849
|
+
const fromNextPageToken = getValueByPath(fromObject, [
|
|
14850
|
+
'nextPageToken',
|
|
14851
|
+
]);
|
|
14852
|
+
if (fromNextPageToken != null) {
|
|
14853
|
+
setValueByPath(toObject, ['nextPageToken'], fromNextPageToken);
|
|
14854
|
+
}
|
|
14855
|
+
const fromFileSearchStores = getValueByPath(fromObject, [
|
|
14856
|
+
'fileSearchStores',
|
|
14857
|
+
]);
|
|
14858
|
+
if (fromFileSearchStores != null) {
|
|
14859
|
+
let transformedList = fromFileSearchStores;
|
|
14860
|
+
if (Array.isArray(transformedList)) {
|
|
14861
|
+
transformedList = transformedList.map((item) => {
|
|
14862
|
+
return item;
|
|
14863
|
+
});
|
|
14864
|
+
}
|
|
14865
|
+
setValueByPath(toObject, ['fileSearchStores'], transformedList);
|
|
14866
|
+
}
|
|
14867
|
+
return toObject;
|
|
14868
|
+
}
|
|
14869
|
+
function uploadToFileSearchStoreConfigToMldev(fromObject, parentObject) {
|
|
14870
|
+
const toObject = {};
|
|
14871
|
+
const fromMimeType = getValueByPath(fromObject, ['mimeType']);
|
|
14872
|
+
if (parentObject !== undefined && fromMimeType != null) {
|
|
14873
|
+
setValueByPath(parentObject, ['mimeType'], fromMimeType);
|
|
14874
|
+
}
|
|
14875
|
+
const fromDisplayName = getValueByPath(fromObject, ['displayName']);
|
|
14876
|
+
if (parentObject !== undefined && fromDisplayName != null) {
|
|
14877
|
+
setValueByPath(parentObject, ['displayName'], fromDisplayName);
|
|
14878
|
+
}
|
|
14879
|
+
const fromCustomMetadata = getValueByPath(fromObject, [
|
|
14880
|
+
'customMetadata',
|
|
14881
|
+
]);
|
|
14882
|
+
if (parentObject !== undefined && fromCustomMetadata != null) {
|
|
14883
|
+
let transformedList = fromCustomMetadata;
|
|
14884
|
+
if (Array.isArray(transformedList)) {
|
|
14885
|
+
transformedList = transformedList.map((item) => {
|
|
14886
|
+
return item;
|
|
14887
|
+
});
|
|
14888
|
+
}
|
|
14889
|
+
setValueByPath(parentObject, ['customMetadata'], transformedList);
|
|
14890
|
+
}
|
|
14891
|
+
const fromChunkingConfig = getValueByPath(fromObject, [
|
|
14892
|
+
'chunkingConfig',
|
|
14893
|
+
]);
|
|
14894
|
+
if (parentObject !== undefined && fromChunkingConfig != null) {
|
|
14895
|
+
setValueByPath(parentObject, ['chunkingConfig'], fromChunkingConfig);
|
|
14896
|
+
}
|
|
14897
|
+
return toObject;
|
|
14898
|
+
}
|
|
14899
|
+
function uploadToFileSearchStoreParametersToMldev(fromObject) {
|
|
14900
|
+
const toObject = {};
|
|
14901
|
+
const fromFileSearchStoreName = getValueByPath(fromObject, [
|
|
14902
|
+
'fileSearchStoreName',
|
|
14903
|
+
]);
|
|
14904
|
+
if (fromFileSearchStoreName != null) {
|
|
14905
|
+
setValueByPath(toObject, ['_url', 'file_search_store_name'], fromFileSearchStoreName);
|
|
14906
|
+
}
|
|
14907
|
+
const fromConfig = getValueByPath(fromObject, ['config']);
|
|
14908
|
+
if (fromConfig != null) {
|
|
14909
|
+
uploadToFileSearchStoreConfigToMldev(fromConfig, toObject);
|
|
14910
|
+
}
|
|
14911
|
+
return toObject;
|
|
14912
|
+
}
|
|
14913
|
+
function uploadToFileSearchStoreResumableResponseFromMldev(fromObject) {
|
|
14914
|
+
const toObject = {};
|
|
14915
|
+
const fromSdkHttpResponse = getValueByPath(fromObject, [
|
|
14916
|
+
'sdkHttpResponse',
|
|
14917
|
+
]);
|
|
14918
|
+
if (fromSdkHttpResponse != null) {
|
|
14919
|
+
setValueByPath(toObject, ['sdkHttpResponse'], fromSdkHttpResponse);
|
|
14920
|
+
}
|
|
14921
|
+
return toObject;
|
|
14922
|
+
}
|
|
14923
|
+
|
|
14924
|
+
/**
|
|
14925
|
+
* @license
|
|
14926
|
+
* Copyright 2025 Google LLC
|
|
14927
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
14928
|
+
*/
|
|
14929
|
+
// Code generated by the Google Gen AI SDK generator DO NOT EDIT.
|
|
14930
|
+
function deleteDocumentConfigToMldev(fromObject, parentObject) {
|
|
14931
|
+
const toObject = {};
|
|
14932
|
+
const fromForce = getValueByPath(fromObject, ['force']);
|
|
14933
|
+
if (parentObject !== undefined && fromForce != null) {
|
|
14934
|
+
setValueByPath(parentObject, ['_query', 'force'], fromForce);
|
|
14935
|
+
}
|
|
14936
|
+
return toObject;
|
|
14937
|
+
}
|
|
14938
|
+
function deleteDocumentParametersToMldev(fromObject) {
|
|
14939
|
+
const toObject = {};
|
|
14940
|
+
const fromName = getValueByPath(fromObject, ['name']);
|
|
14941
|
+
if (fromName != null) {
|
|
14942
|
+
setValueByPath(toObject, ['_url', 'name'], fromName);
|
|
14943
|
+
}
|
|
14944
|
+
const fromConfig = getValueByPath(fromObject, ['config']);
|
|
14945
|
+
if (fromConfig != null) {
|
|
14946
|
+
deleteDocumentConfigToMldev(fromConfig, toObject);
|
|
14947
|
+
}
|
|
14948
|
+
return toObject;
|
|
14949
|
+
}
|
|
14950
|
+
function getDocumentParametersToMldev(fromObject) {
|
|
14951
|
+
const toObject = {};
|
|
14952
|
+
const fromName = getValueByPath(fromObject, ['name']);
|
|
14953
|
+
if (fromName != null) {
|
|
14954
|
+
setValueByPath(toObject, ['_url', 'name'], fromName);
|
|
14955
|
+
}
|
|
14956
|
+
return toObject;
|
|
14957
|
+
}
|
|
14958
|
+
function listDocumentsConfigToMldev(fromObject, parentObject) {
|
|
14959
|
+
const toObject = {};
|
|
14960
|
+
const fromPageSize = getValueByPath(fromObject, ['pageSize']);
|
|
14961
|
+
if (parentObject !== undefined && fromPageSize != null) {
|
|
14962
|
+
setValueByPath(parentObject, ['_query', 'pageSize'], fromPageSize);
|
|
14963
|
+
}
|
|
14964
|
+
const fromPageToken = getValueByPath(fromObject, ['pageToken']);
|
|
14965
|
+
if (parentObject !== undefined && fromPageToken != null) {
|
|
14966
|
+
setValueByPath(parentObject, ['_query', 'pageToken'], fromPageToken);
|
|
14967
|
+
}
|
|
14968
|
+
return toObject;
|
|
14969
|
+
}
|
|
14970
|
+
function listDocumentsParametersToMldev(fromObject) {
|
|
14971
|
+
const toObject = {};
|
|
14972
|
+
const fromParent = getValueByPath(fromObject, ['parent']);
|
|
14973
|
+
if (fromParent != null) {
|
|
14974
|
+
setValueByPath(toObject, ['_url', 'parent'], fromParent);
|
|
14975
|
+
}
|
|
14976
|
+
const fromConfig = getValueByPath(fromObject, ['config']);
|
|
14977
|
+
if (fromConfig != null) {
|
|
14978
|
+
listDocumentsConfigToMldev(fromConfig, toObject);
|
|
14979
|
+
}
|
|
14980
|
+
return toObject;
|
|
14981
|
+
}
|
|
14982
|
+
function listDocumentsResponseFromMldev(fromObject) {
|
|
14983
|
+
const toObject = {};
|
|
14984
|
+
const fromSdkHttpResponse = getValueByPath(fromObject, [
|
|
14985
|
+
'sdkHttpResponse',
|
|
14986
|
+
]);
|
|
14987
|
+
if (fromSdkHttpResponse != null) {
|
|
14988
|
+
setValueByPath(toObject, ['sdkHttpResponse'], fromSdkHttpResponse);
|
|
14989
|
+
}
|
|
14990
|
+
const fromNextPageToken = getValueByPath(fromObject, [
|
|
14991
|
+
'nextPageToken',
|
|
14992
|
+
]);
|
|
14993
|
+
if (fromNextPageToken != null) {
|
|
14994
|
+
setValueByPath(toObject, ['nextPageToken'], fromNextPageToken);
|
|
14995
|
+
}
|
|
14996
|
+
const fromDocuments = getValueByPath(fromObject, ['documents']);
|
|
14997
|
+
if (fromDocuments != null) {
|
|
14998
|
+
let transformedList = fromDocuments;
|
|
14999
|
+
if (Array.isArray(transformedList)) {
|
|
15000
|
+
transformedList = transformedList.map((item) => {
|
|
15001
|
+
return item;
|
|
15002
|
+
});
|
|
15003
|
+
}
|
|
15004
|
+
setValueByPath(toObject, ['documents'], transformedList);
|
|
15005
|
+
}
|
|
15006
|
+
return toObject;
|
|
15007
|
+
}
|
|
15008
|
+
|
|
15009
|
+
/**
|
|
15010
|
+
* @license
|
|
15011
|
+
* Copyright 2025 Google LLC
|
|
15012
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
15013
|
+
*/
|
|
15014
|
+
class Documents extends BaseModule {
|
|
15015
|
+
constructor(apiClient) {
|
|
15016
|
+
super();
|
|
15017
|
+
this.apiClient = apiClient;
|
|
15018
|
+
/**
|
|
15019
|
+
* Lists documents.
|
|
15020
|
+
*
|
|
15021
|
+
* @param params - The parameters for the list request.
|
|
15022
|
+
* @return - A pager of documents.
|
|
15023
|
+
*
|
|
15024
|
+
* @example
|
|
15025
|
+
* ```ts
|
|
15026
|
+
* const documents = await ai.documents.list({config: {'pageSize': 2}});
|
|
15027
|
+
* for await (const document of documents) {
|
|
15028
|
+
* console.log(document);
|
|
15029
|
+
* }
|
|
15030
|
+
* ```
|
|
15031
|
+
*/
|
|
15032
|
+
this.list = async (params) => {
|
|
15033
|
+
return new Pager(PagedItem.PAGED_ITEM_DOCUMENTS, (x) => this.listInternal({
|
|
15034
|
+
parent: params.parent,
|
|
15035
|
+
config: x.config,
|
|
15036
|
+
}), await this.listInternal(params), params);
|
|
15037
|
+
};
|
|
15038
|
+
}
|
|
15039
|
+
/**
|
|
15040
|
+
* Gets a Document.
|
|
15041
|
+
*
|
|
15042
|
+
* @param params - The parameters for getting a document.
|
|
15043
|
+
* @return Document.
|
|
15044
|
+
*/
|
|
15045
|
+
async get(params) {
|
|
15046
|
+
var _a, _b;
|
|
15047
|
+
let response;
|
|
15048
|
+
let path = '';
|
|
15049
|
+
let queryParams = {};
|
|
15050
|
+
if (this.apiClient.isVertexAI()) {
|
|
15051
|
+
throw new Error('This method is only supported by the Gemini Developer API.');
|
|
15052
|
+
}
|
|
15053
|
+
else {
|
|
15054
|
+
const body = getDocumentParametersToMldev(params);
|
|
15055
|
+
path = formatMap('{name}', body['_url']);
|
|
15056
|
+
queryParams = body['_query'];
|
|
15057
|
+
delete body['_url'];
|
|
15058
|
+
delete body['_query'];
|
|
15059
|
+
response = this.apiClient
|
|
15060
|
+
.request({
|
|
15061
|
+
path: path,
|
|
15062
|
+
queryParams: queryParams,
|
|
15063
|
+
body: JSON.stringify(body),
|
|
15064
|
+
httpMethod: 'GET',
|
|
15065
|
+
httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
|
|
15066
|
+
abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
|
|
15067
|
+
})
|
|
15068
|
+
.then((httpResponse) => {
|
|
15069
|
+
return httpResponse.json();
|
|
15070
|
+
});
|
|
15071
|
+
return response.then((resp) => {
|
|
15072
|
+
return resp;
|
|
15073
|
+
});
|
|
15074
|
+
}
|
|
15075
|
+
}
|
|
15076
|
+
/**
|
|
15077
|
+
* Deletes a Document.
|
|
15078
|
+
*
|
|
15079
|
+
* @param params - The parameters for deleting a document.
|
|
15080
|
+
*/
|
|
15081
|
+
async delete(params) {
|
|
15082
|
+
var _a, _b;
|
|
15083
|
+
let path = '';
|
|
15084
|
+
let queryParams = {};
|
|
15085
|
+
if (this.apiClient.isVertexAI()) {
|
|
15086
|
+
throw new Error('This method is only supported by the Gemini Developer API.');
|
|
15087
|
+
}
|
|
15088
|
+
else {
|
|
15089
|
+
const body = deleteDocumentParametersToMldev(params);
|
|
15090
|
+
path = formatMap('{name}', body['_url']);
|
|
15091
|
+
queryParams = body['_query'];
|
|
15092
|
+
delete body['_url'];
|
|
15093
|
+
delete body['_query'];
|
|
15094
|
+
await this.apiClient.request({
|
|
15095
|
+
path: path,
|
|
15096
|
+
queryParams: queryParams,
|
|
15097
|
+
body: JSON.stringify(body),
|
|
15098
|
+
httpMethod: 'DELETE',
|
|
15099
|
+
httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
|
|
15100
|
+
abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
|
|
15101
|
+
});
|
|
15102
|
+
}
|
|
15103
|
+
}
|
|
15104
|
+
/**
|
|
15105
|
+
* Lists all Documents in a FileSearchStore.
|
|
15106
|
+
*
|
|
15107
|
+
* @param params - The parameters for listing documents.
|
|
15108
|
+
* @return ListDocumentsResponse.
|
|
15109
|
+
*/
|
|
15110
|
+
async listInternal(params) {
|
|
15111
|
+
var _a, _b;
|
|
15112
|
+
let response;
|
|
15113
|
+
let path = '';
|
|
15114
|
+
let queryParams = {};
|
|
15115
|
+
if (this.apiClient.isVertexAI()) {
|
|
15116
|
+
throw new Error('This method is only supported by the Gemini Developer API.');
|
|
15117
|
+
}
|
|
15118
|
+
else {
|
|
15119
|
+
const body = listDocumentsParametersToMldev(params);
|
|
15120
|
+
path = formatMap('{parent}/documents', body['_url']);
|
|
15121
|
+
queryParams = body['_query'];
|
|
15122
|
+
delete body['_url'];
|
|
15123
|
+
delete body['_query'];
|
|
15124
|
+
response = this.apiClient
|
|
15125
|
+
.request({
|
|
15126
|
+
path: path,
|
|
15127
|
+
queryParams: queryParams,
|
|
15128
|
+
body: JSON.stringify(body),
|
|
15129
|
+
httpMethod: 'GET',
|
|
15130
|
+
httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
|
|
15131
|
+
abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
|
|
15132
|
+
})
|
|
15133
|
+
.then((httpResponse) => {
|
|
15134
|
+
return httpResponse.json();
|
|
15135
|
+
});
|
|
15136
|
+
return response.then((apiResponse) => {
|
|
15137
|
+
const resp = listDocumentsResponseFromMldev(apiResponse);
|
|
15138
|
+
const typedResp = new ListDocumentsResponse();
|
|
15139
|
+
Object.assign(typedResp, resp);
|
|
15140
|
+
return typedResp;
|
|
15141
|
+
});
|
|
15142
|
+
}
|
|
15143
|
+
}
|
|
15144
|
+
}
|
|
15145
|
+
|
|
15146
|
+
/**
|
|
15147
|
+
* @license
|
|
15148
|
+
* Copyright 2025 Google LLC
|
|
15149
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
15150
|
+
*/
|
|
15151
|
+
class FileSearchStores extends BaseModule {
|
|
15152
|
+
constructor(apiClient, documents = new Documents(apiClient)) {
|
|
15153
|
+
super();
|
|
15154
|
+
this.apiClient = apiClient;
|
|
15155
|
+
this.documents = documents;
|
|
15156
|
+
/**
|
|
15157
|
+
* Lists file search stores.
|
|
15158
|
+
*
|
|
15159
|
+
* @param params - The parameters for the list request.
|
|
15160
|
+
* @return - A pager of file search stores.
|
|
15161
|
+
*
|
|
15162
|
+
* @example
|
|
15163
|
+
* ```ts
|
|
15164
|
+
* const fileSearchStores = await ai.fileSearchStores.list({config: {'pageSize': 2}});
|
|
15165
|
+
* for await (const fileSearchStore of fileSearchStores) {
|
|
15166
|
+
* console.log(fileSearchStore);
|
|
15167
|
+
* }
|
|
15168
|
+
* ```
|
|
15169
|
+
*/
|
|
15170
|
+
this.list = async (params = {}) => {
|
|
15171
|
+
return new Pager(PagedItem.PAGED_ITEM_FILE_SEARCH_STORES, (x) => this.listInternal(x), await this.listInternal(params), params);
|
|
15172
|
+
};
|
|
15173
|
+
}
|
|
15174
|
+
/**
|
|
15175
|
+
* Uploads a file asynchronously to a given File Search Store.
|
|
15176
|
+
* This method is not available in Vertex AI.
|
|
15177
|
+
* Supported upload sources:
|
|
15178
|
+
* - Node.js: File path (string) or Blob object.
|
|
15179
|
+
* - Browser: Blob object (e.g., File).
|
|
15180
|
+
*
|
|
15181
|
+
* @remarks
|
|
15182
|
+
* The `mimeType` can be specified in the `config` parameter. If omitted:
|
|
15183
|
+
* - For file path (string) inputs, the `mimeType` will be inferred from the
|
|
15184
|
+
* file extension.
|
|
15185
|
+
* - For Blob object inputs, the `mimeType` will be set to the Blob's `type`
|
|
15186
|
+
* property.
|
|
15187
|
+
*
|
|
15188
|
+
* This section can contain multiple paragraphs and code examples.
|
|
15189
|
+
*
|
|
15190
|
+
* @param params - Optional parameters specified in the
|
|
15191
|
+
* `types.UploadToFileSearchStoreParameters` interface.
|
|
15192
|
+
* @see {@link types.UploadToFileSearchStoreParameters#config} for the optional
|
|
15193
|
+
* config in the parameters.
|
|
15194
|
+
* @return A promise that resolves to a long running operation.
|
|
15195
|
+
* @throws An error if called on a Vertex AI client.
|
|
15196
|
+
* @throws An error if the `mimeType` is not provided and can not be inferred,
|
|
15197
|
+
* the `mimeType` can be provided in the `params.config` parameter.
|
|
15198
|
+
* @throws An error occurs if a suitable upload location cannot be established.
|
|
15199
|
+
*
|
|
15200
|
+
* @example
|
|
15201
|
+
* The following code uploads a file to a given file search store.
|
|
15202
|
+
*
|
|
15203
|
+
* ```ts
|
|
15204
|
+
* const operation = await ai.fileSearchStores.upload({fileSearchStoreName: 'fileSearchStores/foo-bar', file: 'file.txt', config: {
|
|
15205
|
+
* mimeType: 'text/plain',
|
|
15206
|
+
* }});
|
|
15207
|
+
* console.log(operation.name);
|
|
15208
|
+
* ```
|
|
15209
|
+
*/
|
|
15210
|
+
async uploadToFileSearchStore(params) {
|
|
15211
|
+
if (this.apiClient.isVertexAI()) {
|
|
15212
|
+
throw new Error('Vertex AI does not support uploading files to a file search store.');
|
|
15213
|
+
}
|
|
15214
|
+
return this.apiClient.uploadFileToFileSearchStore(params.fileSearchStoreName, params.file, params.config);
|
|
15215
|
+
}
|
|
15216
|
+
/**
|
|
15217
|
+
* Creates a File Search Store.
|
|
15218
|
+
*
|
|
15219
|
+
* @param params - The parameters for creating a File Search Store.
|
|
15220
|
+
* @return FileSearchStore.
|
|
15221
|
+
*/
|
|
15222
|
+
async create(params) {
|
|
15223
|
+
var _a, _b;
|
|
15224
|
+
let response;
|
|
15225
|
+
let path = '';
|
|
15226
|
+
let queryParams = {};
|
|
15227
|
+
if (this.apiClient.isVertexAI()) {
|
|
15228
|
+
throw new Error('This method is only supported by the Gemini Developer API.');
|
|
15229
|
+
}
|
|
15230
|
+
else {
|
|
15231
|
+
const body = createFileSearchStoreParametersToMldev(params);
|
|
15232
|
+
path = formatMap('fileSearchStores', body['_url']);
|
|
15233
|
+
queryParams = body['_query'];
|
|
15234
|
+
delete body['_url'];
|
|
15235
|
+
delete body['_query'];
|
|
15236
|
+
response = this.apiClient
|
|
15237
|
+
.request({
|
|
15238
|
+
path: path,
|
|
15239
|
+
queryParams: queryParams,
|
|
15240
|
+
body: JSON.stringify(body),
|
|
15241
|
+
httpMethod: 'POST',
|
|
15242
|
+
httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
|
|
15243
|
+
abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
|
|
15244
|
+
})
|
|
15245
|
+
.then((httpResponse) => {
|
|
15246
|
+
return httpResponse.json();
|
|
15247
|
+
});
|
|
15248
|
+
return response.then((resp) => {
|
|
15249
|
+
return resp;
|
|
15250
|
+
});
|
|
15251
|
+
}
|
|
15252
|
+
}
|
|
15253
|
+
/**
|
|
15254
|
+
* Gets a File Search Store.
|
|
15255
|
+
*
|
|
15256
|
+
* @param params - The parameters for getting a File Search Store.
|
|
15257
|
+
* @return FileSearchStore.
|
|
15258
|
+
*/
|
|
15259
|
+
async get(params) {
|
|
15260
|
+
var _a, _b;
|
|
15261
|
+
let response;
|
|
15262
|
+
let path = '';
|
|
15263
|
+
let queryParams = {};
|
|
15264
|
+
if (this.apiClient.isVertexAI()) {
|
|
15265
|
+
throw new Error('This method is only supported by the Gemini Developer API.');
|
|
15266
|
+
}
|
|
15267
|
+
else {
|
|
15268
|
+
const body = getFileSearchStoreParametersToMldev(params);
|
|
15269
|
+
path = formatMap('{name}', body['_url']);
|
|
15270
|
+
queryParams = body['_query'];
|
|
15271
|
+
delete body['_url'];
|
|
15272
|
+
delete body['_query'];
|
|
15273
|
+
response = this.apiClient
|
|
15274
|
+
.request({
|
|
15275
|
+
path: path,
|
|
15276
|
+
queryParams: queryParams,
|
|
15277
|
+
body: JSON.stringify(body),
|
|
15278
|
+
httpMethod: 'GET',
|
|
15279
|
+
httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
|
|
15280
|
+
abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
|
|
15281
|
+
})
|
|
15282
|
+
.then((httpResponse) => {
|
|
15283
|
+
return httpResponse.json();
|
|
15284
|
+
});
|
|
15285
|
+
return response.then((resp) => {
|
|
15286
|
+
return resp;
|
|
15287
|
+
});
|
|
15288
|
+
}
|
|
15289
|
+
}
|
|
15290
|
+
/**
|
|
15291
|
+
* Deletes a File Search Store.
|
|
15292
|
+
*
|
|
15293
|
+
* @param params - The parameters for deleting a File Search Store.
|
|
15294
|
+
*/
|
|
15295
|
+
async delete(params) {
|
|
15296
|
+
var _a, _b;
|
|
15297
|
+
let path = '';
|
|
15298
|
+
let queryParams = {};
|
|
15299
|
+
if (this.apiClient.isVertexAI()) {
|
|
15300
|
+
throw new Error('This method is only supported by the Gemini Developer API.');
|
|
15301
|
+
}
|
|
15302
|
+
else {
|
|
15303
|
+
const body = deleteFileSearchStoreParametersToMldev(params);
|
|
15304
|
+
path = formatMap('{name}', body['_url']);
|
|
15305
|
+
queryParams = body['_query'];
|
|
15306
|
+
delete body['_url'];
|
|
15307
|
+
delete body['_query'];
|
|
15308
|
+
await this.apiClient.request({
|
|
15309
|
+
path: path,
|
|
15310
|
+
queryParams: queryParams,
|
|
15311
|
+
body: JSON.stringify(body),
|
|
15312
|
+
httpMethod: 'DELETE',
|
|
15313
|
+
httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
|
|
15314
|
+
abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
|
|
15315
|
+
});
|
|
15316
|
+
}
|
|
15317
|
+
}
|
|
15318
|
+
/**
|
|
15319
|
+
* Lists all FileSearchStore owned by the user.
|
|
15320
|
+
*
|
|
15321
|
+
* @param params - The parameters for listing file search stores.
|
|
15322
|
+
* @return ListFileSearchStoresResponse.
|
|
15323
|
+
*/
|
|
15324
|
+
async listInternal(params) {
|
|
15325
|
+
var _a, _b;
|
|
15326
|
+
let response;
|
|
15327
|
+
let path = '';
|
|
15328
|
+
let queryParams = {};
|
|
15329
|
+
if (this.apiClient.isVertexAI()) {
|
|
15330
|
+
throw new Error('This method is only supported by the Gemini Developer API.');
|
|
15331
|
+
}
|
|
15332
|
+
else {
|
|
15333
|
+
const body = listFileSearchStoresParametersToMldev(params);
|
|
15334
|
+
path = formatMap('fileSearchStores', body['_url']);
|
|
15335
|
+
queryParams = body['_query'];
|
|
15336
|
+
delete body['_url'];
|
|
15337
|
+
delete body['_query'];
|
|
15338
|
+
response = this.apiClient
|
|
15339
|
+
.request({
|
|
15340
|
+
path: path,
|
|
15341
|
+
queryParams: queryParams,
|
|
15342
|
+
body: JSON.stringify(body),
|
|
15343
|
+
httpMethod: 'GET',
|
|
15344
|
+
httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
|
|
15345
|
+
abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
|
|
15346
|
+
})
|
|
15347
|
+
.then((httpResponse) => {
|
|
15348
|
+
return httpResponse.json();
|
|
15349
|
+
});
|
|
15350
|
+
return response.then((apiResponse) => {
|
|
15351
|
+
const resp = listFileSearchStoresResponseFromMldev(apiResponse);
|
|
15352
|
+
const typedResp = new ListFileSearchStoresResponse();
|
|
15353
|
+
Object.assign(typedResp, resp);
|
|
15354
|
+
return typedResp;
|
|
15355
|
+
});
|
|
15356
|
+
}
|
|
15357
|
+
}
|
|
15358
|
+
async uploadToFileSearchStoreInternal(params) {
|
|
15359
|
+
var _a, _b;
|
|
15360
|
+
let response;
|
|
15361
|
+
let path = '';
|
|
15362
|
+
let queryParams = {};
|
|
15363
|
+
if (this.apiClient.isVertexAI()) {
|
|
15364
|
+
throw new Error('This method is only supported by the Gemini Developer API.');
|
|
15365
|
+
}
|
|
15366
|
+
else {
|
|
15367
|
+
const body = uploadToFileSearchStoreParametersToMldev(params);
|
|
15368
|
+
path = formatMap('upload/v1beta/{file_search_store_name}:uploadToFileSearchStore', body['_url']);
|
|
15369
|
+
queryParams = body['_query'];
|
|
15370
|
+
delete body['_url'];
|
|
15371
|
+
delete body['_query'];
|
|
15372
|
+
response = this.apiClient
|
|
15373
|
+
.request({
|
|
15374
|
+
path: path,
|
|
15375
|
+
queryParams: queryParams,
|
|
15376
|
+
body: JSON.stringify(body),
|
|
15377
|
+
httpMethod: 'POST',
|
|
15378
|
+
httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
|
|
15379
|
+
abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
|
|
15380
|
+
})
|
|
15381
|
+
.then((httpResponse) => {
|
|
15382
|
+
return httpResponse.json();
|
|
15383
|
+
});
|
|
15384
|
+
return response.then((apiResponse) => {
|
|
15385
|
+
const resp = uploadToFileSearchStoreResumableResponseFromMldev(apiResponse);
|
|
15386
|
+
const typedResp = new UploadToFileSearchStoreResumableResponse();
|
|
15387
|
+
Object.assign(typedResp, resp);
|
|
15388
|
+
return typedResp;
|
|
15389
|
+
});
|
|
15390
|
+
}
|
|
15391
|
+
}
|
|
15392
|
+
/**
|
|
15393
|
+
* Imports a File from File Service to a FileSearchStore.
|
|
15394
|
+
*
|
|
15395
|
+
* This is a long-running operation, see aip.dev/151
|
|
15396
|
+
*
|
|
15397
|
+
* @param params - The parameters for importing a file to a file search store.
|
|
15398
|
+
* @return ImportFileOperation.
|
|
15399
|
+
*/
|
|
15400
|
+
async importFile(params) {
|
|
15401
|
+
var _a, _b;
|
|
15402
|
+
let response;
|
|
15403
|
+
let path = '';
|
|
15404
|
+
let queryParams = {};
|
|
15405
|
+
if (this.apiClient.isVertexAI()) {
|
|
15406
|
+
throw new Error('This method is only supported by the Gemini Developer API.');
|
|
15407
|
+
}
|
|
15408
|
+
else {
|
|
15409
|
+
const body = importFileParametersToMldev(params);
|
|
15410
|
+
path = formatMap('{file_search_store_name}:importFile', body['_url']);
|
|
15411
|
+
queryParams = body['_query'];
|
|
15412
|
+
delete body['_url'];
|
|
15413
|
+
delete body['_query'];
|
|
15414
|
+
response = this.apiClient
|
|
15415
|
+
.request({
|
|
15416
|
+
path: path,
|
|
15417
|
+
queryParams: queryParams,
|
|
15418
|
+
body: JSON.stringify(body),
|
|
15419
|
+
httpMethod: 'POST',
|
|
15420
|
+
httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
|
|
15421
|
+
abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
|
|
15422
|
+
})
|
|
15423
|
+
.then((httpResponse) => {
|
|
15424
|
+
return httpResponse.json();
|
|
15425
|
+
});
|
|
15426
|
+
return response.then((apiResponse) => {
|
|
15427
|
+
const resp = importFileOperationFromMldev(apiResponse);
|
|
15428
|
+
const typedResp = new ImportFileOperation();
|
|
15429
|
+
Object.assign(typedResp, resp);
|
|
15430
|
+
return typedResp;
|
|
15431
|
+
});
|
|
15432
|
+
}
|
|
15433
|
+
}
|
|
15434
|
+
}
|
|
15435
|
+
|
|
15436
|
+
/**
|
|
15437
|
+
* @license
|
|
15438
|
+
* Copyright 2025 Google LLC
|
|
15439
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
15440
|
+
*/
|
|
15441
|
+
const GOOGLE_API_KEY_HEADER = 'x-goog-api-key';
|
|
15442
|
+
const REQUIRED_VERTEX_AI_SCOPE = 'https://www.googleapis.com/auth/cloud-platform';
|
|
15443
|
+
class NodeAuth {
|
|
15444
|
+
constructor(opts) {
|
|
15445
|
+
if (opts.apiKey !== undefined) {
|
|
15446
|
+
this.apiKey = opts.apiKey;
|
|
15447
|
+
return;
|
|
15448
|
+
}
|
|
15449
|
+
const vertexAuthOptions = buildGoogleAuthOptions(opts.googleAuthOptions);
|
|
15450
|
+
this.googleAuth = new GoogleAuth(vertexAuthOptions);
|
|
15451
|
+
}
|
|
15452
|
+
async addAuthHeaders(headers, url) {
|
|
15453
|
+
if (this.apiKey !== undefined) {
|
|
15454
|
+
if (this.apiKey.startsWith('auth_tokens/')) {
|
|
15455
|
+
throw new Error('Ephemeral tokens are only supported by the live API.');
|
|
15456
|
+
}
|
|
15457
|
+
this.addKeyHeader(headers);
|
|
15458
|
+
return;
|
|
15459
|
+
}
|
|
15460
|
+
return this.addGoogleAuthHeaders(headers, url);
|
|
15461
|
+
}
|
|
15462
|
+
addKeyHeader(headers) {
|
|
15463
|
+
if (headers.get(GOOGLE_API_KEY_HEADER) !== null) {
|
|
15464
|
+
return;
|
|
15465
|
+
}
|
|
15466
|
+
if (this.apiKey === undefined) {
|
|
15467
|
+
// This should never happen, this method is only called
|
|
15468
|
+
// when apiKey is set.
|
|
15469
|
+
throw new Error('Trying to set API key header but apiKey is not set');
|
|
15470
|
+
}
|
|
15471
|
+
headers.append(GOOGLE_API_KEY_HEADER, this.apiKey);
|
|
15472
|
+
}
|
|
15473
|
+
async addGoogleAuthHeaders(headers, url) {
|
|
15474
|
+
if (this.googleAuth === undefined) {
|
|
15475
|
+
// This should never happen, addGoogleAuthHeaders should only be
|
|
15476
|
+
// called when there is no apiKey set and in these cases googleAuth
|
|
15477
|
+
// is set.
|
|
15478
|
+
throw new Error('Trying to set google-auth headers but googleAuth is unset');
|
|
15479
|
+
}
|
|
15480
|
+
const authHeaders = await this.googleAuth.getRequestHeaders(url);
|
|
15481
|
+
for (const [key, value] of authHeaders) {
|
|
15482
|
+
if (headers.get(key) !== null) {
|
|
15483
|
+
continue;
|
|
15484
|
+
}
|
|
15485
|
+
headers.append(key, value);
|
|
15486
|
+
}
|
|
15487
|
+
}
|
|
15488
|
+
}
|
|
15489
|
+
function buildGoogleAuthOptions(googleAuthOptions) {
|
|
15490
|
+
let authOptions;
|
|
15491
|
+
if (!googleAuthOptions) {
|
|
15492
|
+
authOptions = {
|
|
15493
|
+
scopes: [REQUIRED_VERTEX_AI_SCOPE],
|
|
15494
|
+
};
|
|
15495
|
+
return authOptions;
|
|
15496
|
+
}
|
|
15497
|
+
else {
|
|
15498
|
+
authOptions = googleAuthOptions;
|
|
15499
|
+
if (!authOptions.scopes) {
|
|
15500
|
+
authOptions.scopes = [REQUIRED_VERTEX_AI_SCOPE];
|
|
15501
|
+
return authOptions;
|
|
15502
|
+
}
|
|
15503
|
+
else if ((typeof authOptions.scopes === 'string' &&
|
|
15504
|
+
authOptions.scopes !== REQUIRED_VERTEX_AI_SCOPE) ||
|
|
15505
|
+
(Array.isArray(authOptions.scopes) &&
|
|
15506
|
+
authOptions.scopes.indexOf(REQUIRED_VERTEX_AI_SCOPE) < 0)) {
|
|
15507
|
+
throw new Error(`Invalid auth scopes. Scopes must include: ${REQUIRED_VERTEX_AI_SCOPE}`);
|
|
15508
|
+
}
|
|
15509
|
+
return authOptions;
|
|
15510
|
+
}
|
|
15511
|
+
}
|
|
15512
|
+
|
|
15513
|
+
/**
|
|
15514
|
+
* @license
|
|
15515
|
+
* Copyright 2025 Google LLC
|
|
15516
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
15517
|
+
*/
|
|
15518
|
+
class NodeDownloader {
|
|
15519
|
+
async download(params, apiClient) {
|
|
15520
|
+
if (params.downloadPath) {
|
|
15521
|
+
const response = await downloadFile(params, apiClient);
|
|
15522
|
+
if (response instanceof HttpResponse) {
|
|
15523
|
+
const writer = createWriteStream(params.downloadPath);
|
|
15524
|
+
const body = Readable.fromWeb(response.responseInternal.body);
|
|
15525
|
+
body.pipe(writer);
|
|
15526
|
+
await finished(writer);
|
|
15527
|
+
}
|
|
15528
|
+
else {
|
|
15529
|
+
try {
|
|
15530
|
+
await writeFile(params.downloadPath, response, {
|
|
15531
|
+
encoding: 'base64',
|
|
15532
|
+
});
|
|
15533
|
+
}
|
|
15534
|
+
catch (error) {
|
|
15535
|
+
throw new Error(`Failed to write file to ${params.downloadPath}: ${error}`);
|
|
15536
|
+
}
|
|
15537
|
+
}
|
|
15538
|
+
}
|
|
15539
|
+
}
|
|
15540
|
+
}
|
|
15541
|
+
async function downloadFile(params, apiClient) {
|
|
15542
|
+
var _a, _b, _c;
|
|
15543
|
+
const name = tFileName(params.file);
|
|
15544
|
+
if (name !== undefined) {
|
|
15545
|
+
return await apiClient.request({
|
|
15546
|
+
path: `files/${name}:download`,
|
|
15547
|
+
httpMethod: 'GET',
|
|
15548
|
+
queryParams: {
|
|
15549
|
+
'alt': 'media',
|
|
15550
|
+
},
|
|
15551
|
+
httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
|
|
15552
|
+
abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
|
|
15553
|
+
});
|
|
15554
|
+
}
|
|
15555
|
+
else if (isGeneratedVideo(params.file)) {
|
|
15556
|
+
const videoBytes = (_c = params.file.video) === null || _c === void 0 ? void 0 : _c.videoBytes;
|
|
15557
|
+
if (typeof videoBytes === 'string') {
|
|
15558
|
+
return videoBytes;
|
|
15559
|
+
}
|
|
15560
|
+
else {
|
|
15561
|
+
throw new Error('Failed to download generated video, Uri or videoBytes not found.');
|
|
15562
|
+
}
|
|
15563
|
+
}
|
|
15564
|
+
else if (isVideo(params.file)) {
|
|
15565
|
+
const videoBytes = params.file.videoBytes;
|
|
15566
|
+
if (typeof videoBytes === 'string') {
|
|
15567
|
+
return videoBytes;
|
|
15568
|
+
}
|
|
15569
|
+
else {
|
|
15570
|
+
throw new Error('Failed to download video, Uri or videoBytes not found.');
|
|
15571
|
+
}
|
|
15572
|
+
}
|
|
15573
|
+
else {
|
|
15574
|
+
throw new Error('Unsupported file type');
|
|
15575
|
+
}
|
|
15576
|
+
}
|
|
15577
|
+
|
|
15578
|
+
/**
|
|
15579
|
+
* @license
|
|
15580
|
+
* Copyright 2025 Google LLC
|
|
15581
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
15582
|
+
*/
|
|
15583
|
+
class NodeWebSocketFactory {
|
|
15584
|
+
create(url, headers, callbacks) {
|
|
15585
|
+
return new NodeWebSocket(url, headers, callbacks);
|
|
15586
|
+
}
|
|
15587
|
+
}
|
|
15588
|
+
class NodeWebSocket {
|
|
15589
|
+
constructor(url, headers, callbacks) {
|
|
15590
|
+
this.url = url;
|
|
15591
|
+
this.headers = headers;
|
|
15592
|
+
this.callbacks = callbacks;
|
|
15593
|
+
}
|
|
15594
|
+
connect() {
|
|
15595
|
+
this.ws = new NodeWs.WebSocket(this.url, { headers: this.headers });
|
|
15596
|
+
this.ws.onopen = this.callbacks.onopen;
|
|
15597
|
+
this.ws.onerror = this.callbacks.onerror;
|
|
15598
|
+
this.ws.onclose = this.callbacks.onclose;
|
|
15599
|
+
this.ws.onmessage = this.callbacks.onmessage;
|
|
15600
|
+
}
|
|
15601
|
+
send(message) {
|
|
15602
|
+
if (this.ws === undefined) {
|
|
15603
|
+
throw new Error('WebSocket is not connected');
|
|
15604
|
+
}
|
|
15605
|
+
this.ws.send(message);
|
|
15606
|
+
}
|
|
15607
|
+
close() {
|
|
15608
|
+
if (this.ws === undefined) {
|
|
15609
|
+
throw new Error('WebSocket is not connected');
|
|
15610
|
+
}
|
|
15611
|
+
this.ws.close();
|
|
15612
|
+
}
|
|
15613
|
+
}
|
|
15614
|
+
|
|
15615
|
+
/**
|
|
15616
|
+
* @license
|
|
15617
|
+
* Copyright 2025 Google LLC
|
|
15618
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
15619
|
+
*/
|
|
15620
|
+
// Code generated by the Google Gen AI SDK generator DO NOT EDIT.
|
|
15621
|
+
function cancelTuningJobParametersToMldev(fromObject, _rootObject) {
|
|
15622
|
+
const toObject = {};
|
|
15623
|
+
const fromName = getValueByPath(fromObject, ['name']);
|
|
15624
|
+
if (fromName != null) {
|
|
15625
|
+
setValueByPath(toObject, ['_url', 'name'], fromName);
|
|
15626
|
+
}
|
|
15627
|
+
return toObject;
|
|
15628
|
+
}
|
|
15629
|
+
function cancelTuningJobParametersToVertex(fromObject, _rootObject) {
|
|
15630
|
+
const toObject = {};
|
|
15631
|
+
const fromName = getValueByPath(fromObject, ['name']);
|
|
15632
|
+
if (fromName != null) {
|
|
15633
|
+
setValueByPath(toObject, ['_url', 'name'], fromName);
|
|
15634
|
+
}
|
|
15635
|
+
return toObject;
|
|
15636
|
+
}
|
|
15637
|
+
function createTuningJobConfigToMldev(fromObject, parentObject, _rootObject) {
|
|
15638
|
+
const toObject = {};
|
|
15639
|
+
if (getValueByPath(fromObject, ['validationDataset']) !== undefined) {
|
|
15640
|
+
throw new Error('validationDataset parameter is not supported in Gemini API.');
|
|
15641
|
+
}
|
|
15642
|
+
const fromTunedModelDisplayName = getValueByPath(fromObject, [
|
|
15643
|
+
'tunedModelDisplayName',
|
|
15644
|
+
]);
|
|
15645
|
+
if (parentObject !== undefined && fromTunedModelDisplayName != null) {
|
|
15646
|
+
setValueByPath(parentObject, ['displayName'], fromTunedModelDisplayName);
|
|
15647
|
+
}
|
|
15648
|
+
if (getValueByPath(fromObject, ['description']) !== undefined) {
|
|
15649
|
+
throw new Error('description parameter is not supported in Gemini API.');
|
|
14592
15650
|
}
|
|
14593
15651
|
const fromEpochCount = getValueByPath(fromObject, ['epochCount']);
|
|
14594
15652
|
if (parentObject !== undefined && fromEpochCount != null) {
|
|
@@ -15570,7 +16628,28 @@ const INITIAL_RETRY_DELAY_MS = 1000;
|
|
|
15570
16628
|
const DELAY_MULTIPLIER = 2;
|
|
15571
16629
|
const X_GOOG_UPLOAD_STATUS_HEADER_FIELD = 'x-goog-upload-status';
|
|
15572
16630
|
async function uploadBlob(file, uploadUrl, apiClient) {
|
|
15573
|
-
var _a
|
|
16631
|
+
var _a;
|
|
16632
|
+
const response = await uploadBlobInternal(file, uploadUrl, apiClient);
|
|
16633
|
+
const responseJson = (await (response === null || response === void 0 ? void 0 : response.json()));
|
|
16634
|
+
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') {
|
|
16635
|
+
throw new Error('Failed to upload file: Upload status is not finalized.');
|
|
16636
|
+
}
|
|
16637
|
+
return responseJson['file'];
|
|
16638
|
+
}
|
|
16639
|
+
async function uploadBlobToFileSearchStore(file, uploadUrl, apiClient) {
|
|
16640
|
+
var _a;
|
|
16641
|
+
const response = await uploadBlobInternal(file, uploadUrl, apiClient);
|
|
16642
|
+
const responseJson = (await (response === null || response === void 0 ? void 0 : response.json()));
|
|
16643
|
+
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') {
|
|
16644
|
+
throw new Error('Failed to upload file: Upload status is not finalized.');
|
|
16645
|
+
}
|
|
16646
|
+
const resp = uploadToFileSearchStoreOperationFromMldev(responseJson);
|
|
16647
|
+
const typedResp = new UploadToFileSearchStoreOperation();
|
|
16648
|
+
Object.assign(typedResp, resp);
|
|
16649
|
+
return typedResp;
|
|
16650
|
+
}
|
|
16651
|
+
async function uploadBlobInternal(file, uploadUrl, apiClient) {
|
|
16652
|
+
var _a, _b;
|
|
15574
16653
|
let fileSize = 0;
|
|
15575
16654
|
let offset = 0;
|
|
15576
16655
|
let response = new HttpResponse(new Response());
|
|
@@ -15618,11 +16697,7 @@ async function uploadBlob(file, uploadUrl, apiClient) {
|
|
|
15618
16697
|
throw new Error('All content has been uploaded, but the upload status is not finalized.');
|
|
15619
16698
|
}
|
|
15620
16699
|
}
|
|
15621
|
-
|
|
15622
|
-
if (((_c = response === null || response === void 0 ? void 0 : response.headers) === null || _c === void 0 ? void 0 : _c[X_GOOG_UPLOAD_STATUS_HEADER_FIELD]) !== 'final') {
|
|
15623
|
-
throw new Error('Failed to upload file: Upload status is not finalized.');
|
|
15624
|
-
}
|
|
15625
|
-
return responseJson['file'];
|
|
16700
|
+
return response;
|
|
15626
16701
|
}
|
|
15627
16702
|
async function getBlobStat(file) {
|
|
15628
16703
|
const fileStat = { size: file.size, type: file.type };
|
|
@@ -15658,6 +16733,14 @@ class NodeUploader {
|
|
|
15658
16733
|
return uploadBlob(file, uploadUrl, apiClient);
|
|
15659
16734
|
}
|
|
15660
16735
|
}
|
|
16736
|
+
async uploadToFileSearchStore(file, uploadUrl, apiClient) {
|
|
16737
|
+
if (typeof file === 'string') {
|
|
16738
|
+
return await this.uploadFileToFileSearchStoreFromPath(file, uploadUrl, apiClient);
|
|
16739
|
+
}
|
|
16740
|
+
else {
|
|
16741
|
+
return uploadBlobToFileSearchStore(file, uploadUrl, apiClient);
|
|
16742
|
+
}
|
|
16743
|
+
}
|
|
15661
16744
|
/**
|
|
15662
16745
|
* Infers the MIME type of a file based on its extension.
|
|
15663
16746
|
*
|
|
@@ -15749,12 +16832,34 @@ class NodeUploader {
|
|
|
15749
16832
|
return mimeType;
|
|
15750
16833
|
}
|
|
15751
16834
|
async uploadFileFromPath(file, uploadUrl, apiClient) {
|
|
15752
|
-
var _a
|
|
16835
|
+
var _a;
|
|
16836
|
+
const response = await this.uploadFileFromPathInternal(file, uploadUrl, apiClient);
|
|
16837
|
+
const responseJson = (await (response === null || response === void 0 ? void 0 : response.json()));
|
|
16838
|
+
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') {
|
|
16839
|
+
throw new Error('Failed to upload file: Upload status is not finalized.');
|
|
16840
|
+
}
|
|
16841
|
+
return responseJson['file'];
|
|
16842
|
+
}
|
|
16843
|
+
async uploadFileToFileSearchStoreFromPath(file, uploadUrl, apiClient) {
|
|
16844
|
+
var _a;
|
|
16845
|
+
const response = await this.uploadFileFromPathInternal(file, uploadUrl, apiClient);
|
|
16846
|
+
const responseJson = (await (response === null || response === void 0 ? void 0 : response.json()));
|
|
16847
|
+
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') {
|
|
16848
|
+
throw new Error('Failed to upload file: Upload status is not finalized.');
|
|
16849
|
+
}
|
|
16850
|
+
const resp = uploadToFileSearchStoreOperationFromMldev(responseJson);
|
|
16851
|
+
const typedResp = new UploadToFileSearchStoreOperation();
|
|
16852
|
+
Object.assign(typedResp, resp);
|
|
16853
|
+
return typedResp;
|
|
16854
|
+
}
|
|
16855
|
+
async uploadFileFromPathInternal(file, uploadUrl, apiClient) {
|
|
16856
|
+
var _a, _b;
|
|
15753
16857
|
let fileSize = 0;
|
|
15754
16858
|
let offset = 0;
|
|
15755
16859
|
let response = new HttpResponse(new Response());
|
|
15756
16860
|
let uploadCommand = 'upload';
|
|
15757
16861
|
let fileHandle;
|
|
16862
|
+
const fileName = path.basename(file);
|
|
15758
16863
|
try {
|
|
15759
16864
|
fileHandle = await fs.open(file, 'r');
|
|
15760
16865
|
if (!fileHandle) {
|
|
@@ -15786,6 +16891,7 @@ class NodeUploader {
|
|
|
15786
16891
|
'X-Goog-Upload-Command': uploadCommand,
|
|
15787
16892
|
'X-Goog-Upload-Offset': String(offset),
|
|
15788
16893
|
'Content-Length': String(bytesRead),
|
|
16894
|
+
'X-Goog-Upload-File-Name': fileName,
|
|
15789
16895
|
},
|
|
15790
16896
|
},
|
|
15791
16897
|
});
|
|
@@ -15806,11 +16912,7 @@ class NodeUploader {
|
|
|
15806
16912
|
throw new Error('All content has been uploaded, but the upload status is not finalized.');
|
|
15807
16913
|
}
|
|
15808
16914
|
}
|
|
15809
|
-
|
|
15810
|
-
if (((_c = response === null || response === void 0 ? void 0 : response.headers) === null || _c === void 0 ? void 0 : _c[X_GOOG_UPLOAD_STATUS_HEADER_FIELD]) !== 'final') {
|
|
15811
|
-
throw new Error('Failed to upload file: Upload status is not finalized.');
|
|
15812
|
-
}
|
|
15813
|
-
return responseJson['file'];
|
|
16915
|
+
return response;
|
|
15814
16916
|
}
|
|
15815
16917
|
finally {
|
|
15816
16918
|
// Ensure the file handle is always closed
|
|
@@ -15949,6 +17051,7 @@ class GoogleGenAI {
|
|
|
15949
17051
|
this.operations = new Operations(this.apiClient);
|
|
15950
17052
|
this.authTokens = new Tokens(this.apiClient);
|
|
15951
17053
|
this.tunings = new Tunings(this.apiClient);
|
|
17054
|
+
this.fileSearchStores = new FileSearchStores(this.apiClient);
|
|
15952
17055
|
}
|
|
15953
17056
|
}
|
|
15954
17057
|
function getEnv(env) {
|
|
@@ -15973,5 +17076,5 @@ function getApiKeyFromEnv() {
|
|
|
15973
17076
|
return envGoogleApiKey || envGeminiApiKey || undefined;
|
|
15974
17077
|
}
|
|
15975
17078
|
|
|
15976
|
-
export { ActivityHandling, AdapterSize, ApiError, ApiSpec, AuthType, Batches, Behavior, BlockedReason, Caches, Chat, Chats, ComputeTokensResponse, ContentReferenceImage, ControlReferenceImage, ControlReferenceType, CountTokensResponse, CreateFileResponse, DeleteCachedContentResponse, DeleteFileResponse, DeleteModelResponse, DynamicRetrievalConfigMode, EditImageResponse, EditMode, EmbedContentResponse, EndSensitivity, Environment, FeatureSelectionPreference, FileSource, FileState, Files, FinishReason, FunctionCallingConfigMode, FunctionResponse, FunctionResponseBlob, FunctionResponseFileData, FunctionResponsePart, FunctionResponseScheduling, GenerateContentResponse, GenerateContentResponsePromptFeedback, GenerateContentResponseUsageMetadata, GenerateImagesResponse, GenerateVideosOperation, GenerateVideosResponse, GoogleGenAI, HarmBlockMethod, HarmBlockThreshold, HarmCategory, HarmProbability, HarmSeverity, HttpResponse, ImagePromptLanguage, InlinedEmbedContentResponse, InlinedResponse, JobState, Language, ListBatchJobsResponse, ListCachedContentsResponse, ListFilesResponse, ListModelsResponse, ListTuningJobsResponse, Live, LiveClientToolResponse, LiveMusicPlaybackControl, LiveMusicServerMessage, LiveSendToolResponseParameters, LiveServerMessage, MaskReferenceImage, MaskReferenceMode, MediaModality, MediaResolution, Modality, Mode, Models, MusicGenerationMode, Operations, Outcome, PagedItem, Pager, PersonGeneration, RawReferenceImage, RecontextImageResponse, ReplayResponse, SafetyFilterLevel, Scale, SegmentImageResponse, SegmentMode, Session, SingleEmbedContentResponse, StartSensitivity, StyleReferenceImage, SubjectReferenceImage, SubjectReferenceType, Tokens, TrafficType, TuningMethod, TuningMode, TuningTask, TurnCompleteReason, TurnCoverage, Type, UpscaleImageResponse, UrlRetrievalStatus, VideoCompressionQuality, VideoGenerationMaskMode, VideoGenerationReferenceType, createFunctionResponsePartFromBase64, createFunctionResponsePartFromUri, createModelContent, createPartFromBase64, createPartFromCodeExecutionResult, createPartFromExecutableCode, createPartFromFunctionCall, createPartFromFunctionResponse, createPartFromText, createPartFromUri, createUserContent, mcpToTool, setDefaultBaseUrls };
|
|
17079
|
+
export { ActivityHandling, AdapterSize, ApiError, ApiSpec, AuthType, Batches, Behavior, BlockedReason, Caches, Chat, Chats, ComputeTokensResponse, ContentReferenceImage, ControlReferenceImage, ControlReferenceType, CountTokensResponse, CreateFileResponse, DeleteCachedContentResponse, DeleteFileResponse, DeleteModelResponse, DocumentState, DynamicRetrievalConfigMode, EditImageResponse, EditMode, EmbedContentResponse, EndSensitivity, Environment, FeatureSelectionPreference, FileSource, FileState, Files, FinishReason, FunctionCallingConfigMode, FunctionResponse, FunctionResponseBlob, FunctionResponseFileData, FunctionResponsePart, FunctionResponseScheduling, GenerateContentResponse, GenerateContentResponsePromptFeedback, GenerateContentResponseUsageMetadata, GenerateImagesResponse, GenerateVideosOperation, GenerateVideosResponse, GoogleGenAI, HarmBlockMethod, HarmBlockThreshold, HarmCategory, HarmProbability, HarmSeverity, HttpElementLocation, HttpResponse, ImagePromptLanguage, ImportFileOperation, ImportFileResponse, InlinedEmbedContentResponse, InlinedResponse, JobState, Language, ListBatchJobsResponse, ListCachedContentsResponse, ListDocumentsResponse, ListFileSearchStoresResponse, ListFilesResponse, ListModelsResponse, ListTuningJobsResponse, Live, LiveClientToolResponse, LiveMusicPlaybackControl, LiveMusicServerMessage, LiveSendToolResponseParameters, LiveServerMessage, MaskReferenceImage, MaskReferenceMode, MediaModality, MediaResolution, Modality, Mode, Models, MusicGenerationMode, Operations, Outcome, PagedItem, Pager, PersonGeneration, PhishBlockThreshold, RawReferenceImage, RecontextImageResponse, ReplayResponse, SafetyFilterLevel, Scale, SegmentImageResponse, SegmentMode, Session, SingleEmbedContentResponse, StartSensitivity, StyleReferenceImage, SubjectReferenceImage, SubjectReferenceType, Tokens, TrafficType, TuningMethod, TuningMode, TuningTask, TurnCompleteReason, TurnCoverage, Type, UploadToFileSearchStoreOperation, UploadToFileSearchStoreResponse, UploadToFileSearchStoreResumableResponse, UpscaleImageResponse, UrlRetrievalStatus, VideoCompressionQuality, VideoGenerationMaskMode, VideoGenerationReferenceType, createFunctionResponsePartFromBase64, createFunctionResponsePartFromUri, createModelContent, createPartFromBase64, createPartFromCodeExecutionResult, createPartFromExecutableCode, createPartFromFunctionCall, createPartFromFunctionResponse, createPartFromText, createPartFromUri, createUserContent, mcpToTool, setDefaultBaseUrls };
|
|
15977
17080
|
//# sourceMappingURL=index.mjs.map
|