@google/genai 1.8.0 → 1.9.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/genai.d.ts +45 -4
- package/dist/index.cjs +99 -192
- package/dist/index.mjs +99 -192
- package/dist/index.mjs.map +1 -1
- package/dist/node/index.cjs +99 -191
- package/dist/node/index.mjs +99 -191
- package/dist/node/index.mjs.map +1 -1
- package/dist/node/node.d.ts +45 -4
- package/dist/web/index.mjs +99 -192
- package/dist/web/index.mjs.map +1 -1
- package/dist/web/web.d.ts +45 -4
- package/package.json +5 -5
package/dist/genai.d.ts
CHANGED
|
@@ -3498,11 +3498,38 @@ export { Image_2 as Image }
|
|
|
3498
3498
|
|
|
3499
3499
|
/** Enum that specifies the language of the text in the prompt. */
|
|
3500
3500
|
export declare enum ImagePromptLanguage {
|
|
3501
|
+
/**
|
|
3502
|
+
* Auto-detect the language.
|
|
3503
|
+
*/
|
|
3501
3504
|
auto = "auto",
|
|
3505
|
+
/**
|
|
3506
|
+
* English
|
|
3507
|
+
*/
|
|
3502
3508
|
en = "en",
|
|
3509
|
+
/**
|
|
3510
|
+
* Japanese
|
|
3511
|
+
*/
|
|
3503
3512
|
ja = "ja",
|
|
3513
|
+
/**
|
|
3514
|
+
* Korean
|
|
3515
|
+
*/
|
|
3504
3516
|
ko = "ko",
|
|
3505
|
-
|
|
3517
|
+
/**
|
|
3518
|
+
* Hindi
|
|
3519
|
+
*/
|
|
3520
|
+
hi = "hi",
|
|
3521
|
+
/**
|
|
3522
|
+
* Chinese
|
|
3523
|
+
*/
|
|
3524
|
+
zh = "zh",
|
|
3525
|
+
/**
|
|
3526
|
+
* Portuguese
|
|
3527
|
+
*/
|
|
3528
|
+
pt = "pt",
|
|
3529
|
+
/**
|
|
3530
|
+
* Spanish
|
|
3531
|
+
*/
|
|
3532
|
+
es = "es"
|
|
3506
3533
|
}
|
|
3507
3534
|
|
|
3508
3535
|
/** Config for inlined request. */
|
|
@@ -3800,7 +3827,7 @@ export declare class Live {
|
|
|
3800
3827
|
if (GOOGLE_GENAI_USE_VERTEXAI) {
|
|
3801
3828
|
model = 'gemini-2.0-flash-live-preview-04-09';
|
|
3802
3829
|
} else {
|
|
3803
|
-
model = 'gemini-2.
|
|
3830
|
+
model = 'gemini-live-2.5-flash-preview';
|
|
3804
3831
|
}
|
|
3805
3832
|
const session = await ai.live.connect({
|
|
3806
3833
|
model: model,
|
|
@@ -4766,6 +4793,14 @@ export declare class Models extends BaseModule {
|
|
|
4766
4793
|
* ```
|
|
4767
4794
|
*/
|
|
4768
4795
|
generateContent: (params: types.GenerateContentParameters) => Promise<types.GenerateContentResponse>;
|
|
4796
|
+
/**
|
|
4797
|
+
* This logic is needed for GenerateContentConfig only.
|
|
4798
|
+
* Previously we made GenerateContentConfig.responseSchema field to accept
|
|
4799
|
+
* unknown. Since v1.9.0, we switch to use backend JSON schema support.
|
|
4800
|
+
* To maintain backward compatibility, we move the data that was treated as
|
|
4801
|
+
* JSON schema from the responseSchema field to the responseJsonSchema field.
|
|
4802
|
+
*/
|
|
4803
|
+
private maybeMoveToResponseJsonSchem;
|
|
4769
4804
|
/**
|
|
4770
4805
|
* Makes an API request to generate content with a given model and yields the
|
|
4771
4806
|
* response in chunks.
|
|
@@ -5778,7 +5813,7 @@ export declare class Session {
|
|
|
5778
5813
|
if (GOOGLE_GENAI_USE_VERTEXAI) {
|
|
5779
5814
|
model = 'gemini-2.0-flash-live-preview-04-09';
|
|
5780
5815
|
} else {
|
|
5781
|
-
model = 'gemini-2.
|
|
5816
|
+
model = 'gemini-live-2.5-flash-preview';
|
|
5782
5817
|
}
|
|
5783
5818
|
const session = await ai.live.connect({
|
|
5784
5819
|
model: model,
|
|
@@ -6073,14 +6108,20 @@ export declare class Tokens extends BaseModule {
|
|
|
6073
6108
|
* @experimental
|
|
6074
6109
|
*
|
|
6075
6110
|
* @remarks
|
|
6076
|
-
*
|
|
6111
|
+
* Ephemeral auth tokens is only supported in the Gemini Developer API.
|
|
6077
6112
|
* It can be used for the session connection to the Live constrained API.
|
|
6113
|
+
* Support in v1alpha only.
|
|
6078
6114
|
*
|
|
6079
6115
|
* @param params - The parameters for the create request.
|
|
6080
6116
|
* @return The created auth token.
|
|
6081
6117
|
*
|
|
6082
6118
|
* @example
|
|
6083
6119
|
* ```ts
|
|
6120
|
+
* const ai = new GoogleGenAI({
|
|
6121
|
+
* apiKey: token.name,
|
|
6122
|
+
* httpOptions: { apiVersion: 'v1alpha' } // Support in v1alpha only.
|
|
6123
|
+
* });
|
|
6124
|
+
*
|
|
6084
6125
|
* // Case 1: If LiveEphemeralParameters is unset, unlock LiveConnectConfig
|
|
6085
6126
|
* // when using the token in Live API sessions. Each session connection can
|
|
6086
6127
|
* // use a different configuration.
|
package/dist/index.cjs
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var zod = require('zod');
|
|
4
|
-
|
|
5
3
|
/**
|
|
6
4
|
* @license
|
|
7
5
|
* Copyright 2025 Google LLC
|
|
@@ -763,11 +761,38 @@ exports.PersonGeneration = void 0;
|
|
|
763
761
|
/** Enum that specifies the language of the text in the prompt. */
|
|
764
762
|
exports.ImagePromptLanguage = void 0;
|
|
765
763
|
(function (ImagePromptLanguage) {
|
|
764
|
+
/**
|
|
765
|
+
* Auto-detect the language.
|
|
766
|
+
*/
|
|
766
767
|
ImagePromptLanguage["auto"] = "auto";
|
|
768
|
+
/**
|
|
769
|
+
* English
|
|
770
|
+
*/
|
|
767
771
|
ImagePromptLanguage["en"] = "en";
|
|
772
|
+
/**
|
|
773
|
+
* Japanese
|
|
774
|
+
*/
|
|
768
775
|
ImagePromptLanguage["ja"] = "ja";
|
|
776
|
+
/**
|
|
777
|
+
* Korean
|
|
778
|
+
*/
|
|
769
779
|
ImagePromptLanguage["ko"] = "ko";
|
|
780
|
+
/**
|
|
781
|
+
* Hindi
|
|
782
|
+
*/
|
|
770
783
|
ImagePromptLanguage["hi"] = "hi";
|
|
784
|
+
/**
|
|
785
|
+
* Chinese
|
|
786
|
+
*/
|
|
787
|
+
ImagePromptLanguage["zh"] = "zh";
|
|
788
|
+
/**
|
|
789
|
+
* Portuguese
|
|
790
|
+
*/
|
|
791
|
+
ImagePromptLanguage["pt"] = "pt";
|
|
792
|
+
/**
|
|
793
|
+
* Spanish
|
|
794
|
+
*/
|
|
795
|
+
ImagePromptLanguage["es"] = "es";
|
|
771
796
|
})(exports.ImagePromptLanguage || (exports.ImagePromptLanguage = {}));
|
|
772
797
|
/** Enum representing the mask mode of a mask reference image. */
|
|
773
798
|
exports.MaskReferenceMode = void 0;
|
|
@@ -1868,133 +1893,12 @@ function tContents(origin) {
|
|
|
1868
1893
|
}
|
|
1869
1894
|
return result;
|
|
1870
1895
|
}
|
|
1871
|
-
// The fields that are supported by JSONSchema. Must be kept in sync with the
|
|
1872
|
-
// JSONSchema interface above.
|
|
1873
|
-
const supportedJsonSchemaFields = new Set([
|
|
1874
|
-
'type',
|
|
1875
|
-
'format',
|
|
1876
|
-
'title',
|
|
1877
|
-
'description',
|
|
1878
|
-
'default',
|
|
1879
|
-
'items',
|
|
1880
|
-
'minItems',
|
|
1881
|
-
'maxItems',
|
|
1882
|
-
'enum',
|
|
1883
|
-
'properties',
|
|
1884
|
-
'required',
|
|
1885
|
-
'minProperties',
|
|
1886
|
-
'maxProperties',
|
|
1887
|
-
'minimum',
|
|
1888
|
-
'maximum',
|
|
1889
|
-
'minLength',
|
|
1890
|
-
'maxLength',
|
|
1891
|
-
'pattern',
|
|
1892
|
-
'anyOf',
|
|
1893
|
-
'propertyOrdering',
|
|
1894
|
-
]);
|
|
1895
|
-
const jsonSchemaTypeValidator = zod.z.enum([
|
|
1896
|
-
'string',
|
|
1897
|
-
'number',
|
|
1898
|
-
'integer',
|
|
1899
|
-
'object',
|
|
1900
|
-
'array',
|
|
1901
|
-
'boolean',
|
|
1902
|
-
'null',
|
|
1903
|
-
]);
|
|
1904
|
-
// Handles all types and arrays of all types.
|
|
1905
|
-
const schemaTypeUnion = zod.z.union([
|
|
1906
|
-
jsonSchemaTypeValidator,
|
|
1907
|
-
zod.z.array(jsonSchemaTypeValidator),
|
|
1908
|
-
]);
|
|
1909
|
-
/**
|
|
1910
|
-
* Creates a zod validator for JSONSchema.
|
|
1911
|
-
*
|
|
1912
|
-
* @param strictMode Whether to enable strict mode, default to true. When
|
|
1913
|
-
* strict mode is enabled, the zod validator will throw error if there
|
|
1914
|
-
* are unrecognized fields in the input data. If strict mode is
|
|
1915
|
-
* disabled, the zod validator will ignore the unrecognized fields, only
|
|
1916
|
-
* populate the fields that are listed in the JSONSchema. Regardless of
|
|
1917
|
-
* the mode the type mismatch will always result in an error, for example
|
|
1918
|
-
* items field should be a single JSONSchema, but for tuple type it would
|
|
1919
|
-
* be an array of JSONSchema, this will always result in an error.
|
|
1920
|
-
* @return The zod validator for JSONSchema.
|
|
1921
|
-
*/
|
|
1922
|
-
function createJsonSchemaValidator(strictMode = true) {
|
|
1923
|
-
const jsonSchemaValidator = zod.z.lazy(() => {
|
|
1924
|
-
// Define the base object shape *inside* the z.lazy callback
|
|
1925
|
-
const baseShape = zod.z.object({
|
|
1926
|
-
// --- Type ---
|
|
1927
|
-
type: schemaTypeUnion.optional(),
|
|
1928
|
-
// --- Annotations ---
|
|
1929
|
-
format: zod.z.string().optional(),
|
|
1930
|
-
title: zod.z.string().optional(),
|
|
1931
|
-
description: zod.z.string().optional(),
|
|
1932
|
-
default: zod.z.unknown().optional(),
|
|
1933
|
-
// --- Array Validations ---
|
|
1934
|
-
items: jsonSchemaValidator.optional(),
|
|
1935
|
-
minItems: zod.z.coerce.string().optional(),
|
|
1936
|
-
maxItems: zod.z.coerce.string().optional(),
|
|
1937
|
-
// --- Generic Validations ---
|
|
1938
|
-
enum: zod.z.array(zod.z.unknown()).optional(),
|
|
1939
|
-
// --- Object Validations ---
|
|
1940
|
-
properties: zod.z.record(zod.z.string(), jsonSchemaValidator).optional(),
|
|
1941
|
-
required: zod.z.array(zod.z.string()).optional(),
|
|
1942
|
-
minProperties: zod.z.coerce.string().optional(),
|
|
1943
|
-
maxProperties: zod.z.coerce.string().optional(),
|
|
1944
|
-
propertyOrdering: zod.z.array(zod.z.string()).optional(),
|
|
1945
|
-
// --- Numeric Validations ---
|
|
1946
|
-
minimum: zod.z.number().optional(),
|
|
1947
|
-
maximum: zod.z.number().optional(),
|
|
1948
|
-
// --- String Validations ---
|
|
1949
|
-
minLength: zod.z.coerce.string().optional(),
|
|
1950
|
-
maxLength: zod.z.coerce.string().optional(),
|
|
1951
|
-
pattern: zod.z.string().optional(),
|
|
1952
|
-
// --- Schema Composition ---
|
|
1953
|
-
anyOf: zod.z.array(jsonSchemaValidator).optional(),
|
|
1954
|
-
// --- Additional Properties --- This field is not included in the
|
|
1955
|
-
// JSONSchema, will not be communicated to the model, it is here purely
|
|
1956
|
-
// for enabling the zod validation strict mode.
|
|
1957
|
-
additionalProperties: zod.z.boolean().optional(),
|
|
1958
|
-
});
|
|
1959
|
-
// Conditionally apply .strict() based on the flag
|
|
1960
|
-
return strictMode ? baseShape.strict() : baseShape;
|
|
1961
|
-
});
|
|
1962
|
-
return jsonSchemaValidator;
|
|
1963
|
-
}
|
|
1964
1896
|
/*
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
zod_to_json_schema will squash the types into an array instead of put them
|
|
1971
|
-
in anyOf fields. Otherwise, it will put the types in anyOf fields.
|
|
1972
|
-
See the following link for more details:
|
|
1973
|
-
https://github.com/zodjs/zod-to-json-schema/blob/main/src/index.ts#L101
|
|
1974
|
-
The logic here is trying to undo that optimization, flattening the array of
|
|
1975
|
-
types to anyOf fields.
|
|
1976
|
-
type field
|
|
1977
|
-
|
|
|
1978
|
-
___________________________
|
|
1979
|
-
/ \
|
|
1980
|
-
/ \
|
|
1981
|
-
/ \
|
|
1982
|
-
Array Type.*
|
|
1983
|
-
/ \ |
|
|
1984
|
-
Include null. Not included null type = Type.*.
|
|
1985
|
-
[null, Type.*, Type.*] multiple types.
|
|
1986
|
-
[null, Type.*] [Type.*, Type.*]
|
|
1987
|
-
/ \
|
|
1988
|
-
remove null \
|
|
1989
|
-
add nullable = true \
|
|
1990
|
-
/ \ \
|
|
1991
|
-
[Type.*] [Type.*, Type.*] \
|
|
1992
|
-
only one type left multiple types left \
|
|
1993
|
-
add type = Type.*. \ /
|
|
1994
|
-
\ /
|
|
1995
|
-
not populate the type field in final result
|
|
1996
|
-
and make the types into anyOf fields
|
|
1997
|
-
anyOf:[{type: 'Type.*'}, {type: 'Type.*'}];
|
|
1897
|
+
Transform the type field from an array of types to an array of anyOf fields.
|
|
1898
|
+
Example:
|
|
1899
|
+
{type: ['STRING', 'NUMBER']}
|
|
1900
|
+
will be transformed to
|
|
1901
|
+
{anyOf: [{type: 'STRING'}, {type: 'NUMBER'}]}
|
|
1998
1902
|
*/
|
|
1999
1903
|
function flattenTypeArrayToAnyOf(typeList, resultingSchema) {
|
|
2000
1904
|
if (typeList.includes('null')) {
|
|
@@ -2140,15 +2044,11 @@ function processJsonSchema(_jsonSchema) {
|
|
|
2140
2044
|
// https://github.com/StefanTerdell/zod-to-json-schema/blob/70525efe555cd226691e093d171370a3b10921d1/src/zodToJsonSchema.ts#L7
|
|
2141
2045
|
// typebox can return unknown, see details in
|
|
2142
2046
|
// https://github.com/sinclairzx81/typebox/blob/5a5431439f7d5ca6b494d0d18fbfd7b1a356d67c/src/type/create/type.ts#L35
|
|
2047
|
+
// Note: proper json schemas with the $schema field set never arrive to this
|
|
2048
|
+
// transformer. Schemas with $schema are routed to the equivalent API json
|
|
2049
|
+
// schema field.
|
|
2143
2050
|
function tSchema(schema) {
|
|
2144
|
-
|
|
2145
|
-
delete schema['$schema'];
|
|
2146
|
-
const validatedJsonSchema = createJsonSchemaValidator().parse(schema);
|
|
2147
|
-
return processJsonSchema(validatedJsonSchema);
|
|
2148
|
-
}
|
|
2149
|
-
else {
|
|
2150
|
-
return processJsonSchema(schema);
|
|
2151
|
-
}
|
|
2051
|
+
return processJsonSchema(schema);
|
|
2152
2052
|
}
|
|
2153
2053
|
function tSpeechConfig(speechConfig) {
|
|
2154
2054
|
if (typeof speechConfig === 'object') {
|
|
@@ -2177,10 +2077,28 @@ function tTool(tool) {
|
|
|
2177
2077
|
if (tool.functionDeclarations) {
|
|
2178
2078
|
for (const functionDeclaration of tool.functionDeclarations) {
|
|
2179
2079
|
if (functionDeclaration.parameters) {
|
|
2180
|
-
|
|
2080
|
+
if (!Object.keys(functionDeclaration.parameters).includes('$schema')) {
|
|
2081
|
+
functionDeclaration.parameters = processJsonSchema(functionDeclaration.parameters);
|
|
2082
|
+
}
|
|
2083
|
+
else {
|
|
2084
|
+
if (!functionDeclaration.parametersJsonSchema) {
|
|
2085
|
+
functionDeclaration.parametersJsonSchema =
|
|
2086
|
+
functionDeclaration.parameters;
|
|
2087
|
+
delete functionDeclaration.parameters;
|
|
2088
|
+
}
|
|
2089
|
+
}
|
|
2181
2090
|
}
|
|
2182
2091
|
if (functionDeclaration.response) {
|
|
2183
|
-
|
|
2092
|
+
if (!Object.keys(functionDeclaration.response).includes('$schema')) {
|
|
2093
|
+
functionDeclaration.response = processJsonSchema(functionDeclaration.response);
|
|
2094
|
+
}
|
|
2095
|
+
else {
|
|
2096
|
+
if (!functionDeclaration.responseJsonSchema) {
|
|
2097
|
+
functionDeclaration.responseJsonSchema =
|
|
2098
|
+
functionDeclaration.response;
|
|
2099
|
+
delete functionDeclaration.response;
|
|
2100
|
+
}
|
|
2101
|
+
}
|
|
2184
2102
|
}
|
|
2185
2103
|
}
|
|
2186
2104
|
}
|
|
@@ -2385,7 +2303,7 @@ function mcpToGeminiTool(mcpTool, config = {}) {
|
|
|
2385
2303
|
const functionDeclaration = {
|
|
2386
2304
|
name: mcpToolSchema['name'],
|
|
2387
2305
|
description: mcpToolSchema['description'],
|
|
2388
|
-
|
|
2306
|
+
parametersJsonSchema: mcpToolSchema['inputSchema'],
|
|
2389
2307
|
};
|
|
2390
2308
|
if (config.behavior) {
|
|
2391
2309
|
functionDeclaration['behavior'] = config.behavior;
|
|
@@ -2417,53 +2335,6 @@ function mcpToolsToGeminiTool(mcpTools, config = {}) {
|
|
|
2417
2335
|
}
|
|
2418
2336
|
return { functionDeclarations: functionDeclarations };
|
|
2419
2337
|
}
|
|
2420
|
-
// Filters the list schema field to only include fields that are supported by
|
|
2421
|
-
// JSONSchema.
|
|
2422
|
-
function filterListSchemaField(fieldValue) {
|
|
2423
|
-
const listSchemaFieldValue = [];
|
|
2424
|
-
for (const listFieldValue of fieldValue) {
|
|
2425
|
-
listSchemaFieldValue.push(filterToJsonSchema(listFieldValue));
|
|
2426
|
-
}
|
|
2427
|
-
return listSchemaFieldValue;
|
|
2428
|
-
}
|
|
2429
|
-
// Filters the dict schema field to only include fields that are supported by
|
|
2430
|
-
// JSONSchema.
|
|
2431
|
-
function filterDictSchemaField(fieldValue) {
|
|
2432
|
-
const dictSchemaFieldValue = {};
|
|
2433
|
-
for (const [key, value] of Object.entries(fieldValue)) {
|
|
2434
|
-
const valueRecord = value;
|
|
2435
|
-
dictSchemaFieldValue[key] = filterToJsonSchema(valueRecord);
|
|
2436
|
-
}
|
|
2437
|
-
return dictSchemaFieldValue;
|
|
2438
|
-
}
|
|
2439
|
-
// Filters the schema to only include fields that are supported by JSONSchema.
|
|
2440
|
-
function filterToJsonSchema(schema) {
|
|
2441
|
-
const schemaFieldNames = new Set(['items']); // 'additional_properties' to come
|
|
2442
|
-
const listSchemaFieldNames = new Set(['anyOf']); // 'one_of', 'all_of', 'not' to come
|
|
2443
|
-
const dictSchemaFieldNames = new Set(['properties']); // 'defs' to come
|
|
2444
|
-
const filteredSchema = {};
|
|
2445
|
-
for (const [fieldName, fieldValue] of Object.entries(schema)) {
|
|
2446
|
-
if (schemaFieldNames.has(fieldName)) {
|
|
2447
|
-
filteredSchema[fieldName] = filterToJsonSchema(fieldValue);
|
|
2448
|
-
}
|
|
2449
|
-
else if (listSchemaFieldNames.has(fieldName)) {
|
|
2450
|
-
filteredSchema[fieldName] = filterListSchemaField(fieldValue);
|
|
2451
|
-
}
|
|
2452
|
-
else if (dictSchemaFieldNames.has(fieldName)) {
|
|
2453
|
-
filteredSchema[fieldName] = filterDictSchemaField(fieldValue);
|
|
2454
|
-
}
|
|
2455
|
-
else if (fieldName === 'type') {
|
|
2456
|
-
const typeValue = fieldValue.toUpperCase();
|
|
2457
|
-
filteredSchema[fieldName] = Object.values(exports.Type).includes(typeValue)
|
|
2458
|
-
? typeValue
|
|
2459
|
-
: exports.Type.TYPE_UNSPECIFIED;
|
|
2460
|
-
}
|
|
2461
|
-
else if (supportedJsonSchemaFields.has(fieldName)) {
|
|
2462
|
-
filteredSchema[fieldName] = fieldValue;
|
|
2463
|
-
}
|
|
2464
|
-
}
|
|
2465
|
-
return filteredSchema;
|
|
2466
|
-
}
|
|
2467
2338
|
// Transforms a source input into a BatchJobSource object with validation.
|
|
2468
2339
|
function tBatchJobSource(apiClient, src) {
|
|
2469
2340
|
if (typeof src !== 'string' && !Array.isArray(src)) {
|
|
@@ -6379,7 +6250,7 @@ const CONTENT_TYPE_HEADER = 'Content-Type';
|
|
|
6379
6250
|
const SERVER_TIMEOUT_HEADER = 'X-Server-Timeout';
|
|
6380
6251
|
const USER_AGENT_HEADER = 'User-Agent';
|
|
6381
6252
|
const GOOGLE_API_CLIENT_HEADER = 'x-goog-api-client';
|
|
6382
|
-
const SDK_VERSION = '1.
|
|
6253
|
+
const SDK_VERSION = '1.9.0'; // x-release-please-version
|
|
6383
6254
|
const LIBRARY_LABEL = `google-genai-sdk/${SDK_VERSION}`;
|
|
6384
6255
|
const VERTEX_AI_API_DEFAULT_VERSION = 'v1beta1';
|
|
6385
6256
|
const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
|
|
@@ -6610,7 +6481,14 @@ class ApiClient {
|
|
|
6610
6481
|
const abortController = new AbortController();
|
|
6611
6482
|
const signal = abortController.signal;
|
|
6612
6483
|
if (httpOptions.timeout && (httpOptions === null || httpOptions === void 0 ? void 0 : httpOptions.timeout) > 0) {
|
|
6613
|
-
setTimeout(() => abortController.abort(), httpOptions.timeout);
|
|
6484
|
+
const timeoutHandle = setTimeout(() => abortController.abort(), httpOptions.timeout);
|
|
6485
|
+
if (timeoutHandle &&
|
|
6486
|
+
typeof timeoutHandle.unref ===
|
|
6487
|
+
'function') {
|
|
6488
|
+
// call unref to prevent nodejs process from hanging, see
|
|
6489
|
+
// https://nodejs.org/api/timers.html#timeoutunref
|
|
6490
|
+
timeoutHandle.unref();
|
|
6491
|
+
}
|
|
6614
6492
|
}
|
|
6615
6493
|
if (abortSignal) {
|
|
6616
6494
|
abortSignal.addEventListener('abort', () => {
|
|
@@ -6673,7 +6551,7 @@ class ApiClient {
|
|
|
6673
6551
|
}
|
|
6674
6552
|
break;
|
|
6675
6553
|
}
|
|
6676
|
-
const chunkString = decoder.decode(value);
|
|
6554
|
+
const chunkString = decoder.decode(value, { stream: true });
|
|
6677
6555
|
// Parse and throw an error if the chunk contains an error.
|
|
6678
6556
|
try {
|
|
6679
6557
|
const chunkJson = JSON.parse(chunkString);
|
|
@@ -13973,7 +13851,7 @@ class Live {
|
|
|
13973
13851
|
if (GOOGLE_GENAI_USE_VERTEXAI) {
|
|
13974
13852
|
model = 'gemini-2.0-flash-live-preview-04-09';
|
|
13975
13853
|
} else {
|
|
13976
|
-
model = 'gemini-2.
|
|
13854
|
+
model = 'gemini-live-2.5-flash-preview';
|
|
13977
13855
|
}
|
|
13978
13856
|
const session = await ai.live.connect({
|
|
13979
13857
|
model: model,
|
|
@@ -14019,6 +13897,9 @@ class Live {
|
|
|
14019
13897
|
let keyName = 'key';
|
|
14020
13898
|
if (apiKey === null || apiKey === void 0 ? void 0 : apiKey.startsWith('auth_tokens/')) {
|
|
14021
13899
|
console.warn('Warning: Ephemeral token support is experimental and may change in future versions.');
|
|
13900
|
+
if (apiVersion !== 'v1alpha') {
|
|
13901
|
+
console.warn("Warning: The SDK's ephemeral token support is in v1alpha only. Please use const ai = new GoogleGenAI({apiKey: token.name, httpOptions: { apiVersion: 'v1alpha' }}); before session connection.");
|
|
13902
|
+
}
|
|
14022
13903
|
method = 'BidiGenerateContentConstrained';
|
|
14023
13904
|
keyName = 'access_token';
|
|
14024
13905
|
}
|
|
@@ -14294,7 +14175,7 @@ class Session {
|
|
|
14294
14175
|
if (GOOGLE_GENAI_USE_VERTEXAI) {
|
|
14295
14176
|
model = 'gemini-2.0-flash-live-preview-04-09';
|
|
14296
14177
|
} else {
|
|
14297
|
-
model = 'gemini-2.
|
|
14178
|
+
model = 'gemini-live-2.5-flash-preview';
|
|
14298
14179
|
}
|
|
14299
14180
|
const session = await ai.live.connect({
|
|
14300
14181
|
model: model,
|
|
@@ -14423,6 +14304,7 @@ class Models extends BaseModule {
|
|
|
14423
14304
|
this.generateContent = async (params) => {
|
|
14424
14305
|
var _a, _b, _c, _d, _e;
|
|
14425
14306
|
const transformedParams = await this.processParamsForMcpUsage(params);
|
|
14307
|
+
this.maybeMoveToResponseJsonSchem(params);
|
|
14426
14308
|
if (!hasMcpClientTools(params) || shouldDisableAfc(params.config)) {
|
|
14427
14309
|
return await this.generateContentInternal(transformedParams);
|
|
14428
14310
|
}
|
|
@@ -14509,6 +14391,7 @@ class Models extends BaseModule {
|
|
|
14509
14391
|
* ```
|
|
14510
14392
|
*/
|
|
14511
14393
|
this.generateContentStream = async (params) => {
|
|
14394
|
+
this.maybeMoveToResponseJsonSchem(params);
|
|
14512
14395
|
if (shouldDisableAfc(params.config)) {
|
|
14513
14396
|
const transformedParams = await this.processParamsForMcpUsage(params);
|
|
14514
14397
|
return await this.generateContentStreamInternal(transformedParams);
|
|
@@ -14660,6 +14543,24 @@ class Models extends BaseModule {
|
|
|
14660
14543
|
return await this.upscaleImageInternal(apiParams);
|
|
14661
14544
|
};
|
|
14662
14545
|
}
|
|
14546
|
+
/**
|
|
14547
|
+
* This logic is needed for GenerateContentConfig only.
|
|
14548
|
+
* Previously we made GenerateContentConfig.responseSchema field to accept
|
|
14549
|
+
* unknown. Since v1.9.0, we switch to use backend JSON schema support.
|
|
14550
|
+
* To maintain backward compatibility, we move the data that was treated as
|
|
14551
|
+
* JSON schema from the responseSchema field to the responseJsonSchema field.
|
|
14552
|
+
*/
|
|
14553
|
+
maybeMoveToResponseJsonSchem(params) {
|
|
14554
|
+
if (params.config && params.config.responseSchema) {
|
|
14555
|
+
if (!params.config.responseJsonSchema) {
|
|
14556
|
+
if (Object.keys(params.config.responseSchema).includes('$schema')) {
|
|
14557
|
+
params.config.responseJsonSchema = params.config.responseSchema;
|
|
14558
|
+
delete params.config.responseSchema;
|
|
14559
|
+
}
|
|
14560
|
+
}
|
|
14561
|
+
}
|
|
14562
|
+
return;
|
|
14563
|
+
}
|
|
14663
14564
|
/**
|
|
14664
14565
|
* Transforms the CallableTools in the parameters to be simply Tools, it
|
|
14665
14566
|
* copies the params into a new object and replaces the tools, it does not
|
|
@@ -16720,14 +16621,20 @@ class Tokens extends BaseModule {
|
|
|
16720
16621
|
* @experimental
|
|
16721
16622
|
*
|
|
16722
16623
|
* @remarks
|
|
16723
|
-
*
|
|
16624
|
+
* Ephemeral auth tokens is only supported in the Gemini Developer API.
|
|
16724
16625
|
* It can be used for the session connection to the Live constrained API.
|
|
16626
|
+
* Support in v1alpha only.
|
|
16725
16627
|
*
|
|
16726
16628
|
* @param params - The parameters for the create request.
|
|
16727
16629
|
* @return The created auth token.
|
|
16728
16630
|
*
|
|
16729
16631
|
* @example
|
|
16730
16632
|
* ```ts
|
|
16633
|
+
* const ai = new GoogleGenAI({
|
|
16634
|
+
* apiKey: token.name,
|
|
16635
|
+
* httpOptions: { apiVersion: 'v1alpha' } // Support in v1alpha only.
|
|
16636
|
+
* });
|
|
16637
|
+
*
|
|
16731
16638
|
* // Case 1: If LiveEphemeralParameters is unset, unlock LiveConnectConfig
|
|
16732
16639
|
* // when using the token in Live API sessions. Each session connection can
|
|
16733
16640
|
* // use a different configuration.
|