@google/genai 1.45.0 → 1.46.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/dist/genai.d.ts +437 -111
- package/dist/index.cjs +431 -47
- package/dist/index.mjs +431 -48
- package/dist/index.mjs.map +1 -1
- package/dist/node/index.cjs +453 -67
- package/dist/node/index.mjs +453 -68
- package/dist/node/index.mjs.map +1 -1
- package/dist/node/node.d.ts +437 -111
- package/dist/tokenizer/node.cjs +40 -12
- package/dist/tokenizer/node.d.ts +74 -2
- package/dist/tokenizer/node.mjs +40 -12
- package/dist/tokenizer/node.mjs.map +1 -1
- package/dist/vertex_internal/index.cjs +87 -54
- package/dist/vertex_internal/index.cjs.map +1 -1
- package/dist/vertex_internal/index.d.ts +87 -9
- package/dist/vertex_internal/index.js +87 -54
- package/dist/vertex_internal/index.js.map +1 -1
- package/dist/web/index.mjs +431 -48
- package/dist/web/index.mjs.map +1 -1
- package/dist/web/web.d.ts +437 -111
- package/package.json +1 -1
|
@@ -833,12 +833,16 @@ declare interface CitationMetadata {
|
|
|
833
833
|
citations?: Citation[];
|
|
834
834
|
}
|
|
835
835
|
|
|
836
|
-
/** Result of executing the
|
|
836
|
+
/** Result of executing the `ExecutableCode`.
|
|
837
|
+
|
|
838
|
+
Generated only when the `CodeExecution` tool is used. */
|
|
837
839
|
declare interface CodeExecutionResult {
|
|
838
840
|
/** Required. Outcome of the code execution. */
|
|
839
841
|
outcome?: Outcome;
|
|
840
842
|
/** Optional. Contains stdout when code execution is successful, stderr or other description otherwise. */
|
|
841
843
|
output?: string;
|
|
844
|
+
/** The identifier of the `ExecutableCode` part this result is for. Only populated if the corresponding `ExecutableCode` has an id. */
|
|
845
|
+
id?: string;
|
|
842
846
|
}
|
|
843
847
|
|
|
844
848
|
/** Success and error statistics of processing multiple entities (for example, DataItems or structured data rows) in batch. This data type is not supported in Gemini API. */
|
|
@@ -2084,12 +2088,18 @@ declare interface ExactMatchMetricValue {
|
|
|
2084
2088
|
score?: number;
|
|
2085
2089
|
}
|
|
2086
2090
|
|
|
2087
|
-
/**
|
|
2091
|
+
/** Model-generated code executed server-side, results returned to the model.
|
|
2092
|
+
|
|
2093
|
+
Only generated when using the `CodeExecution` tool, in which the code will
|
|
2094
|
+
be automatically executed, and a corresponding `CodeExecutionResult` will
|
|
2095
|
+
also be generated. */
|
|
2088
2096
|
declare interface ExecutableCode {
|
|
2089
2097
|
/** Required. The code to be executed. */
|
|
2090
2098
|
code?: string;
|
|
2091
2099
|
/** Required. Programming language of the `code`. */
|
|
2092
2100
|
language?: Language;
|
|
2101
|
+
/** Unique identifier of the `ExecutableCode` part. The server returns the `CodeExecutionResult` with the matching `id`. */
|
|
2102
|
+
id?: string;
|
|
2093
2103
|
}
|
|
2094
2104
|
|
|
2095
2105
|
/** Retrieve from data source powered by external API for grounding. The external API is not owned by Google, but need to follow the pre-defined API spec. This data type is not supported in Gemini API. */
|
|
@@ -5243,8 +5253,8 @@ export declare class NodeDownloader implements Downloader {
|
|
|
5243
5253
|
|
|
5244
5254
|
export declare class NodeUploader implements Uploader {
|
|
5245
5255
|
stat(file: string | Blob): Promise<FileStat>;
|
|
5246
|
-
upload(file: string | Blob, uploadUrl: string, apiClient: ApiClient): Promise<File_2>;
|
|
5247
|
-
uploadToFileSearchStore(file: string | Blob, uploadUrl: string, apiClient: ApiClient): Promise<UploadToFileSearchStoreOperation>;
|
|
5256
|
+
upload(file: string | Blob, uploadUrl: string, apiClient: ApiClient, httpOptions?: HttpOptions): Promise<File_2>;
|
|
5257
|
+
uploadToFileSearchStore(file: string | Blob, uploadUrl: string, apiClient: ApiClient, httpOptions?: HttpOptions): Promise<UploadToFileSearchStoreOperation>;
|
|
5248
5258
|
/**
|
|
5249
5259
|
* Infers the MIME type of a file based on its extension.
|
|
5250
5260
|
*
|
|
@@ -5378,6 +5388,10 @@ declare interface Part {
|
|
|
5378
5388
|
thoughtSignature?: string;
|
|
5379
5389
|
/** Optional. Video metadata. The metadata should only be specified while the video data is presented in inline_data or file_data. */
|
|
5380
5390
|
videoMetadata?: VideoMetadata;
|
|
5391
|
+
/** Server-side tool call. This field is populated when the model predicts a tool invocation that should be executed on the server. The client is expected to echo this message back to the API. */
|
|
5392
|
+
toolCall?: ToolCall;
|
|
5393
|
+
/** The output from a server-side ToolCall execution. This field is populated by the client with the results of executing the corresponding ToolCall. */
|
|
5394
|
+
toolResponse?: ToolResponse;
|
|
5381
5395
|
}
|
|
5382
5396
|
|
|
5383
5397
|
/** Partial argument value of the function call. This data type is not supported in Gemini API. */
|
|
@@ -6540,6 +6554,21 @@ declare interface Tool {
|
|
|
6540
6554
|
mcpServers?: McpServer[];
|
|
6541
6555
|
}
|
|
6542
6556
|
|
|
6557
|
+
/** A predicted server-side `ToolCall` returned from the model.
|
|
6558
|
+
|
|
6559
|
+
This message contains information about a tool that the model wants to invoke.
|
|
6560
|
+
The client is NOT expected to execute this `ToolCall`. Instead, the
|
|
6561
|
+
client should pass this `ToolCall` back to the API in a subsequent turn
|
|
6562
|
+
within a `Content` message, along with the corresponding `ToolResponse`. */
|
|
6563
|
+
declare interface ToolCall {
|
|
6564
|
+
/** Unique identifier of the tool call. The server returns the tool response with the matching `id`. */
|
|
6565
|
+
id?: string;
|
|
6566
|
+
/** The type of tool that was called. */
|
|
6567
|
+
toolType?: ToolType;
|
|
6568
|
+
/** The tool call arguments. Example: {"arg1": "value1", "arg2": "value2"}. */
|
|
6569
|
+
args?: Record<string, unknown>;
|
|
6570
|
+
}
|
|
6571
|
+
|
|
6543
6572
|
/** Tool that executes code generated by the model, and automatically returns the result to the model. See also [ExecutableCode]and [CodeExecutionResult] which are input and output to this tool. This data type is not supported in Gemini API. */
|
|
6544
6573
|
declare interface ToolCodeExecution {
|
|
6545
6574
|
}
|
|
@@ -6552,6 +6581,8 @@ declare interface ToolConfig {
|
|
|
6552
6581
|
retrievalConfig?: RetrievalConfig;
|
|
6553
6582
|
/** Optional. Function calling config. */
|
|
6554
6583
|
functionCallingConfig?: FunctionCallingConfig;
|
|
6584
|
+
/** If true, the API response will include the server-side tool calls and responses within the `Content` message. This allows clients to observe the server's tool invocations. */
|
|
6585
|
+
includeServerSideToolInvocations?: boolean;
|
|
6555
6586
|
}
|
|
6556
6587
|
|
|
6557
6588
|
declare type ToolListUnion = ToolUnion[];
|
|
@@ -6564,6 +6595,49 @@ declare interface ToolParallelAiSearch {
|
|
|
6564
6595
|
customConfigs?: Record<string, unknown>;
|
|
6565
6596
|
}
|
|
6566
6597
|
|
|
6598
|
+
/** The output from a server-side `ToolCall` execution.
|
|
6599
|
+
|
|
6600
|
+
This message contains the results of a tool invocation that was initiated by a
|
|
6601
|
+
`ToolCall` from the model. The client should pass this `ToolResponse` back to
|
|
6602
|
+
the API in a subsequent turn within a `Content` message, along with the
|
|
6603
|
+
corresponding `ToolCall`. */
|
|
6604
|
+
declare class ToolResponse {
|
|
6605
|
+
/** The identifier of the tool call this response is for. */
|
|
6606
|
+
id?: string;
|
|
6607
|
+
/** The type of tool that was called, matching the tool_type in the corresponding ToolCall. */
|
|
6608
|
+
toolType?: ToolType;
|
|
6609
|
+
/** The tool response. */
|
|
6610
|
+
response?: Record<string, unknown>;
|
|
6611
|
+
}
|
|
6612
|
+
|
|
6613
|
+
/** The type of tool in the function call. */
|
|
6614
|
+
declare enum ToolType {
|
|
6615
|
+
/**
|
|
6616
|
+
* Unspecified tool type.
|
|
6617
|
+
*/
|
|
6618
|
+
TOOL_TYPE_UNSPECIFIED = "TOOL_TYPE_UNSPECIFIED",
|
|
6619
|
+
/**
|
|
6620
|
+
* Google search tool, maps to Tool.google_search.search_types.web_search.
|
|
6621
|
+
*/
|
|
6622
|
+
GOOGLE_SEARCH_WEB = "GOOGLE_SEARCH_WEB",
|
|
6623
|
+
/**
|
|
6624
|
+
* Image search tool, maps to Tool.google_search.search_types.image_search.
|
|
6625
|
+
*/
|
|
6626
|
+
GOOGLE_SEARCH_IMAGE = "GOOGLE_SEARCH_IMAGE",
|
|
6627
|
+
/**
|
|
6628
|
+
* URL context tool, maps to Tool.url_context.
|
|
6629
|
+
*/
|
|
6630
|
+
URL_CONTEXT = "URL_CONTEXT",
|
|
6631
|
+
/**
|
|
6632
|
+
* Google maps tool, maps to Tool.google_maps.
|
|
6633
|
+
*/
|
|
6634
|
+
GOOGLE_MAPS = "GOOGLE_MAPS",
|
|
6635
|
+
/**
|
|
6636
|
+
* File search tool, maps to Tool.file_search.
|
|
6637
|
+
*/
|
|
6638
|
+
FILE_SEARCH = "FILE_SEARCH"
|
|
6639
|
+
}
|
|
6640
|
+
|
|
6567
6641
|
declare type ToolUnion = Tool | CallableTool;
|
|
6568
6642
|
|
|
6569
6643
|
/** Output only. The traffic type for this request. This enum is not supported in Gemini API. */
|
|
@@ -6922,8 +6996,8 @@ declare namespace types {
|
|
|
6922
6996
|
createPartFromExecutableCode,
|
|
6923
6997
|
createUserContent,
|
|
6924
6998
|
createModelContent,
|
|
6925
|
-
Outcome,
|
|
6926
6999
|
Language,
|
|
7000
|
+
Outcome,
|
|
6927
7001
|
FunctionResponseScheduling,
|
|
6928
7002
|
Type,
|
|
6929
7003
|
PhishBlockThreshold,
|
|
@@ -6954,6 +7028,7 @@ declare namespace types {
|
|
|
6954
7028
|
PairwiseChoice,
|
|
6955
7029
|
TuningTask,
|
|
6956
7030
|
PartMediaResolutionLevel,
|
|
7031
|
+
ToolType,
|
|
6957
7032
|
ResourceScope,
|
|
6958
7033
|
FeatureSelectionPreference,
|
|
6959
7034
|
Environment,
|
|
@@ -6984,9 +7059,11 @@ declare namespace types {
|
|
|
6984
7059
|
Scale,
|
|
6985
7060
|
MusicGenerationMode,
|
|
6986
7061
|
LiveMusicPlaybackControl,
|
|
6987
|
-
PartMediaResolution,
|
|
6988
|
-
CodeExecutionResult,
|
|
6989
7062
|
ExecutableCode,
|
|
7063
|
+
CodeExecutionResult,
|
|
7064
|
+
PartMediaResolution,
|
|
7065
|
+
ToolCall,
|
|
7066
|
+
ToolResponse,
|
|
6990
7067
|
FileData,
|
|
6991
7068
|
PartialArg,
|
|
6992
7069
|
FunctionCall,
|
|
@@ -7460,7 +7537,7 @@ export declare interface Uploader {
|
|
|
7460
7537
|
* @param apiClient The ApiClient to use for uploading.
|
|
7461
7538
|
* @return A Promise that resolves to types.File.
|
|
7462
7539
|
*/
|
|
7463
|
-
upload(file: string | Blob, uploadUrl: string, apiClient: ApiClient): Promise<File_2>;
|
|
7540
|
+
upload(file: string | Blob, uploadUrl: string, apiClient: ApiClient, httpOptions?: HttpOptions): Promise<File_2>;
|
|
7464
7541
|
/**
|
|
7465
7542
|
* Uploads a file to file search store via the given upload url.
|
|
7466
7543
|
*
|
|
@@ -7469,9 +7546,10 @@ export declare interface Uploader {
|
|
|
7469
7546
|
* uploaded to. The uploadUrl must be a url that was returned by the
|
|
7470
7547
|
* https://generativelanguage.googleapis.com/upload/v1beta/{file_search_store_name}:uploadToFileSearchStore endpoint
|
|
7471
7548
|
* @param apiClient The ApiClient to use for uploading.
|
|
7549
|
+
* @param httpOptions Optional HTTP options to merge.
|
|
7472
7550
|
* @return A Promise that resolves to types.UploadToFileSearchStoreOperation.
|
|
7473
7551
|
*/
|
|
7474
|
-
uploadToFileSearchStore(file: string | Blob, uploadUrl: string, apiClient: ApiClient): Promise<UploadToFileSearchStoreOperation>;
|
|
7552
|
+
uploadToFileSearchStore(file: string | Blob, uploadUrl: string, apiClient: ApiClient, httpOptions?: HttpOptions): Promise<UploadToFileSearchStoreOperation>;
|
|
7475
7553
|
/**
|
|
7476
7554
|
* Returns the file's mimeType and the size of a given file. If the file is a
|
|
7477
7555
|
* string path, the file type is determined by the file extension. If the
|
|
@@ -382,6 +382,18 @@ function uploadToFileSearchStoreResponseFromMldev(fromObject) {
|
|
|
382
382
|
* Copyright 2025 Google LLC
|
|
383
383
|
* SPDX-License-Identifier: Apache-2.0
|
|
384
384
|
*/
|
|
385
|
+
/** Programming language of the `code`. */
|
|
386
|
+
var Language;
|
|
387
|
+
(function (Language) {
|
|
388
|
+
/**
|
|
389
|
+
* Unspecified language. This value should not be used.
|
|
390
|
+
*/
|
|
391
|
+
Language["LANGUAGE_UNSPECIFIED"] = "LANGUAGE_UNSPECIFIED";
|
|
392
|
+
/**
|
|
393
|
+
* Python >= 3.10, with numpy and simpy available.
|
|
394
|
+
*/
|
|
395
|
+
Language["PYTHON"] = "PYTHON";
|
|
396
|
+
})(Language || (Language = {}));
|
|
385
397
|
/** Outcome of the code execution. */
|
|
386
398
|
var Outcome;
|
|
387
399
|
(function (Outcome) {
|
|
@@ -402,18 +414,6 @@ var Outcome;
|
|
|
402
414
|
*/
|
|
403
415
|
Outcome["OUTCOME_DEADLINE_EXCEEDED"] = "OUTCOME_DEADLINE_EXCEEDED";
|
|
404
416
|
})(Outcome || (Outcome = {}));
|
|
405
|
-
/** Programming language of the `code`. */
|
|
406
|
-
var Language;
|
|
407
|
-
(function (Language) {
|
|
408
|
-
/**
|
|
409
|
-
* Unspecified language. This value should not be used.
|
|
410
|
-
*/
|
|
411
|
-
Language["LANGUAGE_UNSPECIFIED"] = "LANGUAGE_UNSPECIFIED";
|
|
412
|
-
/**
|
|
413
|
-
* Python >= 3.10, with numpy and simpy available.
|
|
414
|
-
*/
|
|
415
|
-
Language["PYTHON"] = "PYTHON";
|
|
416
|
-
})(Language || (Language = {}));
|
|
417
417
|
/** Specifies how the response should be scheduled in the conversation. */
|
|
418
418
|
var FunctionResponseScheduling;
|
|
419
419
|
(function (FunctionResponseScheduling) {
|
|
@@ -1242,6 +1242,34 @@ var PartMediaResolutionLevel;
|
|
|
1242
1242
|
*/
|
|
1243
1243
|
PartMediaResolutionLevel["MEDIA_RESOLUTION_ULTRA_HIGH"] = "MEDIA_RESOLUTION_ULTRA_HIGH";
|
|
1244
1244
|
})(PartMediaResolutionLevel || (PartMediaResolutionLevel = {}));
|
|
1245
|
+
/** The type of tool in the function call. */
|
|
1246
|
+
var ToolType;
|
|
1247
|
+
(function (ToolType) {
|
|
1248
|
+
/**
|
|
1249
|
+
* Unspecified tool type.
|
|
1250
|
+
*/
|
|
1251
|
+
ToolType["TOOL_TYPE_UNSPECIFIED"] = "TOOL_TYPE_UNSPECIFIED";
|
|
1252
|
+
/**
|
|
1253
|
+
* Google search tool, maps to Tool.google_search.search_types.web_search.
|
|
1254
|
+
*/
|
|
1255
|
+
ToolType["GOOGLE_SEARCH_WEB"] = "GOOGLE_SEARCH_WEB";
|
|
1256
|
+
/**
|
|
1257
|
+
* Image search tool, maps to Tool.google_search.search_types.image_search.
|
|
1258
|
+
*/
|
|
1259
|
+
ToolType["GOOGLE_SEARCH_IMAGE"] = "GOOGLE_SEARCH_IMAGE";
|
|
1260
|
+
/**
|
|
1261
|
+
* URL context tool, maps to Tool.url_context.
|
|
1262
|
+
*/
|
|
1263
|
+
ToolType["URL_CONTEXT"] = "URL_CONTEXT";
|
|
1264
|
+
/**
|
|
1265
|
+
* Google maps tool, maps to Tool.google_maps.
|
|
1266
|
+
*/
|
|
1267
|
+
ToolType["GOOGLE_MAPS"] = "GOOGLE_MAPS";
|
|
1268
|
+
/**
|
|
1269
|
+
* File search tool, maps to Tool.file_search.
|
|
1270
|
+
*/
|
|
1271
|
+
ToolType["FILE_SEARCH"] = "FILE_SEARCH";
|
|
1272
|
+
})(ToolType || (ToolType = {}));
|
|
1245
1273
|
/** Resource scope. */
|
|
1246
1274
|
var ResourceScope;
|
|
1247
1275
|
(function (ResourceScope) {
|
|
@@ -1777,7 +1805,7 @@ const CONTENT_TYPE_HEADER = 'Content-Type';
|
|
|
1777
1805
|
const SERVER_TIMEOUT_HEADER = 'X-Server-Timeout';
|
|
1778
1806
|
const USER_AGENT_HEADER = 'User-Agent';
|
|
1779
1807
|
const GOOGLE_API_CLIENT_HEADER = 'x-goog-api-client';
|
|
1780
|
-
const SDK_VERSION = '1.
|
|
1808
|
+
const SDK_VERSION = '1.46.0'; // x-release-please-version
|
|
1781
1809
|
const LIBRARY_LABEL = `google-genai-sdk/${SDK_VERSION}`;
|
|
1782
1810
|
const VERTEX_AI_API_DEFAULT_VERSION = 'v1beta1';
|
|
1783
1811
|
const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
|
|
@@ -2651,18 +2679,18 @@ const MAX_RETRY_COUNT = 3;
|
|
|
2651
2679
|
const INITIAL_RETRY_DELAY_MS = 1000;
|
|
2652
2680
|
const DELAY_MULTIPLIER = 2;
|
|
2653
2681
|
const X_GOOG_UPLOAD_STATUS_HEADER_FIELD = 'x-goog-upload-status';
|
|
2654
|
-
async function uploadBlob(file, uploadUrl, apiClient) {
|
|
2682
|
+
async function uploadBlob(file, uploadUrl, apiClient, httpOptions) {
|
|
2655
2683
|
var _a;
|
|
2656
|
-
const response = await uploadBlobInternal(file, uploadUrl, apiClient);
|
|
2684
|
+
const response = await uploadBlobInternal(file, uploadUrl, apiClient, httpOptions);
|
|
2657
2685
|
const responseJson = (await (response === null || response === void 0 ? void 0 : response.json()));
|
|
2658
2686
|
if (((_a = response === null || response === void 0 ? void 0 : response.headers) === null || _a === void 0 ? void 0 : _a[X_GOOG_UPLOAD_STATUS_HEADER_FIELD]) !== 'final') {
|
|
2659
2687
|
throw new Error('Failed to upload file: Upload status is not finalized.');
|
|
2660
2688
|
}
|
|
2661
2689
|
return responseJson['file'];
|
|
2662
2690
|
}
|
|
2663
|
-
async function uploadBlobToFileSearchStore(file, uploadUrl, apiClient) {
|
|
2691
|
+
async function uploadBlobToFileSearchStore(file, uploadUrl, apiClient, httpOptions) {
|
|
2664
2692
|
var _a;
|
|
2665
|
-
const response = await uploadBlobInternal(file, uploadUrl, apiClient);
|
|
2693
|
+
const response = await uploadBlobInternal(file, uploadUrl, apiClient, httpOptions);
|
|
2666
2694
|
const responseJson = (await (response === null || response === void 0 ? void 0 : response.json()));
|
|
2667
2695
|
if (((_a = response === null || response === void 0 ? void 0 : response.headers) === null || _a === void 0 ? void 0 : _a[X_GOOG_UPLOAD_STATUS_HEADER_FIELD]) !== 'final') {
|
|
2668
2696
|
throw new Error('Failed to upload file: Upload status is not finalized.');
|
|
@@ -2672,8 +2700,18 @@ async function uploadBlobToFileSearchStore(file, uploadUrl, apiClient) {
|
|
|
2672
2700
|
Object.assign(typedResp, resp);
|
|
2673
2701
|
return typedResp;
|
|
2674
2702
|
}
|
|
2675
|
-
async function uploadBlobInternal(file, uploadUrl, apiClient) {
|
|
2676
|
-
var _a, _b;
|
|
2703
|
+
async function uploadBlobInternal(file, uploadUrl, apiClient, httpOptions) {
|
|
2704
|
+
var _a, _b, _c;
|
|
2705
|
+
let finalUrl = uploadUrl;
|
|
2706
|
+
const effectiveBaseUrl = (httpOptions === null || httpOptions === void 0 ? void 0 : httpOptions.baseUrl) || ((_a = apiClient.clientOptions.httpOptions) === null || _a === void 0 ? void 0 : _a.baseUrl);
|
|
2707
|
+
if (effectiveBaseUrl) {
|
|
2708
|
+
const baseUri = new URL(effectiveBaseUrl);
|
|
2709
|
+
const uploadUri = new URL(uploadUrl);
|
|
2710
|
+
uploadUri.protocol = baseUri.protocol;
|
|
2711
|
+
uploadUri.host = baseUri.host;
|
|
2712
|
+
uploadUri.port = baseUri.port;
|
|
2713
|
+
finalUrl = uploadUri.toString();
|
|
2714
|
+
}
|
|
2677
2715
|
let fileSize = 0;
|
|
2678
2716
|
let offset = 0;
|
|
2679
2717
|
let response = new HttpResponse(new Response());
|
|
@@ -2688,21 +2726,14 @@ async function uploadBlobInternal(file, uploadUrl, apiClient) {
|
|
|
2688
2726
|
let retryCount = 0;
|
|
2689
2727
|
let currentDelayMs = INITIAL_RETRY_DELAY_MS;
|
|
2690
2728
|
while (retryCount < MAX_RETRY_COUNT) {
|
|
2729
|
+
const mergedHeaders = Object.assign(Object.assign({}, ((httpOptions === null || httpOptions === void 0 ? void 0 : httpOptions.headers) || {})), { 'X-Goog-Upload-Command': uploadCommand, 'X-Goog-Upload-Offset': String(offset), 'Content-Length': String(chunkSize) });
|
|
2691
2730
|
response = await apiClient.request({
|
|
2692
2731
|
path: '',
|
|
2693
2732
|
body: chunk,
|
|
2694
2733
|
httpMethod: 'POST',
|
|
2695
|
-
httpOptions: {
|
|
2696
|
-
apiVersion: '',
|
|
2697
|
-
baseUrl: uploadUrl,
|
|
2698
|
-
headers: {
|
|
2699
|
-
'X-Goog-Upload-Command': uploadCommand,
|
|
2700
|
-
'X-Goog-Upload-Offset': String(offset),
|
|
2701
|
-
'Content-Length': String(chunkSize),
|
|
2702
|
-
},
|
|
2703
|
-
},
|
|
2734
|
+
httpOptions: Object.assign(Object.assign({}, httpOptions), { apiVersion: '', baseUrl: finalUrl, headers: mergedHeaders }),
|
|
2704
2735
|
});
|
|
2705
|
-
if ((
|
|
2736
|
+
if ((_b = response === null || response === void 0 ? void 0 : response.headers) === null || _b === void 0 ? void 0 : _b[X_GOOG_UPLOAD_STATUS_HEADER_FIELD]) {
|
|
2706
2737
|
break;
|
|
2707
2738
|
}
|
|
2708
2739
|
retryCount++;
|
|
@@ -2712,7 +2743,7 @@ async function uploadBlobInternal(file, uploadUrl, apiClient) {
|
|
|
2712
2743
|
offset += chunkSize;
|
|
2713
2744
|
// The `x-goog-upload-status` header field can be `active`, `final` and
|
|
2714
2745
|
//`cancelled` in resposne.
|
|
2715
|
-
if (((
|
|
2746
|
+
if (((_c = response === null || response === void 0 ? void 0 : response.headers) === null || _c === void 0 ? void 0 : _c[X_GOOG_UPLOAD_STATUS_HEADER_FIELD]) !== 'active') {
|
|
2716
2747
|
break;
|
|
2717
2748
|
}
|
|
2718
2749
|
// TODO(b/401391430) Investigate why the upload status is not finalized
|
|
@@ -2749,20 +2780,20 @@ class NodeUploader {
|
|
|
2749
2780
|
return await getBlobStat(file);
|
|
2750
2781
|
}
|
|
2751
2782
|
}
|
|
2752
|
-
async upload(file, uploadUrl, apiClient) {
|
|
2783
|
+
async upload(file, uploadUrl, apiClient, httpOptions) {
|
|
2753
2784
|
if (typeof file === 'string') {
|
|
2754
|
-
return await this.uploadFileFromPath(file, uploadUrl, apiClient);
|
|
2785
|
+
return await this.uploadFileFromPath(file, uploadUrl, apiClient, httpOptions);
|
|
2755
2786
|
}
|
|
2756
2787
|
else {
|
|
2757
|
-
return uploadBlob(file, uploadUrl, apiClient);
|
|
2788
|
+
return uploadBlob(file, uploadUrl, apiClient, httpOptions);
|
|
2758
2789
|
}
|
|
2759
2790
|
}
|
|
2760
|
-
async uploadToFileSearchStore(file, uploadUrl, apiClient) {
|
|
2791
|
+
async uploadToFileSearchStore(file, uploadUrl, apiClient, httpOptions) {
|
|
2761
2792
|
if (typeof file === 'string') {
|
|
2762
|
-
return await this.uploadFileToFileSearchStoreFromPath(file, uploadUrl, apiClient);
|
|
2793
|
+
return await this.uploadFileToFileSearchStoreFromPath(file, uploadUrl, apiClient, httpOptions);
|
|
2763
2794
|
}
|
|
2764
2795
|
else {
|
|
2765
|
-
return uploadBlobToFileSearchStore(file, uploadUrl, apiClient);
|
|
2796
|
+
return uploadBlobToFileSearchStore(file, uploadUrl, apiClient, httpOptions);
|
|
2766
2797
|
}
|
|
2767
2798
|
}
|
|
2768
2799
|
/**
|
|
@@ -2855,18 +2886,18 @@ class NodeUploader {
|
|
|
2855
2886
|
// Return the MIME type.
|
|
2856
2887
|
return mimeType;
|
|
2857
2888
|
}
|
|
2858
|
-
async uploadFileFromPath(file, uploadUrl, apiClient) {
|
|
2889
|
+
async uploadFileFromPath(file, uploadUrl, apiClient, httpOptions) {
|
|
2859
2890
|
var _a;
|
|
2860
|
-
const response = await this.uploadFileFromPathInternal(file, uploadUrl, apiClient);
|
|
2891
|
+
const response = await this.uploadFileFromPathInternal(file, uploadUrl, apiClient, httpOptions);
|
|
2861
2892
|
const responseJson = (await (response === null || response === void 0 ? void 0 : response.json()));
|
|
2862
2893
|
if (((_a = response === null || response === void 0 ? void 0 : response.headers) === null || _a === void 0 ? void 0 : _a[X_GOOG_UPLOAD_STATUS_HEADER_FIELD]) !== 'final') {
|
|
2863
2894
|
throw new Error('Failed to upload file: Upload status is not finalized.');
|
|
2864
2895
|
}
|
|
2865
2896
|
return responseJson['file'];
|
|
2866
2897
|
}
|
|
2867
|
-
async uploadFileToFileSearchStoreFromPath(file, uploadUrl, apiClient) {
|
|
2898
|
+
async uploadFileToFileSearchStoreFromPath(file, uploadUrl, apiClient, httpOptions) {
|
|
2868
2899
|
var _a;
|
|
2869
|
-
const response = await this.uploadFileFromPathInternal(file, uploadUrl, apiClient);
|
|
2900
|
+
const response = await this.uploadFileFromPathInternal(file, uploadUrl, apiClient, httpOptions);
|
|
2870
2901
|
const responseJson = (await (response === null || response === void 0 ? void 0 : response.json()));
|
|
2871
2902
|
if (((_a = response === null || response === void 0 ? void 0 : response.headers) === null || _a === void 0 ? void 0 : _a[X_GOOG_UPLOAD_STATUS_HEADER_FIELD]) !== 'final') {
|
|
2872
2903
|
throw new Error('Failed to upload file: Upload status is not finalized.');
|
|
@@ -2876,8 +2907,18 @@ class NodeUploader {
|
|
|
2876
2907
|
Object.assign(typedResp, resp);
|
|
2877
2908
|
return typedResp;
|
|
2878
2909
|
}
|
|
2879
|
-
async uploadFileFromPathInternal(file, uploadUrl, apiClient) {
|
|
2880
|
-
var _a, _b;
|
|
2910
|
+
async uploadFileFromPathInternal(file, uploadUrl, apiClient, httpOptions) {
|
|
2911
|
+
var _a, _b, _c;
|
|
2912
|
+
let finalUrl = uploadUrl;
|
|
2913
|
+
const effectiveBaseUrl = (httpOptions === null || httpOptions === void 0 ? void 0 : httpOptions.baseUrl) || ((_a = apiClient.clientOptions.httpOptions) === null || _a === void 0 ? void 0 : _a.baseUrl);
|
|
2914
|
+
if (effectiveBaseUrl) {
|
|
2915
|
+
const baseUri = new URL(effectiveBaseUrl);
|
|
2916
|
+
const uploadUri = new URL(uploadUrl);
|
|
2917
|
+
uploadUri.protocol = baseUri.protocol;
|
|
2918
|
+
uploadUri.host = baseUri.host;
|
|
2919
|
+
uploadUri.port = baseUri.port;
|
|
2920
|
+
finalUrl = uploadUri.toString();
|
|
2921
|
+
}
|
|
2881
2922
|
let fileSize = 0;
|
|
2882
2923
|
let offset = 0;
|
|
2883
2924
|
let response = new HttpResponse(new Response());
|
|
@@ -2904,22 +2945,14 @@ class NodeUploader {
|
|
|
2904
2945
|
let retryCount = 0;
|
|
2905
2946
|
let currentDelayMs = INITIAL_RETRY_DELAY_MS;
|
|
2906
2947
|
while (retryCount < MAX_RETRY_COUNT) {
|
|
2948
|
+
const mergedHeaders = Object.assign(Object.assign({}, ((httpOptions === null || httpOptions === void 0 ? void 0 : httpOptions.headers) || {})), { 'X-Goog-Upload-Command': uploadCommand, 'X-Goog-Upload-Offset': String(offset), 'Content-Length': String(bytesRead), 'X-Goog-Upload-File-Name': fileName });
|
|
2907
2949
|
response = await apiClient.request({
|
|
2908
2950
|
path: '',
|
|
2909
2951
|
body: chunk,
|
|
2910
2952
|
httpMethod: 'POST',
|
|
2911
|
-
httpOptions: {
|
|
2912
|
-
apiVersion: '',
|
|
2913
|
-
baseUrl: uploadUrl,
|
|
2914
|
-
headers: {
|
|
2915
|
-
'X-Goog-Upload-Command': uploadCommand,
|
|
2916
|
-
'X-Goog-Upload-Offset': String(offset),
|
|
2917
|
-
'Content-Length': String(bytesRead),
|
|
2918
|
-
'X-Goog-Upload-File-Name': fileName,
|
|
2919
|
-
},
|
|
2920
|
-
},
|
|
2953
|
+
httpOptions: Object.assign(Object.assign({}, httpOptions), { apiVersion: '', baseUrl: finalUrl, headers: mergedHeaders }),
|
|
2921
2954
|
});
|
|
2922
|
-
if ((
|
|
2955
|
+
if ((_b = response === null || response === void 0 ? void 0 : response.headers) === null || _b === void 0 ? void 0 : _b[X_GOOG_UPLOAD_STATUS_HEADER_FIELD]) {
|
|
2923
2956
|
break;
|
|
2924
2957
|
}
|
|
2925
2958
|
retryCount++;
|
|
@@ -2929,7 +2962,7 @@ class NodeUploader {
|
|
|
2929
2962
|
offset += bytesRead;
|
|
2930
2963
|
// The `x-goog-upload-status` header field can be `active`, `final` and
|
|
2931
2964
|
//`cancelled` in resposne.
|
|
2932
|
-
if (((
|
|
2965
|
+
if (((_c = response === null || response === void 0 ? void 0 : response.headers) === null || _c === void 0 ? void 0 : _c[X_GOOG_UPLOAD_STATUS_HEADER_FIELD]) !== 'active') {
|
|
2933
2966
|
break;
|
|
2934
2967
|
}
|
|
2935
2968
|
if (fileSize <= offset) {
|