@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/node.d.ts
CHANGED
|
@@ -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
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
|
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
|
-
|
|
6077
|
+
LiveMusicSetWeightedPromptsParameters,
|
|
6078
|
+
LiveEphemeralParameters,
|
|
6079
|
+
CreateAuthTokenConfig,
|
|
6024
6080
|
OperationGetParameters,
|
|
6025
6081
|
BlobImageUnion,
|
|
6026
6082
|
PartUnion,
|
package/dist/web/index.mjs
CHANGED
|
@@ -5968,7 +5968,7 @@ function weightedPromptToMldev(apiClient, fromObject) {
|
|
|
5968
5968
|
}
|
|
5969
5969
|
return toObject;
|
|
5970
5970
|
}
|
|
5971
|
-
function
|
|
5971
|
+
function liveMusicSetWeightedPromptsParametersToMldev(apiClient, fromObject) {
|
|
5972
5972
|
const toObject = {};
|
|
5973
5973
|
const fromWeightedPrompts = getValueByPath(fromObject, [
|
|
5974
5974
|
'weightedPrompts',
|
|
@@ -10209,7 +10209,7 @@ const CONTENT_TYPE_HEADER = 'Content-Type';
|
|
|
10209
10209
|
const SERVER_TIMEOUT_HEADER = 'X-Server-Timeout';
|
|
10210
10210
|
const USER_AGENT_HEADER = 'User-Agent';
|
|
10211
10211
|
const GOOGLE_API_CLIENT_HEADER = 'x-goog-api-client';
|
|
10212
|
-
const SDK_VERSION = '0.
|
|
10212
|
+
const SDK_VERSION = '1.0.0'; // x-release-please-version
|
|
10213
10213
|
const LIBRARY_LABEL = `google-genai-sdk/${SDK_VERSION}`;
|
|
10214
10214
|
const VERTEX_AI_API_DEFAULT_VERSION = 'v1beta1';
|
|
10215
10215
|
const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
|
|
@@ -10744,7 +10744,11 @@ function hasMcpToolUsage(tools) {
|
|
|
10744
10744
|
// Sets the MCP version label in the Google API client header.
|
|
10745
10745
|
function setMcpUsageHeader(headers) {
|
|
10746
10746
|
var _a;
|
|
10747
|
-
|
|
10747
|
+
const existingHeader = (_a = headers[GOOGLE_API_CLIENT_HEADER]) !== null && _a !== void 0 ? _a : '';
|
|
10748
|
+
if (existingHeader.includes(MCP_LABEL)) {
|
|
10749
|
+
return;
|
|
10750
|
+
}
|
|
10751
|
+
headers[GOOGLE_API_CLIENT_HEADER] = (existingHeader + ` ${MCP_LABEL}`).trimStart();
|
|
10748
10752
|
}
|
|
10749
10753
|
// Checks whether the list of tools contains any MCP clients. Will return true
|
|
10750
10754
|
// if there is at least one MCP client.
|
|
@@ -10788,7 +10792,7 @@ function listAllTools(mcpClient, maxTools = 100) {
|
|
|
10788
10792
|
* McpCallableTool can be used for model inference and invoking MCP clients with
|
|
10789
10793
|
* given function call arguments.
|
|
10790
10794
|
*
|
|
10791
|
-
* @experimental Built-in MCP support is
|
|
10795
|
+
* @experimental Built-in MCP support is an experimental feature, may change in future
|
|
10792
10796
|
* versions.
|
|
10793
10797
|
*/
|
|
10794
10798
|
class McpCallableTool {
|
|
@@ -10883,7 +10887,7 @@ function isMcpClient(client) {
|
|
|
10883
10887
|
* arguments. (often for automatic function calling).
|
|
10884
10888
|
* Use the config to modify tool parameters such as behavior.
|
|
10885
10889
|
*
|
|
10886
|
-
* @experimental Built-in MCP support is
|
|
10890
|
+
* @experimental Built-in MCP support is an experimental feature, may change in future
|
|
10887
10891
|
* versions.
|
|
10888
10892
|
*/
|
|
10889
10893
|
function mcpToTool(...args) {
|
|
@@ -10917,7 +10921,13 @@ function mcpToTool(...args) {
|
|
|
10917
10921
|
*/
|
|
10918
10922
|
async function handleWebSocketMessage$1(apiClient, onmessage, event) {
|
|
10919
10923
|
const serverMessage = new LiveMusicServerMessage();
|
|
10920
|
-
|
|
10924
|
+
let data;
|
|
10925
|
+
if (event.data instanceof Blob) {
|
|
10926
|
+
data = JSON.parse(await event.data.text());
|
|
10927
|
+
}
|
|
10928
|
+
else {
|
|
10929
|
+
data = JSON.parse(event.data);
|
|
10930
|
+
}
|
|
10921
10931
|
const response = liveMusicServerMessageFromMldev(apiClient, data);
|
|
10922
10932
|
Object.assign(serverMessage, response);
|
|
10923
10933
|
onmessage(serverMessage);
|
|
@@ -11028,13 +11038,13 @@ class LiveMusicSession {
|
|
|
11028
11038
|
|
|
11029
11039
|
@experimental
|
|
11030
11040
|
*/
|
|
11031
|
-
async
|
|
11041
|
+
async setWeightedPrompts(params) {
|
|
11032
11042
|
if (!params.weightedPrompts ||
|
|
11033
11043
|
Object.keys(params.weightedPrompts).length === 0) {
|
|
11034
11044
|
throw new Error('Weighted prompts must be set and contain at least one entry.');
|
|
11035
11045
|
}
|
|
11036
|
-
const
|
|
11037
|
-
const clientContent = liveMusicClientContentToMldev(this.apiClient,
|
|
11046
|
+
const setWeightedPromptsParameters = liveMusicSetWeightedPromptsParametersToMldev(this.apiClient, params);
|
|
11047
|
+
const clientContent = liveMusicClientContentToMldev(this.apiClient, setWeightedPromptsParameters);
|
|
11038
11048
|
this.conn.send(JSON.stringify({ clientContent }));
|
|
11039
11049
|
}
|
|
11040
11050
|
/**
|
|
@@ -11182,7 +11192,7 @@ class Live {
|
|
|
11182
11192
|
Establishes a connection to the specified model with the given
|
|
11183
11193
|
configuration and returns a Session object representing that connection.
|
|
11184
11194
|
|
|
11185
|
-
@experimental Built-in MCP support is
|
|
11195
|
+
@experimental Built-in MCP support is an experimental feature, may change in
|
|
11186
11196
|
future versions.
|
|
11187
11197
|
|
|
11188
11198
|
@remarks
|
|
@@ -11638,25 +11648,14 @@ class Models extends BaseModule {
|
|
|
11638
11648
|
*/
|
|
11639
11649
|
this.generateContent = async (params) => {
|
|
11640
11650
|
var _a, _b, _c, _d, _e;
|
|
11641
|
-
|
|
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
|
-
}
|
|
11651
|
+
const transformedParams = await this.processParamsForMcpUsage(params);
|
|
11652
11652
|
if (!hasMcpClientTools(params) || shouldDisableAfc(params.config)) {
|
|
11653
|
-
return await this.generateContentInternal(
|
|
11653
|
+
return await this.generateContentInternal(transformedParams);
|
|
11654
11654
|
}
|
|
11655
11655
|
// TODO: b/418266406 - Improve the check for CallableTools and Tools.
|
|
11656
11656
|
if (hasNonMcpTools(params)) {
|
|
11657
11657
|
throw new Error('Automatic function calling with CallableTools and Tools is not yet supported.');
|
|
11658
11658
|
}
|
|
11659
|
-
const transformedParams = await this.transformCallableTools(params);
|
|
11660
11659
|
let response;
|
|
11661
11660
|
let functionResponseContent;
|
|
11662
11661
|
const automaticFunctionCallingHistory = tContents(this.apiClient, transformedParams.contents);
|
|
@@ -11737,19 +11736,8 @@ class Models extends BaseModule {
|
|
|
11737
11736
|
* ```
|
|
11738
11737
|
*/
|
|
11739
11738
|
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
11739
|
if (shouldDisableAfc(params.config)) {
|
|
11752
|
-
const transformedParams = await this.
|
|
11740
|
+
const transformedParams = await this.processParamsForMcpUsage(params);
|
|
11753
11741
|
return await this.generateContentStreamInternal(transformedParams);
|
|
11754
11742
|
}
|
|
11755
11743
|
else {
|
|
@@ -11902,10 +11890,11 @@ class Models extends BaseModule {
|
|
|
11902
11890
|
/**
|
|
11903
11891
|
* Transforms the CallableTools in the parameters to be simply Tools, it
|
|
11904
11892
|
* copies the params into a new object and replaces the tools, it does not
|
|
11905
|
-
* modify the original params.
|
|
11893
|
+
* modify the original params. Also sets the MCP usage header if there are
|
|
11894
|
+
* MCP tools in the parameters.
|
|
11906
11895
|
*/
|
|
11907
|
-
async
|
|
11908
|
-
var _a;
|
|
11896
|
+
async processParamsForMcpUsage(params) {
|
|
11897
|
+
var _a, _b, _c;
|
|
11909
11898
|
const tools = (_a = params.config) === null || _a === void 0 ? void 0 : _a.tools;
|
|
11910
11899
|
if (!tools) {
|
|
11911
11900
|
return params;
|
|
@@ -11923,6 +11912,17 @@ class Models extends BaseModule {
|
|
|
11923
11912
|
config: Object.assign(Object.assign({}, params.config), { tools: transformedTools }),
|
|
11924
11913
|
};
|
|
11925
11914
|
newParams.config.tools = transformedTools;
|
|
11915
|
+
if (params.config &&
|
|
11916
|
+
params.config.tools &&
|
|
11917
|
+
hasMcpToolUsage(params.config.tools)) {
|
|
11918
|
+
const headers = (_c = (_b = params.config.httpOptions) === null || _b === void 0 ? void 0 : _b.headers) !== null && _c !== void 0 ? _c : {};
|
|
11919
|
+
let newHeaders = Object.assign({}, headers);
|
|
11920
|
+
if (Object.keys(newHeaders).length === 0) {
|
|
11921
|
+
newHeaders = this.apiClient.getDefaultHeaders();
|
|
11922
|
+
}
|
|
11923
|
+
setMcpUsageHeader(newHeaders);
|
|
11924
|
+
newParams.config.httpOptions = Object.assign(Object.assign({}, params.config.httpOptions), { headers: newHeaders });
|
|
11925
|
+
}
|
|
11926
11926
|
return newParams;
|
|
11927
11927
|
}
|
|
11928
11928
|
async initAfcToolsMap(params) {
|
|
@@ -11960,7 +11960,7 @@ class Models extends BaseModule {
|
|
|
11960
11960
|
remoteCallCount++;
|
|
11961
11961
|
wereFunctionsCalled = false;
|
|
11962
11962
|
}
|
|
11963
|
-
const transformedParams = yield __await(models.
|
|
11963
|
+
const transformedParams = yield __await(models.processParamsForMcpUsage(params));
|
|
11964
11964
|
const response = yield __await(models.generateContentStreamInternal(transformedParams));
|
|
11965
11965
|
const functionResponses = [];
|
|
11966
11966
|
const responseContents = [];
|