@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/index.cjs
CHANGED
|
@@ -7370,20 +7370,25 @@ class Chat {
|
|
|
7370
7370
|
* Copyright 2025 Google LLC
|
|
7371
7371
|
* SPDX-License-Identifier: Apache-2.0
|
|
7372
7372
|
*/
|
|
7373
|
-
|
|
7374
|
-
function createFileSearchStoreConfigToMldev(fromObject, parentObject) {
|
|
7373
|
+
function createFileSearchStoreConfigToMldev(apiClient, fromObject, parentObject) {
|
|
7375
7374
|
const toObject = {};
|
|
7376
7375
|
const fromDisplayName = getValueByPath(fromObject, ['displayName']);
|
|
7377
7376
|
if (parentObject !== undefined && fromDisplayName != null) {
|
|
7378
7377
|
setValueByPath(parentObject, ['displayName'], fromDisplayName);
|
|
7379
7378
|
}
|
|
7379
|
+
const fromEmbeddingModel = getValueByPath(fromObject, [
|
|
7380
|
+
'embeddingModel',
|
|
7381
|
+
]);
|
|
7382
|
+
if (parentObject !== undefined && fromEmbeddingModel != null) {
|
|
7383
|
+
setValueByPath(parentObject, ['embeddingModel'], tModel(apiClient, fromEmbeddingModel));
|
|
7384
|
+
}
|
|
7380
7385
|
return toObject;
|
|
7381
7386
|
}
|
|
7382
|
-
function createFileSearchStoreParametersToMldev(fromObject) {
|
|
7387
|
+
function createFileSearchStoreParametersToMldev(apiClient, fromObject) {
|
|
7383
7388
|
const toObject = {};
|
|
7384
7389
|
const fromConfig = getValueByPath(fromObject, ['config']);
|
|
7385
7390
|
if (fromConfig != null) {
|
|
7386
|
-
createFileSearchStoreConfigToMldev(fromConfig, toObject);
|
|
7391
|
+
createFileSearchStoreConfigToMldev(apiClient, fromConfig, toObject);
|
|
7387
7392
|
}
|
|
7388
7393
|
return toObject;
|
|
7389
7394
|
}
|
|
@@ -7626,7 +7631,7 @@ const CONTENT_TYPE_HEADER = 'Content-Type';
|
|
|
7626
7631
|
const SERVER_TIMEOUT_HEADER = 'X-Server-Timeout';
|
|
7627
7632
|
const USER_AGENT_HEADER = 'User-Agent';
|
|
7628
7633
|
const GOOGLE_API_CLIENT_HEADER = 'x-goog-api-client';
|
|
7629
|
-
const SDK_VERSION = '
|
|
7634
|
+
const SDK_VERSION = '2.0.0'; // x-release-please-version
|
|
7630
7635
|
const LIBRARY_LABEL = `google-genai-sdk/${SDK_VERSION}`;
|
|
7631
7636
|
const VERTEX_AI_API_DEFAULT_VERSION = 'v1beta1';
|
|
7632
7637
|
const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
|
|
@@ -7891,6 +7896,24 @@ class ApiClient {
|
|
|
7891
7896
|
const abortController = new AbortController();
|
|
7892
7897
|
const signal = abortController.signal;
|
|
7893
7898
|
if (httpOptions.timeout && (httpOptions === null || httpOptions === void 0 ? void 0 : httpOptions.timeout) > 0) {
|
|
7899
|
+
// In Node > 18, the built-in fetch is backed by Undici. Undici sets a global
|
|
7900
|
+
// dispatcher on the global scope which tracks its internal headersTimeout and
|
|
7901
|
+
// bodyTimeout using Symbol properties.
|
|
7902
|
+
const dispatcherSymbol = Symbol.for('undici.globalDispatcher.1');
|
|
7903
|
+
const globalDispatcher = globalThis[dispatcherSymbol];
|
|
7904
|
+
if (globalDispatcher) {
|
|
7905
|
+
const symbols = Object.getOwnPropertySymbols(globalDispatcher);
|
|
7906
|
+
for (const sym of symbols) {
|
|
7907
|
+
const desc = sym.description;
|
|
7908
|
+
if ((desc === null || desc === void 0 ? void 0 : desc.includes('headers timeout')) ||
|
|
7909
|
+
(desc === null || desc === void 0 ? void 0 : desc.includes('body timeout'))) {
|
|
7910
|
+
const currentTimeout = globalDispatcher[sym];
|
|
7911
|
+
if (typeof currentTimeout === 'number') {
|
|
7912
|
+
globalDispatcher[sym] = Math.max(currentTimeout, httpOptions.timeout);
|
|
7913
|
+
}
|
|
7914
|
+
}
|
|
7915
|
+
}
|
|
7916
|
+
}
|
|
7894
7917
|
const timeoutHandle = setTimeout(() => abortController.abort(), httpOptions.timeout);
|
|
7895
7918
|
if (timeoutHandle &&
|
|
7896
7919
|
typeof timeoutHandle.unref ===
|
|
@@ -7924,7 +7947,7 @@ class ApiClient {
|
|
|
7924
7947
|
throw e;
|
|
7925
7948
|
}
|
|
7926
7949
|
else {
|
|
7927
|
-
throw new Error(
|
|
7950
|
+
throw new Error(`exception ${e} sending request`, { cause: e });
|
|
7928
7951
|
}
|
|
7929
7952
|
});
|
|
7930
7953
|
}
|
|
@@ -7939,7 +7962,7 @@ class ApiClient {
|
|
|
7939
7962
|
throw e;
|
|
7940
7963
|
}
|
|
7941
7964
|
else {
|
|
7942
|
-
throw new Error(
|
|
7965
|
+
throw new Error(`exception ${e} sending request`, { cause: e });
|
|
7943
7966
|
}
|
|
7944
7967
|
});
|
|
7945
7968
|
}
|
|
@@ -8067,11 +8090,14 @@ class ApiClient {
|
|
|
8067
8090
|
for (const [key, value] of Object.entries(httpOptions.headers)) {
|
|
8068
8091
|
headers.append(key, value);
|
|
8069
8092
|
}
|
|
8070
|
-
|
|
8071
|
-
|
|
8072
|
-
|
|
8073
|
-
|
|
8074
|
-
|
|
8093
|
+
}
|
|
8094
|
+
// Append a timeout header if it is set, note that the timeout option is
|
|
8095
|
+
// in milliseconds but the header is in seconds.
|
|
8096
|
+
// NOTE: This is intentionally outside the httpOptions.headers guard above
|
|
8097
|
+
// so that the X-Server-Timeout header is always sent whenever a timeout
|
|
8098
|
+
// is configured, even if the caller did not supply any custom headers.
|
|
8099
|
+
if ((httpOptions === null || httpOptions === void 0 ? void 0 : httpOptions.timeout) && httpOptions.timeout > 0) {
|
|
8100
|
+
headers.append(SERVER_TIMEOUT_HEADER, String(Math.ceil(httpOptions.timeout / 1000)));
|
|
8075
8101
|
}
|
|
8076
8102
|
await this.clientOptions.auth.addAuthHeaders(headers, url);
|
|
8077
8103
|
return headers;
|
|
@@ -9175,6 +9201,46 @@ class FileSearchStores extends BaseModule {
|
|
|
9175
9201
|
}
|
|
9176
9202
|
return this.apiClient.uploadFileToFileSearchStore(params.fileSearchStoreName, params.file, params.config);
|
|
9177
9203
|
}
|
|
9204
|
+
/**
|
|
9205
|
+
* Downloads media using a Media ID or URI.
|
|
9206
|
+
* This method is only supported in the Gemini Developer client.
|
|
9207
|
+
*
|
|
9208
|
+
* @param uri - The URI or Media ID of the blob.
|
|
9209
|
+
* @param config - Optional configuration for the download.
|
|
9210
|
+
* @returns A promise that resolves to the blob data as a Uint8Array.
|
|
9211
|
+
*/
|
|
9212
|
+
async downloadMedia(uri, config) {
|
|
9213
|
+
if (this.apiClient.isVertexAI()) {
|
|
9214
|
+
throw new Error('This method is only supported in the Gemini Developer client.');
|
|
9215
|
+
}
|
|
9216
|
+
const parsedUri = new URL(uri, 'http://dummy.com');
|
|
9217
|
+
let pathname = parsedUri.pathname;
|
|
9218
|
+
if (pathname.startsWith('/')) {
|
|
9219
|
+
pathname = pathname.slice(1);
|
|
9220
|
+
}
|
|
9221
|
+
if (!pathname.includes('/media/')) {
|
|
9222
|
+
throw new Error(`Invalid uri format: ${uri}. Expected to contain /media/`);
|
|
9223
|
+
}
|
|
9224
|
+
const queryParams = {};
|
|
9225
|
+
parsedUri.searchParams.forEach((value, key) => {
|
|
9226
|
+
queryParams[key] = value;
|
|
9227
|
+
});
|
|
9228
|
+
queryParams['alt'] = 'media';
|
|
9229
|
+
const httpOptions = Object.assign({}, config === null || config === void 0 ? void 0 : config.httpOptions);
|
|
9230
|
+
const response = await this.apiClient.request({
|
|
9231
|
+
path: pathname,
|
|
9232
|
+
httpMethod: 'GET',
|
|
9233
|
+
queryParams: queryParams,
|
|
9234
|
+
httpOptions: httpOptions,
|
|
9235
|
+
});
|
|
9236
|
+
if (response instanceof HttpResponse) {
|
|
9237
|
+
const arrayBuffer = await response.responseInternal.arrayBuffer();
|
|
9238
|
+
return new Uint8Array(arrayBuffer);
|
|
9239
|
+
}
|
|
9240
|
+
else {
|
|
9241
|
+
throw new Error('Unexpected response type from downloadMedia');
|
|
9242
|
+
}
|
|
9243
|
+
}
|
|
9178
9244
|
/**
|
|
9179
9245
|
* Creates a File Search Store.
|
|
9180
9246
|
*
|
|
@@ -9190,7 +9256,7 @@ class FileSearchStores extends BaseModule {
|
|
|
9190
9256
|
throw new Error('This method is only supported by the Gemini Developer API.');
|
|
9191
9257
|
}
|
|
9192
9258
|
else {
|
|
9193
|
-
const body = createFileSearchStoreParametersToMldev(params);
|
|
9259
|
+
const body = createFileSearchStoreParametersToMldev(this.apiClient, params);
|
|
9194
9260
|
path = formatMap('fileSearchStores', body['_url']);
|
|
9195
9261
|
queryParams = body['_query'];
|
|
9196
9262
|
delete body['_url'];
|
|
@@ -11221,7 +11287,7 @@ class BaseGeminiNextGenAPIClient {
|
|
|
11221
11287
|
const authHeaders = await this.authHeaders(options);
|
|
11222
11288
|
let headers = buildHeaders([
|
|
11223
11289
|
idempotencyHeaders,
|
|
11224
|
-
{ Accept: 'application/json', 'User-Agent': this.getUserAgent() },
|
|
11290
|
+
{ Accept: 'application/json', 'User-Agent': this.getUserAgent(), 'Api-Revision': '2026-05-20' },
|
|
11225
11291
|
this._options.defaultHeaders,
|
|
11226
11292
|
bodyHeaders,
|
|
11227
11293
|
options.headers,
|
|
@@ -20780,7 +20846,6 @@ class GoogleGenAI {
|
|
|
20780
20846
|
if (this._interactions !== undefined) {
|
|
20781
20847
|
return this._interactions;
|
|
20782
20848
|
}
|
|
20783
|
-
console.warn('GoogleGenAI.interactions: Interactions usage is experimental and may change in future versions.');
|
|
20784
20849
|
this._interactions = this.getNextGenClient().interactions;
|
|
20785
20850
|
return this._interactions;
|
|
20786
20851
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -7368,20 +7368,25 @@ class Chat {
|
|
|
7368
7368
|
* Copyright 2025 Google LLC
|
|
7369
7369
|
* SPDX-License-Identifier: Apache-2.0
|
|
7370
7370
|
*/
|
|
7371
|
-
|
|
7372
|
-
function createFileSearchStoreConfigToMldev(fromObject, parentObject) {
|
|
7371
|
+
function createFileSearchStoreConfigToMldev(apiClient, fromObject, parentObject) {
|
|
7373
7372
|
const toObject = {};
|
|
7374
7373
|
const fromDisplayName = getValueByPath(fromObject, ['displayName']);
|
|
7375
7374
|
if (parentObject !== undefined && fromDisplayName != null) {
|
|
7376
7375
|
setValueByPath(parentObject, ['displayName'], fromDisplayName);
|
|
7377
7376
|
}
|
|
7377
|
+
const fromEmbeddingModel = getValueByPath(fromObject, [
|
|
7378
|
+
'embeddingModel',
|
|
7379
|
+
]);
|
|
7380
|
+
if (parentObject !== undefined && fromEmbeddingModel != null) {
|
|
7381
|
+
setValueByPath(parentObject, ['embeddingModel'], tModel(apiClient, fromEmbeddingModel));
|
|
7382
|
+
}
|
|
7378
7383
|
return toObject;
|
|
7379
7384
|
}
|
|
7380
|
-
function createFileSearchStoreParametersToMldev(fromObject) {
|
|
7385
|
+
function createFileSearchStoreParametersToMldev(apiClient, fromObject) {
|
|
7381
7386
|
const toObject = {};
|
|
7382
7387
|
const fromConfig = getValueByPath(fromObject, ['config']);
|
|
7383
7388
|
if (fromConfig != null) {
|
|
7384
|
-
createFileSearchStoreConfigToMldev(fromConfig, toObject);
|
|
7389
|
+
createFileSearchStoreConfigToMldev(apiClient, fromConfig, toObject);
|
|
7385
7390
|
}
|
|
7386
7391
|
return toObject;
|
|
7387
7392
|
}
|
|
@@ -7624,7 +7629,7 @@ const CONTENT_TYPE_HEADER = 'Content-Type';
|
|
|
7624
7629
|
const SERVER_TIMEOUT_HEADER = 'X-Server-Timeout';
|
|
7625
7630
|
const USER_AGENT_HEADER = 'User-Agent';
|
|
7626
7631
|
const GOOGLE_API_CLIENT_HEADER = 'x-goog-api-client';
|
|
7627
|
-
const SDK_VERSION = '
|
|
7632
|
+
const SDK_VERSION = '2.0.0'; // x-release-please-version
|
|
7628
7633
|
const LIBRARY_LABEL = `google-genai-sdk/${SDK_VERSION}`;
|
|
7629
7634
|
const VERTEX_AI_API_DEFAULT_VERSION = 'v1beta1';
|
|
7630
7635
|
const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
|
|
@@ -7889,6 +7894,24 @@ class ApiClient {
|
|
|
7889
7894
|
const abortController = new AbortController();
|
|
7890
7895
|
const signal = abortController.signal;
|
|
7891
7896
|
if (httpOptions.timeout && (httpOptions === null || httpOptions === void 0 ? void 0 : httpOptions.timeout) > 0) {
|
|
7897
|
+
// In Node > 18, the built-in fetch is backed by Undici. Undici sets a global
|
|
7898
|
+
// dispatcher on the global scope which tracks its internal headersTimeout and
|
|
7899
|
+
// bodyTimeout using Symbol properties.
|
|
7900
|
+
const dispatcherSymbol = Symbol.for('undici.globalDispatcher.1');
|
|
7901
|
+
const globalDispatcher = globalThis[dispatcherSymbol];
|
|
7902
|
+
if (globalDispatcher) {
|
|
7903
|
+
const symbols = Object.getOwnPropertySymbols(globalDispatcher);
|
|
7904
|
+
for (const sym of symbols) {
|
|
7905
|
+
const desc = sym.description;
|
|
7906
|
+
if ((desc === null || desc === void 0 ? void 0 : desc.includes('headers timeout')) ||
|
|
7907
|
+
(desc === null || desc === void 0 ? void 0 : desc.includes('body timeout'))) {
|
|
7908
|
+
const currentTimeout = globalDispatcher[sym];
|
|
7909
|
+
if (typeof currentTimeout === 'number') {
|
|
7910
|
+
globalDispatcher[sym] = Math.max(currentTimeout, httpOptions.timeout);
|
|
7911
|
+
}
|
|
7912
|
+
}
|
|
7913
|
+
}
|
|
7914
|
+
}
|
|
7892
7915
|
const timeoutHandle = setTimeout(() => abortController.abort(), httpOptions.timeout);
|
|
7893
7916
|
if (timeoutHandle &&
|
|
7894
7917
|
typeof timeoutHandle.unref ===
|
|
@@ -7922,7 +7945,7 @@ class ApiClient {
|
|
|
7922
7945
|
throw e;
|
|
7923
7946
|
}
|
|
7924
7947
|
else {
|
|
7925
|
-
throw new Error(
|
|
7948
|
+
throw new Error(`exception ${e} sending request`, { cause: e });
|
|
7926
7949
|
}
|
|
7927
7950
|
});
|
|
7928
7951
|
}
|
|
@@ -7937,7 +7960,7 @@ class ApiClient {
|
|
|
7937
7960
|
throw e;
|
|
7938
7961
|
}
|
|
7939
7962
|
else {
|
|
7940
|
-
throw new Error(
|
|
7963
|
+
throw new Error(`exception ${e} sending request`, { cause: e });
|
|
7941
7964
|
}
|
|
7942
7965
|
});
|
|
7943
7966
|
}
|
|
@@ -8065,11 +8088,14 @@ class ApiClient {
|
|
|
8065
8088
|
for (const [key, value] of Object.entries(httpOptions.headers)) {
|
|
8066
8089
|
headers.append(key, value);
|
|
8067
8090
|
}
|
|
8068
|
-
|
|
8069
|
-
|
|
8070
|
-
|
|
8071
|
-
|
|
8072
|
-
|
|
8091
|
+
}
|
|
8092
|
+
// Append a timeout header if it is set, note that the timeout option is
|
|
8093
|
+
// in milliseconds but the header is in seconds.
|
|
8094
|
+
// NOTE: This is intentionally outside the httpOptions.headers guard above
|
|
8095
|
+
// so that the X-Server-Timeout header is always sent whenever a timeout
|
|
8096
|
+
// is configured, even if the caller did not supply any custom headers.
|
|
8097
|
+
if ((httpOptions === null || httpOptions === void 0 ? void 0 : httpOptions.timeout) && httpOptions.timeout > 0) {
|
|
8098
|
+
headers.append(SERVER_TIMEOUT_HEADER, String(Math.ceil(httpOptions.timeout / 1000)));
|
|
8073
8099
|
}
|
|
8074
8100
|
await this.clientOptions.auth.addAuthHeaders(headers, url);
|
|
8075
8101
|
return headers;
|
|
@@ -9173,6 +9199,46 @@ class FileSearchStores extends BaseModule {
|
|
|
9173
9199
|
}
|
|
9174
9200
|
return this.apiClient.uploadFileToFileSearchStore(params.fileSearchStoreName, params.file, params.config);
|
|
9175
9201
|
}
|
|
9202
|
+
/**
|
|
9203
|
+
* Downloads media using a Media ID or URI.
|
|
9204
|
+
* This method is only supported in the Gemini Developer client.
|
|
9205
|
+
*
|
|
9206
|
+
* @param uri - The URI or Media ID of the blob.
|
|
9207
|
+
* @param config - Optional configuration for the download.
|
|
9208
|
+
* @returns A promise that resolves to the blob data as a Uint8Array.
|
|
9209
|
+
*/
|
|
9210
|
+
async downloadMedia(uri, config) {
|
|
9211
|
+
if (this.apiClient.isVertexAI()) {
|
|
9212
|
+
throw new Error('This method is only supported in the Gemini Developer client.');
|
|
9213
|
+
}
|
|
9214
|
+
const parsedUri = new URL(uri, 'http://dummy.com');
|
|
9215
|
+
let pathname = parsedUri.pathname;
|
|
9216
|
+
if (pathname.startsWith('/')) {
|
|
9217
|
+
pathname = pathname.slice(1);
|
|
9218
|
+
}
|
|
9219
|
+
if (!pathname.includes('/media/')) {
|
|
9220
|
+
throw new Error(`Invalid uri format: ${uri}. Expected to contain /media/`);
|
|
9221
|
+
}
|
|
9222
|
+
const queryParams = {};
|
|
9223
|
+
parsedUri.searchParams.forEach((value, key) => {
|
|
9224
|
+
queryParams[key] = value;
|
|
9225
|
+
});
|
|
9226
|
+
queryParams['alt'] = 'media';
|
|
9227
|
+
const httpOptions = Object.assign({}, config === null || config === void 0 ? void 0 : config.httpOptions);
|
|
9228
|
+
const response = await this.apiClient.request({
|
|
9229
|
+
path: pathname,
|
|
9230
|
+
httpMethod: 'GET',
|
|
9231
|
+
queryParams: queryParams,
|
|
9232
|
+
httpOptions: httpOptions,
|
|
9233
|
+
});
|
|
9234
|
+
if (response instanceof HttpResponse) {
|
|
9235
|
+
const arrayBuffer = await response.responseInternal.arrayBuffer();
|
|
9236
|
+
return new Uint8Array(arrayBuffer);
|
|
9237
|
+
}
|
|
9238
|
+
else {
|
|
9239
|
+
throw new Error('Unexpected response type from downloadMedia');
|
|
9240
|
+
}
|
|
9241
|
+
}
|
|
9176
9242
|
/**
|
|
9177
9243
|
* Creates a File Search Store.
|
|
9178
9244
|
*
|
|
@@ -9188,7 +9254,7 @@ class FileSearchStores extends BaseModule {
|
|
|
9188
9254
|
throw new Error('This method is only supported by the Gemini Developer API.');
|
|
9189
9255
|
}
|
|
9190
9256
|
else {
|
|
9191
|
-
const body = createFileSearchStoreParametersToMldev(params);
|
|
9257
|
+
const body = createFileSearchStoreParametersToMldev(this.apiClient, params);
|
|
9192
9258
|
path = formatMap('fileSearchStores', body['_url']);
|
|
9193
9259
|
queryParams = body['_query'];
|
|
9194
9260
|
delete body['_url'];
|
|
@@ -11219,7 +11285,7 @@ class BaseGeminiNextGenAPIClient {
|
|
|
11219
11285
|
const authHeaders = await this.authHeaders(options);
|
|
11220
11286
|
let headers = buildHeaders([
|
|
11221
11287
|
idempotencyHeaders,
|
|
11222
|
-
{ Accept: 'application/json', 'User-Agent': this.getUserAgent() },
|
|
11288
|
+
{ Accept: 'application/json', 'User-Agent': this.getUserAgent(), 'Api-Revision': '2026-05-20' },
|
|
11223
11289
|
this._options.defaultHeaders,
|
|
11224
11290
|
bodyHeaders,
|
|
11225
11291
|
options.headers,
|
|
@@ -20778,7 +20844,6 @@ class GoogleGenAI {
|
|
|
20778
20844
|
if (this._interactions !== undefined) {
|
|
20779
20845
|
return this._interactions;
|
|
20780
20846
|
}
|
|
20781
|
-
console.warn('GoogleGenAI.interactions: Interactions usage is experimental and may change in future versions.');
|
|
20782
20847
|
this._interactions = this.getNextGenClient().interactions;
|
|
20783
20848
|
return this._interactions;
|
|
20784
20849
|
}
|