@google/genai 1.4.0 → 1.5.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 +26 -4
- package/dist/index.cjs +42 -2
- package/dist/index.mjs +42 -2
- package/dist/index.mjs.map +1 -1
- package/dist/node/index.cjs +49 -3
- package/dist/node/index.mjs +49 -3
- package/dist/node/index.mjs.map +1 -1
- package/dist/node/node.d.ts +26 -4
- package/dist/web/index.mjs +42 -2
- package/dist/web/index.mjs.map +1 -1
- package/dist/web/web.d.ts +26 -4
- package/package.json +6 -1
package/dist/node/index.cjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var zod = require('zod');
|
|
4
|
+
var types_js = require('@modelcontextprotocol/sdk/types.js');
|
|
4
5
|
var googleAuthLibrary = require('google-auth-library');
|
|
5
6
|
var fs = require('fs');
|
|
6
7
|
var node_stream = require('node:stream');
|
|
@@ -3663,7 +3664,7 @@ class Caches extends BaseModule {
|
|
|
3663
3664
|
* @example
|
|
3664
3665
|
* ```ts
|
|
3665
3666
|
* const cachedContents = await ai.caches.list({config: {'pageSize': 2}});
|
|
3666
|
-
* for (const cachedContent of cachedContents) {
|
|
3667
|
+
* for await (const cachedContent of cachedContents) {
|
|
3667
3668
|
* console.log(cachedContent);
|
|
3668
3669
|
* }
|
|
3669
3670
|
* ```
|
|
@@ -8149,6 +8150,9 @@ function generateVideosConfigToMldev(apiClient, fromObject, parentObject) {
|
|
|
8149
8150
|
if (getValueByPath(fromObject, ['generateAudio']) !== undefined) {
|
|
8150
8151
|
throw new Error('generateAudio parameter is not supported in Gemini API.');
|
|
8151
8152
|
}
|
|
8153
|
+
if (getValueByPath(fromObject, ['lastFrame']) !== undefined) {
|
|
8154
|
+
throw new Error('lastFrame parameter is not supported in Gemini API.');
|
|
8155
|
+
}
|
|
8152
8156
|
return toObject;
|
|
8153
8157
|
}
|
|
8154
8158
|
function generateVideosParametersToMldev(apiClient, fromObject) {
|
|
@@ -8165,6 +8169,9 @@ function generateVideosParametersToMldev(apiClient, fromObject) {
|
|
|
8165
8169
|
if (fromImage != null) {
|
|
8166
8170
|
setValueByPath(toObject, ['instances[0]', 'image'], imageToMldev(apiClient, fromImage));
|
|
8167
8171
|
}
|
|
8172
|
+
if (getValueByPath(fromObject, ['video']) !== undefined) {
|
|
8173
|
+
throw new Error('video parameter is not supported in Gemini API.');
|
|
8174
|
+
}
|
|
8168
8175
|
const fromConfig = getValueByPath(fromObject, ['config']);
|
|
8169
8176
|
if (fromConfig != null) {
|
|
8170
8177
|
setValueByPath(toObject, ['config'], generateVideosConfigToMldev(apiClient, fromConfig, toObject));
|
|
@@ -9443,6 +9450,22 @@ function computeTokensParametersToVertex(apiClient, fromObject) {
|
|
|
9443
9450
|
}
|
|
9444
9451
|
return toObject;
|
|
9445
9452
|
}
|
|
9453
|
+
function videoToVertex(apiClient, fromObject) {
|
|
9454
|
+
const toObject = {};
|
|
9455
|
+
const fromUri = getValueByPath(fromObject, ['uri']);
|
|
9456
|
+
if (fromUri != null) {
|
|
9457
|
+
setValueByPath(toObject, ['gcsUri'], fromUri);
|
|
9458
|
+
}
|
|
9459
|
+
const fromVideoBytes = getValueByPath(fromObject, ['videoBytes']);
|
|
9460
|
+
if (fromVideoBytes != null) {
|
|
9461
|
+
setValueByPath(toObject, ['bytesBase64Encoded'], tBytes(apiClient, fromVideoBytes));
|
|
9462
|
+
}
|
|
9463
|
+
const fromMimeType = getValueByPath(fromObject, ['mimeType']);
|
|
9464
|
+
if (fromMimeType != null) {
|
|
9465
|
+
setValueByPath(toObject, ['mimeType'], fromMimeType);
|
|
9466
|
+
}
|
|
9467
|
+
return toObject;
|
|
9468
|
+
}
|
|
9446
9469
|
function generateVideosConfigToVertex(apiClient, fromObject, parentObject) {
|
|
9447
9470
|
const toObject = {};
|
|
9448
9471
|
const fromNumberOfVideos = getValueByPath(fromObject, [
|
|
@@ -9505,6 +9528,10 @@ function generateVideosConfigToVertex(apiClient, fromObject, parentObject) {
|
|
|
9505
9528
|
if (parentObject !== undefined && fromGenerateAudio != null) {
|
|
9506
9529
|
setValueByPath(parentObject, ['parameters', 'generateAudio'], fromGenerateAudio);
|
|
9507
9530
|
}
|
|
9531
|
+
const fromLastFrame = getValueByPath(fromObject, ['lastFrame']);
|
|
9532
|
+
if (parentObject !== undefined && fromLastFrame != null) {
|
|
9533
|
+
setValueByPath(parentObject, ['instances[0]', 'lastFrame'], imageToVertex(apiClient, fromLastFrame));
|
|
9534
|
+
}
|
|
9508
9535
|
return toObject;
|
|
9509
9536
|
}
|
|
9510
9537
|
function generateVideosParametersToVertex(apiClient, fromObject) {
|
|
@@ -9521,6 +9548,10 @@ function generateVideosParametersToVertex(apiClient, fromObject) {
|
|
|
9521
9548
|
if (fromImage != null) {
|
|
9522
9549
|
setValueByPath(toObject, ['instances[0]', 'image'], imageToVertex(apiClient, fromImage));
|
|
9523
9550
|
}
|
|
9551
|
+
const fromVideo = getValueByPath(fromObject, ['video']);
|
|
9552
|
+
if (fromVideo != null) {
|
|
9553
|
+
setValueByPath(toObject, ['instances[0]', 'video'], videoToVertex(apiClient, fromVideo));
|
|
9554
|
+
}
|
|
9524
9555
|
const fromConfig = getValueByPath(fromObject, ['config']);
|
|
9525
9556
|
if (fromConfig != null) {
|
|
9526
9557
|
setValueByPath(toObject, ['config'], generateVideosConfigToVertex(apiClient, fromConfig, toObject));
|
|
@@ -10693,7 +10724,7 @@ const CONTENT_TYPE_HEADER = 'Content-Type';
|
|
|
10693
10724
|
const SERVER_TIMEOUT_HEADER = 'X-Server-Timeout';
|
|
10694
10725
|
const USER_AGENT_HEADER = 'User-Agent';
|
|
10695
10726
|
const GOOGLE_API_CLIENT_HEADER = 'x-goog-api-client';
|
|
10696
|
-
const SDK_VERSION = '1.
|
|
10727
|
+
const SDK_VERSION = '1.5.0'; // x-release-please-version
|
|
10697
10728
|
const LIBRARY_LABEL = `google-genai-sdk/${SDK_VERSION}`;
|
|
10698
10729
|
const VERTEX_AI_API_DEFAULT_VERSION = 'v1beta1';
|
|
10699
10730
|
const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
|
|
@@ -11336,9 +11367,18 @@ class McpCallableTool {
|
|
|
11336
11367
|
for (const functionCall of functionCalls) {
|
|
11337
11368
|
if (functionCall.name in this.functionNameToMcpClient) {
|
|
11338
11369
|
const mcpClient = this.functionNameToMcpClient[functionCall.name];
|
|
11370
|
+
let requestOptions = undefined;
|
|
11371
|
+
// TODO: b/424238654 - Add support for finer grained timeout control.
|
|
11372
|
+
if (this.config.timeout) {
|
|
11373
|
+
requestOptions = {
|
|
11374
|
+
timeout: this.config.timeout,
|
|
11375
|
+
};
|
|
11376
|
+
}
|
|
11339
11377
|
const callToolResponse = await mcpClient.callTool({
|
|
11340
11378
|
name: functionCall.name,
|
|
11341
11379
|
arguments: functionCall.args,
|
|
11380
|
+
CallToolResultSchema: types_js.CallToolResultSchema,
|
|
11381
|
+
requestOptions,
|
|
11342
11382
|
});
|
|
11343
11383
|
functionCallResponseParts.push({
|
|
11344
11384
|
functionResponse: {
|
|
@@ -15783,7 +15823,7 @@ const LANGUAGE_LABEL_PREFIX = 'gl-node/';
|
|
|
15783
15823
|
*/
|
|
15784
15824
|
class GoogleGenAI {
|
|
15785
15825
|
constructor(options) {
|
|
15786
|
-
var _a, _b, _c, _d, _e;
|
|
15826
|
+
var _a, _b, _c, _d, _e, _f;
|
|
15787
15827
|
// Validate explicitly set initializer values.
|
|
15788
15828
|
if ((options.project || options.location) && options.apiKey) {
|
|
15789
15829
|
throw new Error('Project/location and API key are mutually exclusive in the client initializer.');
|
|
@@ -15798,6 +15838,12 @@ class GoogleGenAI {
|
|
|
15798
15838
|
this.location = (_e = options.location) !== null && _e !== void 0 ? _e : envLocation;
|
|
15799
15839
|
// Handle when to use Vertex AI in express mode (api key)
|
|
15800
15840
|
if (options.vertexai) {
|
|
15841
|
+
if ((_f = options.googleAuthOptions) === null || _f === void 0 ? void 0 : _f.credentials) {
|
|
15842
|
+
// Explicit credentials take precedence over implicit api_key.
|
|
15843
|
+
console.debug('The user provided Google Cloud credentials will take precedence' +
|
|
15844
|
+
' over the API key from the environment variable.');
|
|
15845
|
+
this.apiKey = undefined;
|
|
15846
|
+
}
|
|
15801
15847
|
// Explicit api_key and explicit project/location already handled above.
|
|
15802
15848
|
if ((envProject || envLocation) && options.apiKey) {
|
|
15803
15849
|
// Explicit api_key takes precedence over implicit project/location.
|
package/dist/node/index.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
+
import { CallToolResultSchema } from '@modelcontextprotocol/sdk/types.js';
|
|
2
3
|
import { GoogleAuth } from 'google-auth-library';
|
|
3
4
|
import { createWriteStream, writeFile } from 'fs';
|
|
4
5
|
import { Readable } from 'node:stream';
|
|
@@ -3641,7 +3642,7 @@ class Caches extends BaseModule {
|
|
|
3641
3642
|
* @example
|
|
3642
3643
|
* ```ts
|
|
3643
3644
|
* const cachedContents = await ai.caches.list({config: {'pageSize': 2}});
|
|
3644
|
-
* for (const cachedContent of cachedContents) {
|
|
3645
|
+
* for await (const cachedContent of cachedContents) {
|
|
3645
3646
|
* console.log(cachedContent);
|
|
3646
3647
|
* }
|
|
3647
3648
|
* ```
|
|
@@ -8127,6 +8128,9 @@ function generateVideosConfigToMldev(apiClient, fromObject, parentObject) {
|
|
|
8127
8128
|
if (getValueByPath(fromObject, ['generateAudio']) !== undefined) {
|
|
8128
8129
|
throw new Error('generateAudio parameter is not supported in Gemini API.');
|
|
8129
8130
|
}
|
|
8131
|
+
if (getValueByPath(fromObject, ['lastFrame']) !== undefined) {
|
|
8132
|
+
throw new Error('lastFrame parameter is not supported in Gemini API.');
|
|
8133
|
+
}
|
|
8130
8134
|
return toObject;
|
|
8131
8135
|
}
|
|
8132
8136
|
function generateVideosParametersToMldev(apiClient, fromObject) {
|
|
@@ -8143,6 +8147,9 @@ function generateVideosParametersToMldev(apiClient, fromObject) {
|
|
|
8143
8147
|
if (fromImage != null) {
|
|
8144
8148
|
setValueByPath(toObject, ['instances[0]', 'image'], imageToMldev(apiClient, fromImage));
|
|
8145
8149
|
}
|
|
8150
|
+
if (getValueByPath(fromObject, ['video']) !== undefined) {
|
|
8151
|
+
throw new Error('video parameter is not supported in Gemini API.');
|
|
8152
|
+
}
|
|
8146
8153
|
const fromConfig = getValueByPath(fromObject, ['config']);
|
|
8147
8154
|
if (fromConfig != null) {
|
|
8148
8155
|
setValueByPath(toObject, ['config'], generateVideosConfigToMldev(apiClient, fromConfig, toObject));
|
|
@@ -9421,6 +9428,22 @@ function computeTokensParametersToVertex(apiClient, fromObject) {
|
|
|
9421
9428
|
}
|
|
9422
9429
|
return toObject;
|
|
9423
9430
|
}
|
|
9431
|
+
function videoToVertex(apiClient, fromObject) {
|
|
9432
|
+
const toObject = {};
|
|
9433
|
+
const fromUri = getValueByPath(fromObject, ['uri']);
|
|
9434
|
+
if (fromUri != null) {
|
|
9435
|
+
setValueByPath(toObject, ['gcsUri'], fromUri);
|
|
9436
|
+
}
|
|
9437
|
+
const fromVideoBytes = getValueByPath(fromObject, ['videoBytes']);
|
|
9438
|
+
if (fromVideoBytes != null) {
|
|
9439
|
+
setValueByPath(toObject, ['bytesBase64Encoded'], tBytes(apiClient, fromVideoBytes));
|
|
9440
|
+
}
|
|
9441
|
+
const fromMimeType = getValueByPath(fromObject, ['mimeType']);
|
|
9442
|
+
if (fromMimeType != null) {
|
|
9443
|
+
setValueByPath(toObject, ['mimeType'], fromMimeType);
|
|
9444
|
+
}
|
|
9445
|
+
return toObject;
|
|
9446
|
+
}
|
|
9424
9447
|
function generateVideosConfigToVertex(apiClient, fromObject, parentObject) {
|
|
9425
9448
|
const toObject = {};
|
|
9426
9449
|
const fromNumberOfVideos = getValueByPath(fromObject, [
|
|
@@ -9483,6 +9506,10 @@ function generateVideosConfigToVertex(apiClient, fromObject, parentObject) {
|
|
|
9483
9506
|
if (parentObject !== undefined && fromGenerateAudio != null) {
|
|
9484
9507
|
setValueByPath(parentObject, ['parameters', 'generateAudio'], fromGenerateAudio);
|
|
9485
9508
|
}
|
|
9509
|
+
const fromLastFrame = getValueByPath(fromObject, ['lastFrame']);
|
|
9510
|
+
if (parentObject !== undefined && fromLastFrame != null) {
|
|
9511
|
+
setValueByPath(parentObject, ['instances[0]', 'lastFrame'], imageToVertex(apiClient, fromLastFrame));
|
|
9512
|
+
}
|
|
9486
9513
|
return toObject;
|
|
9487
9514
|
}
|
|
9488
9515
|
function generateVideosParametersToVertex(apiClient, fromObject) {
|
|
@@ -9499,6 +9526,10 @@ function generateVideosParametersToVertex(apiClient, fromObject) {
|
|
|
9499
9526
|
if (fromImage != null) {
|
|
9500
9527
|
setValueByPath(toObject, ['instances[0]', 'image'], imageToVertex(apiClient, fromImage));
|
|
9501
9528
|
}
|
|
9529
|
+
const fromVideo = getValueByPath(fromObject, ['video']);
|
|
9530
|
+
if (fromVideo != null) {
|
|
9531
|
+
setValueByPath(toObject, ['instances[0]', 'video'], videoToVertex(apiClient, fromVideo));
|
|
9532
|
+
}
|
|
9502
9533
|
const fromConfig = getValueByPath(fromObject, ['config']);
|
|
9503
9534
|
if (fromConfig != null) {
|
|
9504
9535
|
setValueByPath(toObject, ['config'], generateVideosConfigToVertex(apiClient, fromConfig, toObject));
|
|
@@ -10671,7 +10702,7 @@ const CONTENT_TYPE_HEADER = 'Content-Type';
|
|
|
10671
10702
|
const SERVER_TIMEOUT_HEADER = 'X-Server-Timeout';
|
|
10672
10703
|
const USER_AGENT_HEADER = 'User-Agent';
|
|
10673
10704
|
const GOOGLE_API_CLIENT_HEADER = 'x-goog-api-client';
|
|
10674
|
-
const SDK_VERSION = '1.
|
|
10705
|
+
const SDK_VERSION = '1.5.0'; // x-release-please-version
|
|
10675
10706
|
const LIBRARY_LABEL = `google-genai-sdk/${SDK_VERSION}`;
|
|
10676
10707
|
const VERTEX_AI_API_DEFAULT_VERSION = 'v1beta1';
|
|
10677
10708
|
const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
|
|
@@ -11314,9 +11345,18 @@ class McpCallableTool {
|
|
|
11314
11345
|
for (const functionCall of functionCalls) {
|
|
11315
11346
|
if (functionCall.name in this.functionNameToMcpClient) {
|
|
11316
11347
|
const mcpClient = this.functionNameToMcpClient[functionCall.name];
|
|
11348
|
+
let requestOptions = undefined;
|
|
11349
|
+
// TODO: b/424238654 - Add support for finer grained timeout control.
|
|
11350
|
+
if (this.config.timeout) {
|
|
11351
|
+
requestOptions = {
|
|
11352
|
+
timeout: this.config.timeout,
|
|
11353
|
+
};
|
|
11354
|
+
}
|
|
11317
11355
|
const callToolResponse = await mcpClient.callTool({
|
|
11318
11356
|
name: functionCall.name,
|
|
11319
11357
|
arguments: functionCall.args,
|
|
11358
|
+
CallToolResultSchema,
|
|
11359
|
+
requestOptions,
|
|
11320
11360
|
});
|
|
11321
11361
|
functionCallResponseParts.push({
|
|
11322
11362
|
functionResponse: {
|
|
@@ -15761,7 +15801,7 @@ const LANGUAGE_LABEL_PREFIX = 'gl-node/';
|
|
|
15761
15801
|
*/
|
|
15762
15802
|
class GoogleGenAI {
|
|
15763
15803
|
constructor(options) {
|
|
15764
|
-
var _a, _b, _c, _d, _e;
|
|
15804
|
+
var _a, _b, _c, _d, _e, _f;
|
|
15765
15805
|
// Validate explicitly set initializer values.
|
|
15766
15806
|
if ((options.project || options.location) && options.apiKey) {
|
|
15767
15807
|
throw new Error('Project/location and API key are mutually exclusive in the client initializer.');
|
|
@@ -15776,6 +15816,12 @@ class GoogleGenAI {
|
|
|
15776
15816
|
this.location = (_e = options.location) !== null && _e !== void 0 ? _e : envLocation;
|
|
15777
15817
|
// Handle when to use Vertex AI in express mode (api key)
|
|
15778
15818
|
if (options.vertexai) {
|
|
15819
|
+
if ((_f = options.googleAuthOptions) === null || _f === void 0 ? void 0 : _f.credentials) {
|
|
15820
|
+
// Explicit credentials take precedence over implicit api_key.
|
|
15821
|
+
console.debug('The user provided Google Cloud credentials will take precedence' +
|
|
15822
|
+
' over the API key from the environment variable.');
|
|
15823
|
+
this.apiKey = undefined;
|
|
15824
|
+
}
|
|
15779
15825
|
// Explicit api_key and explicit project/location already handled above.
|
|
15780
15826
|
if ((envProject || envLocation) && options.apiKey) {
|
|
15781
15827
|
// Explicit api_key takes precedence over implicit project/location.
|