@google/genai 1.40.0 → 1.41.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 +23 -10
- package/dist/index.cjs +51 -4
- package/dist/index.mjs +51 -4
- package/dist/index.mjs.map +1 -1
- package/dist/node/index.cjs +50 -4
- package/dist/node/index.mjs +50 -4
- package/dist/node/index.mjs.map +1 -1
- package/dist/node/node.d.ts +23 -10
- package/dist/tokenizer/node.d.ts +9 -0
- package/dist/tokenizer/node.mjs.map +1 -1
- package/dist/web/index.mjs +51 -4
- package/dist/web/index.mjs.map +1 -1
- package/dist/web/web.d.ts +23 -10
- package/package.json +3 -2
package/dist/node/index.cjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var pRetry = require('p-retry');
|
|
3
4
|
var googleAuthLibrary = require('google-auth-library');
|
|
4
5
|
var fs = require('fs');
|
|
5
6
|
var fs$1 = require('fs/promises');
|
|
@@ -11639,10 +11640,22 @@ const CONTENT_TYPE_HEADER = 'Content-Type';
|
|
|
11639
11640
|
const SERVER_TIMEOUT_HEADER = 'X-Server-Timeout';
|
|
11640
11641
|
const USER_AGENT_HEADER = 'User-Agent';
|
|
11641
11642
|
const GOOGLE_API_CLIENT_HEADER = 'x-goog-api-client';
|
|
11642
|
-
const SDK_VERSION = '1.
|
|
11643
|
+
const SDK_VERSION = '1.41.0'; // x-release-please-version
|
|
11643
11644
|
const LIBRARY_LABEL = `google-genai-sdk/${SDK_VERSION}`;
|
|
11644
11645
|
const VERTEX_AI_API_DEFAULT_VERSION = 'v1beta1';
|
|
11645
11646
|
const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
|
|
11647
|
+
// Default retry options.
|
|
11648
|
+
// The config is based on https://cloud.google.com/storage/docs/retry-strategy.
|
|
11649
|
+
const DEFAULT_RETRY_ATTEMPTS = 5; // Including the initial call
|
|
11650
|
+
// LINT.IfChange
|
|
11651
|
+
const DEFAULT_RETRY_HTTP_STATUS_CODES = [
|
|
11652
|
+
408, // Request timeout
|
|
11653
|
+
429, // Too many requests
|
|
11654
|
+
500, // Internal server error
|
|
11655
|
+
502, // Bad gateway
|
|
11656
|
+
503, // Service unavailable
|
|
11657
|
+
504, // Gateway timeout
|
|
11658
|
+
];
|
|
11646
11659
|
/**
|
|
11647
11660
|
* The ApiClient class is used to send requests to the Gemini API or Vertex AI
|
|
11648
11661
|
* endpoints.
|
|
@@ -12027,8 +12040,25 @@ class ApiClient {
|
|
|
12027
12040
|
});
|
|
12028
12041
|
}
|
|
12029
12042
|
async apiCall(url, requestInit) {
|
|
12030
|
-
|
|
12031
|
-
|
|
12043
|
+
var _a;
|
|
12044
|
+
if (!this.clientOptions.httpOptions ||
|
|
12045
|
+
!this.clientOptions.httpOptions.retryOptions) {
|
|
12046
|
+
return fetch(url, requestInit);
|
|
12047
|
+
}
|
|
12048
|
+
const retryOptions = this.clientOptions.httpOptions.retryOptions;
|
|
12049
|
+
const runFetch = async () => {
|
|
12050
|
+
const response = await fetch(url, requestInit);
|
|
12051
|
+
if (response.ok) {
|
|
12052
|
+
return response;
|
|
12053
|
+
}
|
|
12054
|
+
if (DEFAULT_RETRY_HTTP_STATUS_CODES.includes(response.status)) {
|
|
12055
|
+
throw new Error(`Retryable HTTP Error: ${response.statusText}`);
|
|
12056
|
+
}
|
|
12057
|
+
throw new pRetry.AbortError(`Non-retryable exception ${response.statusText} sending request`);
|
|
12058
|
+
};
|
|
12059
|
+
return pRetry(runFetch, {
|
|
12060
|
+
// Retry attempts is one less than the number of total attempts.
|
|
12061
|
+
retries: ((_a = retryOptions.attempts) !== null && _a !== void 0 ? _a : DEFAULT_RETRY_ATTEMPTS) - 1,
|
|
12032
12062
|
});
|
|
12033
12063
|
}
|
|
12034
12064
|
getDefaultHeaders() {
|
|
@@ -17876,7 +17906,7 @@ class BaseGeminiNextGenAPIClient {
|
|
|
17876
17906
|
}
|
|
17877
17907
|
async fetchWithTimeout(url, init, ms, controller) {
|
|
17878
17908
|
const _b = init || {}, { signal, method } = _b, options = __rest(_b, ["signal", "method"]);
|
|
17879
|
-
const abort =
|
|
17909
|
+
const abort = this._makeAbort(controller);
|
|
17880
17910
|
if (signal)
|
|
17881
17911
|
signal.addEventListener('abort', abort, { once: true });
|
|
17882
17912
|
const timeout = setTimeout(abort, ms);
|
|
@@ -17992,6 +18022,11 @@ class BaseGeminiNextGenAPIClient {
|
|
|
17992
18022
|
this.validateHeaders(headers);
|
|
17993
18023
|
return headers.values;
|
|
17994
18024
|
}
|
|
18025
|
+
_makeAbort(controller) {
|
|
18026
|
+
// note: we can't just inline this method inside `fetchWithTimeout()` because then the closure
|
|
18027
|
+
// would capture all request options, and cause a memory leak.
|
|
18028
|
+
return () => controller.abort();
|
|
18029
|
+
}
|
|
17995
18030
|
buildBody({ options: { body, headers: rawHeaders } }) {
|
|
17996
18031
|
if (!body) {
|
|
17997
18032
|
return { bodyHeaders: undefined, body: undefined };
|
|
@@ -18341,6 +18376,9 @@ function createTuningJobConfigToMldev(fromObject, parentObject, _rootObject) {
|
|
|
18341
18376
|
if (getValueByPath(fromObject, ['outputUri']) !== undefined) {
|
|
18342
18377
|
throw new Error('outputUri parameter is not supported in Gemini API.');
|
|
18343
18378
|
}
|
|
18379
|
+
if (getValueByPath(fromObject, ['encryptionSpec']) !== undefined) {
|
|
18380
|
+
throw new Error('encryptionSpec parameter is not supported in Gemini API.');
|
|
18381
|
+
}
|
|
18344
18382
|
return toObject;
|
|
18345
18383
|
}
|
|
18346
18384
|
function createTuningJobConfigToVertex(fromObject, parentObject, rootObject) {
|
|
@@ -18576,6 +18614,12 @@ function createTuningJobConfigToVertex(fromObject, parentObject, rootObject) {
|
|
|
18576
18614
|
if (parentObject !== undefined && fromOutputUri != null) {
|
|
18577
18615
|
setValueByPath(parentObject, ['outputUri'], fromOutputUri);
|
|
18578
18616
|
}
|
|
18617
|
+
const fromEncryptionSpec = getValueByPath(fromObject, [
|
|
18618
|
+
'encryptionSpec',
|
|
18619
|
+
]);
|
|
18620
|
+
if (parentObject !== undefined && fromEncryptionSpec != null) {
|
|
18621
|
+
setValueByPath(parentObject, ['encryptionSpec'], fromEncryptionSpec);
|
|
18622
|
+
}
|
|
18579
18623
|
return toObject;
|
|
18580
18624
|
}
|
|
18581
18625
|
function createTuningJobParametersPrivateToMldev(fromObject, rootObject) {
|
|
@@ -19828,6 +19872,7 @@ const LANGUAGE_LABEL_PREFIX = 'gl-node/';
|
|
|
19828
19872
|
*/
|
|
19829
19873
|
class GoogleGenAI {
|
|
19830
19874
|
get interactions() {
|
|
19875
|
+
var _a;
|
|
19831
19876
|
if (this._interactions !== undefined) {
|
|
19832
19877
|
return this._interactions;
|
|
19833
19878
|
}
|
|
@@ -19844,6 +19889,7 @@ class GoogleGenAI {
|
|
|
19844
19889
|
clientAdapter: this.apiClient,
|
|
19845
19890
|
defaultHeaders: this.apiClient.getDefaultHeaders(),
|
|
19846
19891
|
timeout: httpOpts === null || httpOpts === void 0 ? void 0 : httpOpts.timeout,
|
|
19892
|
+
maxRetries: (_a = httpOpts === null || httpOpts === void 0 ? void 0 : httpOpts.retryOptions) === null || _a === void 0 ? void 0 : _a.attempts,
|
|
19847
19893
|
});
|
|
19848
19894
|
this._interactions = nextGenClient.interactions;
|
|
19849
19895
|
return this._interactions;
|
package/dist/node/index.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import pRetry, { AbortError } from 'p-retry';
|
|
1
2
|
import { GoogleAuth } from 'google-auth-library';
|
|
2
3
|
import { createWriteStream } from 'fs';
|
|
3
4
|
import * as fs from 'fs/promises';
|
|
@@ -11617,10 +11618,22 @@ const CONTENT_TYPE_HEADER = 'Content-Type';
|
|
|
11617
11618
|
const SERVER_TIMEOUT_HEADER = 'X-Server-Timeout';
|
|
11618
11619
|
const USER_AGENT_HEADER = 'User-Agent';
|
|
11619
11620
|
const GOOGLE_API_CLIENT_HEADER = 'x-goog-api-client';
|
|
11620
|
-
const SDK_VERSION = '1.
|
|
11621
|
+
const SDK_VERSION = '1.41.0'; // x-release-please-version
|
|
11621
11622
|
const LIBRARY_LABEL = `google-genai-sdk/${SDK_VERSION}`;
|
|
11622
11623
|
const VERTEX_AI_API_DEFAULT_VERSION = 'v1beta1';
|
|
11623
11624
|
const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
|
|
11625
|
+
// Default retry options.
|
|
11626
|
+
// The config is based on https://cloud.google.com/storage/docs/retry-strategy.
|
|
11627
|
+
const DEFAULT_RETRY_ATTEMPTS = 5; // Including the initial call
|
|
11628
|
+
// LINT.IfChange
|
|
11629
|
+
const DEFAULT_RETRY_HTTP_STATUS_CODES = [
|
|
11630
|
+
408, // Request timeout
|
|
11631
|
+
429, // Too many requests
|
|
11632
|
+
500, // Internal server error
|
|
11633
|
+
502, // Bad gateway
|
|
11634
|
+
503, // Service unavailable
|
|
11635
|
+
504, // Gateway timeout
|
|
11636
|
+
];
|
|
11624
11637
|
/**
|
|
11625
11638
|
* The ApiClient class is used to send requests to the Gemini API or Vertex AI
|
|
11626
11639
|
* endpoints.
|
|
@@ -12005,8 +12018,25 @@ class ApiClient {
|
|
|
12005
12018
|
});
|
|
12006
12019
|
}
|
|
12007
12020
|
async apiCall(url, requestInit) {
|
|
12008
|
-
|
|
12009
|
-
|
|
12021
|
+
var _a;
|
|
12022
|
+
if (!this.clientOptions.httpOptions ||
|
|
12023
|
+
!this.clientOptions.httpOptions.retryOptions) {
|
|
12024
|
+
return fetch(url, requestInit);
|
|
12025
|
+
}
|
|
12026
|
+
const retryOptions = this.clientOptions.httpOptions.retryOptions;
|
|
12027
|
+
const runFetch = async () => {
|
|
12028
|
+
const response = await fetch(url, requestInit);
|
|
12029
|
+
if (response.ok) {
|
|
12030
|
+
return response;
|
|
12031
|
+
}
|
|
12032
|
+
if (DEFAULT_RETRY_HTTP_STATUS_CODES.includes(response.status)) {
|
|
12033
|
+
throw new Error(`Retryable HTTP Error: ${response.statusText}`);
|
|
12034
|
+
}
|
|
12035
|
+
throw new AbortError(`Non-retryable exception ${response.statusText} sending request`);
|
|
12036
|
+
};
|
|
12037
|
+
return pRetry(runFetch, {
|
|
12038
|
+
// Retry attempts is one less than the number of total attempts.
|
|
12039
|
+
retries: ((_a = retryOptions.attempts) !== null && _a !== void 0 ? _a : DEFAULT_RETRY_ATTEMPTS) - 1,
|
|
12010
12040
|
});
|
|
12011
12041
|
}
|
|
12012
12042
|
getDefaultHeaders() {
|
|
@@ -17854,7 +17884,7 @@ class BaseGeminiNextGenAPIClient {
|
|
|
17854
17884
|
}
|
|
17855
17885
|
async fetchWithTimeout(url, init, ms, controller) {
|
|
17856
17886
|
const _b = init || {}, { signal, method } = _b, options = __rest(_b, ["signal", "method"]);
|
|
17857
|
-
const abort =
|
|
17887
|
+
const abort = this._makeAbort(controller);
|
|
17858
17888
|
if (signal)
|
|
17859
17889
|
signal.addEventListener('abort', abort, { once: true });
|
|
17860
17890
|
const timeout = setTimeout(abort, ms);
|
|
@@ -17970,6 +18000,11 @@ class BaseGeminiNextGenAPIClient {
|
|
|
17970
18000
|
this.validateHeaders(headers);
|
|
17971
18001
|
return headers.values;
|
|
17972
18002
|
}
|
|
18003
|
+
_makeAbort(controller) {
|
|
18004
|
+
// note: we can't just inline this method inside `fetchWithTimeout()` because then the closure
|
|
18005
|
+
// would capture all request options, and cause a memory leak.
|
|
18006
|
+
return () => controller.abort();
|
|
18007
|
+
}
|
|
17973
18008
|
buildBody({ options: { body, headers: rawHeaders } }) {
|
|
17974
18009
|
if (!body) {
|
|
17975
18010
|
return { bodyHeaders: undefined, body: undefined };
|
|
@@ -18319,6 +18354,9 @@ function createTuningJobConfigToMldev(fromObject, parentObject, _rootObject) {
|
|
|
18319
18354
|
if (getValueByPath(fromObject, ['outputUri']) !== undefined) {
|
|
18320
18355
|
throw new Error('outputUri parameter is not supported in Gemini API.');
|
|
18321
18356
|
}
|
|
18357
|
+
if (getValueByPath(fromObject, ['encryptionSpec']) !== undefined) {
|
|
18358
|
+
throw new Error('encryptionSpec parameter is not supported in Gemini API.');
|
|
18359
|
+
}
|
|
18322
18360
|
return toObject;
|
|
18323
18361
|
}
|
|
18324
18362
|
function createTuningJobConfigToVertex(fromObject, parentObject, rootObject) {
|
|
@@ -18554,6 +18592,12 @@ function createTuningJobConfigToVertex(fromObject, parentObject, rootObject) {
|
|
|
18554
18592
|
if (parentObject !== undefined && fromOutputUri != null) {
|
|
18555
18593
|
setValueByPath(parentObject, ['outputUri'], fromOutputUri);
|
|
18556
18594
|
}
|
|
18595
|
+
const fromEncryptionSpec = getValueByPath(fromObject, [
|
|
18596
|
+
'encryptionSpec',
|
|
18597
|
+
]);
|
|
18598
|
+
if (parentObject !== undefined && fromEncryptionSpec != null) {
|
|
18599
|
+
setValueByPath(parentObject, ['encryptionSpec'], fromEncryptionSpec);
|
|
18600
|
+
}
|
|
18557
18601
|
return toObject;
|
|
18558
18602
|
}
|
|
18559
18603
|
function createTuningJobParametersPrivateToMldev(fromObject, rootObject) {
|
|
@@ -19806,6 +19850,7 @@ const LANGUAGE_LABEL_PREFIX = 'gl-node/';
|
|
|
19806
19850
|
*/
|
|
19807
19851
|
class GoogleGenAI {
|
|
19808
19852
|
get interactions() {
|
|
19853
|
+
var _a;
|
|
19809
19854
|
if (this._interactions !== undefined) {
|
|
19810
19855
|
return this._interactions;
|
|
19811
19856
|
}
|
|
@@ -19822,6 +19867,7 @@ class GoogleGenAI {
|
|
|
19822
19867
|
clientAdapter: this.apiClient,
|
|
19823
19868
|
defaultHeaders: this.apiClient.getDefaultHeaders(),
|
|
19824
19869
|
timeout: httpOpts === null || httpOpts === void 0 ? void 0 : httpOpts.timeout,
|
|
19870
|
+
maxRetries: (_a = httpOpts === null || httpOpts === void 0 ? void 0 : httpOpts.retryOptions) === null || _a === void 0 ? void 0 : _a.attempts,
|
|
19825
19871
|
});
|
|
19826
19872
|
this._interactions = nextGenClient.interactions;
|
|
19827
19873
|
return this._interactions;
|