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