@google/genai 0.15.0 → 1.0.1
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 +0 -17
- package/dist/genai.d.ts +70 -14
- package/dist/index.mjs +43 -40
- package/dist/index.mjs.map +1 -1
- package/dist/node/index.mjs +43 -40
- package/dist/node/index.mjs.map +1 -1
- package/dist/node/node.d.ts +70 -14
- package/dist/web/index.mjs +43 -40
- package/dist/web/index.mjs.map +1 -1
- package/dist/web/web.d.ts +70 -14
- package/package.json +8 -17
- package/dist/index.js +0 -14209
- package/dist/index.js.map +0 -1
- package/dist/node/index.js +0 -14614
- package/dist/node/index.js.map +0 -1
package/dist/node/index.mjs
CHANGED
|
@@ -4205,7 +4205,10 @@ class Chat {
|
|
|
4205
4205
|
this.recordHistory(inputContent, modelOutput, automaticFunctionCallingHistory);
|
|
4206
4206
|
return;
|
|
4207
4207
|
})();
|
|
4208
|
-
await this.sendPromise
|
|
4208
|
+
await this.sendPromise.catch(() => {
|
|
4209
|
+
// Resets sendPromise to avoid subsequent calls failing
|
|
4210
|
+
this.sendPromise = Promise.resolve();
|
|
4211
|
+
});
|
|
4209
4212
|
return responsePromise;
|
|
4210
4213
|
}
|
|
4211
4214
|
/**
|
|
@@ -5973,7 +5976,7 @@ function weightedPromptToMldev(apiClient, fromObject) {
|
|
|
5973
5976
|
}
|
|
5974
5977
|
return toObject;
|
|
5975
5978
|
}
|
|
5976
|
-
function
|
|
5979
|
+
function liveMusicSetWeightedPromptsParametersToMldev(apiClient, fromObject) {
|
|
5977
5980
|
const toObject = {};
|
|
5978
5981
|
const fromWeightedPrompts = getValueByPath(fromObject, [
|
|
5979
5982
|
'weightedPrompts',
|
|
@@ -10214,7 +10217,7 @@ const CONTENT_TYPE_HEADER = 'Content-Type';
|
|
|
10214
10217
|
const SERVER_TIMEOUT_HEADER = 'X-Server-Timeout';
|
|
10215
10218
|
const USER_AGENT_HEADER = 'User-Agent';
|
|
10216
10219
|
const GOOGLE_API_CLIENT_HEADER = 'x-goog-api-client';
|
|
10217
|
-
const SDK_VERSION = '0.
|
|
10220
|
+
const SDK_VERSION = '1.0.1'; // x-release-please-version
|
|
10218
10221
|
const LIBRARY_LABEL = `google-genai-sdk/${SDK_VERSION}`;
|
|
10219
10222
|
const VERTEX_AI_API_DEFAULT_VERSION = 'v1beta1';
|
|
10220
10223
|
const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
|
|
@@ -10749,7 +10752,11 @@ function hasMcpToolUsage(tools) {
|
|
|
10749
10752
|
// Sets the MCP version label in the Google API client header.
|
|
10750
10753
|
function setMcpUsageHeader(headers) {
|
|
10751
10754
|
var _a;
|
|
10752
|
-
|
|
10755
|
+
const existingHeader = (_a = headers[GOOGLE_API_CLIENT_HEADER]) !== null && _a !== void 0 ? _a : '';
|
|
10756
|
+
if (existingHeader.includes(MCP_LABEL)) {
|
|
10757
|
+
return;
|
|
10758
|
+
}
|
|
10759
|
+
headers[GOOGLE_API_CLIENT_HEADER] = (existingHeader + ` ${MCP_LABEL}`).trimStart();
|
|
10753
10760
|
}
|
|
10754
10761
|
// Checks whether the list of tools contains any MCP clients. Will return true
|
|
10755
10762
|
// if there is at least one MCP client.
|
|
@@ -10793,7 +10800,7 @@ function listAllTools(mcpClient, maxTools = 100) {
|
|
|
10793
10800
|
* McpCallableTool can be used for model inference and invoking MCP clients with
|
|
10794
10801
|
* given function call arguments.
|
|
10795
10802
|
*
|
|
10796
|
-
* @experimental Built-in MCP support is
|
|
10803
|
+
* @experimental Built-in MCP support is an experimental feature, may change in future
|
|
10797
10804
|
* versions.
|
|
10798
10805
|
*/
|
|
10799
10806
|
class McpCallableTool {
|
|
@@ -10888,7 +10895,7 @@ function isMcpClient(client) {
|
|
|
10888
10895
|
* arguments. (often for automatic function calling).
|
|
10889
10896
|
* Use the config to modify tool parameters such as behavior.
|
|
10890
10897
|
*
|
|
10891
|
-
* @experimental Built-in MCP support is
|
|
10898
|
+
* @experimental Built-in MCP support is an experimental feature, may change in future
|
|
10892
10899
|
* versions.
|
|
10893
10900
|
*/
|
|
10894
10901
|
function mcpToTool(...args) {
|
|
@@ -10922,7 +10929,13 @@ function mcpToTool(...args) {
|
|
|
10922
10929
|
*/
|
|
10923
10930
|
async function handleWebSocketMessage$1(apiClient, onmessage, event) {
|
|
10924
10931
|
const serverMessage = new LiveMusicServerMessage();
|
|
10925
|
-
|
|
10932
|
+
let data;
|
|
10933
|
+
if (event.data instanceof Blob) {
|
|
10934
|
+
data = JSON.parse(await event.data.text());
|
|
10935
|
+
}
|
|
10936
|
+
else {
|
|
10937
|
+
data = JSON.parse(event.data);
|
|
10938
|
+
}
|
|
10926
10939
|
const response = liveMusicServerMessageFromMldev(apiClient, data);
|
|
10927
10940
|
Object.assign(serverMessage, response);
|
|
10928
10941
|
onmessage(serverMessage);
|
|
@@ -11033,13 +11046,13 @@ class LiveMusicSession {
|
|
|
11033
11046
|
|
|
11034
11047
|
@experimental
|
|
11035
11048
|
*/
|
|
11036
|
-
async
|
|
11049
|
+
async setWeightedPrompts(params) {
|
|
11037
11050
|
if (!params.weightedPrompts ||
|
|
11038
11051
|
Object.keys(params.weightedPrompts).length === 0) {
|
|
11039
11052
|
throw new Error('Weighted prompts must be set and contain at least one entry.');
|
|
11040
11053
|
}
|
|
11041
|
-
const
|
|
11042
|
-
const clientContent = liveMusicClientContentToMldev(this.apiClient,
|
|
11054
|
+
const setWeightedPromptsParameters = liveMusicSetWeightedPromptsParametersToMldev(this.apiClient, params);
|
|
11055
|
+
const clientContent = liveMusicClientContentToMldev(this.apiClient, setWeightedPromptsParameters);
|
|
11043
11056
|
this.conn.send(JSON.stringify({ clientContent }));
|
|
11044
11057
|
}
|
|
11045
11058
|
/**
|
|
@@ -11187,7 +11200,7 @@ class Live {
|
|
|
11187
11200
|
Establishes a connection to the specified model with the given
|
|
11188
11201
|
configuration and returns a Session object representing that connection.
|
|
11189
11202
|
|
|
11190
|
-
@experimental Built-in MCP support is
|
|
11203
|
+
@experimental Built-in MCP support is an experimental feature, may change in
|
|
11191
11204
|
future versions.
|
|
11192
11205
|
|
|
11193
11206
|
@remarks
|
|
@@ -11643,25 +11656,14 @@ class Models extends BaseModule {
|
|
|
11643
11656
|
*/
|
|
11644
11657
|
this.generateContent = async (params) => {
|
|
11645
11658
|
var _a, _b, _c, _d, _e;
|
|
11646
|
-
|
|
11647
|
-
params.config.tools &&
|
|
11648
|
-
hasMcpToolUsage(params.config.tools)) {
|
|
11649
|
-
if (!params.config.httpOptions) {
|
|
11650
|
-
params.config.httpOptions = {};
|
|
11651
|
-
}
|
|
11652
|
-
if (!params.config.httpOptions.headers) {
|
|
11653
|
-
params.config.httpOptions.headers = this.apiClient.getDefaultHeaders();
|
|
11654
|
-
}
|
|
11655
|
-
setMcpUsageHeader(params.config.httpOptions.headers);
|
|
11656
|
-
}
|
|
11659
|
+
const transformedParams = await this.processParamsForMcpUsage(params);
|
|
11657
11660
|
if (!hasMcpClientTools(params) || shouldDisableAfc(params.config)) {
|
|
11658
|
-
return await this.generateContentInternal(
|
|
11661
|
+
return await this.generateContentInternal(transformedParams);
|
|
11659
11662
|
}
|
|
11660
11663
|
// TODO: b/418266406 - Improve the check for CallableTools and Tools.
|
|
11661
11664
|
if (hasNonMcpTools(params)) {
|
|
11662
11665
|
throw new Error('Automatic function calling with CallableTools and Tools is not yet supported.');
|
|
11663
11666
|
}
|
|
11664
|
-
const transformedParams = await this.transformCallableTools(params);
|
|
11665
11667
|
let response;
|
|
11666
11668
|
let functionResponseContent;
|
|
11667
11669
|
const automaticFunctionCallingHistory = tContents(this.apiClient, transformedParams.contents);
|
|
@@ -11742,19 +11744,8 @@ class Models extends BaseModule {
|
|
|
11742
11744
|
* ```
|
|
11743
11745
|
*/
|
|
11744
11746
|
this.generateContentStream = async (params) => {
|
|
11745
|
-
if (params.config &&
|
|
11746
|
-
params.config.tools &&
|
|
11747
|
-
hasMcpToolUsage(params.config.tools)) {
|
|
11748
|
-
if (!params.config.httpOptions) {
|
|
11749
|
-
params.config.httpOptions = {};
|
|
11750
|
-
}
|
|
11751
|
-
if (!params.config.httpOptions.headers) {
|
|
11752
|
-
params.config.httpOptions.headers = this.apiClient.getDefaultHeaders();
|
|
11753
|
-
}
|
|
11754
|
-
setMcpUsageHeader(params.config.httpOptions.headers);
|
|
11755
|
-
}
|
|
11756
11747
|
if (shouldDisableAfc(params.config)) {
|
|
11757
|
-
const transformedParams = await this.
|
|
11748
|
+
const transformedParams = await this.processParamsForMcpUsage(params);
|
|
11758
11749
|
return await this.generateContentStreamInternal(transformedParams);
|
|
11759
11750
|
}
|
|
11760
11751
|
else {
|
|
@@ -11907,10 +11898,11 @@ class Models extends BaseModule {
|
|
|
11907
11898
|
/**
|
|
11908
11899
|
* Transforms the CallableTools in the parameters to be simply Tools, it
|
|
11909
11900
|
* copies the params into a new object and replaces the tools, it does not
|
|
11910
|
-
* modify the original params.
|
|
11901
|
+
* modify the original params. Also sets the MCP usage header if there are
|
|
11902
|
+
* MCP tools in the parameters.
|
|
11911
11903
|
*/
|
|
11912
|
-
async
|
|
11913
|
-
var _a;
|
|
11904
|
+
async processParamsForMcpUsage(params) {
|
|
11905
|
+
var _a, _b, _c;
|
|
11914
11906
|
const tools = (_a = params.config) === null || _a === void 0 ? void 0 : _a.tools;
|
|
11915
11907
|
if (!tools) {
|
|
11916
11908
|
return params;
|
|
@@ -11928,6 +11920,17 @@ class Models extends BaseModule {
|
|
|
11928
11920
|
config: Object.assign(Object.assign({}, params.config), { tools: transformedTools }),
|
|
11929
11921
|
};
|
|
11930
11922
|
newParams.config.tools = transformedTools;
|
|
11923
|
+
if (params.config &&
|
|
11924
|
+
params.config.tools &&
|
|
11925
|
+
hasMcpToolUsage(params.config.tools)) {
|
|
11926
|
+
const headers = (_c = (_b = params.config.httpOptions) === null || _b === void 0 ? void 0 : _b.headers) !== null && _c !== void 0 ? _c : {};
|
|
11927
|
+
let newHeaders = Object.assign({}, headers);
|
|
11928
|
+
if (Object.keys(newHeaders).length === 0) {
|
|
11929
|
+
newHeaders = this.apiClient.getDefaultHeaders();
|
|
11930
|
+
}
|
|
11931
|
+
setMcpUsageHeader(newHeaders);
|
|
11932
|
+
newParams.config.httpOptions = Object.assign(Object.assign({}, params.config.httpOptions), { headers: newHeaders });
|
|
11933
|
+
}
|
|
11931
11934
|
return newParams;
|
|
11932
11935
|
}
|
|
11933
11936
|
async initAfcToolsMap(params) {
|
|
@@ -11965,7 +11968,7 @@ class Models extends BaseModule {
|
|
|
11965
11968
|
remoteCallCount++;
|
|
11966
11969
|
wereFunctionsCalled = false;
|
|
11967
11970
|
}
|
|
11968
|
-
const transformedParams = yield __await(models.
|
|
11971
|
+
const transformedParams = yield __await(models.processParamsForMcpUsage(params));
|
|
11969
11972
|
const response = yield __await(models.generateContentStreamInternal(transformedParams));
|
|
11970
11973
|
const functionResponses = [];
|
|
11971
11974
|
const responseContents = [];
|