@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
package/dist/node/index.cjs
CHANGED
|
@@ -12675,20 +12675,25 @@ function videoToVertex(fromObject, _rootObject) {
|
|
|
12675
12675
|
* Copyright 2025 Google LLC
|
|
12676
12676
|
* SPDX-License-Identifier: Apache-2.0
|
|
12677
12677
|
*/
|
|
12678
|
-
|
|
12679
|
-
function createFileSearchStoreConfigToMldev(fromObject, parentObject) {
|
|
12678
|
+
function createFileSearchStoreConfigToMldev(apiClient, fromObject, parentObject) {
|
|
12680
12679
|
const toObject = {};
|
|
12681
12680
|
const fromDisplayName = getValueByPath(fromObject, ['displayName']);
|
|
12682
12681
|
if (parentObject !== undefined && fromDisplayName != null) {
|
|
12683
12682
|
setValueByPath(parentObject, ['displayName'], fromDisplayName);
|
|
12684
12683
|
}
|
|
12684
|
+
const fromEmbeddingModel = getValueByPath(fromObject, [
|
|
12685
|
+
'embeddingModel',
|
|
12686
|
+
]);
|
|
12687
|
+
if (parentObject !== undefined && fromEmbeddingModel != null) {
|
|
12688
|
+
setValueByPath(parentObject, ['embeddingModel'], tModel(apiClient, fromEmbeddingModel));
|
|
12689
|
+
}
|
|
12685
12690
|
return toObject;
|
|
12686
12691
|
}
|
|
12687
|
-
function createFileSearchStoreParametersToMldev(fromObject) {
|
|
12692
|
+
function createFileSearchStoreParametersToMldev(apiClient, fromObject) {
|
|
12688
12693
|
const toObject = {};
|
|
12689
12694
|
const fromConfig = getValueByPath(fromObject, ['config']);
|
|
12690
12695
|
if (fromConfig != null) {
|
|
12691
|
-
createFileSearchStoreConfigToMldev(fromConfig, toObject);
|
|
12696
|
+
createFileSearchStoreConfigToMldev(apiClient, fromConfig, toObject);
|
|
12692
12697
|
}
|
|
12693
12698
|
return toObject;
|
|
12694
12699
|
}
|
|
@@ -12914,7 +12919,7 @@ const CONTENT_TYPE_HEADER = 'Content-Type';
|
|
|
12914
12919
|
const SERVER_TIMEOUT_HEADER = 'X-Server-Timeout';
|
|
12915
12920
|
const USER_AGENT_HEADER = 'User-Agent';
|
|
12916
12921
|
const GOOGLE_API_CLIENT_HEADER = 'x-goog-api-client';
|
|
12917
|
-
const SDK_VERSION = '
|
|
12922
|
+
const SDK_VERSION = '2.0.0'; // x-release-please-version
|
|
12918
12923
|
const LIBRARY_LABEL = `google-genai-sdk/${SDK_VERSION}`;
|
|
12919
12924
|
const VERTEX_AI_API_DEFAULT_VERSION = 'v1beta1';
|
|
12920
12925
|
const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
|
|
@@ -13179,6 +13184,24 @@ class ApiClient {
|
|
|
13179
13184
|
const abortController = new AbortController();
|
|
13180
13185
|
const signal = abortController.signal;
|
|
13181
13186
|
if (httpOptions.timeout && (httpOptions === null || httpOptions === void 0 ? void 0 : httpOptions.timeout) > 0) {
|
|
13187
|
+
// In Node > 18, the built-in fetch is backed by Undici. Undici sets a global
|
|
13188
|
+
// dispatcher on the global scope which tracks its internal headersTimeout and
|
|
13189
|
+
// bodyTimeout using Symbol properties.
|
|
13190
|
+
const dispatcherSymbol = Symbol.for('undici.globalDispatcher.1');
|
|
13191
|
+
const globalDispatcher = globalThis[dispatcherSymbol];
|
|
13192
|
+
if (globalDispatcher) {
|
|
13193
|
+
const symbols = Object.getOwnPropertySymbols(globalDispatcher);
|
|
13194
|
+
for (const sym of symbols) {
|
|
13195
|
+
const desc = sym.description;
|
|
13196
|
+
if ((desc === null || desc === void 0 ? void 0 : desc.includes('headers timeout')) ||
|
|
13197
|
+
(desc === null || desc === void 0 ? void 0 : desc.includes('body timeout'))) {
|
|
13198
|
+
const currentTimeout = globalDispatcher[sym];
|
|
13199
|
+
if (typeof currentTimeout === 'number') {
|
|
13200
|
+
globalDispatcher[sym] = Math.max(currentTimeout, httpOptions.timeout);
|
|
13201
|
+
}
|
|
13202
|
+
}
|
|
13203
|
+
}
|
|
13204
|
+
}
|
|
13182
13205
|
const timeoutHandle = setTimeout(() => abortController.abort(), httpOptions.timeout);
|
|
13183
13206
|
if (timeoutHandle &&
|
|
13184
13207
|
typeof timeoutHandle.unref ===
|
|
@@ -13212,7 +13235,7 @@ class ApiClient {
|
|
|
13212
13235
|
throw e;
|
|
13213
13236
|
}
|
|
13214
13237
|
else {
|
|
13215
|
-
throw new Error(
|
|
13238
|
+
throw new Error(`exception ${e} sending request`, { cause: e });
|
|
13216
13239
|
}
|
|
13217
13240
|
});
|
|
13218
13241
|
}
|
|
@@ -13227,7 +13250,7 @@ class ApiClient {
|
|
|
13227
13250
|
throw e;
|
|
13228
13251
|
}
|
|
13229
13252
|
else {
|
|
13230
|
-
throw new Error(
|
|
13253
|
+
throw new Error(`exception ${e} sending request`, { cause: e });
|
|
13231
13254
|
}
|
|
13232
13255
|
});
|
|
13233
13256
|
}
|
|
@@ -13355,11 +13378,14 @@ class ApiClient {
|
|
|
13355
13378
|
for (const [key, value] of Object.entries(httpOptions.headers)) {
|
|
13356
13379
|
headers.append(key, value);
|
|
13357
13380
|
}
|
|
13358
|
-
|
|
13359
|
-
|
|
13360
|
-
|
|
13361
|
-
|
|
13362
|
-
|
|
13381
|
+
}
|
|
13382
|
+
// Append a timeout header if it is set, note that the timeout option is
|
|
13383
|
+
// in milliseconds but the header is in seconds.
|
|
13384
|
+
// NOTE: This is intentionally outside the httpOptions.headers guard above
|
|
13385
|
+
// so that the X-Server-Timeout header is always sent whenever a timeout
|
|
13386
|
+
// is configured, even if the caller did not supply any custom headers.
|
|
13387
|
+
if ((httpOptions === null || httpOptions === void 0 ? void 0 : httpOptions.timeout) && httpOptions.timeout > 0) {
|
|
13388
|
+
headers.append(SERVER_TIMEOUT_HEADER, String(Math.ceil(httpOptions.timeout / 1000)));
|
|
13363
13389
|
}
|
|
13364
13390
|
await this.clientOptions.auth.addAuthHeaders(headers, url);
|
|
13365
13391
|
return headers;
|
|
@@ -17276,6 +17302,46 @@ class FileSearchStores extends BaseModule {
|
|
|
17276
17302
|
}
|
|
17277
17303
|
return this.apiClient.uploadFileToFileSearchStore(params.fileSearchStoreName, params.file, params.config);
|
|
17278
17304
|
}
|
|
17305
|
+
/**
|
|
17306
|
+
* Downloads media using a Media ID or URI.
|
|
17307
|
+
* This method is only supported in the Gemini Developer client.
|
|
17308
|
+
*
|
|
17309
|
+
* @param uri - The URI or Media ID of the blob.
|
|
17310
|
+
* @param config - Optional configuration for the download.
|
|
17311
|
+
* @returns A promise that resolves to the blob data as a Uint8Array.
|
|
17312
|
+
*/
|
|
17313
|
+
async downloadMedia(uri, config) {
|
|
17314
|
+
if (this.apiClient.isVertexAI()) {
|
|
17315
|
+
throw new Error('This method is only supported in the Gemini Developer client.');
|
|
17316
|
+
}
|
|
17317
|
+
const parsedUri = new URL(uri, 'http://dummy.com');
|
|
17318
|
+
let pathname = parsedUri.pathname;
|
|
17319
|
+
if (pathname.startsWith('/')) {
|
|
17320
|
+
pathname = pathname.slice(1);
|
|
17321
|
+
}
|
|
17322
|
+
if (!pathname.includes('/media/')) {
|
|
17323
|
+
throw new Error(`Invalid uri format: ${uri}. Expected to contain /media/`);
|
|
17324
|
+
}
|
|
17325
|
+
const queryParams = {};
|
|
17326
|
+
parsedUri.searchParams.forEach((value, key) => {
|
|
17327
|
+
queryParams[key] = value;
|
|
17328
|
+
});
|
|
17329
|
+
queryParams['alt'] = 'media';
|
|
17330
|
+
const httpOptions = Object.assign({}, config === null || config === void 0 ? void 0 : config.httpOptions);
|
|
17331
|
+
const response = await this.apiClient.request({
|
|
17332
|
+
path: pathname,
|
|
17333
|
+
httpMethod: 'GET',
|
|
17334
|
+
queryParams: queryParams,
|
|
17335
|
+
httpOptions: httpOptions,
|
|
17336
|
+
});
|
|
17337
|
+
if (response instanceof HttpResponse) {
|
|
17338
|
+
const arrayBuffer = await response.responseInternal.arrayBuffer();
|
|
17339
|
+
return new Uint8Array(arrayBuffer);
|
|
17340
|
+
}
|
|
17341
|
+
else {
|
|
17342
|
+
throw new Error('Unexpected response type from downloadMedia');
|
|
17343
|
+
}
|
|
17344
|
+
}
|
|
17279
17345
|
/**
|
|
17280
17346
|
* Creates a File Search Store.
|
|
17281
17347
|
*
|
|
@@ -17291,7 +17357,7 @@ class FileSearchStores extends BaseModule {
|
|
|
17291
17357
|
throw new Error('This method is only supported by the Gemini Developer API.');
|
|
17292
17358
|
}
|
|
17293
17359
|
else {
|
|
17294
|
-
const body = createFileSearchStoreParametersToMldev(params);
|
|
17360
|
+
const body = createFileSearchStoreParametersToMldev(this.apiClient, params);
|
|
17295
17361
|
path = formatMap('fileSearchStores', body['_url']);
|
|
17296
17362
|
queryParams = body['_query'];
|
|
17297
17363
|
delete body['_url'];
|
|
@@ -19322,7 +19388,7 @@ class BaseGeminiNextGenAPIClient {
|
|
|
19322
19388
|
const authHeaders = await this.authHeaders(options);
|
|
19323
19389
|
let headers = buildHeaders([
|
|
19324
19390
|
idempotencyHeaders,
|
|
19325
|
-
{ Accept: 'application/json', 'User-Agent': this.getUserAgent() },
|
|
19391
|
+
{ Accept: 'application/json', 'User-Agent': this.getUserAgent(), 'Api-Revision': '2026-05-20' },
|
|
19326
19392
|
this._options.defaultHeaders,
|
|
19327
19393
|
bodyHeaders,
|
|
19328
19394
|
options.headers,
|
|
@@ -21223,7 +21289,6 @@ class GoogleGenAI {
|
|
|
21223
21289
|
if (this._interactions !== undefined) {
|
|
21224
21290
|
return this._interactions;
|
|
21225
21291
|
}
|
|
21226
|
-
console.warn('GoogleGenAI.interactions: Interactions usage is experimental and may change in future versions.');
|
|
21227
21292
|
this._interactions = this.getNextGenClient().interactions;
|
|
21228
21293
|
return this._interactions;
|
|
21229
21294
|
}
|
package/dist/node/index.mjs
CHANGED
|
@@ -12653,20 +12653,25 @@ function videoToVertex(fromObject, _rootObject) {
|
|
|
12653
12653
|
* Copyright 2025 Google LLC
|
|
12654
12654
|
* SPDX-License-Identifier: Apache-2.0
|
|
12655
12655
|
*/
|
|
12656
|
-
|
|
12657
|
-
function createFileSearchStoreConfigToMldev(fromObject, parentObject) {
|
|
12656
|
+
function createFileSearchStoreConfigToMldev(apiClient, fromObject, parentObject) {
|
|
12658
12657
|
const toObject = {};
|
|
12659
12658
|
const fromDisplayName = getValueByPath(fromObject, ['displayName']);
|
|
12660
12659
|
if (parentObject !== undefined && fromDisplayName != null) {
|
|
12661
12660
|
setValueByPath(parentObject, ['displayName'], fromDisplayName);
|
|
12662
12661
|
}
|
|
12662
|
+
const fromEmbeddingModel = getValueByPath(fromObject, [
|
|
12663
|
+
'embeddingModel',
|
|
12664
|
+
]);
|
|
12665
|
+
if (parentObject !== undefined && fromEmbeddingModel != null) {
|
|
12666
|
+
setValueByPath(parentObject, ['embeddingModel'], tModel(apiClient, fromEmbeddingModel));
|
|
12667
|
+
}
|
|
12663
12668
|
return toObject;
|
|
12664
12669
|
}
|
|
12665
|
-
function createFileSearchStoreParametersToMldev(fromObject) {
|
|
12670
|
+
function createFileSearchStoreParametersToMldev(apiClient, fromObject) {
|
|
12666
12671
|
const toObject = {};
|
|
12667
12672
|
const fromConfig = getValueByPath(fromObject, ['config']);
|
|
12668
12673
|
if (fromConfig != null) {
|
|
12669
|
-
createFileSearchStoreConfigToMldev(fromConfig, toObject);
|
|
12674
|
+
createFileSearchStoreConfigToMldev(apiClient, fromConfig, toObject);
|
|
12670
12675
|
}
|
|
12671
12676
|
return toObject;
|
|
12672
12677
|
}
|
|
@@ -12892,7 +12897,7 @@ const CONTENT_TYPE_HEADER = 'Content-Type';
|
|
|
12892
12897
|
const SERVER_TIMEOUT_HEADER = 'X-Server-Timeout';
|
|
12893
12898
|
const USER_AGENT_HEADER = 'User-Agent';
|
|
12894
12899
|
const GOOGLE_API_CLIENT_HEADER = 'x-goog-api-client';
|
|
12895
|
-
const SDK_VERSION = '
|
|
12900
|
+
const SDK_VERSION = '2.0.0'; // x-release-please-version
|
|
12896
12901
|
const LIBRARY_LABEL = `google-genai-sdk/${SDK_VERSION}`;
|
|
12897
12902
|
const VERTEX_AI_API_DEFAULT_VERSION = 'v1beta1';
|
|
12898
12903
|
const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
|
|
@@ -13157,6 +13162,24 @@ class ApiClient {
|
|
|
13157
13162
|
const abortController = new AbortController();
|
|
13158
13163
|
const signal = abortController.signal;
|
|
13159
13164
|
if (httpOptions.timeout && (httpOptions === null || httpOptions === void 0 ? void 0 : httpOptions.timeout) > 0) {
|
|
13165
|
+
// In Node > 18, the built-in fetch is backed by Undici. Undici sets a global
|
|
13166
|
+
// dispatcher on the global scope which tracks its internal headersTimeout and
|
|
13167
|
+
// bodyTimeout using Symbol properties.
|
|
13168
|
+
const dispatcherSymbol = Symbol.for('undici.globalDispatcher.1');
|
|
13169
|
+
const globalDispatcher = globalThis[dispatcherSymbol];
|
|
13170
|
+
if (globalDispatcher) {
|
|
13171
|
+
const symbols = Object.getOwnPropertySymbols(globalDispatcher);
|
|
13172
|
+
for (const sym of symbols) {
|
|
13173
|
+
const desc = sym.description;
|
|
13174
|
+
if ((desc === null || desc === void 0 ? void 0 : desc.includes('headers timeout')) ||
|
|
13175
|
+
(desc === null || desc === void 0 ? void 0 : desc.includes('body timeout'))) {
|
|
13176
|
+
const currentTimeout = globalDispatcher[sym];
|
|
13177
|
+
if (typeof currentTimeout === 'number') {
|
|
13178
|
+
globalDispatcher[sym] = Math.max(currentTimeout, httpOptions.timeout);
|
|
13179
|
+
}
|
|
13180
|
+
}
|
|
13181
|
+
}
|
|
13182
|
+
}
|
|
13160
13183
|
const timeoutHandle = setTimeout(() => abortController.abort(), httpOptions.timeout);
|
|
13161
13184
|
if (timeoutHandle &&
|
|
13162
13185
|
typeof timeoutHandle.unref ===
|
|
@@ -13190,7 +13213,7 @@ class ApiClient {
|
|
|
13190
13213
|
throw e;
|
|
13191
13214
|
}
|
|
13192
13215
|
else {
|
|
13193
|
-
throw new Error(
|
|
13216
|
+
throw new Error(`exception ${e} sending request`, { cause: e });
|
|
13194
13217
|
}
|
|
13195
13218
|
});
|
|
13196
13219
|
}
|
|
@@ -13205,7 +13228,7 @@ class ApiClient {
|
|
|
13205
13228
|
throw e;
|
|
13206
13229
|
}
|
|
13207
13230
|
else {
|
|
13208
|
-
throw new Error(
|
|
13231
|
+
throw new Error(`exception ${e} sending request`, { cause: e });
|
|
13209
13232
|
}
|
|
13210
13233
|
});
|
|
13211
13234
|
}
|
|
@@ -13333,11 +13356,14 @@ class ApiClient {
|
|
|
13333
13356
|
for (const [key, value] of Object.entries(httpOptions.headers)) {
|
|
13334
13357
|
headers.append(key, value);
|
|
13335
13358
|
}
|
|
13336
|
-
|
|
13337
|
-
|
|
13338
|
-
|
|
13339
|
-
|
|
13340
|
-
|
|
13359
|
+
}
|
|
13360
|
+
// Append a timeout header if it is set, note that the timeout option is
|
|
13361
|
+
// in milliseconds but the header is in seconds.
|
|
13362
|
+
// NOTE: This is intentionally outside the httpOptions.headers guard above
|
|
13363
|
+
// so that the X-Server-Timeout header is always sent whenever a timeout
|
|
13364
|
+
// is configured, even if the caller did not supply any custom headers.
|
|
13365
|
+
if ((httpOptions === null || httpOptions === void 0 ? void 0 : httpOptions.timeout) && httpOptions.timeout > 0) {
|
|
13366
|
+
headers.append(SERVER_TIMEOUT_HEADER, String(Math.ceil(httpOptions.timeout / 1000)));
|
|
13341
13367
|
}
|
|
13342
13368
|
await this.clientOptions.auth.addAuthHeaders(headers, url);
|
|
13343
13369
|
return headers;
|
|
@@ -17254,6 +17280,46 @@ class FileSearchStores extends BaseModule {
|
|
|
17254
17280
|
}
|
|
17255
17281
|
return this.apiClient.uploadFileToFileSearchStore(params.fileSearchStoreName, params.file, params.config);
|
|
17256
17282
|
}
|
|
17283
|
+
/**
|
|
17284
|
+
* Downloads media using a Media ID or URI.
|
|
17285
|
+
* This method is only supported in the Gemini Developer client.
|
|
17286
|
+
*
|
|
17287
|
+
* @param uri - The URI or Media ID of the blob.
|
|
17288
|
+
* @param config - Optional configuration for the download.
|
|
17289
|
+
* @returns A promise that resolves to the blob data as a Uint8Array.
|
|
17290
|
+
*/
|
|
17291
|
+
async downloadMedia(uri, config) {
|
|
17292
|
+
if (this.apiClient.isVertexAI()) {
|
|
17293
|
+
throw new Error('This method is only supported in the Gemini Developer client.');
|
|
17294
|
+
}
|
|
17295
|
+
const parsedUri = new URL(uri, 'http://dummy.com');
|
|
17296
|
+
let pathname = parsedUri.pathname;
|
|
17297
|
+
if (pathname.startsWith('/')) {
|
|
17298
|
+
pathname = pathname.slice(1);
|
|
17299
|
+
}
|
|
17300
|
+
if (!pathname.includes('/media/')) {
|
|
17301
|
+
throw new Error(`Invalid uri format: ${uri}. Expected to contain /media/`);
|
|
17302
|
+
}
|
|
17303
|
+
const queryParams = {};
|
|
17304
|
+
parsedUri.searchParams.forEach((value, key) => {
|
|
17305
|
+
queryParams[key] = value;
|
|
17306
|
+
});
|
|
17307
|
+
queryParams['alt'] = 'media';
|
|
17308
|
+
const httpOptions = Object.assign({}, config === null || config === void 0 ? void 0 : config.httpOptions);
|
|
17309
|
+
const response = await this.apiClient.request({
|
|
17310
|
+
path: pathname,
|
|
17311
|
+
httpMethod: 'GET',
|
|
17312
|
+
queryParams: queryParams,
|
|
17313
|
+
httpOptions: httpOptions,
|
|
17314
|
+
});
|
|
17315
|
+
if (response instanceof HttpResponse) {
|
|
17316
|
+
const arrayBuffer = await response.responseInternal.arrayBuffer();
|
|
17317
|
+
return new Uint8Array(arrayBuffer);
|
|
17318
|
+
}
|
|
17319
|
+
else {
|
|
17320
|
+
throw new Error('Unexpected response type from downloadMedia');
|
|
17321
|
+
}
|
|
17322
|
+
}
|
|
17257
17323
|
/**
|
|
17258
17324
|
* Creates a File Search Store.
|
|
17259
17325
|
*
|
|
@@ -17269,7 +17335,7 @@ class FileSearchStores extends BaseModule {
|
|
|
17269
17335
|
throw new Error('This method is only supported by the Gemini Developer API.');
|
|
17270
17336
|
}
|
|
17271
17337
|
else {
|
|
17272
|
-
const body = createFileSearchStoreParametersToMldev(params);
|
|
17338
|
+
const body = createFileSearchStoreParametersToMldev(this.apiClient, params);
|
|
17273
17339
|
path = formatMap('fileSearchStores', body['_url']);
|
|
17274
17340
|
queryParams = body['_query'];
|
|
17275
17341
|
delete body['_url'];
|
|
@@ -19300,7 +19366,7 @@ class BaseGeminiNextGenAPIClient {
|
|
|
19300
19366
|
const authHeaders = await this.authHeaders(options);
|
|
19301
19367
|
let headers = buildHeaders([
|
|
19302
19368
|
idempotencyHeaders,
|
|
19303
|
-
{ Accept: 'application/json', 'User-Agent': this.getUserAgent() },
|
|
19369
|
+
{ Accept: 'application/json', 'User-Agent': this.getUserAgent(), 'Api-Revision': '2026-05-20' },
|
|
19304
19370
|
this._options.defaultHeaders,
|
|
19305
19371
|
bodyHeaders,
|
|
19306
19372
|
options.headers,
|
|
@@ -21201,7 +21267,6 @@ class GoogleGenAI {
|
|
|
21201
21267
|
if (this._interactions !== undefined) {
|
|
21202
21268
|
return this._interactions;
|
|
21203
21269
|
}
|
|
21204
|
-
console.warn('GoogleGenAI.interactions: Interactions usage is experimental and may change in future versions.');
|
|
21205
21270
|
this._interactions = this.getNextGenClient().interactions;
|
|
21206
21271
|
return this._interactions;
|
|
21207
21272
|
}
|