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