@google/genai 1.30.0 → 1.31.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/index.cjs CHANGED
@@ -2196,6 +2196,9 @@ class GenerateVideosOperation {
2196
2196
  /** Response for the list tuning jobs method. */
2197
2197
  class ListTuningJobsResponse {
2198
2198
  }
2199
+ /** Empty response for tunings.cancel method. */
2200
+ class CancelTuningJobResponse {
2201
+ }
2199
2202
  /** Empty response for caches.delete method. */
2200
2203
  class DeleteCachedContentResponse {
2201
2204
  }
@@ -4663,6 +4666,23 @@ class Batches extends BaseModule {
4663
4666
  constructor(apiClient) {
4664
4667
  super();
4665
4668
  this.apiClient = apiClient;
4669
+ /**
4670
+ * Lists batch jobs.
4671
+ *
4672
+ * @param params - The parameters for the list request.
4673
+ * @return - A pager of batch jobs.
4674
+ *
4675
+ * @example
4676
+ * ```ts
4677
+ * const batchJobs = await ai.batches.list({config: {'pageSize': 2}});
4678
+ * for await (const batchJob of batchJobs) {
4679
+ * console.log(batchJob);
4680
+ * }
4681
+ * ```
4682
+ */
4683
+ this.list = async (params = {}) => {
4684
+ return new Pager(exports.PagedItem.PAGED_ITEM_BATCH_JOBS, (x) => this.listInternal(x), await this.listInternal(params), params);
4685
+ };
4666
4686
  /**
4667
4687
  * Create batch job.
4668
4688
  *
@@ -4711,23 +4731,6 @@ class Batches extends BaseModule {
4711
4731
  }
4712
4732
  return this.createEmbeddingsInternal(params);
4713
4733
  };
4714
- /**
4715
- * Lists batch job configurations.
4716
- *
4717
- * @param params - The parameters for the list request.
4718
- * @return The paginated results of the list of batch jobs.
4719
- *
4720
- * @example
4721
- * ```ts
4722
- * const batchJobs = await ai.batches.list({config: {'pageSize': 2}});
4723
- * for await (const batchJob of batchJobs) {
4724
- * console.log(batchJob);
4725
- * }
4726
- * ```
4727
- */
4728
- this.list = async (params = {}) => {
4729
- return new Pager(exports.PagedItem.PAGED_ITEM_BATCH_JOBS, (x) => this.listInternal(x), await this.listInternal(params), params);
4730
- };
4731
4734
  }
4732
4735
  // Helper function to handle inlined generate content requests
4733
4736
  createInlinedGenerateContentRequest(params) {
@@ -5830,10 +5833,10 @@ class Caches extends BaseModule {
5830
5833
  super();
5831
5834
  this.apiClient = apiClient;
5832
5835
  /**
5833
- * Lists cached content configurations.
5836
+ * Lists cached contents.
5834
5837
  *
5835
5838
  * @param params - The parameters for the list request.
5836
- * @return The paginated results of the list of cached contents.
5839
+ * @return - A pager of cached contents.
5837
5840
  *
5838
5841
  * @example
5839
5842
  * ```ts
@@ -6584,162 +6587,397 @@ class Chat {
6584
6587
  * Copyright 2025 Google LLC
6585
6588
  * SPDX-License-Identifier: Apache-2.0
6586
6589
  */
6587
- /**
6588
- * API errors raised by the GenAI API.
6589
- */
6590
- class ApiError extends Error {
6591
- constructor(options) {
6592
- super(options.message);
6593
- this.name = 'ApiError';
6594
- this.status = options.status;
6595
- Object.setPrototypeOf(this, ApiError.prototype);
6590
+ // Code generated by the Google Gen AI SDK generator DO NOT EDIT.
6591
+ function createFileSearchStoreConfigToMldev(fromObject, parentObject) {
6592
+ const toObject = {};
6593
+ const fromDisplayName = getValueByPath(fromObject, ['displayName']);
6594
+ if (parentObject !== undefined && fromDisplayName != null) {
6595
+ setValueByPath(parentObject, ['displayName'], fromDisplayName);
6596
6596
  }
6597
+ return toObject;
6597
6598
  }
6598
-
6599
- /**
6600
- * @license
6601
- * Copyright 2025 Google LLC
6602
- * SPDX-License-Identifier: Apache-2.0
6603
- */
6604
- const CONTENT_TYPE_HEADER = 'Content-Type';
6605
- const SERVER_TIMEOUT_HEADER = 'X-Server-Timeout';
6606
- const USER_AGENT_HEADER = 'User-Agent';
6607
- const GOOGLE_API_CLIENT_HEADER = 'x-goog-api-client';
6608
- const SDK_VERSION = '1.30.0'; // x-release-please-version
6609
- const LIBRARY_LABEL = `google-genai-sdk/${SDK_VERSION}`;
6610
- const VERTEX_AI_API_DEFAULT_VERSION = 'v1beta1';
6611
- const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
6612
- const responseLineRE = /^\s*data: (.*)(?:\n\n|\r\r|\r\n\r\n)/;
6613
- /**
6614
- * The ApiClient class is used to send requests to the Gemini API or Vertex AI
6615
- * endpoints.
6616
- */
6617
- class ApiClient {
6618
- constructor(opts) {
6619
- var _a, _b;
6620
- this.clientOptions = Object.assign(Object.assign({}, opts), { project: opts.project, location: opts.location, apiKey: opts.apiKey, vertexai: opts.vertexai });
6621
- const initHttpOptions = {};
6622
- if (this.clientOptions.vertexai) {
6623
- initHttpOptions.apiVersion =
6624
- (_a = this.clientOptions.apiVersion) !== null && _a !== void 0 ? _a : VERTEX_AI_API_DEFAULT_VERSION;
6625
- initHttpOptions.baseUrl = this.baseUrlFromProjectLocation();
6626
- this.normalizeAuthParameters();
6627
- }
6628
- else {
6629
- // Gemini API
6630
- initHttpOptions.apiVersion =
6631
- (_b = this.clientOptions.apiVersion) !== null && _b !== void 0 ? _b : GOOGLE_AI_API_DEFAULT_VERSION;
6632
- initHttpOptions.baseUrl = `https://generativelanguage.googleapis.com/`;
6633
- }
6634
- initHttpOptions.headers = this.getDefaultHeaders();
6635
- this.clientOptions.httpOptions = initHttpOptions;
6636
- if (opts.httpOptions) {
6637
- this.clientOptions.httpOptions = this.patchHttpOptions(initHttpOptions, opts.httpOptions);
6638
- }
6639
- }
6640
- /**
6641
- * Determines the base URL for Vertex AI based on project and location.
6642
- * Uses the global endpoint if location is 'global' or if project/location
6643
- * are not specified (implying API key usage).
6644
- * @private
6645
- */
6646
- baseUrlFromProjectLocation() {
6647
- if (this.clientOptions.project &&
6648
- this.clientOptions.location &&
6649
- this.clientOptions.location !== 'global') {
6650
- // Regional endpoint
6651
- return `https://${this.clientOptions.location}-aiplatform.googleapis.com/`;
6652
- }
6653
- // Global endpoint (covers 'global' location and API key usage)
6654
- return `https://aiplatform.googleapis.com/`;
6599
+ function createFileSearchStoreParametersToMldev(fromObject) {
6600
+ const toObject = {};
6601
+ const fromConfig = getValueByPath(fromObject, ['config']);
6602
+ if (fromConfig != null) {
6603
+ createFileSearchStoreConfigToMldev(fromConfig, toObject);
6655
6604
  }
6656
- /**
6657
- * Normalizes authentication parameters for Vertex AI.
6658
- * If project and location are provided, API key is cleared.
6659
- * If project and location are not provided (implying API key usage),
6660
- * project and location are cleared.
6661
- * @private
6662
- */
6663
- normalizeAuthParameters() {
6664
- if (this.clientOptions.project && this.clientOptions.location) {
6665
- // Using project/location for auth, clear potential API key
6666
- this.clientOptions.apiKey = undefined;
6667
- return;
6668
- }
6669
- // Using API key for auth (or no auth provided yet), clear project/location
6670
- this.clientOptions.project = undefined;
6671
- this.clientOptions.location = undefined;
6605
+ return toObject;
6606
+ }
6607
+ function deleteFileSearchStoreConfigToMldev(fromObject, parentObject) {
6608
+ const toObject = {};
6609
+ const fromForce = getValueByPath(fromObject, ['force']);
6610
+ if (parentObject !== undefined && fromForce != null) {
6611
+ setValueByPath(parentObject, ['_query', 'force'], fromForce);
6672
6612
  }
6673
- isVertexAI() {
6674
- var _a;
6675
- return (_a = this.clientOptions.vertexai) !== null && _a !== void 0 ? _a : false;
6613
+ return toObject;
6614
+ }
6615
+ function deleteFileSearchStoreParametersToMldev(fromObject) {
6616
+ const toObject = {};
6617
+ const fromName = getValueByPath(fromObject, ['name']);
6618
+ if (fromName != null) {
6619
+ setValueByPath(toObject, ['_url', 'name'], fromName);
6676
6620
  }
6677
- getProject() {
6678
- return this.clientOptions.project;
6621
+ const fromConfig = getValueByPath(fromObject, ['config']);
6622
+ if (fromConfig != null) {
6623
+ deleteFileSearchStoreConfigToMldev(fromConfig, toObject);
6679
6624
  }
6680
- getLocation() {
6681
- return this.clientOptions.location;
6625
+ return toObject;
6626
+ }
6627
+ function getFileSearchStoreParametersToMldev(fromObject) {
6628
+ const toObject = {};
6629
+ const fromName = getValueByPath(fromObject, ['name']);
6630
+ if (fromName != null) {
6631
+ setValueByPath(toObject, ['_url', 'name'], fromName);
6682
6632
  }
6683
- getApiVersion() {
6684
- if (this.clientOptions.httpOptions &&
6685
- this.clientOptions.httpOptions.apiVersion !== undefined) {
6686
- return this.clientOptions.httpOptions.apiVersion;
6633
+ return toObject;
6634
+ }
6635
+ function importFileConfigToMldev(fromObject, parentObject) {
6636
+ const toObject = {};
6637
+ const fromCustomMetadata = getValueByPath(fromObject, [
6638
+ 'customMetadata',
6639
+ ]);
6640
+ if (parentObject !== undefined && fromCustomMetadata != null) {
6641
+ let transformedList = fromCustomMetadata;
6642
+ if (Array.isArray(transformedList)) {
6643
+ transformedList = transformedList.map((item) => {
6644
+ return item;
6645
+ });
6687
6646
  }
6688
- throw new Error('API version is not set.');
6647
+ setValueByPath(parentObject, ['customMetadata'], transformedList);
6689
6648
  }
6690
- getBaseUrl() {
6691
- if (this.clientOptions.httpOptions &&
6692
- this.clientOptions.httpOptions.baseUrl !== undefined) {
6693
- return this.clientOptions.httpOptions.baseUrl;
6694
- }
6695
- throw new Error('Base URL is not set.');
6649
+ const fromChunkingConfig = getValueByPath(fromObject, [
6650
+ 'chunkingConfig',
6651
+ ]);
6652
+ if (parentObject !== undefined && fromChunkingConfig != null) {
6653
+ setValueByPath(parentObject, ['chunkingConfig'], fromChunkingConfig);
6696
6654
  }
6697
- getRequestUrl() {
6698
- return this.getRequestUrlInternal(this.clientOptions.httpOptions);
6655
+ return toObject;
6656
+ }
6657
+ function importFileOperationFromMldev(fromObject) {
6658
+ const toObject = {};
6659
+ const fromName = getValueByPath(fromObject, ['name']);
6660
+ if (fromName != null) {
6661
+ setValueByPath(toObject, ['name'], fromName);
6699
6662
  }
6700
- getHeaders() {
6701
- if (this.clientOptions.httpOptions &&
6702
- this.clientOptions.httpOptions.headers !== undefined) {
6703
- return this.clientOptions.httpOptions.headers;
6704
- }
6705
- else {
6706
- throw new Error('Headers are not set.');
6707
- }
6663
+ const fromMetadata = getValueByPath(fromObject, ['metadata']);
6664
+ if (fromMetadata != null) {
6665
+ setValueByPath(toObject, ['metadata'], fromMetadata);
6708
6666
  }
6709
- getRequestUrlInternal(httpOptions) {
6710
- if (!httpOptions ||
6711
- httpOptions.baseUrl === undefined ||
6712
- httpOptions.apiVersion === undefined) {
6713
- throw new Error('HTTP options are not correctly set.');
6714
- }
6715
- const baseUrl = httpOptions.baseUrl.endsWith('/')
6716
- ? httpOptions.baseUrl.slice(0, -1)
6717
- : httpOptions.baseUrl;
6718
- const urlElement = [baseUrl];
6719
- if (httpOptions.apiVersion && httpOptions.apiVersion !== '') {
6720
- urlElement.push(httpOptions.apiVersion);
6721
- }
6722
- return urlElement.join('/');
6667
+ const fromDone = getValueByPath(fromObject, ['done']);
6668
+ if (fromDone != null) {
6669
+ setValueByPath(toObject, ['done'], fromDone);
6723
6670
  }
6724
- getBaseResourcePath() {
6725
- return `projects/${this.clientOptions.project}/locations/${this.clientOptions.location}`;
6671
+ const fromError = getValueByPath(fromObject, ['error']);
6672
+ if (fromError != null) {
6673
+ setValueByPath(toObject, ['error'], fromError);
6726
6674
  }
6727
- getApiKey() {
6728
- return this.clientOptions.apiKey;
6675
+ const fromResponse = getValueByPath(fromObject, ['response']);
6676
+ if (fromResponse != null) {
6677
+ setValueByPath(toObject, ['response'], importFileResponseFromMldev(fromResponse));
6729
6678
  }
6730
- getWebsocketBaseUrl() {
6731
- const baseUrl = this.getBaseUrl();
6732
- const urlParts = new URL(baseUrl);
6733
- urlParts.protocol = urlParts.protocol == 'http:' ? 'ws' : 'wss';
6734
- return urlParts.toString();
6679
+ return toObject;
6680
+ }
6681
+ function importFileParametersToMldev(fromObject) {
6682
+ const toObject = {};
6683
+ const fromFileSearchStoreName = getValueByPath(fromObject, [
6684
+ 'fileSearchStoreName',
6685
+ ]);
6686
+ if (fromFileSearchStoreName != null) {
6687
+ setValueByPath(toObject, ['_url', 'file_search_store_name'], fromFileSearchStoreName);
6735
6688
  }
6736
- setBaseUrl(url) {
6737
- if (this.clientOptions.httpOptions) {
6738
- this.clientOptions.httpOptions.baseUrl = url;
6739
- }
6740
- else {
6741
- throw new Error('HTTP options are not correctly set.');
6742
- }
6689
+ const fromFileName = getValueByPath(fromObject, ['fileName']);
6690
+ if (fromFileName != null) {
6691
+ setValueByPath(toObject, ['fileName'], fromFileName);
6692
+ }
6693
+ const fromConfig = getValueByPath(fromObject, ['config']);
6694
+ if (fromConfig != null) {
6695
+ importFileConfigToMldev(fromConfig, toObject);
6696
+ }
6697
+ return toObject;
6698
+ }
6699
+ function importFileResponseFromMldev(fromObject) {
6700
+ const toObject = {};
6701
+ const fromSdkHttpResponse = getValueByPath(fromObject, [
6702
+ 'sdkHttpResponse',
6703
+ ]);
6704
+ if (fromSdkHttpResponse != null) {
6705
+ setValueByPath(toObject, ['sdkHttpResponse'], fromSdkHttpResponse);
6706
+ }
6707
+ const fromParent = getValueByPath(fromObject, ['parent']);
6708
+ if (fromParent != null) {
6709
+ setValueByPath(toObject, ['parent'], fromParent);
6710
+ }
6711
+ const fromDocumentName = getValueByPath(fromObject, ['documentName']);
6712
+ if (fromDocumentName != null) {
6713
+ setValueByPath(toObject, ['documentName'], fromDocumentName);
6714
+ }
6715
+ return toObject;
6716
+ }
6717
+ function listFileSearchStoresConfigToMldev(fromObject, parentObject) {
6718
+ const toObject = {};
6719
+ const fromPageSize = getValueByPath(fromObject, ['pageSize']);
6720
+ if (parentObject !== undefined && fromPageSize != null) {
6721
+ setValueByPath(parentObject, ['_query', 'pageSize'], fromPageSize);
6722
+ }
6723
+ const fromPageToken = getValueByPath(fromObject, ['pageToken']);
6724
+ if (parentObject !== undefined && fromPageToken != null) {
6725
+ setValueByPath(parentObject, ['_query', 'pageToken'], fromPageToken);
6726
+ }
6727
+ return toObject;
6728
+ }
6729
+ function listFileSearchStoresParametersToMldev(fromObject) {
6730
+ const toObject = {};
6731
+ const fromConfig = getValueByPath(fromObject, ['config']);
6732
+ if (fromConfig != null) {
6733
+ listFileSearchStoresConfigToMldev(fromConfig, toObject);
6734
+ }
6735
+ return toObject;
6736
+ }
6737
+ function listFileSearchStoresResponseFromMldev(fromObject) {
6738
+ const toObject = {};
6739
+ const fromSdkHttpResponse = getValueByPath(fromObject, [
6740
+ 'sdkHttpResponse',
6741
+ ]);
6742
+ if (fromSdkHttpResponse != null) {
6743
+ setValueByPath(toObject, ['sdkHttpResponse'], fromSdkHttpResponse);
6744
+ }
6745
+ const fromNextPageToken = getValueByPath(fromObject, [
6746
+ 'nextPageToken',
6747
+ ]);
6748
+ if (fromNextPageToken != null) {
6749
+ setValueByPath(toObject, ['nextPageToken'], fromNextPageToken);
6750
+ }
6751
+ const fromFileSearchStores = getValueByPath(fromObject, [
6752
+ 'fileSearchStores',
6753
+ ]);
6754
+ if (fromFileSearchStores != null) {
6755
+ let transformedList = fromFileSearchStores;
6756
+ if (Array.isArray(transformedList)) {
6757
+ transformedList = transformedList.map((item) => {
6758
+ return item;
6759
+ });
6760
+ }
6761
+ setValueByPath(toObject, ['fileSearchStores'], transformedList);
6762
+ }
6763
+ return toObject;
6764
+ }
6765
+ function uploadToFileSearchStoreConfigToMldev(fromObject, parentObject) {
6766
+ const toObject = {};
6767
+ const fromMimeType = getValueByPath(fromObject, ['mimeType']);
6768
+ if (parentObject !== undefined && fromMimeType != null) {
6769
+ setValueByPath(parentObject, ['mimeType'], fromMimeType);
6770
+ }
6771
+ const fromDisplayName = getValueByPath(fromObject, ['displayName']);
6772
+ if (parentObject !== undefined && fromDisplayName != null) {
6773
+ setValueByPath(parentObject, ['displayName'], fromDisplayName);
6774
+ }
6775
+ const fromCustomMetadata = getValueByPath(fromObject, [
6776
+ 'customMetadata',
6777
+ ]);
6778
+ if (parentObject !== undefined && fromCustomMetadata != null) {
6779
+ let transformedList = fromCustomMetadata;
6780
+ if (Array.isArray(transformedList)) {
6781
+ transformedList = transformedList.map((item) => {
6782
+ return item;
6783
+ });
6784
+ }
6785
+ setValueByPath(parentObject, ['customMetadata'], transformedList);
6786
+ }
6787
+ const fromChunkingConfig = getValueByPath(fromObject, [
6788
+ 'chunkingConfig',
6789
+ ]);
6790
+ if (parentObject !== undefined && fromChunkingConfig != null) {
6791
+ setValueByPath(parentObject, ['chunkingConfig'], fromChunkingConfig);
6792
+ }
6793
+ return toObject;
6794
+ }
6795
+ function uploadToFileSearchStoreParametersToMldev(fromObject) {
6796
+ const toObject = {};
6797
+ const fromFileSearchStoreName = getValueByPath(fromObject, [
6798
+ 'fileSearchStoreName',
6799
+ ]);
6800
+ if (fromFileSearchStoreName != null) {
6801
+ setValueByPath(toObject, ['_url', 'file_search_store_name'], fromFileSearchStoreName);
6802
+ }
6803
+ const fromConfig = getValueByPath(fromObject, ['config']);
6804
+ if (fromConfig != null) {
6805
+ uploadToFileSearchStoreConfigToMldev(fromConfig, toObject);
6806
+ }
6807
+ return toObject;
6808
+ }
6809
+ function uploadToFileSearchStoreResumableResponseFromMldev(fromObject) {
6810
+ const toObject = {};
6811
+ const fromSdkHttpResponse = getValueByPath(fromObject, [
6812
+ 'sdkHttpResponse',
6813
+ ]);
6814
+ if (fromSdkHttpResponse != null) {
6815
+ setValueByPath(toObject, ['sdkHttpResponse'], fromSdkHttpResponse);
6816
+ }
6817
+ return toObject;
6818
+ }
6819
+
6820
+ /**
6821
+ * @license
6822
+ * Copyright 2025 Google LLC
6823
+ * SPDX-License-Identifier: Apache-2.0
6824
+ */
6825
+ /**
6826
+ * API errors raised by the GenAI API.
6827
+ */
6828
+ class ApiError extends Error {
6829
+ constructor(options) {
6830
+ super(options.message);
6831
+ this.name = 'ApiError';
6832
+ this.status = options.status;
6833
+ Object.setPrototypeOf(this, ApiError.prototype);
6834
+ }
6835
+ }
6836
+
6837
+ /**
6838
+ * @license
6839
+ * Copyright 2025 Google LLC
6840
+ * SPDX-License-Identifier: Apache-2.0
6841
+ */
6842
+ const CONTENT_TYPE_HEADER = 'Content-Type';
6843
+ const SERVER_TIMEOUT_HEADER = 'X-Server-Timeout';
6844
+ const USER_AGENT_HEADER = 'User-Agent';
6845
+ const GOOGLE_API_CLIENT_HEADER = 'x-goog-api-client';
6846
+ const SDK_VERSION = '1.31.0'; // x-release-please-version
6847
+ const LIBRARY_LABEL = `google-genai-sdk/${SDK_VERSION}`;
6848
+ const VERTEX_AI_API_DEFAULT_VERSION = 'v1beta1';
6849
+ const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
6850
+ const responseLineRE = /^\s*data: (.*)(?:\n\n|\r\r|\r\n\r\n)/;
6851
+ /**
6852
+ * The ApiClient class is used to send requests to the Gemini API or Vertex AI
6853
+ * endpoints.
6854
+ */
6855
+ class ApiClient {
6856
+ constructor(opts) {
6857
+ var _a, _b;
6858
+ this.clientOptions = Object.assign(Object.assign({}, opts), { project: opts.project, location: opts.location, apiKey: opts.apiKey, vertexai: opts.vertexai });
6859
+ const initHttpOptions = {};
6860
+ if (this.clientOptions.vertexai) {
6861
+ initHttpOptions.apiVersion =
6862
+ (_a = this.clientOptions.apiVersion) !== null && _a !== void 0 ? _a : VERTEX_AI_API_DEFAULT_VERSION;
6863
+ initHttpOptions.baseUrl = this.baseUrlFromProjectLocation();
6864
+ this.normalizeAuthParameters();
6865
+ }
6866
+ else {
6867
+ // Gemini API
6868
+ initHttpOptions.apiVersion =
6869
+ (_b = this.clientOptions.apiVersion) !== null && _b !== void 0 ? _b : GOOGLE_AI_API_DEFAULT_VERSION;
6870
+ initHttpOptions.baseUrl = `https://generativelanguage.googleapis.com/`;
6871
+ }
6872
+ initHttpOptions.headers = this.getDefaultHeaders();
6873
+ this.clientOptions.httpOptions = initHttpOptions;
6874
+ if (opts.httpOptions) {
6875
+ this.clientOptions.httpOptions = this.patchHttpOptions(initHttpOptions, opts.httpOptions);
6876
+ }
6877
+ }
6878
+ /**
6879
+ * Determines the base URL for Vertex AI based on project and location.
6880
+ * Uses the global endpoint if location is 'global' or if project/location
6881
+ * are not specified (implying API key usage).
6882
+ * @private
6883
+ */
6884
+ baseUrlFromProjectLocation() {
6885
+ if (this.clientOptions.project &&
6886
+ this.clientOptions.location &&
6887
+ this.clientOptions.location !== 'global') {
6888
+ // Regional endpoint
6889
+ return `https://${this.clientOptions.location}-aiplatform.googleapis.com/`;
6890
+ }
6891
+ // Global endpoint (covers 'global' location and API key usage)
6892
+ return `https://aiplatform.googleapis.com/`;
6893
+ }
6894
+ /**
6895
+ * Normalizes authentication parameters for Vertex AI.
6896
+ * If project and location are provided, API key is cleared.
6897
+ * If project and location are not provided (implying API key usage),
6898
+ * project and location are cleared.
6899
+ * @private
6900
+ */
6901
+ normalizeAuthParameters() {
6902
+ if (this.clientOptions.project && this.clientOptions.location) {
6903
+ // Using project/location for auth, clear potential API key
6904
+ this.clientOptions.apiKey = undefined;
6905
+ return;
6906
+ }
6907
+ // Using API key for auth (or no auth provided yet), clear project/location
6908
+ this.clientOptions.project = undefined;
6909
+ this.clientOptions.location = undefined;
6910
+ }
6911
+ isVertexAI() {
6912
+ var _a;
6913
+ return (_a = this.clientOptions.vertexai) !== null && _a !== void 0 ? _a : false;
6914
+ }
6915
+ getProject() {
6916
+ return this.clientOptions.project;
6917
+ }
6918
+ getLocation() {
6919
+ return this.clientOptions.location;
6920
+ }
6921
+ getApiVersion() {
6922
+ if (this.clientOptions.httpOptions &&
6923
+ this.clientOptions.httpOptions.apiVersion !== undefined) {
6924
+ return this.clientOptions.httpOptions.apiVersion;
6925
+ }
6926
+ throw new Error('API version is not set.');
6927
+ }
6928
+ getBaseUrl() {
6929
+ if (this.clientOptions.httpOptions &&
6930
+ this.clientOptions.httpOptions.baseUrl !== undefined) {
6931
+ return this.clientOptions.httpOptions.baseUrl;
6932
+ }
6933
+ throw new Error('Base URL is not set.');
6934
+ }
6935
+ getRequestUrl() {
6936
+ return this.getRequestUrlInternal(this.clientOptions.httpOptions);
6937
+ }
6938
+ getHeaders() {
6939
+ if (this.clientOptions.httpOptions &&
6940
+ this.clientOptions.httpOptions.headers !== undefined) {
6941
+ return this.clientOptions.httpOptions.headers;
6942
+ }
6943
+ else {
6944
+ throw new Error('Headers are not set.');
6945
+ }
6946
+ }
6947
+ getRequestUrlInternal(httpOptions) {
6948
+ if (!httpOptions ||
6949
+ httpOptions.baseUrl === undefined ||
6950
+ httpOptions.apiVersion === undefined) {
6951
+ throw new Error('HTTP options are not correctly set.');
6952
+ }
6953
+ const baseUrl = httpOptions.baseUrl.endsWith('/')
6954
+ ? httpOptions.baseUrl.slice(0, -1)
6955
+ : httpOptions.baseUrl;
6956
+ const urlElement = [baseUrl];
6957
+ if (httpOptions.apiVersion && httpOptions.apiVersion !== '') {
6958
+ urlElement.push(httpOptions.apiVersion);
6959
+ }
6960
+ return urlElement.join('/');
6961
+ }
6962
+ getBaseResourcePath() {
6963
+ return `projects/${this.clientOptions.project}/locations/${this.clientOptions.location}`;
6964
+ }
6965
+ getApiKey() {
6966
+ return this.clientOptions.apiKey;
6967
+ }
6968
+ getWebsocketBaseUrl() {
6969
+ const baseUrl = this.getBaseUrl();
6970
+ const urlParts = new URL(baseUrl);
6971
+ urlParts.protocol = urlParts.protocol == 'http:' ? 'ws' : 'wss';
6972
+ return urlParts.toString();
6973
+ }
6974
+ setBaseUrl(url) {
6975
+ if (this.clientOptions.httpOptions) {
6976
+ this.clientOptions.httpOptions.baseUrl = url;
6977
+ }
6978
+ else {
6979
+ throw new Error('HTTP options are not correctly set.');
6980
+ }
6743
6981
  }
6744
6982
  constructUrl(path, httpOptions, prependProjectLocation) {
6745
6983
  const urlElement = [this.getRequestUrlInternal(httpOptions)];
@@ -7054,11 +7292,8 @@ class ApiClient {
7054
7292
  const path = `upload/v1beta/${fileSearchStoreName}:uploadToFileSearchStore`;
7055
7293
  const fileName = this.getFileName(file);
7056
7294
  const body = {};
7057
- if (config === null || config === void 0 ? void 0 : config.customMetadata) {
7058
- body['customMetadata'] = config.customMetadata;
7059
- }
7060
- if (config === null || config === void 0 ? void 0 : config.chunkingConfig) {
7061
- body['chunkingConfig'] = config.chunkingConfig;
7295
+ if (config != null) {
7296
+ uploadToFileSearchStoreConfigToMldev(config, body);
7062
7297
  }
7063
7298
  const uploadUrl = await this.fetchUploadUrl(path, sizeBytes, mimeType, fileName, body, config === null || config === void 0 ? void 0 : config.httpOptions);
7064
7299
  return uploader.uploadToFileSearchStore(file, uploadUrl, this);
@@ -7192,157 +7427,20 @@ function includeExtraBodyToRequestInit(requestInit, extraBody) {
7192
7427
  !Array.isArray(targetValue)) {
7193
7428
  output[key] = deepMerge(targetValue, sourceValue);
7194
7429
  }
7195
- else {
7196
- if (targetValue &&
7197
- sourceValue &&
7198
- typeof targetValue !== typeof sourceValue) {
7199
- console.warn(`includeExtraBodyToRequestInit:deepMerge: Type mismatch for key "${key}". Original type: ${typeof targetValue}, New type: ${typeof sourceValue}. Overwriting.`);
7200
- }
7201
- output[key] = sourceValue;
7202
- }
7203
- }
7204
- }
7205
- return output;
7206
- }
7207
- const mergedBody = deepMerge(currentBodyObject, extraBody);
7208
- requestInit.body = JSON.stringify(mergedBody);
7209
- }
7210
-
7211
- /**
7212
- * @license
7213
- * Copyright 2025 Google LLC
7214
- * SPDX-License-Identifier: Apache-2.0
7215
- */
7216
- function crossError() {
7217
- // TODO(b/399934880): this message needs a link to a help page explaining how to enable conditional exports
7218
- return new Error(`This feature requires the web or Node specific @google/genai implementation, you can fix this by either:
7219
-
7220
- *Enabling conditional exports for your project [recommended]*
7221
-
7222
- *Using a platform specific import* - Make sure your code imports either '@google/genai/web' or '@google/genai/node' instead of '@google/genai'.
7223
- `);
7224
- }
7225
-
7226
- /**
7227
- * @license
7228
- * Copyright 2025 Google LLC
7229
- * SPDX-License-Identifier: Apache-2.0
7230
- */
7231
- class CrossDownloader {
7232
- async download(_params, _apiClient) {
7233
- throw crossError();
7234
- }
7235
- }
7236
-
7237
- const MAX_CHUNK_SIZE = 1024 * 1024 * 8; // bytes
7238
- const MAX_RETRY_COUNT = 3;
7239
- const INITIAL_RETRY_DELAY_MS = 1000;
7240
- const DELAY_MULTIPLIER = 2;
7241
- const X_GOOG_UPLOAD_STATUS_HEADER_FIELD = 'x-goog-upload-status';
7242
- class CrossUploader {
7243
- async upload(file, uploadUrl, apiClient) {
7244
- if (typeof file === 'string') {
7245
- throw crossError();
7246
- }
7247
- else {
7248
- return uploadBlob(file, uploadUrl, apiClient);
7249
- }
7250
- }
7251
- async uploadToFileSearchStore(file, uploadUrl, apiClient) {
7252
- if (typeof file === 'string') {
7253
- throw crossError();
7254
- }
7255
- else {
7256
- return uploadBlobToFileSearchStore(file, uploadUrl, apiClient);
7257
- }
7258
- }
7259
- async stat(file) {
7260
- if (typeof file === 'string') {
7261
- throw crossError();
7262
- }
7263
- else {
7264
- return getBlobStat(file);
7265
- }
7266
- }
7267
- }
7268
- async function uploadBlob(file, uploadUrl, apiClient) {
7269
- var _a;
7270
- const response = await uploadBlobInternal(file, uploadUrl, apiClient);
7271
- const responseJson = (await (response === null || response === void 0 ? void 0 : response.json()));
7272
- 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') {
7273
- throw new Error('Failed to upload file: Upload status is not finalized.');
7274
- }
7275
- return responseJson['file'];
7276
- }
7277
- async function uploadBlobToFileSearchStore(file, uploadUrl, apiClient) {
7278
- var _a;
7279
- const response = await uploadBlobInternal(file, uploadUrl, apiClient);
7280
- const responseJson = (await (response === null || response === void 0 ? void 0 : response.json()));
7281
- 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') {
7282
- throw new Error('Failed to upload file: Upload status is not finalized.');
7283
- }
7284
- const resp = uploadToFileSearchStoreOperationFromMldev(responseJson);
7285
- const typedResp = new UploadToFileSearchStoreOperation();
7286
- Object.assign(typedResp, resp);
7287
- return typedResp;
7288
- }
7289
- async function uploadBlobInternal(file, uploadUrl, apiClient) {
7290
- var _a, _b;
7291
- let fileSize = 0;
7292
- let offset = 0;
7293
- let response = new HttpResponse(new Response());
7294
- let uploadCommand = 'upload';
7295
- fileSize = file.size;
7296
- while (offset < fileSize) {
7297
- const chunkSize = Math.min(MAX_CHUNK_SIZE, fileSize - offset);
7298
- const chunk = file.slice(offset, offset + chunkSize);
7299
- if (offset + chunkSize >= fileSize) {
7300
- uploadCommand += ', finalize';
7301
- }
7302
- let retryCount = 0;
7303
- let currentDelayMs = INITIAL_RETRY_DELAY_MS;
7304
- while (retryCount < MAX_RETRY_COUNT) {
7305
- response = await apiClient.request({
7306
- path: '',
7307
- body: chunk,
7308
- httpMethod: 'POST',
7309
- httpOptions: {
7310
- apiVersion: '',
7311
- baseUrl: uploadUrl,
7312
- headers: {
7313
- 'X-Goog-Upload-Command': uploadCommand,
7314
- 'X-Goog-Upload-Offset': String(offset),
7315
- 'Content-Length': String(chunkSize),
7316
- },
7317
- },
7318
- });
7319
- if ((_a = response === null || response === void 0 ? void 0 : response.headers) === null || _a === void 0 ? void 0 : _a[X_GOOG_UPLOAD_STATUS_HEADER_FIELD]) {
7320
- break;
7321
- }
7322
- retryCount++;
7323
- await sleep(currentDelayMs);
7324
- currentDelayMs = currentDelayMs * DELAY_MULTIPLIER;
7325
- }
7326
- offset += chunkSize;
7327
- // The `x-goog-upload-status` header field can be `active`, `final` and
7328
- //`cancelled` in resposne.
7329
- 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') {
7330
- break;
7331
- }
7332
- // TODO(b/401391430) Investigate why the upload status is not finalized
7333
- // even though all content has been uploaded.
7334
- if (fileSize <= offset) {
7335
- throw new Error('All content has been uploaded, but the upload status is not finalized.');
7430
+ else {
7431
+ if (targetValue &&
7432
+ sourceValue &&
7433
+ typeof targetValue !== typeof sourceValue) {
7434
+ console.warn(`includeExtraBodyToRequestInit:deepMerge: Type mismatch for key "${key}". Original type: ${typeof targetValue}, New type: ${typeof sourceValue}. Overwriting.`);
7435
+ }
7436
+ output[key] = sourceValue;
7437
+ }
7438
+ }
7336
7439
  }
7440
+ return output;
7337
7441
  }
7338
- return response;
7339
- }
7340
- async function getBlobStat(file) {
7341
- const fileStat = { size: file.size, type: file.type };
7342
- return fileStat;
7343
- }
7344
- function sleep(ms) {
7345
- return new Promise((resolvePromise) => setTimeout(resolvePromise, ms));
7442
+ const mergedBody = deepMerge(currentBodyObject, extraBody);
7443
+ requestInit.body = JSON.stringify(mergedBody);
7346
7444
  }
7347
7445
 
7348
7446
  /**
@@ -7350,501 +7448,182 @@ function sleep(ms) {
7350
7448
  * Copyright 2025 Google LLC
7351
7449
  * SPDX-License-Identifier: Apache-2.0
7352
7450
  */
7353
- class CrossWebSocketFactory {
7354
- create(_url, _headers, _callbacks) {
7355
- throw crossError();
7356
- }
7357
- }
7451
+ function crossError() {
7452
+ // TODO(b/399934880): this message needs a link to a help page explaining how to enable conditional exports
7453
+ return new Error(`This feature requires the web or Node specific @google/genai implementation, you can fix this by either:
7358
7454
 
7359
- /**
7360
- * @license
7361
- * Copyright 2025 Google LLC
7362
- * SPDX-License-Identifier: Apache-2.0
7363
- */
7364
- // Code generated by the Google Gen AI SDK generator DO NOT EDIT.
7365
- function createFileParametersToMldev(fromObject) {
7366
- const toObject = {};
7367
- const fromFile = getValueByPath(fromObject, ['file']);
7368
- if (fromFile != null) {
7369
- setValueByPath(toObject, ['file'], fromFile);
7370
- }
7371
- return toObject;
7372
- }
7373
- function createFileResponseFromMldev(fromObject) {
7374
- const toObject = {};
7375
- const fromSdkHttpResponse = getValueByPath(fromObject, [
7376
- 'sdkHttpResponse',
7377
- ]);
7378
- if (fromSdkHttpResponse != null) {
7379
- setValueByPath(toObject, ['sdkHttpResponse'], fromSdkHttpResponse);
7380
- }
7381
- return toObject;
7382
- }
7383
- function deleteFileParametersToMldev(fromObject) {
7384
- const toObject = {};
7385
- const fromName = getValueByPath(fromObject, ['name']);
7386
- if (fromName != null) {
7387
- setValueByPath(toObject, ['_url', 'file'], tFileName(fromName));
7388
- }
7389
- return toObject;
7390
- }
7391
- function deleteFileResponseFromMldev(fromObject) {
7392
- const toObject = {};
7393
- const fromSdkHttpResponse = getValueByPath(fromObject, [
7394
- 'sdkHttpResponse',
7395
- ]);
7396
- if (fromSdkHttpResponse != null) {
7397
- setValueByPath(toObject, ['sdkHttpResponse'], fromSdkHttpResponse);
7398
- }
7399
- return toObject;
7400
- }
7401
- function getFileParametersToMldev(fromObject) {
7402
- const toObject = {};
7403
- const fromName = getValueByPath(fromObject, ['name']);
7404
- if (fromName != null) {
7405
- setValueByPath(toObject, ['_url', 'file'], tFileName(fromName));
7406
- }
7407
- return toObject;
7408
- }
7409
- function listFilesConfigToMldev(fromObject, parentObject) {
7410
- const toObject = {};
7411
- const fromPageSize = getValueByPath(fromObject, ['pageSize']);
7412
- if (parentObject !== undefined && fromPageSize != null) {
7413
- setValueByPath(parentObject, ['_query', 'pageSize'], fromPageSize);
7414
- }
7415
- const fromPageToken = getValueByPath(fromObject, ['pageToken']);
7416
- if (parentObject !== undefined && fromPageToken != null) {
7417
- setValueByPath(parentObject, ['_query', 'pageToken'], fromPageToken);
7418
- }
7419
- return toObject;
7420
- }
7421
- function listFilesParametersToMldev(fromObject) {
7422
- const toObject = {};
7423
- const fromConfig = getValueByPath(fromObject, ['config']);
7424
- if (fromConfig != null) {
7425
- listFilesConfigToMldev(fromConfig, toObject);
7426
- }
7427
- return toObject;
7428
- }
7429
- function listFilesResponseFromMldev(fromObject) {
7430
- const toObject = {};
7431
- const fromSdkHttpResponse = getValueByPath(fromObject, [
7432
- 'sdkHttpResponse',
7433
- ]);
7434
- if (fromSdkHttpResponse != null) {
7435
- setValueByPath(toObject, ['sdkHttpResponse'], fromSdkHttpResponse);
7436
- }
7437
- const fromNextPageToken = getValueByPath(fromObject, [
7438
- 'nextPageToken',
7439
- ]);
7440
- if (fromNextPageToken != null) {
7441
- setValueByPath(toObject, ['nextPageToken'], fromNextPageToken);
7442
- }
7443
- const fromFiles = getValueByPath(fromObject, ['files']);
7444
- if (fromFiles != null) {
7445
- let transformedList = fromFiles;
7446
- if (Array.isArray(transformedList)) {
7447
- transformedList = transformedList.map((item) => {
7448
- return item;
7449
- });
7450
- }
7451
- setValueByPath(toObject, ['files'], transformedList);
7452
- }
7453
- return toObject;
7455
+ *Enabling conditional exports for your project [recommended]*
7456
+
7457
+ *Using a platform specific import* - Make sure your code imports either '@google/genai/web' or '@google/genai/node' instead of '@google/genai'.
7458
+ `);
7454
7459
  }
7455
7460
 
7456
7461
  /**
7457
7462
  * @license
7458
7463
  * Copyright 2025 Google LLC
7459
7464
  * SPDX-License-Identifier: Apache-2.0
7460
- */
7461
- class Files extends BaseModule {
7462
- constructor(apiClient) {
7463
- super();
7464
- this.apiClient = apiClient;
7465
- /**
7466
- * Lists all current project files from the service.
7467
- *
7468
- * @param params - The parameters for the list request
7469
- * @return The paginated results of the list of files
7470
- *
7471
- * @example
7472
- * The following code prints the names of all files from the service, the
7473
- * size of each page is 10.
7474
- *
7475
- * ```ts
7476
- * const listResponse = await ai.files.list({config: {'pageSize': 10}});
7477
- * for await (const file of listResponse) {
7478
- * console.log(file.name);
7479
- * }
7480
- * ```
7481
- */
7482
- this.list = async (params = {}) => {
7483
- return new Pager(exports.PagedItem.PAGED_ITEM_FILES, (x) => this.listInternal(x), await this.listInternal(params), params);
7484
- };
7485
- }
7486
- /**
7487
- * Uploads a file asynchronously to the Gemini API.
7488
- * This method is not available in Vertex AI.
7489
- * Supported upload sources:
7490
- * - Node.js: File path (string) or Blob object.
7491
- * - Browser: Blob object (e.g., File).
7492
- *
7493
- * @remarks
7494
- * The `mimeType` can be specified in the `config` parameter. If omitted:
7495
- * - For file path (string) inputs, the `mimeType` will be inferred from the
7496
- * file extension.
7497
- * - For Blob object inputs, the `mimeType` will be set to the Blob's `type`
7498
- * property.
7499
- * Somex eamples for file extension to mimeType mapping:
7500
- * .txt -> text/plain
7501
- * .json -> application/json
7502
- * .jpg -> image/jpeg
7503
- * .png -> image/png
7504
- * .mp3 -> audio/mpeg
7505
- * .mp4 -> video/mp4
7506
- *
7507
- * This section can contain multiple paragraphs and code examples.
7508
- *
7509
- * @param params - Optional parameters specified in the
7510
- * `types.UploadFileParameters` interface.
7511
- * @see {@link types.UploadFileParameters#config} for the optional
7512
- * config in the parameters.
7513
- * @return A promise that resolves to a `types.File` object.
7514
- * @throws An error if called on a Vertex AI client.
7515
- * @throws An error if the `mimeType` is not provided and can not be inferred,
7516
- * the `mimeType` can be provided in the `params.config` parameter.
7517
- * @throws An error occurs if a suitable upload location cannot be established.
7518
- *
7519
- * @example
7520
- * The following code uploads a file to Gemini API.
7521
- *
7522
- * ```ts
7523
- * const file = await ai.files.upload({file: 'file.txt', config: {
7524
- * mimeType: 'text/plain',
7525
- * }});
7526
- * console.log(file.name);
7527
- * ```
7528
- */
7529
- async upload(params) {
7530
- if (this.apiClient.isVertexAI()) {
7531
- throw new Error('Vertex AI does not support uploading files. You can share files through a GCS bucket.');
7532
- }
7533
- return this.apiClient
7534
- .uploadFile(params.file, params.config)
7535
- .then((resp) => {
7536
- return resp;
7537
- });
7538
- }
7539
- /**
7540
- * Downloads a remotely stored file asynchronously to a location specified in
7541
- * the `params` object. This method only works on Node environment, to
7542
- * download files in the browser, use a browser compliant method like an <a>
7543
- * tag.
7544
- *
7545
- * @param params - The parameters for the download request.
7546
- *
7547
- * @example
7548
- * The following code downloads an example file named "files/mehozpxf877d" as
7549
- * "file.txt".
7550
- *
7551
- * ```ts
7552
- * await ai.files.download({file: file.name, downloadPath: 'file.txt'});
7553
- * ```
7554
- */
7555
- async download(params) {
7556
- await this.apiClient.downloadFile(params);
7557
- }
7558
- async listInternal(params) {
7559
- var _a, _b;
7560
- let response;
7561
- let path = '';
7562
- let queryParams = {};
7563
- if (this.apiClient.isVertexAI()) {
7564
- throw new Error('This method is only supported by the Gemini Developer API.');
7565
- }
7566
- else {
7567
- const body = listFilesParametersToMldev(params);
7568
- path = formatMap('files', body['_url']);
7569
- queryParams = body['_query'];
7570
- delete body['_url'];
7571
- delete body['_query'];
7572
- response = this.apiClient
7573
- .request({
7574
- path: path,
7575
- queryParams: queryParams,
7576
- body: JSON.stringify(body),
7577
- httpMethod: 'GET',
7578
- httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
7579
- abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
7580
- })
7581
- .then((httpResponse) => {
7582
- return httpResponse.json().then((jsonResponse) => {
7583
- const response = jsonResponse;
7584
- response.sdkHttpResponse = {
7585
- headers: httpResponse.headers,
7586
- };
7587
- return response;
7588
- });
7589
- });
7590
- return response.then((apiResponse) => {
7591
- const resp = listFilesResponseFromMldev(apiResponse);
7592
- const typedResp = new ListFilesResponse();
7593
- Object.assign(typedResp, resp);
7594
- return typedResp;
7595
- });
7596
- }
7465
+ */
7466
+ class CrossDownloader {
7467
+ async download(_params, _apiClient) {
7468
+ throw crossError();
7597
7469
  }
7598
- async createInternal(params) {
7599
- var _a, _b;
7600
- let response;
7601
- let path = '';
7602
- let queryParams = {};
7603
- if (this.apiClient.isVertexAI()) {
7604
- throw new Error('This method is only supported by the Gemini Developer API.');
7470
+ }
7471
+
7472
+ const MAX_CHUNK_SIZE = 1024 * 1024 * 8; // bytes
7473
+ const MAX_RETRY_COUNT = 3;
7474
+ const INITIAL_RETRY_DELAY_MS = 1000;
7475
+ const DELAY_MULTIPLIER = 2;
7476
+ const X_GOOG_UPLOAD_STATUS_HEADER_FIELD = 'x-goog-upload-status';
7477
+ class CrossUploader {
7478
+ async upload(file, uploadUrl, apiClient) {
7479
+ if (typeof file === 'string') {
7480
+ throw crossError();
7605
7481
  }
7606
7482
  else {
7607
- const body = createFileParametersToMldev(params);
7608
- path = formatMap('upload/v1beta/files', body['_url']);
7609
- queryParams = body['_query'];
7610
- delete body['_url'];
7611
- delete body['_query'];
7612
- response = this.apiClient
7613
- .request({
7614
- path: path,
7615
- queryParams: queryParams,
7616
- body: JSON.stringify(body),
7617
- httpMethod: 'POST',
7618
- httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
7619
- abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
7620
- })
7621
- .then((httpResponse) => {
7622
- return httpResponse.json();
7623
- });
7624
- return response.then((apiResponse) => {
7625
- const resp = createFileResponseFromMldev(apiResponse);
7626
- const typedResp = new CreateFileResponse();
7627
- Object.assign(typedResp, resp);
7628
- return typedResp;
7629
- });
7483
+ return uploadBlob(file, uploadUrl, apiClient);
7630
7484
  }
7631
7485
  }
7632
- /**
7633
- * Retrieves the file information from the service.
7634
- *
7635
- * @param params - The parameters for the get request
7636
- * @return The Promise that resolves to the types.File object requested.
7637
- *
7638
- * @example
7639
- * ```ts
7640
- * const config: GetFileParameters = {
7641
- * name: fileName,
7642
- * };
7643
- * file = await ai.files.get(config);
7644
- * console.log(file.name);
7645
- * ```
7646
- */
7647
- async get(params) {
7648
- var _a, _b;
7649
- let response;
7650
- let path = '';
7651
- let queryParams = {};
7652
- if (this.apiClient.isVertexAI()) {
7653
- throw new Error('This method is only supported by the Gemini Developer API.');
7486
+ async uploadToFileSearchStore(file, uploadUrl, apiClient) {
7487
+ if (typeof file === 'string') {
7488
+ throw crossError();
7654
7489
  }
7655
7490
  else {
7656
- const body = getFileParametersToMldev(params);
7657
- path = formatMap('files/{file}', body['_url']);
7658
- queryParams = body['_query'];
7659
- delete body['_url'];
7660
- delete body['_query'];
7661
- response = this.apiClient
7662
- .request({
7663
- path: path,
7664
- queryParams: queryParams,
7665
- body: JSON.stringify(body),
7666
- httpMethod: 'GET',
7667
- httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
7668
- abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
7669
- })
7670
- .then((httpResponse) => {
7671
- return httpResponse.json();
7672
- });
7673
- return response.then((resp) => {
7674
- return resp;
7675
- });
7491
+ return uploadBlobToFileSearchStore(file, uploadUrl, apiClient);
7676
7492
  }
7677
7493
  }
7678
- /**
7679
- * Deletes a remotely stored file.
7680
- *
7681
- * @param params - The parameters for the delete request.
7682
- * @return The DeleteFileResponse, the response for the delete method.
7683
- *
7684
- * @example
7685
- * The following code deletes an example file named "files/mehozpxf877d".
7686
- *
7687
- * ```ts
7688
- * await ai.files.delete({name: file.name});
7689
- * ```
7690
- */
7691
- async delete(params) {
7692
- var _a, _b;
7693
- let response;
7694
- let path = '';
7695
- let queryParams = {};
7696
- if (this.apiClient.isVertexAI()) {
7697
- throw new Error('This method is only supported by the Gemini Developer API.');
7494
+ async stat(file) {
7495
+ if (typeof file === 'string') {
7496
+ throw crossError();
7698
7497
  }
7699
7498
  else {
7700
- const body = deleteFileParametersToMldev(params);
7701
- path = formatMap('files/{file}', body['_url']);
7702
- queryParams = body['_query'];
7703
- delete body['_url'];
7704
- delete body['_query'];
7705
- response = this.apiClient
7706
- .request({
7707
- path: path,
7708
- queryParams: queryParams,
7709
- body: JSON.stringify(body),
7710
- httpMethod: 'DELETE',
7711
- httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
7712
- abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
7713
- })
7714
- .then((httpResponse) => {
7715
- return httpResponse.json().then((jsonResponse) => {
7716
- const response = jsonResponse;
7717
- response.sdkHttpResponse = {
7718
- headers: httpResponse.headers,
7719
- };
7720
- return response;
7721
- });
7722
- });
7723
- return response.then((apiResponse) => {
7724
- const resp = deleteFileResponseFromMldev(apiResponse);
7725
- const typedResp = new DeleteFileResponse();
7726
- Object.assign(typedResp, resp);
7727
- return typedResp;
7728
- });
7499
+ return getBlobStat(file);
7729
7500
  }
7730
7501
  }
7731
7502
  }
7732
-
7733
- /**
7734
- * @license
7735
- * Copyright 2025 Google LLC
7736
- * SPDX-License-Identifier: Apache-2.0
7737
- */
7738
- // Code generated by the Google Gen AI SDK generator DO NOT EDIT.
7739
- function createFileSearchStoreConfigToMldev(fromObject, parentObject) {
7740
- const toObject = {};
7741
- const fromDisplayName = getValueByPath(fromObject, ['displayName']);
7742
- if (parentObject !== undefined && fromDisplayName != null) {
7743
- setValueByPath(parentObject, ['displayName'], fromDisplayName);
7503
+ async function uploadBlob(file, uploadUrl, apiClient) {
7504
+ var _a;
7505
+ const response = await uploadBlobInternal(file, uploadUrl, apiClient);
7506
+ const responseJson = (await (response === null || response === void 0 ? void 0 : response.json()));
7507
+ 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') {
7508
+ throw new Error('Failed to upload file: Upload status is not finalized.');
7744
7509
  }
7745
- return toObject;
7510
+ return responseJson['file'];
7746
7511
  }
7747
- function createFileSearchStoreParametersToMldev(fromObject) {
7748
- const toObject = {};
7749
- const fromConfig = getValueByPath(fromObject, ['config']);
7750
- if (fromConfig != null) {
7751
- createFileSearchStoreConfigToMldev(fromConfig, toObject);
7512
+ async function uploadBlobToFileSearchStore(file, uploadUrl, apiClient) {
7513
+ var _a;
7514
+ const response = await uploadBlobInternal(file, uploadUrl, apiClient);
7515
+ const responseJson = (await (response === null || response === void 0 ? void 0 : response.json()));
7516
+ 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') {
7517
+ throw new Error('Failed to upload file: Upload status is not finalized.');
7752
7518
  }
7753
- return toObject;
7519
+ const resp = uploadToFileSearchStoreOperationFromMldev(responseJson);
7520
+ const typedResp = new UploadToFileSearchStoreOperation();
7521
+ Object.assign(typedResp, resp);
7522
+ return typedResp;
7754
7523
  }
7755
- function deleteFileSearchStoreConfigToMldev(fromObject, parentObject) {
7756
- const toObject = {};
7757
- const fromForce = getValueByPath(fromObject, ['force']);
7758
- if (parentObject !== undefined && fromForce != null) {
7759
- setValueByPath(parentObject, ['_query', 'force'], fromForce);
7524
+ async function uploadBlobInternal(file, uploadUrl, apiClient) {
7525
+ var _a, _b;
7526
+ let fileSize = 0;
7527
+ let offset = 0;
7528
+ let response = new HttpResponse(new Response());
7529
+ let uploadCommand = 'upload';
7530
+ fileSize = file.size;
7531
+ while (offset < fileSize) {
7532
+ const chunkSize = Math.min(MAX_CHUNK_SIZE, fileSize - offset);
7533
+ const chunk = file.slice(offset, offset + chunkSize);
7534
+ if (offset + chunkSize >= fileSize) {
7535
+ uploadCommand += ', finalize';
7536
+ }
7537
+ let retryCount = 0;
7538
+ let currentDelayMs = INITIAL_RETRY_DELAY_MS;
7539
+ while (retryCount < MAX_RETRY_COUNT) {
7540
+ response = await apiClient.request({
7541
+ path: '',
7542
+ body: chunk,
7543
+ httpMethod: 'POST',
7544
+ httpOptions: {
7545
+ apiVersion: '',
7546
+ baseUrl: uploadUrl,
7547
+ headers: {
7548
+ 'X-Goog-Upload-Command': uploadCommand,
7549
+ 'X-Goog-Upload-Offset': String(offset),
7550
+ 'Content-Length': String(chunkSize),
7551
+ },
7552
+ },
7553
+ });
7554
+ if ((_a = response === null || response === void 0 ? void 0 : response.headers) === null || _a === void 0 ? void 0 : _a[X_GOOG_UPLOAD_STATUS_HEADER_FIELD]) {
7555
+ break;
7556
+ }
7557
+ retryCount++;
7558
+ await sleep(currentDelayMs);
7559
+ currentDelayMs = currentDelayMs * DELAY_MULTIPLIER;
7560
+ }
7561
+ offset += chunkSize;
7562
+ // The `x-goog-upload-status` header field can be `active`, `final` and
7563
+ //`cancelled` in resposne.
7564
+ 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') {
7565
+ break;
7566
+ }
7567
+ // TODO(b/401391430) Investigate why the upload status is not finalized
7568
+ // even though all content has been uploaded.
7569
+ if (fileSize <= offset) {
7570
+ throw new Error('All content has been uploaded, but the upload status is not finalized.');
7571
+ }
7760
7572
  }
7761
- return toObject;
7573
+ return response;
7762
7574
  }
7763
- function deleteFileSearchStoreParametersToMldev(fromObject) {
7764
- const toObject = {};
7765
- const fromName = getValueByPath(fromObject, ['name']);
7766
- if (fromName != null) {
7767
- setValueByPath(toObject, ['_url', 'name'], fromName);
7768
- }
7769
- const fromConfig = getValueByPath(fromObject, ['config']);
7770
- if (fromConfig != null) {
7771
- deleteFileSearchStoreConfigToMldev(fromConfig, toObject);
7575
+ async function getBlobStat(file) {
7576
+ const fileStat = { size: file.size, type: file.type };
7577
+ return fileStat;
7578
+ }
7579
+ function sleep(ms) {
7580
+ return new Promise((resolvePromise) => setTimeout(resolvePromise, ms));
7581
+ }
7582
+
7583
+ /**
7584
+ * @license
7585
+ * Copyright 2025 Google LLC
7586
+ * SPDX-License-Identifier: Apache-2.0
7587
+ */
7588
+ class CrossWebSocketFactory {
7589
+ create(_url, _headers, _callbacks) {
7590
+ throw crossError();
7772
7591
  }
7773
- return toObject;
7774
7592
  }
7775
- function getFileSearchStoreParametersToMldev(fromObject) {
7593
+
7594
+ /**
7595
+ * @license
7596
+ * Copyright 2025 Google LLC
7597
+ * SPDX-License-Identifier: Apache-2.0
7598
+ */
7599
+ // Code generated by the Google Gen AI SDK generator DO NOT EDIT.
7600
+ function createFileParametersToMldev(fromObject) {
7776
7601
  const toObject = {};
7777
- const fromName = getValueByPath(fromObject, ['name']);
7778
- if (fromName != null) {
7779
- setValueByPath(toObject, ['_url', 'name'], fromName);
7602
+ const fromFile = getValueByPath(fromObject, ['file']);
7603
+ if (fromFile != null) {
7604
+ setValueByPath(toObject, ['file'], fromFile);
7780
7605
  }
7781
7606
  return toObject;
7782
7607
  }
7783
- function importFileConfigToMldev(fromObject, parentObject) {
7608
+ function createFileResponseFromMldev(fromObject) {
7784
7609
  const toObject = {};
7785
- const fromCustomMetadata = getValueByPath(fromObject, [
7786
- 'customMetadata',
7787
- ]);
7788
- if (parentObject !== undefined && fromCustomMetadata != null) {
7789
- let transformedList = fromCustomMetadata;
7790
- if (Array.isArray(transformedList)) {
7791
- transformedList = transformedList.map((item) => {
7792
- return item;
7793
- });
7794
- }
7795
- setValueByPath(parentObject, ['customMetadata'], transformedList);
7796
- }
7797
- const fromChunkingConfig = getValueByPath(fromObject, [
7798
- 'chunkingConfig',
7610
+ const fromSdkHttpResponse = getValueByPath(fromObject, [
7611
+ 'sdkHttpResponse',
7799
7612
  ]);
7800
- if (parentObject !== undefined && fromChunkingConfig != null) {
7801
- setValueByPath(parentObject, ['chunkingConfig'], fromChunkingConfig);
7613
+ if (fromSdkHttpResponse != null) {
7614
+ setValueByPath(toObject, ['sdkHttpResponse'], fromSdkHttpResponse);
7802
7615
  }
7803
7616
  return toObject;
7804
7617
  }
7805
- function importFileOperationFromMldev(fromObject) {
7618
+ function deleteFileParametersToMldev(fromObject) {
7806
7619
  const toObject = {};
7807
7620
  const fromName = getValueByPath(fromObject, ['name']);
7808
7621
  if (fromName != null) {
7809
- setValueByPath(toObject, ['name'], fromName);
7810
- }
7811
- const fromMetadata = getValueByPath(fromObject, ['metadata']);
7812
- if (fromMetadata != null) {
7813
- setValueByPath(toObject, ['metadata'], fromMetadata);
7814
- }
7815
- const fromDone = getValueByPath(fromObject, ['done']);
7816
- if (fromDone != null) {
7817
- setValueByPath(toObject, ['done'], fromDone);
7818
- }
7819
- const fromError = getValueByPath(fromObject, ['error']);
7820
- if (fromError != null) {
7821
- setValueByPath(toObject, ['error'], fromError);
7822
- }
7823
- const fromResponse = getValueByPath(fromObject, ['response']);
7824
- if (fromResponse != null) {
7825
- setValueByPath(toObject, ['response'], importFileResponseFromMldev(fromResponse));
7826
- }
7827
- return toObject;
7828
- }
7829
- function importFileParametersToMldev(fromObject) {
7830
- const toObject = {};
7831
- const fromFileSearchStoreName = getValueByPath(fromObject, [
7832
- 'fileSearchStoreName',
7833
- ]);
7834
- if (fromFileSearchStoreName != null) {
7835
- setValueByPath(toObject, ['_url', 'file_search_store_name'], fromFileSearchStoreName);
7836
- }
7837
- const fromFileName = getValueByPath(fromObject, ['fileName']);
7838
- if (fromFileName != null) {
7839
- setValueByPath(toObject, ['fileName'], fromFileName);
7840
- }
7841
- const fromConfig = getValueByPath(fromObject, ['config']);
7842
- if (fromConfig != null) {
7843
- importFileConfigToMldev(fromConfig, toObject);
7622
+ setValueByPath(toObject, ['_url', 'file'], tFileName(fromName));
7844
7623
  }
7845
7624
  return toObject;
7846
7625
  }
7847
- function importFileResponseFromMldev(fromObject) {
7626
+ function deleteFileResponseFromMldev(fromObject) {
7848
7627
  const toObject = {};
7849
7628
  const fromSdkHttpResponse = getValueByPath(fromObject, [
7850
7629
  'sdkHttpResponse',
@@ -7852,17 +7631,17 @@ function importFileResponseFromMldev(fromObject) {
7852
7631
  if (fromSdkHttpResponse != null) {
7853
7632
  setValueByPath(toObject, ['sdkHttpResponse'], fromSdkHttpResponse);
7854
7633
  }
7855
- const fromParent = getValueByPath(fromObject, ['parent']);
7856
- if (fromParent != null) {
7857
- setValueByPath(toObject, ['parent'], fromParent);
7858
- }
7859
- const fromDocumentName = getValueByPath(fromObject, ['documentName']);
7860
- if (fromDocumentName != null) {
7861
- setValueByPath(toObject, ['documentName'], fromDocumentName);
7634
+ return toObject;
7635
+ }
7636
+ function getFileParametersToMldev(fromObject) {
7637
+ const toObject = {};
7638
+ const fromName = getValueByPath(fromObject, ['name']);
7639
+ if (fromName != null) {
7640
+ setValueByPath(toObject, ['_url', 'file'], tFileName(fromName));
7862
7641
  }
7863
7642
  return toObject;
7864
7643
  }
7865
- function listFileSearchStoresConfigToMldev(fromObject, parentObject) {
7644
+ function listFilesConfigToMldev(fromObject, parentObject) {
7866
7645
  const toObject = {};
7867
7646
  const fromPageSize = getValueByPath(fromObject, ['pageSize']);
7868
7647
  if (parentObject !== undefined && fromPageSize != null) {
@@ -7874,15 +7653,15 @@ function listFileSearchStoresConfigToMldev(fromObject, parentObject) {
7874
7653
  }
7875
7654
  return toObject;
7876
7655
  }
7877
- function listFileSearchStoresParametersToMldev(fromObject) {
7656
+ function listFilesParametersToMldev(fromObject) {
7878
7657
  const toObject = {};
7879
7658
  const fromConfig = getValueByPath(fromObject, ['config']);
7880
7659
  if (fromConfig != null) {
7881
- listFileSearchStoresConfigToMldev(fromConfig, toObject);
7660
+ listFilesConfigToMldev(fromConfig, toObject);
7882
7661
  }
7883
7662
  return toObject;
7884
7663
  }
7885
- function listFileSearchStoresResponseFromMldev(fromObject) {
7664
+ function listFilesResponseFromMldev(fromObject) {
7886
7665
  const toObject = {};
7887
7666
  const fromSdkHttpResponse = getValueByPath(fromObject, [
7888
7667
  'sdkHttpResponse',
@@ -7896,73 +7675,291 @@ function listFileSearchStoresResponseFromMldev(fromObject) {
7896
7675
  if (fromNextPageToken != null) {
7897
7676
  setValueByPath(toObject, ['nextPageToken'], fromNextPageToken);
7898
7677
  }
7899
- const fromFileSearchStores = getValueByPath(fromObject, [
7900
- 'fileSearchStores',
7901
- ]);
7902
- if (fromFileSearchStores != null) {
7903
- let transformedList = fromFileSearchStores;
7678
+ const fromFiles = getValueByPath(fromObject, ['files']);
7679
+ if (fromFiles != null) {
7680
+ let transformedList = fromFiles;
7904
7681
  if (Array.isArray(transformedList)) {
7905
7682
  transformedList = transformedList.map((item) => {
7906
7683
  return item;
7907
7684
  });
7908
7685
  }
7909
- setValueByPath(toObject, ['fileSearchStores'], transformedList);
7910
- }
7911
- return toObject;
7912
- }
7913
- function uploadToFileSearchStoreConfigToMldev(fromObject, parentObject) {
7914
- const toObject = {};
7915
- const fromMimeType = getValueByPath(fromObject, ['mimeType']);
7916
- if (parentObject !== undefined && fromMimeType != null) {
7917
- setValueByPath(parentObject, ['mimeType'], fromMimeType);
7918
- }
7919
- const fromDisplayName = getValueByPath(fromObject, ['displayName']);
7920
- if (parentObject !== undefined && fromDisplayName != null) {
7921
- setValueByPath(parentObject, ['displayName'], fromDisplayName);
7686
+ setValueByPath(toObject, ['files'], transformedList);
7687
+ }
7688
+ return toObject;
7689
+ }
7690
+
7691
+ /**
7692
+ * @license
7693
+ * Copyright 2025 Google LLC
7694
+ * SPDX-License-Identifier: Apache-2.0
7695
+ */
7696
+ class Files extends BaseModule {
7697
+ constructor(apiClient) {
7698
+ super();
7699
+ this.apiClient = apiClient;
7700
+ /**
7701
+ * Lists files.
7702
+ *
7703
+ * @param params - The parameters for the list request.
7704
+ * @return - A pager of files.
7705
+ *
7706
+ * @example
7707
+ * ```ts
7708
+ * const files = await ai.files.list({config: {'pageSize': 2}});
7709
+ * for await (const file of files) {
7710
+ * console.log(file);
7711
+ * }
7712
+ * ```
7713
+ */
7714
+ this.list = async (params = {}) => {
7715
+ return new Pager(exports.PagedItem.PAGED_ITEM_FILES, (x) => this.listInternal(x), await this.listInternal(params), params);
7716
+ };
7717
+ }
7718
+ /**
7719
+ * Uploads a file asynchronously to the Gemini API.
7720
+ * This method is not available in Vertex AI.
7721
+ * Supported upload sources:
7722
+ * - Node.js: File path (string) or Blob object.
7723
+ * - Browser: Blob object (e.g., File).
7724
+ *
7725
+ * @remarks
7726
+ * The `mimeType` can be specified in the `config` parameter. If omitted:
7727
+ * - For file path (string) inputs, the `mimeType` will be inferred from the
7728
+ * file extension.
7729
+ * - For Blob object inputs, the `mimeType` will be set to the Blob's `type`
7730
+ * property.
7731
+ * Somex eamples for file extension to mimeType mapping:
7732
+ * .txt -> text/plain
7733
+ * .json -> application/json
7734
+ * .jpg -> image/jpeg
7735
+ * .png -> image/png
7736
+ * .mp3 -> audio/mpeg
7737
+ * .mp4 -> video/mp4
7738
+ *
7739
+ * This section can contain multiple paragraphs and code examples.
7740
+ *
7741
+ * @param params - Optional parameters specified in the
7742
+ * `types.UploadFileParameters` interface.
7743
+ * @see {@link types.UploadFileParameters#config} for the optional
7744
+ * config in the parameters.
7745
+ * @return A promise that resolves to a `types.File` object.
7746
+ * @throws An error if called on a Vertex AI client.
7747
+ * @throws An error if the `mimeType` is not provided and can not be inferred,
7748
+ * the `mimeType` can be provided in the `params.config` parameter.
7749
+ * @throws An error occurs if a suitable upload location cannot be established.
7750
+ *
7751
+ * @example
7752
+ * The following code uploads a file to Gemini API.
7753
+ *
7754
+ * ```ts
7755
+ * const file = await ai.files.upload({file: 'file.txt', config: {
7756
+ * mimeType: 'text/plain',
7757
+ * }});
7758
+ * console.log(file.name);
7759
+ * ```
7760
+ */
7761
+ async upload(params) {
7762
+ if (this.apiClient.isVertexAI()) {
7763
+ throw new Error('Vertex AI does not support uploading files. You can share files through a GCS bucket.');
7764
+ }
7765
+ return this.apiClient
7766
+ .uploadFile(params.file, params.config)
7767
+ .then((resp) => {
7768
+ return resp;
7769
+ });
7770
+ }
7771
+ /**
7772
+ * Downloads a remotely stored file asynchronously to a location specified in
7773
+ * the `params` object. This method only works on Node environment, to
7774
+ * download files in the browser, use a browser compliant method like an <a>
7775
+ * tag.
7776
+ *
7777
+ * @param params - The parameters for the download request.
7778
+ *
7779
+ * @example
7780
+ * The following code downloads an example file named "files/mehozpxf877d" as
7781
+ * "file.txt".
7782
+ *
7783
+ * ```ts
7784
+ * await ai.files.download({file: file.name, downloadPath: 'file.txt'});
7785
+ * ```
7786
+ */
7787
+ async download(params) {
7788
+ await this.apiClient.downloadFile(params);
7789
+ }
7790
+ async listInternal(params) {
7791
+ var _a, _b;
7792
+ let response;
7793
+ let path = '';
7794
+ let queryParams = {};
7795
+ if (this.apiClient.isVertexAI()) {
7796
+ throw new Error('This method is only supported by the Gemini Developer API.');
7797
+ }
7798
+ else {
7799
+ const body = listFilesParametersToMldev(params);
7800
+ path = formatMap('files', body['_url']);
7801
+ queryParams = body['_query'];
7802
+ delete body['_url'];
7803
+ delete body['_query'];
7804
+ response = this.apiClient
7805
+ .request({
7806
+ path: path,
7807
+ queryParams: queryParams,
7808
+ body: JSON.stringify(body),
7809
+ httpMethod: 'GET',
7810
+ httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
7811
+ abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
7812
+ })
7813
+ .then((httpResponse) => {
7814
+ return httpResponse.json().then((jsonResponse) => {
7815
+ const response = jsonResponse;
7816
+ response.sdkHttpResponse = {
7817
+ headers: httpResponse.headers,
7818
+ };
7819
+ return response;
7820
+ });
7821
+ });
7822
+ return response.then((apiResponse) => {
7823
+ const resp = listFilesResponseFromMldev(apiResponse);
7824
+ const typedResp = new ListFilesResponse();
7825
+ Object.assign(typedResp, resp);
7826
+ return typedResp;
7827
+ });
7828
+ }
7829
+ }
7830
+ async createInternal(params) {
7831
+ var _a, _b;
7832
+ let response;
7833
+ let path = '';
7834
+ let queryParams = {};
7835
+ if (this.apiClient.isVertexAI()) {
7836
+ throw new Error('This method is only supported by the Gemini Developer API.');
7837
+ }
7838
+ else {
7839
+ const body = createFileParametersToMldev(params);
7840
+ path = formatMap('upload/v1beta/files', body['_url']);
7841
+ queryParams = body['_query'];
7842
+ delete body['_url'];
7843
+ delete body['_query'];
7844
+ response = this.apiClient
7845
+ .request({
7846
+ path: path,
7847
+ queryParams: queryParams,
7848
+ body: JSON.stringify(body),
7849
+ httpMethod: 'POST',
7850
+ httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
7851
+ abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
7852
+ })
7853
+ .then((httpResponse) => {
7854
+ return httpResponse.json();
7855
+ });
7856
+ return response.then((apiResponse) => {
7857
+ const resp = createFileResponseFromMldev(apiResponse);
7858
+ const typedResp = new CreateFileResponse();
7859
+ Object.assign(typedResp, resp);
7860
+ return typedResp;
7861
+ });
7862
+ }
7922
7863
  }
7923
- const fromCustomMetadata = getValueByPath(fromObject, [
7924
- 'customMetadata',
7925
- ]);
7926
- if (parentObject !== undefined && fromCustomMetadata != null) {
7927
- let transformedList = fromCustomMetadata;
7928
- if (Array.isArray(transformedList)) {
7929
- transformedList = transformedList.map((item) => {
7930
- return item;
7864
+ /**
7865
+ * Retrieves the file information from the service.
7866
+ *
7867
+ * @param params - The parameters for the get request
7868
+ * @return The Promise that resolves to the types.File object requested.
7869
+ *
7870
+ * @example
7871
+ * ```ts
7872
+ * const config: GetFileParameters = {
7873
+ * name: fileName,
7874
+ * };
7875
+ * file = await ai.files.get(config);
7876
+ * console.log(file.name);
7877
+ * ```
7878
+ */
7879
+ async get(params) {
7880
+ var _a, _b;
7881
+ let response;
7882
+ let path = '';
7883
+ let queryParams = {};
7884
+ if (this.apiClient.isVertexAI()) {
7885
+ throw new Error('This method is only supported by the Gemini Developer API.');
7886
+ }
7887
+ else {
7888
+ const body = getFileParametersToMldev(params);
7889
+ path = formatMap('files/{file}', body['_url']);
7890
+ queryParams = body['_query'];
7891
+ delete body['_url'];
7892
+ delete body['_query'];
7893
+ response = this.apiClient
7894
+ .request({
7895
+ path: path,
7896
+ queryParams: queryParams,
7897
+ body: JSON.stringify(body),
7898
+ httpMethod: 'GET',
7899
+ httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
7900
+ abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
7901
+ })
7902
+ .then((httpResponse) => {
7903
+ return httpResponse.json();
7904
+ });
7905
+ return response.then((resp) => {
7906
+ return resp;
7931
7907
  });
7932
7908
  }
7933
- setValueByPath(parentObject, ['customMetadata'], transformedList);
7934
- }
7935
- const fromChunkingConfig = getValueByPath(fromObject, [
7936
- 'chunkingConfig',
7937
- ]);
7938
- if (parentObject !== undefined && fromChunkingConfig != null) {
7939
- setValueByPath(parentObject, ['chunkingConfig'], fromChunkingConfig);
7940
- }
7941
- return toObject;
7942
- }
7943
- function uploadToFileSearchStoreParametersToMldev(fromObject) {
7944
- const toObject = {};
7945
- const fromFileSearchStoreName = getValueByPath(fromObject, [
7946
- 'fileSearchStoreName',
7947
- ]);
7948
- if (fromFileSearchStoreName != null) {
7949
- setValueByPath(toObject, ['_url', 'file_search_store_name'], fromFileSearchStoreName);
7950
- }
7951
- const fromConfig = getValueByPath(fromObject, ['config']);
7952
- if (fromConfig != null) {
7953
- uploadToFileSearchStoreConfigToMldev(fromConfig, toObject);
7954
7909
  }
7955
- return toObject;
7956
- }
7957
- function uploadToFileSearchStoreResumableResponseFromMldev(fromObject) {
7958
- const toObject = {};
7959
- const fromSdkHttpResponse = getValueByPath(fromObject, [
7960
- 'sdkHttpResponse',
7961
- ]);
7962
- if (fromSdkHttpResponse != null) {
7963
- setValueByPath(toObject, ['sdkHttpResponse'], fromSdkHttpResponse);
7910
+ /**
7911
+ * Deletes a remotely stored file.
7912
+ *
7913
+ * @param params - The parameters for the delete request.
7914
+ * @return The DeleteFileResponse, the response for the delete method.
7915
+ *
7916
+ * @example
7917
+ * The following code deletes an example file named "files/mehozpxf877d".
7918
+ *
7919
+ * ```ts
7920
+ * await ai.files.delete({name: file.name});
7921
+ * ```
7922
+ */
7923
+ async delete(params) {
7924
+ var _a, _b;
7925
+ let response;
7926
+ let path = '';
7927
+ let queryParams = {};
7928
+ if (this.apiClient.isVertexAI()) {
7929
+ throw new Error('This method is only supported by the Gemini Developer API.');
7930
+ }
7931
+ else {
7932
+ const body = deleteFileParametersToMldev(params);
7933
+ path = formatMap('files/{file}', body['_url']);
7934
+ queryParams = body['_query'];
7935
+ delete body['_url'];
7936
+ delete body['_query'];
7937
+ response = this.apiClient
7938
+ .request({
7939
+ path: path,
7940
+ queryParams: queryParams,
7941
+ body: JSON.stringify(body),
7942
+ httpMethod: 'DELETE',
7943
+ httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
7944
+ abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
7945
+ })
7946
+ .then((httpResponse) => {
7947
+ return httpResponse.json().then((jsonResponse) => {
7948
+ const response = jsonResponse;
7949
+ response.sdkHttpResponse = {
7950
+ headers: httpResponse.headers,
7951
+ };
7952
+ return response;
7953
+ });
7954
+ });
7955
+ return response.then((apiResponse) => {
7956
+ const resp = deleteFileResponseFromMldev(apiResponse);
7957
+ const typedResp = new DeleteFileResponse();
7958
+ Object.assign(typedResp, resp);
7959
+ return typedResp;
7960
+ });
7961
+ }
7964
7962
  }
7965
- return toObject;
7966
7963
  }
7967
7964
 
7968
7965
  /**
@@ -8067,17 +8064,14 @@ class Documents extends BaseModule {
8067
8064
  *
8068
8065
  * @example
8069
8066
  * ```ts
8070
- * const documents = await ai.documents.list({config: {'pageSize': 2}});
8067
+ * const documents = await ai.documents.list({parent:'rag_store_name', config: {'pageSize': 2}});
8071
8068
  * for await (const document of documents) {
8072
8069
  * console.log(document);
8073
8070
  * }
8074
8071
  * ```
8075
8072
  */
8076
8073
  this.list = async (params) => {
8077
- return new Pager(exports.PagedItem.PAGED_ITEM_DOCUMENTS, (x) => this.listInternal({
8078
- parent: params.parent,
8079
- config: x.config,
8080
- }), await this.listInternal(params), params);
8074
+ return new Pager(exports.PagedItem.PAGED_ITEM_DOCUMENTS, (x) => this.listInternal({ parent: params.parent, config: x.config }), await this.listInternal(params), params);
8081
8075
  };
8082
8076
  }
8083
8077
  /**
@@ -8145,12 +8139,6 @@ class Documents extends BaseModule {
8145
8139
  });
8146
8140
  }
8147
8141
  }
8148
- /**
8149
- * Lists all Documents in a FileSearchStore.
8150
- *
8151
- * @param params - The parameters for listing documents.
8152
- * @return ListDocumentsResponse.
8153
- */
8154
8142
  async listInternal(params) {
8155
8143
  var _a, _b;
8156
8144
  let response;
@@ -8359,12 +8347,6 @@ class FileSearchStores extends BaseModule {
8359
8347
  });
8360
8348
  }
8361
8349
  }
8362
- /**
8363
- * Lists all FileSearchStore owned by the user.
8364
- *
8365
- * @param params - The parameters for listing file search stores.
8366
- * @return ListFileSearchStoresResponse.
8367
- */
8368
8350
  async listInternal(params) {
8369
8351
  var _a, _b;
8370
8352
  let response;
@@ -15940,6 +15922,26 @@ function cancelTuningJobParametersToVertex(fromObject, _rootObject) {
15940
15922
  }
15941
15923
  return toObject;
15942
15924
  }
15925
+ function cancelTuningJobResponseFromMldev(fromObject, _rootObject) {
15926
+ const toObject = {};
15927
+ const fromSdkHttpResponse = getValueByPath(fromObject, [
15928
+ 'sdkHttpResponse',
15929
+ ]);
15930
+ if (fromSdkHttpResponse != null) {
15931
+ setValueByPath(toObject, ['sdkHttpResponse'], fromSdkHttpResponse);
15932
+ }
15933
+ return toObject;
15934
+ }
15935
+ function cancelTuningJobResponseFromVertex(fromObject, _rootObject) {
15936
+ const toObject = {};
15937
+ const fromSdkHttpResponse = getValueByPath(fromObject, [
15938
+ 'sdkHttpResponse',
15939
+ ]);
15940
+ if (fromSdkHttpResponse != null) {
15941
+ setValueByPath(toObject, ['sdkHttpResponse'], fromSdkHttpResponse);
15942
+ }
15943
+ return toObject;
15944
+ }
15943
15945
  function createTuningJobConfigToMldev(fromObject, parentObject, _rootObject) {
15944
15946
  const toObject = {};
15945
15947
  if (getValueByPath(fromObject, ['validationDataset']) !== undefined) {
@@ -16601,28 +16603,33 @@ class Tunings extends BaseModule {
16601
16603
  super();
16602
16604
  this.apiClient = apiClient;
16603
16605
  /**
16604
- * Gets a TuningJob.
16606
+ * Lists tuning jobs.
16605
16607
  *
16606
- * @param name - The resource name of the tuning job.
16607
- * @return - A TuningJob object.
16608
+ * @param params - The parameters for the list request.
16609
+ * @return - A pager of tuning jobs.
16608
16610
  *
16609
- * @experimental - The SDK's tuning implementation is experimental, and may
16610
- * change in future versions.
16611
+ * @example
16612
+ * ```ts
16613
+ * const tuningJobs = await ai.tunings.list({config: {'pageSize': 2}});
16614
+ * for await (const tuningJob of tuningJobs) {
16615
+ * console.log(tuningJob);
16616
+ * }
16617
+ * ```
16611
16618
  */
16612
- this.get = async (params) => {
16613
- return await this.getInternal(params);
16619
+ this.list = async (params = {}) => {
16620
+ return new Pager(exports.PagedItem.PAGED_ITEM_TUNING_JOBS, (x) => this.listInternal(x), await this.listInternal(params), params);
16614
16621
  };
16615
16622
  /**
16616
- * Lists tuning jobs.
16623
+ * Gets a TuningJob.
16617
16624
  *
16618
- * @param config - The configuration for the list request.
16619
- * @return - A list of tuning jobs.
16625
+ * @param name - The resource name of the tuning job.
16626
+ * @return - A TuningJob object.
16620
16627
  *
16621
16628
  * @experimental - The SDK's tuning implementation is experimental, and may
16622
16629
  * change in future versions.
16623
16630
  */
16624
- this.list = async (params = {}) => {
16625
- return new Pager(exports.PagedItem.PAGED_ITEM_TUNING_JOBS, (x) => this.listInternal(x), await this.listInternal(params), params);
16631
+ this.get = async (params) => {
16632
+ return await this.getInternal(params);
16626
16633
  };
16627
16634
  /**
16628
16635
  * Creates a supervised fine-tuning job.
@@ -16817,6 +16824,7 @@ class Tunings extends BaseModule {
16817
16824
  */
16818
16825
  async cancel(params) {
16819
16826
  var _a, _b, _c, _d;
16827
+ let response;
16820
16828
  let path = '';
16821
16829
  let queryParams = {};
16822
16830
  if (this.apiClient.isVertexAI()) {
@@ -16825,13 +16833,29 @@ class Tunings extends BaseModule {
16825
16833
  queryParams = body['_query'];
16826
16834
  delete body['_url'];
16827
16835
  delete body['_query'];
16828
- await this.apiClient.request({
16836
+ response = this.apiClient
16837
+ .request({
16829
16838
  path: path,
16830
16839
  queryParams: queryParams,
16831
16840
  body: JSON.stringify(body),
16832
16841
  httpMethod: 'POST',
16833
16842
  httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
16834
16843
  abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
16844
+ })
16845
+ .then((httpResponse) => {
16846
+ return httpResponse.json().then((jsonResponse) => {
16847
+ const response = jsonResponse;
16848
+ response.sdkHttpResponse = {
16849
+ headers: httpResponse.headers,
16850
+ };
16851
+ return response;
16852
+ });
16853
+ });
16854
+ return response.then((apiResponse) => {
16855
+ const resp = cancelTuningJobResponseFromVertex(apiResponse);
16856
+ const typedResp = new CancelTuningJobResponse();
16857
+ Object.assign(typedResp, resp);
16858
+ return typedResp;
16835
16859
  });
16836
16860
  }
16837
16861
  else {
@@ -16840,13 +16864,29 @@ class Tunings extends BaseModule {
16840
16864
  queryParams = body['_query'];
16841
16865
  delete body['_url'];
16842
16866
  delete body['_query'];
16843
- await this.apiClient.request({
16867
+ response = this.apiClient
16868
+ .request({
16844
16869
  path: path,
16845
16870
  queryParams: queryParams,
16846
16871
  body: JSON.stringify(body),
16847
16872
  httpMethod: 'POST',
16848
16873
  httpOptions: (_c = params.config) === null || _c === void 0 ? void 0 : _c.httpOptions,
16849
16874
  abortSignal: (_d = params.config) === null || _d === void 0 ? void 0 : _d.abortSignal,
16875
+ })
16876
+ .then((httpResponse) => {
16877
+ return httpResponse.json().then((jsonResponse) => {
16878
+ const response = jsonResponse;
16879
+ response.sdkHttpResponse = {
16880
+ headers: httpResponse.headers,
16881
+ };
16882
+ return response;
16883
+ });
16884
+ });
16885
+ return response.then((apiResponse) => {
16886
+ const resp = cancelTuningJobResponseFromMldev(apiResponse);
16887
+ const typedResp = new CancelTuningJobResponse();
16888
+ Object.assign(typedResp, resp);
16889
+ return typedResp;
16850
16890
  });
16851
16891
  }
16852
16892
  }
@@ -17001,13 +17041,14 @@ class GoogleGenAI {
17001
17041
  this.vertexai = (_a = options.vertexai) !== null && _a !== void 0 ? _a : false;
17002
17042
  this.apiKey = options.apiKey;
17003
17043
  this.apiVersion = options.apiVersion;
17044
+ this.httpOptions = options.httpOptions;
17004
17045
  const auth = new WebAuth(this.apiKey);
17005
17046
  this.apiClient = new ApiClient({
17006
17047
  auth: auth,
17007
17048
  apiVersion: this.apiVersion,
17008
17049
  apiKey: this.apiKey,
17009
17050
  vertexai: this.vertexai,
17010
- httpOptions: options.httpOptions,
17051
+ httpOptions: this.httpOptions,
17011
17052
  userAgentExtra: LANGUAGE_LABEL_PREFIX + 'cross',
17012
17053
  uploader: new CrossUploader(),
17013
17054
  downloader: new CrossDownloader(),
@@ -17028,6 +17069,7 @@ class GoogleGenAI {
17028
17069
  exports.ApiError = ApiError;
17029
17070
  exports.Batches = Batches;
17030
17071
  exports.Caches = Caches;
17072
+ exports.CancelTuningJobResponse = CancelTuningJobResponse;
17031
17073
  exports.Chat = Chat;
17032
17074
  exports.Chats = Chats;
17033
17075
  exports.ComputeTokensResponse = ComputeTokensResponse;