@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/web/index.mjs
CHANGED
|
@@ -12645,20 +12645,25 @@ function videoToVertex(fromObject, _rootObject) {
|
|
|
12645
12645
|
* Copyright 2025 Google LLC
|
|
12646
12646
|
* SPDX-License-Identifier: Apache-2.0
|
|
12647
12647
|
*/
|
|
12648
|
-
|
|
12649
|
-
function createFileSearchStoreConfigToMldev(fromObject, parentObject) {
|
|
12648
|
+
function createFileSearchStoreConfigToMldev(apiClient, fromObject, parentObject) {
|
|
12650
12649
|
const toObject = {};
|
|
12651
12650
|
const fromDisplayName = getValueByPath(fromObject, ['displayName']);
|
|
12652
12651
|
if (parentObject !== undefined && fromDisplayName != null) {
|
|
12653
12652
|
setValueByPath(parentObject, ['displayName'], fromDisplayName);
|
|
12654
12653
|
}
|
|
12654
|
+
const fromEmbeddingModel = getValueByPath(fromObject, [
|
|
12655
|
+
'embeddingModel',
|
|
12656
|
+
]);
|
|
12657
|
+
if (parentObject !== undefined && fromEmbeddingModel != null) {
|
|
12658
|
+
setValueByPath(parentObject, ['embeddingModel'], tModel(apiClient, fromEmbeddingModel));
|
|
12659
|
+
}
|
|
12655
12660
|
return toObject;
|
|
12656
12661
|
}
|
|
12657
|
-
function createFileSearchStoreParametersToMldev(fromObject) {
|
|
12662
|
+
function createFileSearchStoreParametersToMldev(apiClient, fromObject) {
|
|
12658
12663
|
const toObject = {};
|
|
12659
12664
|
const fromConfig = getValueByPath(fromObject, ['config']);
|
|
12660
12665
|
if (fromConfig != null) {
|
|
12661
|
-
createFileSearchStoreConfigToMldev(fromConfig, toObject);
|
|
12666
|
+
createFileSearchStoreConfigToMldev(apiClient, fromConfig, toObject);
|
|
12662
12667
|
}
|
|
12663
12668
|
return toObject;
|
|
12664
12669
|
}
|
|
@@ -12884,7 +12889,7 @@ const CONTENT_TYPE_HEADER = 'Content-Type';
|
|
|
12884
12889
|
const SERVER_TIMEOUT_HEADER = 'X-Server-Timeout';
|
|
12885
12890
|
const USER_AGENT_HEADER = 'User-Agent';
|
|
12886
12891
|
const GOOGLE_API_CLIENT_HEADER = 'x-goog-api-client';
|
|
12887
|
-
const SDK_VERSION = '
|
|
12892
|
+
const SDK_VERSION = '2.0.0'; // x-release-please-version
|
|
12888
12893
|
const LIBRARY_LABEL = `google-genai-sdk/${SDK_VERSION}`;
|
|
12889
12894
|
const VERTEX_AI_API_DEFAULT_VERSION = 'v1beta1';
|
|
12890
12895
|
const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
|
|
@@ -13149,6 +13154,24 @@ class ApiClient {
|
|
|
13149
13154
|
const abortController = new AbortController();
|
|
13150
13155
|
const signal = abortController.signal;
|
|
13151
13156
|
if (httpOptions.timeout && (httpOptions === null || httpOptions === void 0 ? void 0 : httpOptions.timeout) > 0) {
|
|
13157
|
+
// In Node > 18, the built-in fetch is backed by Undici. Undici sets a global
|
|
13158
|
+
// dispatcher on the global scope which tracks its internal headersTimeout and
|
|
13159
|
+
// bodyTimeout using Symbol properties.
|
|
13160
|
+
const dispatcherSymbol = Symbol.for('undici.globalDispatcher.1');
|
|
13161
|
+
const globalDispatcher = globalThis[dispatcherSymbol];
|
|
13162
|
+
if (globalDispatcher) {
|
|
13163
|
+
const symbols = Object.getOwnPropertySymbols(globalDispatcher);
|
|
13164
|
+
for (const sym of symbols) {
|
|
13165
|
+
const desc = sym.description;
|
|
13166
|
+
if ((desc === null || desc === void 0 ? void 0 : desc.includes('headers timeout')) ||
|
|
13167
|
+
(desc === null || desc === void 0 ? void 0 : desc.includes('body timeout'))) {
|
|
13168
|
+
const currentTimeout = globalDispatcher[sym];
|
|
13169
|
+
if (typeof currentTimeout === 'number') {
|
|
13170
|
+
globalDispatcher[sym] = Math.max(currentTimeout, httpOptions.timeout);
|
|
13171
|
+
}
|
|
13172
|
+
}
|
|
13173
|
+
}
|
|
13174
|
+
}
|
|
13152
13175
|
const timeoutHandle = setTimeout(() => abortController.abort(), httpOptions.timeout);
|
|
13153
13176
|
if (timeoutHandle &&
|
|
13154
13177
|
typeof timeoutHandle.unref ===
|
|
@@ -13182,7 +13205,7 @@ class ApiClient {
|
|
|
13182
13205
|
throw e;
|
|
13183
13206
|
}
|
|
13184
13207
|
else {
|
|
13185
|
-
throw new Error(
|
|
13208
|
+
throw new Error(`exception ${e} sending request`, { cause: e });
|
|
13186
13209
|
}
|
|
13187
13210
|
});
|
|
13188
13211
|
}
|
|
@@ -13197,7 +13220,7 @@ class ApiClient {
|
|
|
13197
13220
|
throw e;
|
|
13198
13221
|
}
|
|
13199
13222
|
else {
|
|
13200
|
-
throw new Error(
|
|
13223
|
+
throw new Error(`exception ${e} sending request`, { cause: e });
|
|
13201
13224
|
}
|
|
13202
13225
|
});
|
|
13203
13226
|
}
|
|
@@ -13325,11 +13348,14 @@ class ApiClient {
|
|
|
13325
13348
|
for (const [key, value] of Object.entries(httpOptions.headers)) {
|
|
13326
13349
|
headers.append(key, value);
|
|
13327
13350
|
}
|
|
13328
|
-
|
|
13329
|
-
|
|
13330
|
-
|
|
13331
|
-
|
|
13332
|
-
|
|
13351
|
+
}
|
|
13352
|
+
// Append a timeout header if it is set, note that the timeout option is
|
|
13353
|
+
// in milliseconds but the header is in seconds.
|
|
13354
|
+
// NOTE: This is intentionally outside the httpOptions.headers guard above
|
|
13355
|
+
// so that the X-Server-Timeout header is always sent whenever a timeout
|
|
13356
|
+
// is configured, even if the caller did not supply any custom headers.
|
|
13357
|
+
if ((httpOptions === null || httpOptions === void 0 ? void 0 : httpOptions.timeout) && httpOptions.timeout > 0) {
|
|
13358
|
+
headers.append(SERVER_TIMEOUT_HEADER, String(Math.ceil(httpOptions.timeout / 1000)));
|
|
13333
13359
|
}
|
|
13334
13360
|
await this.clientOptions.auth.addAuthHeaders(headers, url);
|
|
13335
13361
|
return headers;
|
|
@@ -17246,6 +17272,46 @@ class FileSearchStores extends BaseModule {
|
|
|
17246
17272
|
}
|
|
17247
17273
|
return this.apiClient.uploadFileToFileSearchStore(params.fileSearchStoreName, params.file, params.config);
|
|
17248
17274
|
}
|
|
17275
|
+
/**
|
|
17276
|
+
* Downloads media using a Media ID or URI.
|
|
17277
|
+
* This method is only supported in the Gemini Developer client.
|
|
17278
|
+
*
|
|
17279
|
+
* @param uri - The URI or Media ID of the blob.
|
|
17280
|
+
* @param config - Optional configuration for the download.
|
|
17281
|
+
* @returns A promise that resolves to the blob data as a Uint8Array.
|
|
17282
|
+
*/
|
|
17283
|
+
async downloadMedia(uri, config) {
|
|
17284
|
+
if (this.apiClient.isVertexAI()) {
|
|
17285
|
+
throw new Error('This method is only supported in the Gemini Developer client.');
|
|
17286
|
+
}
|
|
17287
|
+
const parsedUri = new URL(uri, 'http://dummy.com');
|
|
17288
|
+
let pathname = parsedUri.pathname;
|
|
17289
|
+
if (pathname.startsWith('/')) {
|
|
17290
|
+
pathname = pathname.slice(1);
|
|
17291
|
+
}
|
|
17292
|
+
if (!pathname.includes('/media/')) {
|
|
17293
|
+
throw new Error(`Invalid uri format: ${uri}. Expected to contain /media/`);
|
|
17294
|
+
}
|
|
17295
|
+
const queryParams = {};
|
|
17296
|
+
parsedUri.searchParams.forEach((value, key) => {
|
|
17297
|
+
queryParams[key] = value;
|
|
17298
|
+
});
|
|
17299
|
+
queryParams['alt'] = 'media';
|
|
17300
|
+
const httpOptions = Object.assign({}, config === null || config === void 0 ? void 0 : config.httpOptions);
|
|
17301
|
+
const response = await this.apiClient.request({
|
|
17302
|
+
path: pathname,
|
|
17303
|
+
httpMethod: 'GET',
|
|
17304
|
+
queryParams: queryParams,
|
|
17305
|
+
httpOptions: httpOptions,
|
|
17306
|
+
});
|
|
17307
|
+
if (response instanceof HttpResponse) {
|
|
17308
|
+
const arrayBuffer = await response.responseInternal.arrayBuffer();
|
|
17309
|
+
return new Uint8Array(arrayBuffer);
|
|
17310
|
+
}
|
|
17311
|
+
else {
|
|
17312
|
+
throw new Error('Unexpected response type from downloadMedia');
|
|
17313
|
+
}
|
|
17314
|
+
}
|
|
17249
17315
|
/**
|
|
17250
17316
|
* Creates a File Search Store.
|
|
17251
17317
|
*
|
|
@@ -17261,7 +17327,7 @@ class FileSearchStores extends BaseModule {
|
|
|
17261
17327
|
throw new Error('This method is only supported by the Gemini Developer API.');
|
|
17262
17328
|
}
|
|
17263
17329
|
else {
|
|
17264
|
-
const body = createFileSearchStoreParametersToMldev(params);
|
|
17330
|
+
const body = createFileSearchStoreParametersToMldev(this.apiClient, params);
|
|
17265
17331
|
path = formatMap('fileSearchStores', body['_url']);
|
|
17266
17332
|
queryParams = body['_query'];
|
|
17267
17333
|
delete body['_url'];
|
|
@@ -19292,7 +19358,7 @@ class BaseGeminiNextGenAPIClient {
|
|
|
19292
19358
|
const authHeaders = await this.authHeaders(options);
|
|
19293
19359
|
let headers = buildHeaders([
|
|
19294
19360
|
idempotencyHeaders,
|
|
19295
|
-
{ Accept: 'application/json', 'User-Agent': this.getUserAgent() },
|
|
19361
|
+
{ Accept: 'application/json', 'User-Agent': this.getUserAgent(), 'Api-Revision': '2026-05-20' },
|
|
19296
19362
|
this._options.defaultHeaders,
|
|
19297
19363
|
bodyHeaders,
|
|
19298
19364
|
options.headers,
|
|
@@ -20822,7 +20888,6 @@ class GoogleGenAI {
|
|
|
20822
20888
|
if (this._interactions !== undefined) {
|
|
20823
20889
|
return this._interactions;
|
|
20824
20890
|
}
|
|
20825
|
-
console.warn('GoogleGenAI.interactions: Interactions usage is experimental and may change in future versions.');
|
|
20826
20891
|
this._interactions = this.getNextGenClient().interactions;
|
|
20827
20892
|
return this._interactions;
|
|
20828
20893
|
}
|