@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/dist/index.mjs CHANGED
@@ -4308,7 +4308,7 @@ const CONTENT_TYPE_HEADER = 'Content-Type';
4308
4308
  const SERVER_TIMEOUT_HEADER = 'X-Server-Timeout';
4309
4309
  const USER_AGENT_HEADER = 'User-Agent';
4310
4310
  const GOOGLE_API_CLIENT_HEADER = 'x-goog-api-client';
4311
- const SDK_VERSION = '0.15.0'; // x-release-please-version
4311
+ const SDK_VERSION = '1.0.0'; // x-release-please-version
4312
4312
  const LIBRARY_LABEL = `google-genai-sdk/${SDK_VERSION}`;
4313
4313
  const VERTEX_AI_API_DEFAULT_VERSION = 'v1beta1';
4314
4314
  const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
@@ -6585,7 +6585,7 @@ function weightedPromptToMldev(apiClient, fromObject) {
6585
6585
  }
6586
6586
  return toObject;
6587
6587
  }
6588
- function liveMusicSetClientContentParametersToMldev(apiClient, fromObject) {
6588
+ function liveMusicSetWeightedPromptsParametersToMldev(apiClient, fromObject) {
6589
6589
  const toObject = {};
6590
6590
  const fromWeightedPrompts = getValueByPath(fromObject, [
6591
6591
  'weightedPrompts',
@@ -10839,7 +10839,11 @@ function hasMcpToolUsage(tools) {
10839
10839
  // Sets the MCP version label in the Google API client header.
10840
10840
  function setMcpUsageHeader(headers) {
10841
10841
  var _a;
10842
- headers[GOOGLE_API_CLIENT_HEADER] = (((_a = headers[GOOGLE_API_CLIENT_HEADER]) !== null && _a !== void 0 ? _a : '') + ` ${MCP_LABEL}`).trimStart();
10842
+ const existingHeader = (_a = headers[GOOGLE_API_CLIENT_HEADER]) !== null && _a !== void 0 ? _a : '';
10843
+ if (existingHeader.includes(MCP_LABEL)) {
10844
+ return;
10845
+ }
10846
+ headers[GOOGLE_API_CLIENT_HEADER] = (existingHeader + ` ${MCP_LABEL}`).trimStart();
10843
10847
  }
10844
10848
  // Checks whether the list of tools contains any MCP clients. Will return true
10845
10849
  // if there is at least one MCP client.
@@ -10883,7 +10887,7 @@ function listAllTools(mcpClient, maxTools = 100) {
10883
10887
  * McpCallableTool can be used for model inference and invoking MCP clients with
10884
10888
  * given function call arguments.
10885
10889
  *
10886
- * @experimental Built-in MCP support is a preview feature, may change in future
10890
+ * @experimental Built-in MCP support is an experimental feature, may change in future
10887
10891
  * versions.
10888
10892
  */
10889
10893
  class McpCallableTool {
@@ -10978,7 +10982,7 @@ function isMcpClient(client) {
10978
10982
  * arguments. (often for automatic function calling).
10979
10983
  * Use the config to modify tool parameters such as behavior.
10980
10984
  *
10981
- * @experimental Built-in MCP support is a preview feature, may change in future
10985
+ * @experimental Built-in MCP support is an experimental feature, may change in future
10982
10986
  * versions.
10983
10987
  */
10984
10988
  function mcpToTool(...args) {
@@ -11012,7 +11016,13 @@ function mcpToTool(...args) {
11012
11016
  */
11013
11017
  async function handleWebSocketMessage$1(apiClient, onmessage, event) {
11014
11018
  const serverMessage = new LiveMusicServerMessage();
11015
- const data = JSON.parse(event.data);
11019
+ let data;
11020
+ if (event.data instanceof Blob) {
11021
+ data = JSON.parse(await event.data.text());
11022
+ }
11023
+ else {
11024
+ data = JSON.parse(event.data);
11025
+ }
11016
11026
  const response = liveMusicServerMessageFromMldev(apiClient, data);
11017
11027
  Object.assign(serverMessage, response);
11018
11028
  onmessage(serverMessage);
@@ -11123,13 +11133,13 @@ class LiveMusicSession {
11123
11133
 
11124
11134
  @experimental
11125
11135
  */
11126
- async setClientContent(params) {
11136
+ async setWeightedPrompts(params) {
11127
11137
  if (!params.weightedPrompts ||
11128
11138
  Object.keys(params.weightedPrompts).length === 0) {
11129
11139
  throw new Error('Weighted prompts must be set and contain at least one entry.');
11130
11140
  }
11131
- const setClientContentParameters = liveMusicSetClientContentParametersToMldev(this.apiClient, params);
11132
- const clientContent = liveMusicClientContentToMldev(this.apiClient, setClientContentParameters);
11141
+ const setWeightedPromptsParameters = liveMusicSetWeightedPromptsParametersToMldev(this.apiClient, params);
11142
+ const clientContent = liveMusicClientContentToMldev(this.apiClient, setWeightedPromptsParameters);
11133
11143
  this.conn.send(JSON.stringify({ clientContent }));
11134
11144
  }
11135
11145
  /**
@@ -11277,7 +11287,7 @@ class Live {
11277
11287
  Establishes a connection to the specified model with the given
11278
11288
  configuration and returns a Session object representing that connection.
11279
11289
 
11280
- @experimental Built-in MCP support is a preview feature, may change in
11290
+ @experimental Built-in MCP support is an experimental feature, may change in
11281
11291
  future versions.
11282
11292
 
11283
11293
  @remarks
@@ -11733,25 +11743,14 @@ class Models extends BaseModule {
11733
11743
  */
11734
11744
  this.generateContent = async (params) => {
11735
11745
  var _a, _b, _c, _d, _e;
11736
- if (params.config &&
11737
- params.config.tools &&
11738
- hasMcpToolUsage(params.config.tools)) {
11739
- if (!params.config.httpOptions) {
11740
- params.config.httpOptions = {};
11741
- }
11742
- if (!params.config.httpOptions.headers) {
11743
- params.config.httpOptions.headers = this.apiClient.getDefaultHeaders();
11744
- }
11745
- setMcpUsageHeader(params.config.httpOptions.headers);
11746
- }
11746
+ const transformedParams = await this.processParamsForMcpUsage(params);
11747
11747
  if (!hasMcpClientTools(params) || shouldDisableAfc(params.config)) {
11748
- return await this.generateContentInternal(params);
11748
+ return await this.generateContentInternal(transformedParams);
11749
11749
  }
11750
11750
  // TODO: b/418266406 - Improve the check for CallableTools and Tools.
11751
11751
  if (hasNonMcpTools(params)) {
11752
11752
  throw new Error('Automatic function calling with CallableTools and Tools is not yet supported.');
11753
11753
  }
11754
- const transformedParams = await this.transformCallableTools(params);
11755
11754
  let response;
11756
11755
  let functionResponseContent;
11757
11756
  const automaticFunctionCallingHistory = tContents(this.apiClient, transformedParams.contents);
@@ -11832,19 +11831,8 @@ class Models extends BaseModule {
11832
11831
  * ```
11833
11832
  */
11834
11833
  this.generateContentStream = async (params) => {
11835
- if (params.config &&
11836
- params.config.tools &&
11837
- hasMcpToolUsage(params.config.tools)) {
11838
- if (!params.config.httpOptions) {
11839
- params.config.httpOptions = {};
11840
- }
11841
- if (!params.config.httpOptions.headers) {
11842
- params.config.httpOptions.headers = this.apiClient.getDefaultHeaders();
11843
- }
11844
- setMcpUsageHeader(params.config.httpOptions.headers);
11845
- }
11846
11834
  if (shouldDisableAfc(params.config)) {
11847
- const transformedParams = await this.transformCallableTools(params);
11835
+ const transformedParams = await this.processParamsForMcpUsage(params);
11848
11836
  return await this.generateContentStreamInternal(transformedParams);
11849
11837
  }
11850
11838
  else {
@@ -11997,10 +11985,11 @@ class Models extends BaseModule {
11997
11985
  /**
11998
11986
  * Transforms the CallableTools in the parameters to be simply Tools, it
11999
11987
  * copies the params into a new object and replaces the tools, it does not
12000
- * modify the original params.
11988
+ * modify the original params. Also sets the MCP usage header if there are
11989
+ * MCP tools in the parameters.
12001
11990
  */
12002
- async transformCallableTools(params) {
12003
- var _a;
11991
+ async processParamsForMcpUsage(params) {
11992
+ var _a, _b, _c;
12004
11993
  const tools = (_a = params.config) === null || _a === void 0 ? void 0 : _a.tools;
12005
11994
  if (!tools) {
12006
11995
  return params;
@@ -12018,6 +12007,17 @@ class Models extends BaseModule {
12018
12007
  config: Object.assign(Object.assign({}, params.config), { tools: transformedTools }),
12019
12008
  };
12020
12009
  newParams.config.tools = transformedTools;
12010
+ if (params.config &&
12011
+ params.config.tools &&
12012
+ hasMcpToolUsage(params.config.tools)) {
12013
+ const headers = (_c = (_b = params.config.httpOptions) === null || _b === void 0 ? void 0 : _b.headers) !== null && _c !== void 0 ? _c : {};
12014
+ let newHeaders = Object.assign({}, headers);
12015
+ if (Object.keys(newHeaders).length === 0) {
12016
+ newHeaders = this.apiClient.getDefaultHeaders();
12017
+ }
12018
+ setMcpUsageHeader(newHeaders);
12019
+ newParams.config.httpOptions = Object.assign(Object.assign({}, params.config.httpOptions), { headers: newHeaders });
12020
+ }
12021
12021
  return newParams;
12022
12022
  }
12023
12023
  async initAfcToolsMap(params) {
@@ -12055,7 +12055,7 @@ class Models extends BaseModule {
12055
12055
  remoteCallCount++;
12056
12056
  wereFunctionsCalled = false;
12057
12057
  }
12058
- const transformedParams = yield __await(models.transformCallableTools(params));
12058
+ const transformedParams = yield __await(models.processParamsForMcpUsage(params));
12059
12059
  const response = yield __await(models.generateContentStreamInternal(transformedParams));
12060
12060
  const functionResponses = [];
12061
12061
  const responseContents = [];