@google/genai 1.40.0 → 1.42.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/genai.d.ts +89 -21
- package/dist/index.cjs +263 -37
- package/dist/index.mjs +264 -38
- package/dist/index.mjs.map +1 -1
- package/dist/node/index.cjs +262 -37
- package/dist/node/index.mjs +263 -38
- package/dist/node/index.mjs.map +1 -1
- package/dist/node/node.d.ts +89 -21
- package/dist/tokenizer/node.cjs +12 -0
- package/dist/tokenizer/node.d.ts +9 -0
- package/dist/tokenizer/node.mjs +12 -0
- package/dist/tokenizer/node.mjs.map +1 -1
- package/dist/web/index.mjs +264 -38
- package/dist/web/index.mjs.map +1 -1
- package/dist/web/web.d.ts +89 -21
- package/package.json +3 -2
package/dist/web/index.mjs
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import pRetry, { AbortError } from 'p-retry';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* @license
|
|
3
5
|
* Copyright 2025 Google LLC
|
|
@@ -1356,6 +1358,18 @@ var Environment;
|
|
|
1356
1358
|
*/
|
|
1357
1359
|
Environment["ENVIRONMENT_BROWSER"] = "ENVIRONMENT_BROWSER";
|
|
1358
1360
|
})(Environment || (Environment = {}));
|
|
1361
|
+
/** Enum representing the Vertex embedding API to use. */
|
|
1362
|
+
var EmbeddingApiType;
|
|
1363
|
+
(function (EmbeddingApiType) {
|
|
1364
|
+
/**
|
|
1365
|
+
* predict API endpoint (default)
|
|
1366
|
+
*/
|
|
1367
|
+
EmbeddingApiType["PREDICT"] = "PREDICT";
|
|
1368
|
+
/**
|
|
1369
|
+
* embedContent API Endpoint
|
|
1370
|
+
*/
|
|
1371
|
+
EmbeddingApiType["EMBED_CONTENT"] = "EMBED_CONTENT";
|
|
1372
|
+
})(EmbeddingApiType || (EmbeddingApiType = {}));
|
|
1359
1373
|
/** Enum that controls the safety filter level for objectionable content. */
|
|
1360
1374
|
var SafetyFilterLevel;
|
|
1361
1375
|
(function (SafetyFilterLevel) {
|
|
@@ -3387,6 +3401,10 @@ function tJobState(state) {
|
|
|
3387
3401
|
return stateString;
|
|
3388
3402
|
}
|
|
3389
3403
|
}
|
|
3404
|
+
function tIsVertexEmbedContentModel(model) {
|
|
3405
|
+
return ((model.includes('gemini') && model !== 'gemini-embedding-001') ||
|
|
3406
|
+
model.includes('maas'));
|
|
3407
|
+
}
|
|
3390
3408
|
|
|
3391
3409
|
/**
|
|
3392
3410
|
* @license
|
|
@@ -8628,33 +8646,103 @@ function embedContentConfigToMldev(fromObject, parentObject, _rootObject) {
|
|
|
8628
8646
|
}
|
|
8629
8647
|
return toObject;
|
|
8630
8648
|
}
|
|
8631
|
-
function embedContentConfigToVertex(fromObject, parentObject,
|
|
8649
|
+
function embedContentConfigToVertex(fromObject, parentObject, rootObject) {
|
|
8632
8650
|
const toObject = {};
|
|
8633
|
-
|
|
8634
|
-
|
|
8635
|
-
|
|
8651
|
+
let discriminatorTaskType = getValueByPath(rootObject, [
|
|
8652
|
+
'embeddingApiType',
|
|
8653
|
+
]);
|
|
8654
|
+
if (discriminatorTaskType === undefined) {
|
|
8655
|
+
discriminatorTaskType = 'PREDICT';
|
|
8636
8656
|
}
|
|
8637
|
-
|
|
8638
|
-
|
|
8639
|
-
|
|
8657
|
+
if (discriminatorTaskType === 'PREDICT') {
|
|
8658
|
+
const fromTaskType = getValueByPath(fromObject, ['taskType']);
|
|
8659
|
+
if (parentObject !== undefined && fromTaskType != null) {
|
|
8660
|
+
setValueByPath(parentObject, ['instances[]', 'task_type'], fromTaskType);
|
|
8661
|
+
}
|
|
8640
8662
|
}
|
|
8641
|
-
|
|
8642
|
-
'
|
|
8663
|
+
else if (discriminatorTaskType === 'EMBED_CONTENT') {
|
|
8664
|
+
const fromTaskType = getValueByPath(fromObject, ['taskType']);
|
|
8665
|
+
if (parentObject !== undefined && fromTaskType != null) {
|
|
8666
|
+
setValueByPath(parentObject, ['taskType'], fromTaskType);
|
|
8667
|
+
}
|
|
8668
|
+
}
|
|
8669
|
+
let discriminatorTitle = getValueByPath(rootObject, [
|
|
8670
|
+
'embeddingApiType',
|
|
8643
8671
|
]);
|
|
8644
|
-
if (
|
|
8645
|
-
|
|
8672
|
+
if (discriminatorTitle === undefined) {
|
|
8673
|
+
discriminatorTitle = 'PREDICT';
|
|
8646
8674
|
}
|
|
8647
|
-
|
|
8648
|
-
|
|
8649
|
-
|
|
8675
|
+
if (discriminatorTitle === 'PREDICT') {
|
|
8676
|
+
const fromTitle = getValueByPath(fromObject, ['title']);
|
|
8677
|
+
if (parentObject !== undefined && fromTitle != null) {
|
|
8678
|
+
setValueByPath(parentObject, ['instances[]', 'title'], fromTitle);
|
|
8679
|
+
}
|
|
8680
|
+
}
|
|
8681
|
+
else if (discriminatorTitle === 'EMBED_CONTENT') {
|
|
8682
|
+
const fromTitle = getValueByPath(fromObject, ['title']);
|
|
8683
|
+
if (parentObject !== undefined && fromTitle != null) {
|
|
8684
|
+
setValueByPath(parentObject, ['title'], fromTitle);
|
|
8685
|
+
}
|
|
8686
|
+
}
|
|
8687
|
+
let discriminatorOutputDimensionality = getValueByPath(rootObject, [
|
|
8688
|
+
'embeddingApiType',
|
|
8689
|
+
]);
|
|
8690
|
+
if (discriminatorOutputDimensionality === undefined) {
|
|
8691
|
+
discriminatorOutputDimensionality = 'PREDICT';
|
|
8692
|
+
}
|
|
8693
|
+
if (discriminatorOutputDimensionality === 'PREDICT') {
|
|
8694
|
+
const fromOutputDimensionality = getValueByPath(fromObject, [
|
|
8695
|
+
'outputDimensionality',
|
|
8696
|
+
]);
|
|
8697
|
+
if (parentObject !== undefined && fromOutputDimensionality != null) {
|
|
8698
|
+
setValueByPath(parentObject, ['parameters', 'outputDimensionality'], fromOutputDimensionality);
|
|
8699
|
+
}
|
|
8700
|
+
}
|
|
8701
|
+
else if (discriminatorOutputDimensionality === 'EMBED_CONTENT') {
|
|
8702
|
+
const fromOutputDimensionality = getValueByPath(fromObject, [
|
|
8703
|
+
'outputDimensionality',
|
|
8704
|
+
]);
|
|
8705
|
+
if (parentObject !== undefined && fromOutputDimensionality != null) {
|
|
8706
|
+
setValueByPath(parentObject, ['outputDimensionality'], fromOutputDimensionality);
|
|
8707
|
+
}
|
|
8708
|
+
}
|
|
8709
|
+
let discriminatorMimeType = getValueByPath(rootObject, [
|
|
8710
|
+
'embeddingApiType',
|
|
8711
|
+
]);
|
|
8712
|
+
if (discriminatorMimeType === undefined) {
|
|
8713
|
+
discriminatorMimeType = 'PREDICT';
|
|
8650
8714
|
}
|
|
8651
|
-
|
|
8652
|
-
|
|
8653
|
-
|
|
8715
|
+
if (discriminatorMimeType === 'PREDICT') {
|
|
8716
|
+
const fromMimeType = getValueByPath(fromObject, ['mimeType']);
|
|
8717
|
+
if (parentObject !== undefined && fromMimeType != null) {
|
|
8718
|
+
setValueByPath(parentObject, ['instances[]', 'mimeType'], fromMimeType);
|
|
8719
|
+
}
|
|
8720
|
+
}
|
|
8721
|
+
let discriminatorAutoTruncate = getValueByPath(rootObject, [
|
|
8722
|
+
'embeddingApiType',
|
|
8723
|
+
]);
|
|
8724
|
+
if (discriminatorAutoTruncate === undefined) {
|
|
8725
|
+
discriminatorAutoTruncate = 'PREDICT';
|
|
8726
|
+
}
|
|
8727
|
+
if (discriminatorAutoTruncate === 'PREDICT') {
|
|
8728
|
+
const fromAutoTruncate = getValueByPath(fromObject, [
|
|
8729
|
+
'autoTruncate',
|
|
8730
|
+
]);
|
|
8731
|
+
if (parentObject !== undefined && fromAutoTruncate != null) {
|
|
8732
|
+
setValueByPath(parentObject, ['parameters', 'autoTruncate'], fromAutoTruncate);
|
|
8733
|
+
}
|
|
8734
|
+
}
|
|
8735
|
+
else if (discriminatorAutoTruncate === 'EMBED_CONTENT') {
|
|
8736
|
+
const fromAutoTruncate = getValueByPath(fromObject, [
|
|
8737
|
+
'autoTruncate',
|
|
8738
|
+
]);
|
|
8739
|
+
if (parentObject !== undefined && fromAutoTruncate != null) {
|
|
8740
|
+
setValueByPath(parentObject, ['autoTruncate'], fromAutoTruncate);
|
|
8741
|
+
}
|
|
8654
8742
|
}
|
|
8655
8743
|
return toObject;
|
|
8656
8744
|
}
|
|
8657
|
-
function
|
|
8745
|
+
function embedContentParametersPrivateToMldev(apiClient, fromObject, rootObject) {
|
|
8658
8746
|
const toObject = {};
|
|
8659
8747
|
const fromModel = getValueByPath(fromObject, ['model']);
|
|
8660
8748
|
if (fromModel != null) {
|
|
@@ -8670,6 +8758,10 @@ function embedContentParametersToMldev(apiClient, fromObject, rootObject) {
|
|
|
8670
8758
|
}
|
|
8671
8759
|
setValueByPath(toObject, ['requests[]', 'content'], transformedList);
|
|
8672
8760
|
}
|
|
8761
|
+
const fromContent = getValueByPath(fromObject, ['content']);
|
|
8762
|
+
if (fromContent != null) {
|
|
8763
|
+
contentToMldev$1(tContent(fromContent));
|
|
8764
|
+
}
|
|
8673
8765
|
const fromConfig = getValueByPath(fromObject, ['config']);
|
|
8674
8766
|
if (fromConfig != null) {
|
|
8675
8767
|
embedContentConfigToMldev(fromConfig, toObject);
|
|
@@ -8680,25 +8772,45 @@ function embedContentParametersToMldev(apiClient, fromObject, rootObject) {
|
|
|
8680
8772
|
}
|
|
8681
8773
|
return toObject;
|
|
8682
8774
|
}
|
|
8683
|
-
function
|
|
8775
|
+
function embedContentParametersPrivateToVertex(apiClient, fromObject, rootObject) {
|
|
8684
8776
|
const toObject = {};
|
|
8685
8777
|
const fromModel = getValueByPath(fromObject, ['model']);
|
|
8686
8778
|
if (fromModel != null) {
|
|
8687
8779
|
setValueByPath(toObject, ['_url', 'model'], tModel(apiClient, fromModel));
|
|
8688
8780
|
}
|
|
8689
|
-
|
|
8690
|
-
|
|
8691
|
-
|
|
8692
|
-
|
|
8693
|
-
|
|
8694
|
-
|
|
8695
|
-
|
|
8781
|
+
let discriminatorContents = getValueByPath(rootObject, [
|
|
8782
|
+
'embeddingApiType',
|
|
8783
|
+
]);
|
|
8784
|
+
if (discriminatorContents === undefined) {
|
|
8785
|
+
discriminatorContents = 'PREDICT';
|
|
8786
|
+
}
|
|
8787
|
+
if (discriminatorContents === 'PREDICT') {
|
|
8788
|
+
const fromContents = getValueByPath(fromObject, ['contents']);
|
|
8789
|
+
if (fromContents != null) {
|
|
8790
|
+
let transformedList = tContentsForEmbed(apiClient, fromContents);
|
|
8791
|
+
if (Array.isArray(transformedList)) {
|
|
8792
|
+
transformedList = transformedList.map((item) => {
|
|
8793
|
+
return item;
|
|
8794
|
+
});
|
|
8795
|
+
}
|
|
8796
|
+
setValueByPath(toObject, ['instances[]', 'content'], transformedList);
|
|
8797
|
+
}
|
|
8798
|
+
}
|
|
8799
|
+
let discriminatorContent = getValueByPath(rootObject, [
|
|
8800
|
+
'embeddingApiType',
|
|
8801
|
+
]);
|
|
8802
|
+
if (discriminatorContent === undefined) {
|
|
8803
|
+
discriminatorContent = 'PREDICT';
|
|
8804
|
+
}
|
|
8805
|
+
if (discriminatorContent === 'EMBED_CONTENT') {
|
|
8806
|
+
const fromContent = getValueByPath(fromObject, ['content']);
|
|
8807
|
+
if (fromContent != null) {
|
|
8808
|
+
setValueByPath(toObject, ['content'], tContent(fromContent));
|
|
8696
8809
|
}
|
|
8697
|
-
setValueByPath(toObject, ['instances[]', 'content'], transformedList);
|
|
8698
8810
|
}
|
|
8699
8811
|
const fromConfig = getValueByPath(fromObject, ['config']);
|
|
8700
8812
|
if (fromConfig != null) {
|
|
8701
|
-
embedContentConfigToVertex(fromConfig, toObject);
|
|
8813
|
+
embedContentConfigToVertex(fromConfig, toObject, rootObject);
|
|
8702
8814
|
}
|
|
8703
8815
|
return toObject;
|
|
8704
8816
|
}
|
|
@@ -8751,6 +8863,24 @@ function embedContentResponseFromVertex(fromObject, rootObject) {
|
|
|
8751
8863
|
if (fromMetadata != null) {
|
|
8752
8864
|
setValueByPath(toObject, ['metadata'], fromMetadata);
|
|
8753
8865
|
}
|
|
8866
|
+
if (rootObject &&
|
|
8867
|
+
getValueByPath(rootObject, ['embeddingApiType']) === 'EMBED_CONTENT') {
|
|
8868
|
+
const embedding = getValueByPath(fromObject, ['embedding']);
|
|
8869
|
+
const usageMetadata = getValueByPath(fromObject, ['usageMetadata']);
|
|
8870
|
+
const truncated = getValueByPath(fromObject, ['truncated']);
|
|
8871
|
+
if (embedding) {
|
|
8872
|
+
const stats = {};
|
|
8873
|
+
if (usageMetadata &&
|
|
8874
|
+
usageMetadata['promptTokenCount']) {
|
|
8875
|
+
stats.tokenCount = usageMetadata['promptTokenCount'];
|
|
8876
|
+
}
|
|
8877
|
+
if (truncated) {
|
|
8878
|
+
stats.truncated = truncated;
|
|
8879
|
+
}
|
|
8880
|
+
embedding.statistics = stats;
|
|
8881
|
+
setValueByPath(toObject, ['embeddings'], [embedding]);
|
|
8882
|
+
}
|
|
8883
|
+
}
|
|
8754
8884
|
return toObject;
|
|
8755
8885
|
}
|
|
8756
8886
|
function endpointFromVertex(fromObject, _rootObject) {
|
|
@@ -11608,10 +11738,22 @@ const CONTENT_TYPE_HEADER = 'Content-Type';
|
|
|
11608
11738
|
const SERVER_TIMEOUT_HEADER = 'X-Server-Timeout';
|
|
11609
11739
|
const USER_AGENT_HEADER = 'User-Agent';
|
|
11610
11740
|
const GOOGLE_API_CLIENT_HEADER = 'x-goog-api-client';
|
|
11611
|
-
const SDK_VERSION = '1.
|
|
11741
|
+
const SDK_VERSION = '1.42.0'; // x-release-please-version
|
|
11612
11742
|
const LIBRARY_LABEL = `google-genai-sdk/${SDK_VERSION}`;
|
|
11613
11743
|
const VERTEX_AI_API_DEFAULT_VERSION = 'v1beta1';
|
|
11614
11744
|
const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
|
|
11745
|
+
// Default retry options.
|
|
11746
|
+
// The config is based on https://cloud.google.com/storage/docs/retry-strategy.
|
|
11747
|
+
const DEFAULT_RETRY_ATTEMPTS = 5; // Including the initial call
|
|
11748
|
+
// LINT.IfChange
|
|
11749
|
+
const DEFAULT_RETRY_HTTP_STATUS_CODES = [
|
|
11750
|
+
408, // Request timeout
|
|
11751
|
+
429, // Too many requests
|
|
11752
|
+
500, // Internal server error
|
|
11753
|
+
502, // Bad gateway
|
|
11754
|
+
503, // Service unavailable
|
|
11755
|
+
504, // Gateway timeout
|
|
11756
|
+
];
|
|
11615
11757
|
/**
|
|
11616
11758
|
* The ApiClient class is used to send requests to the Gemini API or Vertex AI
|
|
11617
11759
|
* endpoints.
|
|
@@ -11996,8 +12138,25 @@ class ApiClient {
|
|
|
11996
12138
|
});
|
|
11997
12139
|
}
|
|
11998
12140
|
async apiCall(url, requestInit) {
|
|
11999
|
-
|
|
12000
|
-
|
|
12141
|
+
var _a;
|
|
12142
|
+
if (!this.clientOptions.httpOptions ||
|
|
12143
|
+
!this.clientOptions.httpOptions.retryOptions) {
|
|
12144
|
+
return fetch(url, requestInit);
|
|
12145
|
+
}
|
|
12146
|
+
const retryOptions = this.clientOptions.httpOptions.retryOptions;
|
|
12147
|
+
const runFetch = async () => {
|
|
12148
|
+
const response = await fetch(url, requestInit);
|
|
12149
|
+
if (response.ok) {
|
|
12150
|
+
return response;
|
|
12151
|
+
}
|
|
12152
|
+
if (DEFAULT_RETRY_HTTP_STATUS_CODES.includes(response.status)) {
|
|
12153
|
+
throw new Error(`Retryable HTTP Error: ${response.statusText}`);
|
|
12154
|
+
}
|
|
12155
|
+
throw new AbortError(`Non-retryable exception ${response.statusText} sending request`);
|
|
12156
|
+
};
|
|
12157
|
+
return pRetry(runFetch, {
|
|
12158
|
+
// Retry attempts is one less than the number of total attempts.
|
|
12159
|
+
retries: ((_a = retryOptions.attempts) !== null && _a !== void 0 ? _a : DEFAULT_RETRY_ATTEMPTS) - 1,
|
|
12001
12160
|
});
|
|
12002
12161
|
}
|
|
12003
12162
|
getDefaultHeaders() {
|
|
@@ -13180,6 +13339,47 @@ class Models extends BaseModule {
|
|
|
13180
13339
|
constructor(apiClient) {
|
|
13181
13340
|
super();
|
|
13182
13341
|
this.apiClient = apiClient;
|
|
13342
|
+
/**
|
|
13343
|
+
* Calculates embeddings for the given contents.
|
|
13344
|
+
*
|
|
13345
|
+
* @param params - The parameters for embedding contents.
|
|
13346
|
+
* @return The response from the API.
|
|
13347
|
+
*
|
|
13348
|
+
* @example
|
|
13349
|
+
* ```ts
|
|
13350
|
+
* const response = await ai.models.embedContent({
|
|
13351
|
+
* model: 'text-embedding-004',
|
|
13352
|
+
* contents: [
|
|
13353
|
+
* 'What is your name?',
|
|
13354
|
+
* 'What is your favorite color?',
|
|
13355
|
+
* ],
|
|
13356
|
+
* config: {
|
|
13357
|
+
* outputDimensionality: 64,
|
|
13358
|
+
* },
|
|
13359
|
+
* });
|
|
13360
|
+
* console.log(response);
|
|
13361
|
+
* ```
|
|
13362
|
+
*/
|
|
13363
|
+
this.embedContent = async (params) => {
|
|
13364
|
+
if (!this.apiClient.isVertexAI()) {
|
|
13365
|
+
return await this.embedContentInternal(params);
|
|
13366
|
+
}
|
|
13367
|
+
const isVertexEmbedContentModel = (params.model.includes('gemini') &&
|
|
13368
|
+
params.model !== 'gemini-embedding-001') ||
|
|
13369
|
+
params.model.includes('maas');
|
|
13370
|
+
if (isVertexEmbedContentModel) {
|
|
13371
|
+
const contents = tContents(params.contents);
|
|
13372
|
+
if (contents.length > 1) {
|
|
13373
|
+
throw new Error('The embedContent API for this model only supports one content at a time.');
|
|
13374
|
+
}
|
|
13375
|
+
const paramsPrivate = Object.assign(Object.assign({}, params), { content: contents[0], embeddingApiType: EmbeddingApiType.EMBED_CONTENT });
|
|
13376
|
+
return await this.embedContentInternal(paramsPrivate);
|
|
13377
|
+
}
|
|
13378
|
+
else {
|
|
13379
|
+
const paramsPrivate = Object.assign(Object.assign({}, params), { embeddingApiType: EmbeddingApiType.PREDICT });
|
|
13380
|
+
return await this.embedContentInternal(paramsPrivate);
|
|
13381
|
+
}
|
|
13382
|
+
};
|
|
13183
13383
|
/**
|
|
13184
13384
|
* Makes an API request to generate content with a given model.
|
|
13185
13385
|
*
|
|
@@ -13867,14 +14067,17 @@ class Models extends BaseModule {
|
|
|
13867
14067
|
* console.log(response);
|
|
13868
14068
|
* ```
|
|
13869
14069
|
*/
|
|
13870
|
-
async
|
|
14070
|
+
async embedContentInternal(params) {
|
|
13871
14071
|
var _a, _b, _c, _d;
|
|
13872
14072
|
let response;
|
|
13873
14073
|
let path = '';
|
|
13874
14074
|
let queryParams = {};
|
|
13875
14075
|
if (this.apiClient.isVertexAI()) {
|
|
13876
|
-
const body =
|
|
13877
|
-
|
|
14076
|
+
const body = embedContentParametersPrivateToVertex(this.apiClient, params, params);
|
|
14077
|
+
const endpointUrl = tIsVertexEmbedContentModel(params.model)
|
|
14078
|
+
? '{model}:embedContent'
|
|
14079
|
+
: '{model}:predict';
|
|
14080
|
+
path = formatMap(endpointUrl, body['_url']);
|
|
13878
14081
|
queryParams = body['_query'];
|
|
13879
14082
|
delete body['_url'];
|
|
13880
14083
|
delete body['_query'];
|
|
@@ -13897,14 +14100,14 @@ class Models extends BaseModule {
|
|
|
13897
14100
|
});
|
|
13898
14101
|
});
|
|
13899
14102
|
return response.then((apiResponse) => {
|
|
13900
|
-
const resp = embedContentResponseFromVertex(apiResponse);
|
|
14103
|
+
const resp = embedContentResponseFromVertex(apiResponse, params);
|
|
13901
14104
|
const typedResp = new EmbedContentResponse();
|
|
13902
14105
|
Object.assign(typedResp, resp);
|
|
13903
14106
|
return typedResp;
|
|
13904
14107
|
});
|
|
13905
14108
|
}
|
|
13906
14109
|
else {
|
|
13907
|
-
const body =
|
|
14110
|
+
const body = embedContentParametersPrivateToMldev(this.apiClient, params);
|
|
13908
14111
|
path = formatMap('{model}:batchEmbedContents', body['_url']);
|
|
13909
14112
|
queryParams = body['_query'];
|
|
13910
14113
|
delete body['_url'];
|
|
@@ -17845,7 +18048,7 @@ class BaseGeminiNextGenAPIClient {
|
|
|
17845
18048
|
}
|
|
17846
18049
|
async fetchWithTimeout(url, init, ms, controller) {
|
|
17847
18050
|
const _b = init || {}, { signal, method } = _b, options = __rest(_b, ["signal", "method"]);
|
|
17848
|
-
const abort =
|
|
18051
|
+
const abort = this._makeAbort(controller);
|
|
17849
18052
|
if (signal)
|
|
17850
18053
|
signal.addEventListener('abort', abort, { once: true });
|
|
17851
18054
|
const timeout = setTimeout(abort, ms);
|
|
@@ -17961,6 +18164,11 @@ class BaseGeminiNextGenAPIClient {
|
|
|
17961
18164
|
this.validateHeaders(headers);
|
|
17962
18165
|
return headers.values;
|
|
17963
18166
|
}
|
|
18167
|
+
_makeAbort(controller) {
|
|
18168
|
+
// note: we can't just inline this method inside `fetchWithTimeout()` because then the closure
|
|
18169
|
+
// would capture all request options, and cause a memory leak.
|
|
18170
|
+
return () => controller.abort();
|
|
18171
|
+
}
|
|
17964
18172
|
buildBody({ options: { body, headers: rawHeaders } }) {
|
|
17965
18173
|
if (!body) {
|
|
17966
18174
|
return { bodyHeaders: undefined, body: undefined };
|
|
@@ -17989,6 +18197,13 @@ class BaseGeminiNextGenAPIClient {
|
|
|
17989
18197
|
(Symbol.iterator in body && 'next' in body && typeof body.next === 'function'))) {
|
|
17990
18198
|
return { bodyHeaders: undefined, body: ReadableStreamFrom(body) };
|
|
17991
18199
|
}
|
|
18200
|
+
else if (typeof body === 'object' &&
|
|
18201
|
+
headers.values.get('content-type') === 'application/x-www-form-urlencoded') {
|
|
18202
|
+
return {
|
|
18203
|
+
bodyHeaders: { 'content-type': 'application/x-www-form-urlencoded' },
|
|
18204
|
+
body: this.stringifyQuery(body),
|
|
18205
|
+
};
|
|
18206
|
+
}
|
|
17992
18207
|
else {
|
|
17993
18208
|
return this.encoder({ body, headers });
|
|
17994
18209
|
}
|
|
@@ -18131,6 +18346,9 @@ function createTuningJobConfigToMldev(fromObject, parentObject, _rootObject) {
|
|
|
18131
18346
|
if (getValueByPath(fromObject, ['outputUri']) !== undefined) {
|
|
18132
18347
|
throw new Error('outputUri parameter is not supported in Gemini API.');
|
|
18133
18348
|
}
|
|
18349
|
+
if (getValueByPath(fromObject, ['encryptionSpec']) !== undefined) {
|
|
18350
|
+
throw new Error('encryptionSpec parameter is not supported in Gemini API.');
|
|
18351
|
+
}
|
|
18134
18352
|
return toObject;
|
|
18135
18353
|
}
|
|
18136
18354
|
function createTuningJobConfigToVertex(fromObject, parentObject, rootObject) {
|
|
@@ -18366,6 +18584,12 @@ function createTuningJobConfigToVertex(fromObject, parentObject, rootObject) {
|
|
|
18366
18584
|
if (parentObject !== undefined && fromOutputUri != null) {
|
|
18367
18585
|
setValueByPath(parentObject, ['outputUri'], fromOutputUri);
|
|
18368
18586
|
}
|
|
18587
|
+
const fromEncryptionSpec = getValueByPath(fromObject, [
|
|
18588
|
+
'encryptionSpec',
|
|
18589
|
+
]);
|
|
18590
|
+
if (parentObject !== undefined && fromEncryptionSpec != null) {
|
|
18591
|
+
setValueByPath(parentObject, ['encryptionSpec'], fromEncryptionSpec);
|
|
18592
|
+
}
|
|
18369
18593
|
return toObject;
|
|
18370
18594
|
}
|
|
18371
18595
|
function createTuningJobParametersPrivateToMldev(fromObject, rootObject) {
|
|
@@ -19454,6 +19678,7 @@ const LANGUAGE_LABEL_PREFIX = 'gl-node/';
|
|
|
19454
19678
|
*/
|
|
19455
19679
|
class GoogleGenAI {
|
|
19456
19680
|
get interactions() {
|
|
19681
|
+
var _a;
|
|
19457
19682
|
if (this._interactions !== undefined) {
|
|
19458
19683
|
return this._interactions;
|
|
19459
19684
|
}
|
|
@@ -19470,6 +19695,7 @@ class GoogleGenAI {
|
|
|
19470
19695
|
clientAdapter: this.apiClient,
|
|
19471
19696
|
defaultHeaders: this.apiClient.getDefaultHeaders(),
|
|
19472
19697
|
timeout: httpOpts === null || httpOpts === void 0 ? void 0 : httpOpts.timeout,
|
|
19698
|
+
maxRetries: (_a = httpOpts === null || httpOpts === void 0 ? void 0 : httpOpts.retryOptions) === null || _a === void 0 ? void 0 : _a.attempts,
|
|
19473
19699
|
});
|
|
19474
19700
|
this._interactions = nextGenClient.interactions;
|
|
19475
19701
|
return this._interactions;
|
|
@@ -19522,5 +19748,5 @@ class GoogleGenAI {
|
|
|
19522
19748
|
}
|
|
19523
19749
|
}
|
|
19524
19750
|
|
|
19525
|
-
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, Models, MusicGenerationMode, Operations, Outcome, PagedItem, Pager, PartMediaResolutionLevel, PersonGeneration, PhishBlockThreshold, RawReferenceImage, RecontextImageResponse, RegisterFilesResponse, ReplayResponse, ResourceScope, SafetyFilterLevel, Scale, SegmentImageResponse, SegmentMode, Session, SingleEmbedContentResponse, StartSensitivity, StyleReferenceImage, SubjectReferenceImage, SubjectReferenceType, ThinkingLevel, Tokens, TrafficType, TuningMethod, TuningMode, TuningTask, TurnCompleteReason, TurnCoverage, Type, UploadToFileSearchStoreOperation, UploadToFileSearchStoreResponse, UploadToFileSearchStoreResumableResponse, UpscaleImageResponse, UrlRetrievalStatus, VadSignalType, VideoCompressionQuality, VideoGenerationMaskMode, VideoGenerationReferenceType, VoiceActivityType, createFunctionResponsePartFromBase64, createFunctionResponsePartFromUri, createModelContent, createPartFromBase64, createPartFromCodeExecutionResult, createPartFromExecutableCode, createPartFromFunctionCall, createPartFromFunctionResponse, createPartFromText, createPartFromUri, createUserContent, mcpToTool, setDefaultBaseUrls };
|
|
19751
|
+
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, EmbeddingApiType, 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, Models, MusicGenerationMode, Operations, Outcome, PagedItem, Pager, PartMediaResolutionLevel, PersonGeneration, PhishBlockThreshold, RawReferenceImage, RecontextImageResponse, RegisterFilesResponse, ReplayResponse, ResourceScope, SafetyFilterLevel, Scale, SegmentImageResponse, SegmentMode, Session, SingleEmbedContentResponse, StartSensitivity, StyleReferenceImage, SubjectReferenceImage, SubjectReferenceType, ThinkingLevel, Tokens, TrafficType, TuningMethod, TuningMode, TuningTask, TurnCompleteReason, TurnCoverage, Type, UploadToFileSearchStoreOperation, UploadToFileSearchStoreResponse, UploadToFileSearchStoreResumableResponse, UpscaleImageResponse, UrlRetrievalStatus, VadSignalType, VideoCompressionQuality, VideoGenerationMaskMode, VideoGenerationReferenceType, VoiceActivityType, createFunctionResponsePartFromBase64, createFunctionResponsePartFromUri, createModelContent, createPartFromBase64, createPartFromCodeExecutionResult, createPartFromExecutableCode, createPartFromFunctionCall, createPartFromFunctionResponse, createPartFromText, createPartFromUri, createUserContent, mcpToTool, setDefaultBaseUrls };
|
|
19526
19752
|
//# sourceMappingURL=index.mjs.map
|