@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.
@@ -909,6 +909,40 @@ export declare class CountTokensResponse {
909
909
  cachedContentTokenCount?: number;
910
910
  }
911
911
 
912
+ /** Optional parameters. */
913
+ export declare interface CreateAuthTokenConfig {
914
+ /** Used to override HTTP request options. */
915
+ httpOptions?: HttpOptions;
916
+ /** Abort signal which can be used to cancel the request.
917
+
918
+ NOTE: AbortSignal is a client-only operation. Using it to cancel an
919
+ operation will not cancel the request in the service. You will still
920
+ be charged usage for any applicable operations.
921
+ */
922
+ abortSignal?: AbortSignal;
923
+ /** An optional time after which, when using the resulting token,
924
+ messages in Live API sessions will be rejected. (Gemini may
925
+ preemptively close the session after this time.)
926
+
927
+ If not set then this defaults to 30 minutes in the future. If set, this
928
+ value must be less than 20 hours in the future. */
929
+ expireTime?: string;
930
+ /** The time after which new Live API sessions using the token
931
+ resulting from this request will be rejected.
932
+
933
+ If not set this defaults to 60 seconds in the future. If set, this value
934
+ must be less than 20 hours in the future. */
935
+ newSessionExpireTime?: string;
936
+ /** The number of times the token can be used. If this value is zero
937
+ then no limit is applied. Default is 1. Resuming a Live API session does
938
+ not count as a use. */
939
+ uses?: number;
940
+ /** Configuration specific to Live API connections created using this token. */
941
+ liveEphemeralParameters?: LiveEphemeralParameters;
942
+ /** Additional fields to lock in the effective LiveConnectParameters. */
943
+ lockAdditionalFields?: string[];
944
+ }
945
+
912
946
  /** Optional configuration for cached content creation. */
913
947
  export declare interface CreateCachedContentConfig {
914
948
  /** Used to override HTTP request options. */
@@ -3224,7 +3258,7 @@ export declare class Live {
3224
3258
  Establishes a connection to the specified model with the given
3225
3259
  configuration and returns a Session object representing that connection.
3226
3260
 
3227
- @experimental Built-in MCP support is a preview feature, may change in
3261
+ @experimental Built-in MCP support is an experimental feature, may change in
3228
3262
  future versions.
3229
3263
 
3230
3264
  @remarks
@@ -3419,6 +3453,15 @@ export declare class LiveClientToolResponse {
3419
3453
 
3420
3454
  /** Session config for the API connection. */
3421
3455
  export declare interface LiveConnectConfig {
3456
+ /** Used to override HTTP request options. */
3457
+ httpOptions?: HttpOptions;
3458
+ /** Abort signal which can be used to cancel the request.
3459
+
3460
+ NOTE: AbortSignal is a client-only operation. Using it to cancel an
3461
+ operation will not cancel the request in the service. You will still
3462
+ be charged usage for any applicable operations.
3463
+ */
3464
+ abortSignal?: AbortSignal;
3422
3465
  /** The generation configuration for the session. */
3423
3466
  generationConfig?: GenerationConfig;
3424
3467
  /** The requested modalities of the response. Represents the set of
@@ -3503,6 +3546,16 @@ export declare interface LiveConnectParameters {
3503
3546
  config?: LiveConnectConfig;
3504
3547
  }
3505
3548
 
3549
+ /** Config for LiveEphemeralParameters for Auth Token creation. */
3550
+ export declare interface LiveEphemeralParameters {
3551
+ /** ID of the model to configure in the ephemeral token for Live API.
3552
+ For a list of models, see `Gemini models
3553
+ <https://ai.google.dev/gemini-api/docs/models>`. */
3554
+ model?: string;
3555
+ /** Configuration specific to Live API connections created using this token. */
3556
+ config?: LiveConnectConfig;
3557
+ }
3558
+
3506
3559
  /**
3507
3560
  LiveMusic class encapsulates the configuration for live music
3508
3561
  generation via Lyria Live models.
@@ -3701,7 +3754,7 @@ export declare interface LiveMusicServerSetupComplete {
3701
3754
 
3702
3755
  @experimental
3703
3756
  */
3704
- declare class LiveMusicSession {
3757
+ export declare class LiveMusicSession {
3705
3758
  readonly conn: WebSocket_2;
3706
3759
  private readonly apiClient;
3707
3760
  constructor(conn: WebSocket_2, apiClient: ApiClient);
@@ -3716,7 +3769,7 @@ declare class LiveMusicSession {
3716
3769
 
3717
3770
  @experimental
3718
3771
  */
3719
- setClientContent(params: types.LiveMusicSetClientContentParameters): Promise<void>;
3772
+ setWeightedPrompts(params: types.LiveMusicSetWeightedPromptsParameters): Promise<void>;
3720
3773
  /**
3721
3774
  Sets a configuration to the model. Updates the session's current
3722
3775
  music generation config.
@@ -3765,18 +3818,18 @@ declare class LiveMusicSession {
3765
3818
  close(): void;
3766
3819
  }
3767
3820
 
3768
- /** Parameters for setting client content for the live API. */
3769
- export declare interface LiveMusicSetClientContentParameters {
3770
- /** A map of text prompts to weights to use for the generation request. */
3771
- weightedPrompts: WeightedPrompt[];
3772
- }
3773
-
3774
- /** Parameters for setting config for the live API. */
3821
+ /** Parameters for setting config for the live music API. */
3775
3822
  export declare interface LiveMusicSetConfigParameters {
3776
3823
  /** Configuration for music generation. */
3777
3824
  musicGenerationConfig: LiveMusicGenerationConfig;
3778
3825
  }
3779
3826
 
3827
+ /** Parameters for setting weighted prompts for the live music API. */
3828
+ export declare interface LiveMusicSetWeightedPromptsParameters {
3829
+ /** A map of text prompts to weights to use for the generation request. */
3830
+ weightedPrompts: WeightedPrompt[];
3831
+ }
3832
+
3780
3833
  /** Prompts and config used for generating this audio chunk. */
3781
3834
  export declare interface LiveMusicSourceMetadata {
3782
3835
  /** Weighted prompts for generating this audio chunk. */
@@ -4017,7 +4070,7 @@ export declare enum MaskReferenceMode {
4017
4070
  * arguments. (often for automatic function calling).
4018
4071
  * Use the config to modify tool parameters such as behavior.
4019
4072
  *
4020
- * @experimental Built-in MCP support is a preview feature, may change in future
4073
+ * @experimental Built-in MCP support is an experimental feature, may change in future
4021
4074
  * versions.
4022
4075
  */
4023
4076
  export declare function mcpToTool(...args: [...Client[], CallableToolConfig | Client]): CallableTool;
@@ -4230,9 +4283,10 @@ export declare class Models extends BaseModule {
4230
4283
  /**
4231
4284
  * Transforms the CallableTools in the parameters to be simply Tools, it
4232
4285
  * copies the params into a new object and replaces the tools, it does not
4233
- * modify the original params.
4286
+ * modify the original params. Also sets the MCP usage header if there are
4287
+ * MCP tools in the parameters.
4234
4288
  */
4235
- private transformCallableTools;
4289
+ private processParamsForMcpUsage;
4236
4290
  private initAfcToolsMap;
4237
4291
  private processAfcStream;
4238
4292
  /**
@@ -6020,7 +6074,9 @@ declare namespace types {
6020
6074
  CallableToolConfig,
6021
6075
  LiveMusicConnectParameters,
6022
6076
  LiveMusicSetConfigParameters,
6023
- LiveMusicSetClientContentParameters,
6077
+ LiveMusicSetWeightedPromptsParameters,
6078
+ LiveEphemeralParameters,
6079
+ CreateAuthTokenConfig,
6024
6080
  OperationGetParameters,
6025
6081
  BlobImageUnion,
6026
6082
  PartUnion,
@@ -4200,7 +4200,10 @@ class Chat {
4200
4200
  this.recordHistory(inputContent, modelOutput, automaticFunctionCallingHistory);
4201
4201
  return;
4202
4202
  })();
4203
- await this.sendPromise;
4203
+ await this.sendPromise.catch(() => {
4204
+ // Resets sendPromise to avoid subsequent calls failing
4205
+ this.sendPromise = Promise.resolve();
4206
+ });
4204
4207
  return responsePromise;
4205
4208
  }
4206
4209
  /**
@@ -5968,7 +5971,7 @@ function weightedPromptToMldev(apiClient, fromObject) {
5968
5971
  }
5969
5972
  return toObject;
5970
5973
  }
5971
- function liveMusicSetClientContentParametersToMldev(apiClient, fromObject) {
5974
+ function liveMusicSetWeightedPromptsParametersToMldev(apiClient, fromObject) {
5972
5975
  const toObject = {};
5973
5976
  const fromWeightedPrompts = getValueByPath(fromObject, [
5974
5977
  'weightedPrompts',
@@ -10209,7 +10212,7 @@ const CONTENT_TYPE_HEADER = 'Content-Type';
10209
10212
  const SERVER_TIMEOUT_HEADER = 'X-Server-Timeout';
10210
10213
  const USER_AGENT_HEADER = 'User-Agent';
10211
10214
  const GOOGLE_API_CLIENT_HEADER = 'x-goog-api-client';
10212
- const SDK_VERSION = '0.15.0'; // x-release-please-version
10215
+ const SDK_VERSION = '1.0.1'; // x-release-please-version
10213
10216
  const LIBRARY_LABEL = `google-genai-sdk/${SDK_VERSION}`;
10214
10217
  const VERTEX_AI_API_DEFAULT_VERSION = 'v1beta1';
10215
10218
  const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
@@ -10744,7 +10747,11 @@ function hasMcpToolUsage(tools) {
10744
10747
  // Sets the MCP version label in the Google API client header.
10745
10748
  function setMcpUsageHeader(headers) {
10746
10749
  var _a;
10747
- headers[GOOGLE_API_CLIENT_HEADER] = (((_a = headers[GOOGLE_API_CLIENT_HEADER]) !== null && _a !== void 0 ? _a : '') + ` ${MCP_LABEL}`).trimStart();
10750
+ const existingHeader = (_a = headers[GOOGLE_API_CLIENT_HEADER]) !== null && _a !== void 0 ? _a : '';
10751
+ if (existingHeader.includes(MCP_LABEL)) {
10752
+ return;
10753
+ }
10754
+ headers[GOOGLE_API_CLIENT_HEADER] = (existingHeader + ` ${MCP_LABEL}`).trimStart();
10748
10755
  }
10749
10756
  // Checks whether the list of tools contains any MCP clients. Will return true
10750
10757
  // if there is at least one MCP client.
@@ -10788,7 +10795,7 @@ function listAllTools(mcpClient, maxTools = 100) {
10788
10795
  * McpCallableTool can be used for model inference and invoking MCP clients with
10789
10796
  * given function call arguments.
10790
10797
  *
10791
- * @experimental Built-in MCP support is a preview feature, may change in future
10798
+ * @experimental Built-in MCP support is an experimental feature, may change in future
10792
10799
  * versions.
10793
10800
  */
10794
10801
  class McpCallableTool {
@@ -10883,7 +10890,7 @@ function isMcpClient(client) {
10883
10890
  * arguments. (often for automatic function calling).
10884
10891
  * Use the config to modify tool parameters such as behavior.
10885
10892
  *
10886
- * @experimental Built-in MCP support is a preview feature, may change in future
10893
+ * @experimental Built-in MCP support is an experimental feature, may change in future
10887
10894
  * versions.
10888
10895
  */
10889
10896
  function mcpToTool(...args) {
@@ -10917,7 +10924,13 @@ function mcpToTool(...args) {
10917
10924
  */
10918
10925
  async function handleWebSocketMessage$1(apiClient, onmessage, event) {
10919
10926
  const serverMessage = new LiveMusicServerMessage();
10920
- const data = JSON.parse(event.data);
10927
+ let data;
10928
+ if (event.data instanceof Blob) {
10929
+ data = JSON.parse(await event.data.text());
10930
+ }
10931
+ else {
10932
+ data = JSON.parse(event.data);
10933
+ }
10921
10934
  const response = liveMusicServerMessageFromMldev(apiClient, data);
10922
10935
  Object.assign(serverMessage, response);
10923
10936
  onmessage(serverMessage);
@@ -11028,13 +11041,13 @@ class LiveMusicSession {
11028
11041
 
11029
11042
  @experimental
11030
11043
  */
11031
- async setClientContent(params) {
11044
+ async setWeightedPrompts(params) {
11032
11045
  if (!params.weightedPrompts ||
11033
11046
  Object.keys(params.weightedPrompts).length === 0) {
11034
11047
  throw new Error('Weighted prompts must be set and contain at least one entry.');
11035
11048
  }
11036
- const setClientContentParameters = liveMusicSetClientContentParametersToMldev(this.apiClient, params);
11037
- const clientContent = liveMusicClientContentToMldev(this.apiClient, setClientContentParameters);
11049
+ const setWeightedPromptsParameters = liveMusicSetWeightedPromptsParametersToMldev(this.apiClient, params);
11050
+ const clientContent = liveMusicClientContentToMldev(this.apiClient, setWeightedPromptsParameters);
11038
11051
  this.conn.send(JSON.stringify({ clientContent }));
11039
11052
  }
11040
11053
  /**
@@ -11182,7 +11195,7 @@ class Live {
11182
11195
  Establishes a connection to the specified model with the given
11183
11196
  configuration and returns a Session object representing that connection.
11184
11197
 
11185
- @experimental Built-in MCP support is a preview feature, may change in
11198
+ @experimental Built-in MCP support is an experimental feature, may change in
11186
11199
  future versions.
11187
11200
 
11188
11201
  @remarks
@@ -11638,25 +11651,14 @@ class Models extends BaseModule {
11638
11651
  */
11639
11652
  this.generateContent = async (params) => {
11640
11653
  var _a, _b, _c, _d, _e;
11641
- if (params.config &&
11642
- params.config.tools &&
11643
- hasMcpToolUsage(params.config.tools)) {
11644
- if (!params.config.httpOptions) {
11645
- params.config.httpOptions = {};
11646
- }
11647
- if (!params.config.httpOptions.headers) {
11648
- params.config.httpOptions.headers = this.apiClient.getDefaultHeaders();
11649
- }
11650
- setMcpUsageHeader(params.config.httpOptions.headers);
11651
- }
11654
+ const transformedParams = await this.processParamsForMcpUsage(params);
11652
11655
  if (!hasMcpClientTools(params) || shouldDisableAfc(params.config)) {
11653
- return await this.generateContentInternal(params);
11656
+ return await this.generateContentInternal(transformedParams);
11654
11657
  }
11655
11658
  // TODO: b/418266406 - Improve the check for CallableTools and Tools.
11656
11659
  if (hasNonMcpTools(params)) {
11657
11660
  throw new Error('Automatic function calling with CallableTools and Tools is not yet supported.');
11658
11661
  }
11659
- const transformedParams = await this.transformCallableTools(params);
11660
11662
  let response;
11661
11663
  let functionResponseContent;
11662
11664
  const automaticFunctionCallingHistory = tContents(this.apiClient, transformedParams.contents);
@@ -11737,19 +11739,8 @@ class Models extends BaseModule {
11737
11739
  * ```
11738
11740
  */
11739
11741
  this.generateContentStream = async (params) => {
11740
- if (params.config &&
11741
- params.config.tools &&
11742
- hasMcpToolUsage(params.config.tools)) {
11743
- if (!params.config.httpOptions) {
11744
- params.config.httpOptions = {};
11745
- }
11746
- if (!params.config.httpOptions.headers) {
11747
- params.config.httpOptions.headers = this.apiClient.getDefaultHeaders();
11748
- }
11749
- setMcpUsageHeader(params.config.httpOptions.headers);
11750
- }
11751
11742
  if (shouldDisableAfc(params.config)) {
11752
- const transformedParams = await this.transformCallableTools(params);
11743
+ const transformedParams = await this.processParamsForMcpUsage(params);
11753
11744
  return await this.generateContentStreamInternal(transformedParams);
11754
11745
  }
11755
11746
  else {
@@ -11902,10 +11893,11 @@ class Models extends BaseModule {
11902
11893
  /**
11903
11894
  * Transforms the CallableTools in the parameters to be simply Tools, it
11904
11895
  * copies the params into a new object and replaces the tools, it does not
11905
- * modify the original params.
11896
+ * modify the original params. Also sets the MCP usage header if there are
11897
+ * MCP tools in the parameters.
11906
11898
  */
11907
- async transformCallableTools(params) {
11908
- var _a;
11899
+ async processParamsForMcpUsage(params) {
11900
+ var _a, _b, _c;
11909
11901
  const tools = (_a = params.config) === null || _a === void 0 ? void 0 : _a.tools;
11910
11902
  if (!tools) {
11911
11903
  return params;
@@ -11923,6 +11915,17 @@ class Models extends BaseModule {
11923
11915
  config: Object.assign(Object.assign({}, params.config), { tools: transformedTools }),
11924
11916
  };
11925
11917
  newParams.config.tools = transformedTools;
11918
+ if (params.config &&
11919
+ params.config.tools &&
11920
+ hasMcpToolUsage(params.config.tools)) {
11921
+ const headers = (_c = (_b = params.config.httpOptions) === null || _b === void 0 ? void 0 : _b.headers) !== null && _c !== void 0 ? _c : {};
11922
+ let newHeaders = Object.assign({}, headers);
11923
+ if (Object.keys(newHeaders).length === 0) {
11924
+ newHeaders = this.apiClient.getDefaultHeaders();
11925
+ }
11926
+ setMcpUsageHeader(newHeaders);
11927
+ newParams.config.httpOptions = Object.assign(Object.assign({}, params.config.httpOptions), { headers: newHeaders });
11928
+ }
11926
11929
  return newParams;
11927
11930
  }
11928
11931
  async initAfcToolsMap(params) {
@@ -11960,7 +11963,7 @@ class Models extends BaseModule {
11960
11963
  remoteCallCount++;
11961
11964
  wereFunctionsCalled = false;
11962
11965
  }
11963
- const transformedParams = yield __await(models.transformCallableTools(params));
11966
+ const transformedParams = yield __await(models.processParamsForMcpUsage(params));
11964
11967
  const response = yield __await(models.generateContentStreamInternal(transformedParams));
11965
11968
  const functionResponses = [];
11966
11969
  const responseContents = [];