@google/genai 1.51.0 → 2.0.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/README.md +1 -4
- package/dist/genai.d.ts +467 -429
- package/dist/index.cjs +80 -15
- package/dist/index.mjs +80 -15
- package/dist/index.mjs.map +1 -1
- package/dist/node/index.cjs +80 -15
- package/dist/node/index.mjs +80 -15
- package/dist/node/index.mjs.map +1 -1
- package/dist/node/node.d.ts +467 -429
- package/dist/tokenizer/node.mjs.map +1 -1
- package/dist/vertex_internal/index.cjs +143 -123
- package/dist/vertex_internal/index.cjs.map +1 -1
- package/dist/vertex_internal/index.d.ts +22 -0
- package/dist/vertex_internal/index.js +143 -123
- package/dist/vertex_internal/index.js.map +1 -1
- package/dist/web/index.mjs +80 -15
- package/dist/web/index.mjs.map +1 -1
- package/dist/web/web.d.ts +467 -429
- package/package.json +2 -2
|
@@ -295,60 +295,6 @@ function _moveValueRecursive(data, sourceKeys, destKeys, keyIdx, excludeKeys) {
|
|
|
295
295
|
}
|
|
296
296
|
}
|
|
297
297
|
|
|
298
|
-
/**
|
|
299
|
-
* @license
|
|
300
|
-
* Copyright 2025 Google LLC
|
|
301
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
302
|
-
*/
|
|
303
|
-
// Code generated by the Google Gen AI SDK generator DO NOT EDIT.
|
|
304
|
-
function uploadToFileSearchStoreConfigToMldev(fromObject, parentObject) {
|
|
305
|
-
const toObject = {};
|
|
306
|
-
const fromMimeType = getValueByPath(fromObject, ['mimeType']);
|
|
307
|
-
if (parentObject !== undefined && fromMimeType != null) {
|
|
308
|
-
setValueByPath(parentObject, ['mimeType'], fromMimeType);
|
|
309
|
-
}
|
|
310
|
-
const fromDisplayName = getValueByPath(fromObject, ['displayName']);
|
|
311
|
-
if (parentObject !== undefined && fromDisplayName != null) {
|
|
312
|
-
setValueByPath(parentObject, ['displayName'], fromDisplayName);
|
|
313
|
-
}
|
|
314
|
-
const fromCustomMetadata = getValueByPath(fromObject, [
|
|
315
|
-
'customMetadata',
|
|
316
|
-
]);
|
|
317
|
-
if (parentObject !== undefined && fromCustomMetadata != null) {
|
|
318
|
-
let transformedList = fromCustomMetadata;
|
|
319
|
-
if (Array.isArray(transformedList)) {
|
|
320
|
-
transformedList = transformedList.map((item) => {
|
|
321
|
-
return item;
|
|
322
|
-
});
|
|
323
|
-
}
|
|
324
|
-
setValueByPath(parentObject, ['customMetadata'], transformedList);
|
|
325
|
-
}
|
|
326
|
-
const fromChunkingConfig = getValueByPath(fromObject, [
|
|
327
|
-
'chunkingConfig',
|
|
328
|
-
]);
|
|
329
|
-
if (parentObject !== undefined && fromChunkingConfig != null) {
|
|
330
|
-
setValueByPath(parentObject, ['chunkingConfig'], fromChunkingConfig);
|
|
331
|
-
}
|
|
332
|
-
return toObject;
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
/**
|
|
336
|
-
* @license
|
|
337
|
-
* Copyright 2025 Google LLC
|
|
338
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
339
|
-
*/
|
|
340
|
-
/**
|
|
341
|
-
* API errors raised by the GenAI API.
|
|
342
|
-
*/
|
|
343
|
-
class ApiError extends Error {
|
|
344
|
-
constructor(options) {
|
|
345
|
-
super(options.message);
|
|
346
|
-
this.name = 'ApiError';
|
|
347
|
-
this.status = options.status;
|
|
348
|
-
Object.setPrototypeOf(this, ApiError.prototype);
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
|
|
352
298
|
/**
|
|
353
299
|
* @license
|
|
354
300
|
* Copyright 2025 Google LLC
|
|
@@ -2002,6 +1948,120 @@ class UploadToFileSearchStoreOperation {
|
|
|
2002
1948
|
}
|
|
2003
1949
|
}
|
|
2004
1950
|
|
|
1951
|
+
/**
|
|
1952
|
+
* @license
|
|
1953
|
+
* Copyright 2025 Google LLC
|
|
1954
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
1955
|
+
*/
|
|
1956
|
+
function _isFile(origin) {
|
|
1957
|
+
return (origin !== null &&
|
|
1958
|
+
origin !== undefined &&
|
|
1959
|
+
typeof origin === 'object' &&
|
|
1960
|
+
'name' in origin);
|
|
1961
|
+
}
|
|
1962
|
+
function isGeneratedVideo(origin) {
|
|
1963
|
+
return (origin !== null &&
|
|
1964
|
+
origin !== undefined &&
|
|
1965
|
+
typeof origin === 'object' &&
|
|
1966
|
+
'video' in origin);
|
|
1967
|
+
}
|
|
1968
|
+
function isVideo(origin) {
|
|
1969
|
+
return (origin !== null &&
|
|
1970
|
+
origin !== undefined &&
|
|
1971
|
+
typeof origin === 'object' &&
|
|
1972
|
+
'uri' in origin);
|
|
1973
|
+
}
|
|
1974
|
+
function tFileName(fromName) {
|
|
1975
|
+
var _a;
|
|
1976
|
+
let name;
|
|
1977
|
+
if (_isFile(fromName)) {
|
|
1978
|
+
name = fromName.name;
|
|
1979
|
+
}
|
|
1980
|
+
if (isVideo(fromName)) {
|
|
1981
|
+
name = fromName.uri;
|
|
1982
|
+
if (name === undefined) {
|
|
1983
|
+
return undefined;
|
|
1984
|
+
}
|
|
1985
|
+
}
|
|
1986
|
+
if (isGeneratedVideo(fromName)) {
|
|
1987
|
+
name = (_a = fromName.video) === null || _a === void 0 ? void 0 : _a.uri;
|
|
1988
|
+
if (name === undefined) {
|
|
1989
|
+
return undefined;
|
|
1990
|
+
}
|
|
1991
|
+
}
|
|
1992
|
+
if (typeof fromName === 'string') {
|
|
1993
|
+
name = fromName;
|
|
1994
|
+
}
|
|
1995
|
+
if (name === undefined) {
|
|
1996
|
+
throw new Error('Could not extract file name from the provided input.');
|
|
1997
|
+
}
|
|
1998
|
+
if (name.startsWith('https://')) {
|
|
1999
|
+
const suffix = name.split('files/')[1];
|
|
2000
|
+
const match = suffix.match(/[a-z0-9]+/);
|
|
2001
|
+
if (match === null) {
|
|
2002
|
+
throw new Error(`Could not extract file name from URI ${name}`);
|
|
2003
|
+
}
|
|
2004
|
+
name = match[0];
|
|
2005
|
+
}
|
|
2006
|
+
else if (name.startsWith('files/')) {
|
|
2007
|
+
name = name.split('files/')[1];
|
|
2008
|
+
}
|
|
2009
|
+
return name;
|
|
2010
|
+
}
|
|
2011
|
+
|
|
2012
|
+
/**
|
|
2013
|
+
* @license
|
|
2014
|
+
* Copyright 2025 Google LLC
|
|
2015
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
2016
|
+
*/
|
|
2017
|
+
function uploadToFileSearchStoreConfigToMldev(fromObject, parentObject) {
|
|
2018
|
+
const toObject = {};
|
|
2019
|
+
const fromMimeType = getValueByPath(fromObject, ['mimeType']);
|
|
2020
|
+
if (parentObject !== undefined && fromMimeType != null) {
|
|
2021
|
+
setValueByPath(parentObject, ['mimeType'], fromMimeType);
|
|
2022
|
+
}
|
|
2023
|
+
const fromDisplayName = getValueByPath(fromObject, ['displayName']);
|
|
2024
|
+
if (parentObject !== undefined && fromDisplayName != null) {
|
|
2025
|
+
setValueByPath(parentObject, ['displayName'], fromDisplayName);
|
|
2026
|
+
}
|
|
2027
|
+
const fromCustomMetadata = getValueByPath(fromObject, [
|
|
2028
|
+
'customMetadata',
|
|
2029
|
+
]);
|
|
2030
|
+
if (parentObject !== undefined && fromCustomMetadata != null) {
|
|
2031
|
+
let transformedList = fromCustomMetadata;
|
|
2032
|
+
if (Array.isArray(transformedList)) {
|
|
2033
|
+
transformedList = transformedList.map((item) => {
|
|
2034
|
+
return item;
|
|
2035
|
+
});
|
|
2036
|
+
}
|
|
2037
|
+
setValueByPath(parentObject, ['customMetadata'], transformedList);
|
|
2038
|
+
}
|
|
2039
|
+
const fromChunkingConfig = getValueByPath(fromObject, [
|
|
2040
|
+
'chunkingConfig',
|
|
2041
|
+
]);
|
|
2042
|
+
if (parentObject !== undefined && fromChunkingConfig != null) {
|
|
2043
|
+
setValueByPath(parentObject, ['chunkingConfig'], fromChunkingConfig);
|
|
2044
|
+
}
|
|
2045
|
+
return toObject;
|
|
2046
|
+
}
|
|
2047
|
+
|
|
2048
|
+
/**
|
|
2049
|
+
* @license
|
|
2050
|
+
* Copyright 2025 Google LLC
|
|
2051
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
2052
|
+
*/
|
|
2053
|
+
/**
|
|
2054
|
+
* API errors raised by the GenAI API.
|
|
2055
|
+
*/
|
|
2056
|
+
class ApiError extends Error {
|
|
2057
|
+
constructor(options) {
|
|
2058
|
+
super(options.message);
|
|
2059
|
+
this.name = 'ApiError';
|
|
2060
|
+
this.status = options.status;
|
|
2061
|
+
Object.setPrototypeOf(this, ApiError.prototype);
|
|
2062
|
+
}
|
|
2063
|
+
}
|
|
2064
|
+
|
|
2005
2065
|
/**
|
|
2006
2066
|
* @license
|
|
2007
2067
|
* Copyright 2025 Google LLC
|
|
@@ -2011,7 +2071,7 @@ const CONTENT_TYPE_HEADER = 'Content-Type';
|
|
|
2011
2071
|
const SERVER_TIMEOUT_HEADER = 'X-Server-Timeout';
|
|
2012
2072
|
const USER_AGENT_HEADER = 'User-Agent';
|
|
2013
2073
|
const GOOGLE_API_CLIENT_HEADER = 'x-goog-api-client';
|
|
2014
|
-
const SDK_VERSION = '
|
|
2074
|
+
const SDK_VERSION = '2.0.0'; // x-release-please-version
|
|
2015
2075
|
const LIBRARY_LABEL = `google-genai-sdk/${SDK_VERSION}`;
|
|
2016
2076
|
const VERTEX_AI_API_DEFAULT_VERSION = 'v1beta1';
|
|
2017
2077
|
const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
|
|
@@ -2276,6 +2336,24 @@ class ApiClient {
|
|
|
2276
2336
|
const abortController = new AbortController();
|
|
2277
2337
|
const signal = abortController.signal;
|
|
2278
2338
|
if (httpOptions.timeout && (httpOptions === null || httpOptions === void 0 ? void 0 : httpOptions.timeout) > 0) {
|
|
2339
|
+
// In Node > 18, the built-in fetch is backed by Undici. Undici sets a global
|
|
2340
|
+
// dispatcher on the global scope which tracks its internal headersTimeout and
|
|
2341
|
+
// bodyTimeout using Symbol properties.
|
|
2342
|
+
const dispatcherSymbol = Symbol.for('undici.globalDispatcher.1');
|
|
2343
|
+
const globalDispatcher = globalThis[dispatcherSymbol];
|
|
2344
|
+
if (globalDispatcher) {
|
|
2345
|
+
const symbols = Object.getOwnPropertySymbols(globalDispatcher);
|
|
2346
|
+
for (const sym of symbols) {
|
|
2347
|
+
const desc = sym.description;
|
|
2348
|
+
if ((desc === null || desc === void 0 ? void 0 : desc.includes('headers timeout')) ||
|
|
2349
|
+
(desc === null || desc === void 0 ? void 0 : desc.includes('body timeout'))) {
|
|
2350
|
+
const currentTimeout = globalDispatcher[sym];
|
|
2351
|
+
if (typeof currentTimeout === 'number') {
|
|
2352
|
+
globalDispatcher[sym] = Math.max(currentTimeout, httpOptions.timeout);
|
|
2353
|
+
}
|
|
2354
|
+
}
|
|
2355
|
+
}
|
|
2356
|
+
}
|
|
2279
2357
|
const timeoutHandle = setTimeout(() => abortController.abort(), httpOptions.timeout);
|
|
2280
2358
|
if (timeoutHandle &&
|
|
2281
2359
|
typeof timeoutHandle.unref ===
|
|
@@ -2309,7 +2387,7 @@ class ApiClient {
|
|
|
2309
2387
|
throw e;
|
|
2310
2388
|
}
|
|
2311
2389
|
else {
|
|
2312
|
-
throw new Error(
|
|
2390
|
+
throw new Error(`exception ${e} sending request`, { cause: e });
|
|
2313
2391
|
}
|
|
2314
2392
|
});
|
|
2315
2393
|
}
|
|
@@ -2324,7 +2402,7 @@ class ApiClient {
|
|
|
2324
2402
|
throw e;
|
|
2325
2403
|
}
|
|
2326
2404
|
else {
|
|
2327
|
-
throw new Error(
|
|
2405
|
+
throw new Error(`exception ${e} sending request`, { cause: e });
|
|
2328
2406
|
}
|
|
2329
2407
|
});
|
|
2330
2408
|
}
|
|
@@ -2452,11 +2530,14 @@ class ApiClient {
|
|
|
2452
2530
|
for (const [key, value] of Object.entries(httpOptions.headers)) {
|
|
2453
2531
|
headers.append(key, value);
|
|
2454
2532
|
}
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2533
|
+
}
|
|
2534
|
+
// Append a timeout header if it is set, note that the timeout option is
|
|
2535
|
+
// in milliseconds but the header is in seconds.
|
|
2536
|
+
// NOTE: This is intentionally outside the httpOptions.headers guard above
|
|
2537
|
+
// so that the X-Server-Timeout header is always sent whenever a timeout
|
|
2538
|
+
// is configured, even if the caller did not supply any custom headers.
|
|
2539
|
+
if ((httpOptions === null || httpOptions === void 0 ? void 0 : httpOptions.timeout) && httpOptions.timeout > 0) {
|
|
2540
|
+
headers.append(SERVER_TIMEOUT_HEADER, String(Math.ceil(httpOptions.timeout / 1000)));
|
|
2460
2541
|
}
|
|
2461
2542
|
await this.clientOptions.auth.addAuthHeaders(headers, url);
|
|
2462
2543
|
return headers;
|
|
@@ -2760,67 +2841,6 @@ function buildGoogleAuthOptions(googleAuthOptions) {
|
|
|
2760
2841
|
}
|
|
2761
2842
|
}
|
|
2762
2843
|
|
|
2763
|
-
/**
|
|
2764
|
-
* @license
|
|
2765
|
-
* Copyright 2025 Google LLC
|
|
2766
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
2767
|
-
*/
|
|
2768
|
-
function _isFile(origin) {
|
|
2769
|
-
return (origin !== null &&
|
|
2770
|
-
origin !== undefined &&
|
|
2771
|
-
typeof origin === 'object' &&
|
|
2772
|
-
'name' in origin);
|
|
2773
|
-
}
|
|
2774
|
-
function isGeneratedVideo(origin) {
|
|
2775
|
-
return (origin !== null &&
|
|
2776
|
-
origin !== undefined &&
|
|
2777
|
-
typeof origin === 'object' &&
|
|
2778
|
-
'video' in origin);
|
|
2779
|
-
}
|
|
2780
|
-
function isVideo(origin) {
|
|
2781
|
-
return (origin !== null &&
|
|
2782
|
-
origin !== undefined &&
|
|
2783
|
-
typeof origin === 'object' &&
|
|
2784
|
-
'uri' in origin);
|
|
2785
|
-
}
|
|
2786
|
-
function tFileName(fromName) {
|
|
2787
|
-
var _a;
|
|
2788
|
-
let name;
|
|
2789
|
-
if (_isFile(fromName)) {
|
|
2790
|
-
name = fromName.name;
|
|
2791
|
-
}
|
|
2792
|
-
if (isVideo(fromName)) {
|
|
2793
|
-
name = fromName.uri;
|
|
2794
|
-
if (name === undefined) {
|
|
2795
|
-
return undefined;
|
|
2796
|
-
}
|
|
2797
|
-
}
|
|
2798
|
-
if (isGeneratedVideo(fromName)) {
|
|
2799
|
-
name = (_a = fromName.video) === null || _a === void 0 ? void 0 : _a.uri;
|
|
2800
|
-
if (name === undefined) {
|
|
2801
|
-
return undefined;
|
|
2802
|
-
}
|
|
2803
|
-
}
|
|
2804
|
-
if (typeof fromName === 'string') {
|
|
2805
|
-
name = fromName;
|
|
2806
|
-
}
|
|
2807
|
-
if (name === undefined) {
|
|
2808
|
-
throw new Error('Could not extract file name from the provided input.');
|
|
2809
|
-
}
|
|
2810
|
-
if (name.startsWith('https://')) {
|
|
2811
|
-
const suffix = name.split('files/')[1];
|
|
2812
|
-
const match = suffix.match(/[a-z0-9]+/);
|
|
2813
|
-
if (match === null) {
|
|
2814
|
-
throw new Error(`Could not extract file name from URI ${name}`);
|
|
2815
|
-
}
|
|
2816
|
-
name = match[0];
|
|
2817
|
-
}
|
|
2818
|
-
else if (name.startsWith('files/')) {
|
|
2819
|
-
name = name.split('files/')[1];
|
|
2820
|
-
}
|
|
2821
|
-
return name;
|
|
2822
|
-
}
|
|
2823
|
-
|
|
2824
2844
|
/**
|
|
2825
2845
|
* @license
|
|
2826
2846
|
* Copyright 2025 Google LLC
|