@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.
@@ -403,6 +403,18 @@ function uploadToFileSearchStoreResponseFromMldev(fromObject) {
403
403
  * Copyright 2025 Google LLC
404
404
  * SPDX-License-Identifier: Apache-2.0
405
405
  */
406
+ /** Programming language of the `code`. */
407
+ var Language;
408
+ (function (Language) {
409
+ /**
410
+ * Unspecified language. This value should not be used.
411
+ */
412
+ Language["LANGUAGE_UNSPECIFIED"] = "LANGUAGE_UNSPECIFIED";
413
+ /**
414
+ * Python >= 3.10, with numpy and simpy available.
415
+ */
416
+ Language["PYTHON"] = "PYTHON";
417
+ })(Language || (Language = {}));
406
418
  /** Outcome of the code execution. */
407
419
  var Outcome;
408
420
  (function (Outcome) {
@@ -423,18 +435,6 @@ var Outcome;
423
435
  */
424
436
  Outcome["OUTCOME_DEADLINE_EXCEEDED"] = "OUTCOME_DEADLINE_EXCEEDED";
425
437
  })(Outcome || (Outcome = {}));
426
- /** Programming language of the `code`. */
427
- var Language;
428
- (function (Language) {
429
- /**
430
- * Unspecified language. This value should not be used.
431
- */
432
- Language["LANGUAGE_UNSPECIFIED"] = "LANGUAGE_UNSPECIFIED";
433
- /**
434
- * Python >= 3.10, with numpy and simpy available.
435
- */
436
- Language["PYTHON"] = "PYTHON";
437
- })(Language || (Language = {}));
438
438
  /** Specifies how the response should be scheduled in the conversation. */
439
439
  var FunctionResponseScheduling;
440
440
  (function (FunctionResponseScheduling) {
@@ -1263,6 +1263,34 @@ var PartMediaResolutionLevel;
1263
1263
  */
1264
1264
  PartMediaResolutionLevel["MEDIA_RESOLUTION_ULTRA_HIGH"] = "MEDIA_RESOLUTION_ULTRA_HIGH";
1265
1265
  })(PartMediaResolutionLevel || (PartMediaResolutionLevel = {}));
1266
+ /** The type of tool in the function call. */
1267
+ var ToolType;
1268
+ (function (ToolType) {
1269
+ /**
1270
+ * Unspecified tool type.
1271
+ */
1272
+ ToolType["TOOL_TYPE_UNSPECIFIED"] = "TOOL_TYPE_UNSPECIFIED";
1273
+ /**
1274
+ * Google search tool, maps to Tool.google_search.search_types.web_search.
1275
+ */
1276
+ ToolType["GOOGLE_SEARCH_WEB"] = "GOOGLE_SEARCH_WEB";
1277
+ /**
1278
+ * Image search tool, maps to Tool.google_search.search_types.image_search.
1279
+ */
1280
+ ToolType["GOOGLE_SEARCH_IMAGE"] = "GOOGLE_SEARCH_IMAGE";
1281
+ /**
1282
+ * URL context tool, maps to Tool.url_context.
1283
+ */
1284
+ ToolType["URL_CONTEXT"] = "URL_CONTEXT";
1285
+ /**
1286
+ * Google maps tool, maps to Tool.google_maps.
1287
+ */
1288
+ ToolType["GOOGLE_MAPS"] = "GOOGLE_MAPS";
1289
+ /**
1290
+ * File search tool, maps to Tool.file_search.
1291
+ */
1292
+ ToolType["FILE_SEARCH"] = "FILE_SEARCH";
1293
+ })(ToolType || (ToolType = {}));
1266
1294
  /** Resource scope. */
1267
1295
  var ResourceScope;
1268
1296
  (function (ResourceScope) {
@@ -1798,7 +1826,7 @@ const CONTENT_TYPE_HEADER = 'Content-Type';
1798
1826
  const SERVER_TIMEOUT_HEADER = 'X-Server-Timeout';
1799
1827
  const USER_AGENT_HEADER = 'User-Agent';
1800
1828
  const GOOGLE_API_CLIENT_HEADER = 'x-goog-api-client';
1801
- const SDK_VERSION = '1.45.0'; // x-release-please-version
1829
+ const SDK_VERSION = '1.46.0'; // x-release-please-version
1802
1830
  const LIBRARY_LABEL = `google-genai-sdk/${SDK_VERSION}`;
1803
1831
  const VERTEX_AI_API_DEFAULT_VERSION = 'v1beta1';
1804
1832
  const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
@@ -2672,18 +2700,18 @@ const MAX_RETRY_COUNT = 3;
2672
2700
  const INITIAL_RETRY_DELAY_MS = 1000;
2673
2701
  const DELAY_MULTIPLIER = 2;
2674
2702
  const X_GOOG_UPLOAD_STATUS_HEADER_FIELD = 'x-goog-upload-status';
2675
- async function uploadBlob(file, uploadUrl, apiClient) {
2703
+ async function uploadBlob(file, uploadUrl, apiClient, httpOptions) {
2676
2704
  var _a;
2677
- const response = await uploadBlobInternal(file, uploadUrl, apiClient);
2705
+ const response = await uploadBlobInternal(file, uploadUrl, apiClient, httpOptions);
2678
2706
  const responseJson = (await (response === null || response === void 0 ? void 0 : response.json()));
2679
2707
  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') {
2680
2708
  throw new Error('Failed to upload file: Upload status is not finalized.');
2681
2709
  }
2682
2710
  return responseJson['file'];
2683
2711
  }
2684
- async function uploadBlobToFileSearchStore(file, uploadUrl, apiClient) {
2712
+ async function uploadBlobToFileSearchStore(file, uploadUrl, apiClient, httpOptions) {
2685
2713
  var _a;
2686
- const response = await uploadBlobInternal(file, uploadUrl, apiClient);
2714
+ const response = await uploadBlobInternal(file, uploadUrl, apiClient, httpOptions);
2687
2715
  const responseJson = (await (response === null || response === void 0 ? void 0 : response.json()));
2688
2716
  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') {
2689
2717
  throw new Error('Failed to upload file: Upload status is not finalized.');
@@ -2693,8 +2721,18 @@ async function uploadBlobToFileSearchStore(file, uploadUrl, apiClient) {
2693
2721
  Object.assign(typedResp, resp);
2694
2722
  return typedResp;
2695
2723
  }
2696
- async function uploadBlobInternal(file, uploadUrl, apiClient) {
2697
- var _a, _b;
2724
+ async function uploadBlobInternal(file, uploadUrl, apiClient, httpOptions) {
2725
+ var _a, _b, _c;
2726
+ let finalUrl = uploadUrl;
2727
+ const effectiveBaseUrl = (httpOptions === null || httpOptions === void 0 ? void 0 : httpOptions.baseUrl) || ((_a = apiClient.clientOptions.httpOptions) === null || _a === void 0 ? void 0 : _a.baseUrl);
2728
+ if (effectiveBaseUrl) {
2729
+ const baseUri = new URL(effectiveBaseUrl);
2730
+ const uploadUri = new URL(uploadUrl);
2731
+ uploadUri.protocol = baseUri.protocol;
2732
+ uploadUri.host = baseUri.host;
2733
+ uploadUri.port = baseUri.port;
2734
+ finalUrl = uploadUri.toString();
2735
+ }
2698
2736
  let fileSize = 0;
2699
2737
  let offset = 0;
2700
2738
  let response = new HttpResponse(new Response());
@@ -2709,21 +2747,14 @@ async function uploadBlobInternal(file, uploadUrl, apiClient) {
2709
2747
  let retryCount = 0;
2710
2748
  let currentDelayMs = INITIAL_RETRY_DELAY_MS;
2711
2749
  while (retryCount < MAX_RETRY_COUNT) {
2750
+ 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) });
2712
2751
  response = await apiClient.request({
2713
2752
  path: '',
2714
2753
  body: chunk,
2715
2754
  httpMethod: 'POST',
2716
- httpOptions: {
2717
- apiVersion: '',
2718
- baseUrl: uploadUrl,
2719
- headers: {
2720
- 'X-Goog-Upload-Command': uploadCommand,
2721
- 'X-Goog-Upload-Offset': String(offset),
2722
- 'Content-Length': String(chunkSize),
2723
- },
2724
- },
2755
+ httpOptions: Object.assign(Object.assign({}, httpOptions), { apiVersion: '', baseUrl: finalUrl, headers: mergedHeaders }),
2725
2756
  });
2726
- if ((_a = response === null || response === void 0 ? void 0 : response.headers) === null || _a === void 0 ? void 0 : _a[X_GOOG_UPLOAD_STATUS_HEADER_FIELD]) {
2757
+ if ((_b = response === null || response === void 0 ? void 0 : response.headers) === null || _b === void 0 ? void 0 : _b[X_GOOG_UPLOAD_STATUS_HEADER_FIELD]) {
2727
2758
  break;
2728
2759
  }
2729
2760
  retryCount++;
@@ -2733,7 +2764,7 @@ async function uploadBlobInternal(file, uploadUrl, apiClient) {
2733
2764
  offset += chunkSize;
2734
2765
  // The `x-goog-upload-status` header field can be `active`, `final` and
2735
2766
  //`cancelled` in resposne.
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]) !== 'active') {
2767
+ 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') {
2737
2768
  break;
2738
2769
  }
2739
2770
  // TODO(b/401391430) Investigate why the upload status is not finalized
@@ -2770,20 +2801,20 @@ class NodeUploader {
2770
2801
  return await getBlobStat(file);
2771
2802
  }
2772
2803
  }
2773
- async upload(file, uploadUrl, apiClient) {
2804
+ async upload(file, uploadUrl, apiClient, httpOptions) {
2774
2805
  if (typeof file === 'string') {
2775
- return await this.uploadFileFromPath(file, uploadUrl, apiClient);
2806
+ return await this.uploadFileFromPath(file, uploadUrl, apiClient, httpOptions);
2776
2807
  }
2777
2808
  else {
2778
- return uploadBlob(file, uploadUrl, apiClient);
2809
+ return uploadBlob(file, uploadUrl, apiClient, httpOptions);
2779
2810
  }
2780
2811
  }
2781
- async uploadToFileSearchStore(file, uploadUrl, apiClient) {
2812
+ async uploadToFileSearchStore(file, uploadUrl, apiClient, httpOptions) {
2782
2813
  if (typeof file === 'string') {
2783
- return await this.uploadFileToFileSearchStoreFromPath(file, uploadUrl, apiClient);
2814
+ return await this.uploadFileToFileSearchStoreFromPath(file, uploadUrl, apiClient, httpOptions);
2784
2815
  }
2785
2816
  else {
2786
- return uploadBlobToFileSearchStore(file, uploadUrl, apiClient);
2817
+ return uploadBlobToFileSearchStore(file, uploadUrl, apiClient, httpOptions);
2787
2818
  }
2788
2819
  }
2789
2820
  /**
@@ -2876,18 +2907,18 @@ class NodeUploader {
2876
2907
  // Return the MIME type.
2877
2908
  return mimeType;
2878
2909
  }
2879
- async uploadFileFromPath(file, uploadUrl, apiClient) {
2910
+ async uploadFileFromPath(file, uploadUrl, apiClient, httpOptions) {
2880
2911
  var _a;
2881
- const response = await this.uploadFileFromPathInternal(file, uploadUrl, apiClient);
2912
+ const response = await this.uploadFileFromPathInternal(file, uploadUrl, apiClient, httpOptions);
2882
2913
  const responseJson = (await (response === null || response === void 0 ? void 0 : response.json()));
2883
2914
  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') {
2884
2915
  throw new Error('Failed to upload file: Upload status is not finalized.');
2885
2916
  }
2886
2917
  return responseJson['file'];
2887
2918
  }
2888
- async uploadFileToFileSearchStoreFromPath(file, uploadUrl, apiClient) {
2919
+ async uploadFileToFileSearchStoreFromPath(file, uploadUrl, apiClient, httpOptions) {
2889
2920
  var _a;
2890
- const response = await this.uploadFileFromPathInternal(file, uploadUrl, apiClient);
2921
+ const response = await this.uploadFileFromPathInternal(file, uploadUrl, apiClient, httpOptions);
2891
2922
  const responseJson = (await (response === null || response === void 0 ? void 0 : response.json()));
2892
2923
  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') {
2893
2924
  throw new Error('Failed to upload file: Upload status is not finalized.');
@@ -2897,8 +2928,18 @@ class NodeUploader {
2897
2928
  Object.assign(typedResp, resp);
2898
2929
  return typedResp;
2899
2930
  }
2900
- async uploadFileFromPathInternal(file, uploadUrl, apiClient) {
2901
- var _a, _b;
2931
+ async uploadFileFromPathInternal(file, uploadUrl, apiClient, httpOptions) {
2932
+ var _a, _b, _c;
2933
+ let finalUrl = uploadUrl;
2934
+ const effectiveBaseUrl = (httpOptions === null || httpOptions === void 0 ? void 0 : httpOptions.baseUrl) || ((_a = apiClient.clientOptions.httpOptions) === null || _a === void 0 ? void 0 : _a.baseUrl);
2935
+ if (effectiveBaseUrl) {
2936
+ const baseUri = new URL(effectiveBaseUrl);
2937
+ const uploadUri = new URL(uploadUrl);
2938
+ uploadUri.protocol = baseUri.protocol;
2939
+ uploadUri.host = baseUri.host;
2940
+ uploadUri.port = baseUri.port;
2941
+ finalUrl = uploadUri.toString();
2942
+ }
2902
2943
  let fileSize = 0;
2903
2944
  let offset = 0;
2904
2945
  let response = new HttpResponse(new Response());
@@ -2925,22 +2966,14 @@ class NodeUploader {
2925
2966
  let retryCount = 0;
2926
2967
  let currentDelayMs = INITIAL_RETRY_DELAY_MS;
2927
2968
  while (retryCount < MAX_RETRY_COUNT) {
2969
+ 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 });
2928
2970
  response = await apiClient.request({
2929
2971
  path: '',
2930
2972
  body: chunk,
2931
2973
  httpMethod: 'POST',
2932
- httpOptions: {
2933
- apiVersion: '',
2934
- baseUrl: uploadUrl,
2935
- headers: {
2936
- 'X-Goog-Upload-Command': uploadCommand,
2937
- 'X-Goog-Upload-Offset': String(offset),
2938
- 'Content-Length': String(bytesRead),
2939
- 'X-Goog-Upload-File-Name': fileName,
2940
- },
2941
- },
2974
+ httpOptions: Object.assign(Object.assign({}, httpOptions), { apiVersion: '', baseUrl: finalUrl, headers: mergedHeaders }),
2942
2975
  });
2943
- if ((_a = response === null || response === void 0 ? void 0 : response.headers) === null || _a === void 0 ? void 0 : _a[X_GOOG_UPLOAD_STATUS_HEADER_FIELD]) {
2976
+ if ((_b = response === null || response === void 0 ? void 0 : response.headers) === null || _b === void 0 ? void 0 : _b[X_GOOG_UPLOAD_STATUS_HEADER_FIELD]) {
2944
2977
  break;
2945
2978
  }
2946
2979
  retryCount++;
@@ -2950,7 +2983,7 @@ class NodeUploader {
2950
2983
  offset += bytesRead;
2951
2984
  // The `x-goog-upload-status` header field can be `active`, `final` and
2952
2985
  //`cancelled` in resposne.
2953
- if (((_b = response === null || response === void 0 ? void 0 : response.headers) === null || _b === void 0 ? void 0 : _b[X_GOOG_UPLOAD_STATUS_HEADER_FIELD]) !== 'active') {
2986
+ 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') {
2954
2987
  break;
2955
2988
  }
2956
2989
  if (fileSize <= offset) {