@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.js
CHANGED
|
@@ -5995,7 +5995,7 @@ function weightedPromptToMldev(apiClient, fromObject) {
|
|
|
5995
5995
|
}
|
|
5996
5996
|
return toObject;
|
|
5997
5997
|
}
|
|
5998
|
-
function
|
|
5998
|
+
function liveMusicSetWeightedPromptsParametersToMldev(apiClient, fromObject) {
|
|
5999
5999
|
const toObject = {};
|
|
6000
6000
|
const fromWeightedPrompts = getValueByPath(fromObject, [
|
|
6001
6001
|
'weightedPrompts',
|
|
@@ -10236,7 +10236,7 @@ const CONTENT_TYPE_HEADER = 'Content-Type';
|
|
|
10236
10236
|
const SERVER_TIMEOUT_HEADER = 'X-Server-Timeout';
|
|
10237
10237
|
const USER_AGENT_HEADER = 'User-Agent';
|
|
10238
10238
|
const GOOGLE_API_CLIENT_HEADER = 'x-goog-api-client';
|
|
10239
|
-
const SDK_VERSION = '0.
|
|
10239
|
+
const SDK_VERSION = '1.0.0'; // x-release-please-version
|
|
10240
10240
|
const LIBRARY_LABEL = `google-genai-sdk/${SDK_VERSION}`;
|
|
10241
10241
|
const VERTEX_AI_API_DEFAULT_VERSION = 'v1beta1';
|
|
10242
10242
|
const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
|
|
@@ -10771,7 +10771,11 @@ function hasMcpToolUsage(tools) {
|
|
|
10771
10771
|
// Sets the MCP version label in the Google API client header.
|
|
10772
10772
|
function setMcpUsageHeader(headers) {
|
|
10773
10773
|
var _a;
|
|
10774
|
-
|
|
10774
|
+
const existingHeader = (_a = headers[GOOGLE_API_CLIENT_HEADER]) !== null && _a !== void 0 ? _a : '';
|
|
10775
|
+
if (existingHeader.includes(MCP_LABEL)) {
|
|
10776
|
+
return;
|
|
10777
|
+
}
|
|
10778
|
+
headers[GOOGLE_API_CLIENT_HEADER] = (existingHeader + ` ${MCP_LABEL}`).trimStart();
|
|
10775
10779
|
}
|
|
10776
10780
|
// Checks whether the list of tools contains any MCP clients. Will return true
|
|
10777
10781
|
// if there is at least one MCP client.
|
|
@@ -10815,7 +10819,7 @@ function listAllTools(mcpClient, maxTools = 100) {
|
|
|
10815
10819
|
* McpCallableTool can be used for model inference and invoking MCP clients with
|
|
10816
10820
|
* given function call arguments.
|
|
10817
10821
|
*
|
|
10818
|
-
* @experimental Built-in MCP support is
|
|
10822
|
+
* @experimental Built-in MCP support is an experimental feature, may change in future
|
|
10819
10823
|
* versions.
|
|
10820
10824
|
*/
|
|
10821
10825
|
class McpCallableTool {
|
|
@@ -10910,7 +10914,7 @@ function isMcpClient(client) {
|
|
|
10910
10914
|
* arguments. (often for automatic function calling).
|
|
10911
10915
|
* Use the config to modify tool parameters such as behavior.
|
|
10912
10916
|
*
|
|
10913
|
-
* @experimental Built-in MCP support is
|
|
10917
|
+
* @experimental Built-in MCP support is an experimental feature, may change in future
|
|
10914
10918
|
* versions.
|
|
10915
10919
|
*/
|
|
10916
10920
|
function mcpToTool(...args) {
|
|
@@ -10944,7 +10948,13 @@ function mcpToTool(...args) {
|
|
|
10944
10948
|
*/
|
|
10945
10949
|
async function handleWebSocketMessage$1(apiClient, onmessage, event) {
|
|
10946
10950
|
const serverMessage = new LiveMusicServerMessage();
|
|
10947
|
-
|
|
10951
|
+
let data;
|
|
10952
|
+
if (event.data instanceof Blob) {
|
|
10953
|
+
data = JSON.parse(await event.data.text());
|
|
10954
|
+
}
|
|
10955
|
+
else {
|
|
10956
|
+
data = JSON.parse(event.data);
|
|
10957
|
+
}
|
|
10948
10958
|
const response = liveMusicServerMessageFromMldev(apiClient, data);
|
|
10949
10959
|
Object.assign(serverMessage, response);
|
|
10950
10960
|
onmessage(serverMessage);
|
|
@@ -11055,13 +11065,13 @@ class LiveMusicSession {
|
|
|
11055
11065
|
|
|
11056
11066
|
@experimental
|
|
11057
11067
|
*/
|
|
11058
|
-
async
|
|
11068
|
+
async setWeightedPrompts(params) {
|
|
11059
11069
|
if (!params.weightedPrompts ||
|
|
11060
11070
|
Object.keys(params.weightedPrompts).length === 0) {
|
|
11061
11071
|
throw new Error('Weighted prompts must be set and contain at least one entry.');
|
|
11062
11072
|
}
|
|
11063
|
-
const
|
|
11064
|
-
const clientContent = liveMusicClientContentToMldev(this.apiClient,
|
|
11073
|
+
const setWeightedPromptsParameters = liveMusicSetWeightedPromptsParametersToMldev(this.apiClient, params);
|
|
11074
|
+
const clientContent = liveMusicClientContentToMldev(this.apiClient, setWeightedPromptsParameters);
|
|
11065
11075
|
this.conn.send(JSON.stringify({ clientContent }));
|
|
11066
11076
|
}
|
|
11067
11077
|
/**
|
|
@@ -11209,7 +11219,7 @@ class Live {
|
|
|
11209
11219
|
Establishes a connection to the specified model with the given
|
|
11210
11220
|
configuration and returns a Session object representing that connection.
|
|
11211
11221
|
|
|
11212
|
-
@experimental Built-in MCP support is
|
|
11222
|
+
@experimental Built-in MCP support is an experimental feature, may change in
|
|
11213
11223
|
future versions.
|
|
11214
11224
|
|
|
11215
11225
|
@remarks
|
|
@@ -11665,25 +11675,14 @@ class Models extends BaseModule {
|
|
|
11665
11675
|
*/
|
|
11666
11676
|
this.generateContent = async (params) => {
|
|
11667
11677
|
var _a, _b, _c, _d, _e;
|
|
11668
|
-
|
|
11669
|
-
params.config.tools &&
|
|
11670
|
-
hasMcpToolUsage(params.config.tools)) {
|
|
11671
|
-
if (!params.config.httpOptions) {
|
|
11672
|
-
params.config.httpOptions = {};
|
|
11673
|
-
}
|
|
11674
|
-
if (!params.config.httpOptions.headers) {
|
|
11675
|
-
params.config.httpOptions.headers = this.apiClient.getDefaultHeaders();
|
|
11676
|
-
}
|
|
11677
|
-
setMcpUsageHeader(params.config.httpOptions.headers);
|
|
11678
|
-
}
|
|
11678
|
+
const transformedParams = await this.processParamsForMcpUsage(params);
|
|
11679
11679
|
if (!hasMcpClientTools(params) || shouldDisableAfc(params.config)) {
|
|
11680
|
-
return await this.generateContentInternal(
|
|
11680
|
+
return await this.generateContentInternal(transformedParams);
|
|
11681
11681
|
}
|
|
11682
11682
|
// TODO: b/418266406 - Improve the check for CallableTools and Tools.
|
|
11683
11683
|
if (hasNonMcpTools(params)) {
|
|
11684
11684
|
throw new Error('Automatic function calling with CallableTools and Tools is not yet supported.');
|
|
11685
11685
|
}
|
|
11686
|
-
const transformedParams = await this.transformCallableTools(params);
|
|
11687
11686
|
let response;
|
|
11688
11687
|
let functionResponseContent;
|
|
11689
11688
|
const automaticFunctionCallingHistory = tContents(this.apiClient, transformedParams.contents);
|
|
@@ -11764,19 +11763,8 @@ class Models extends BaseModule {
|
|
|
11764
11763
|
* ```
|
|
11765
11764
|
*/
|
|
11766
11765
|
this.generateContentStream = async (params) => {
|
|
11767
|
-
if (params.config &&
|
|
11768
|
-
params.config.tools &&
|
|
11769
|
-
hasMcpToolUsage(params.config.tools)) {
|
|
11770
|
-
if (!params.config.httpOptions) {
|
|
11771
|
-
params.config.httpOptions = {};
|
|
11772
|
-
}
|
|
11773
|
-
if (!params.config.httpOptions.headers) {
|
|
11774
|
-
params.config.httpOptions.headers = this.apiClient.getDefaultHeaders();
|
|
11775
|
-
}
|
|
11776
|
-
setMcpUsageHeader(params.config.httpOptions.headers);
|
|
11777
|
-
}
|
|
11778
11766
|
if (shouldDisableAfc(params.config)) {
|
|
11779
|
-
const transformedParams = await this.
|
|
11767
|
+
const transformedParams = await this.processParamsForMcpUsage(params);
|
|
11780
11768
|
return await this.generateContentStreamInternal(transformedParams);
|
|
11781
11769
|
}
|
|
11782
11770
|
else {
|
|
@@ -11929,10 +11917,11 @@ class Models extends BaseModule {
|
|
|
11929
11917
|
/**
|
|
11930
11918
|
* Transforms the CallableTools in the parameters to be simply Tools, it
|
|
11931
11919
|
* copies the params into a new object and replaces the tools, it does not
|
|
11932
|
-
* modify the original params.
|
|
11920
|
+
* modify the original params. Also sets the MCP usage header if there are
|
|
11921
|
+
* MCP tools in the parameters.
|
|
11933
11922
|
*/
|
|
11934
|
-
async
|
|
11935
|
-
var _a;
|
|
11923
|
+
async processParamsForMcpUsage(params) {
|
|
11924
|
+
var _a, _b, _c;
|
|
11936
11925
|
const tools = (_a = params.config) === null || _a === void 0 ? void 0 : _a.tools;
|
|
11937
11926
|
if (!tools) {
|
|
11938
11927
|
return params;
|
|
@@ -11950,6 +11939,17 @@ class Models extends BaseModule {
|
|
|
11950
11939
|
config: Object.assign(Object.assign({}, params.config), { tools: transformedTools }),
|
|
11951
11940
|
};
|
|
11952
11941
|
newParams.config.tools = transformedTools;
|
|
11942
|
+
if (params.config &&
|
|
11943
|
+
params.config.tools &&
|
|
11944
|
+
hasMcpToolUsage(params.config.tools)) {
|
|
11945
|
+
const headers = (_c = (_b = params.config.httpOptions) === null || _b === void 0 ? void 0 : _b.headers) !== null && _c !== void 0 ? _c : {};
|
|
11946
|
+
let newHeaders = Object.assign({}, headers);
|
|
11947
|
+
if (Object.keys(newHeaders).length === 0) {
|
|
11948
|
+
newHeaders = this.apiClient.getDefaultHeaders();
|
|
11949
|
+
}
|
|
11950
|
+
setMcpUsageHeader(newHeaders);
|
|
11951
|
+
newParams.config.httpOptions = Object.assign(Object.assign({}, params.config.httpOptions), { headers: newHeaders });
|
|
11952
|
+
}
|
|
11953
11953
|
return newParams;
|
|
11954
11954
|
}
|
|
11955
11955
|
async initAfcToolsMap(params) {
|
|
@@ -11987,7 +11987,7 @@ class Models extends BaseModule {
|
|
|
11987
11987
|
remoteCallCount++;
|
|
11988
11988
|
wereFunctionsCalled = false;
|
|
11989
11989
|
}
|
|
11990
|
-
const transformedParams = yield __await(models.
|
|
11990
|
+
const transformedParams = yield __await(models.processParamsForMcpUsage(params));
|
|
11991
11991
|
const response = yield __await(models.generateContentStreamInternal(transformedParams));
|
|
11992
11992
|
const functionResponses = [];
|
|
11993
11993
|
const responseContents = [];
|