@google/genai 1.7.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/README.md +43 -0
- package/dist/genai.d.ts +240 -22
- package/dist/index.cjs +373 -224
- package/dist/index.mjs +374 -225
- package/dist/index.mjs.map +1 -1
- package/dist/node/index.cjs +373 -223
- package/dist/node/index.mjs +374 -224
- package/dist/node/index.mjs.map +1 -1
- package/dist/node/node.d.ts +240 -22
- package/dist/web/index.mjs +374 -225
- package/dist/web/index.mjs.map +1 -1
- package/dist/web/web.d.ts +240 -22
- package/package.json +5 -5
package/dist/node/index.cjs
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var zod = require('zod');
|
|
4
3
|
var googleAuthLibrary = require('google-auth-library');
|
|
5
4
|
var fs = require('fs');
|
|
6
5
|
var node_stream = require('node:stream');
|
|
@@ -314,6 +313,22 @@ exports.HarmCategory = void 0;
|
|
|
314
313
|
* Deprecated: Election filter is not longer supported. The harm category is civic integrity.
|
|
315
314
|
*/
|
|
316
315
|
HarmCategory["HARM_CATEGORY_CIVIC_INTEGRITY"] = "HARM_CATEGORY_CIVIC_INTEGRITY";
|
|
316
|
+
/**
|
|
317
|
+
* The harm category is image hate.
|
|
318
|
+
*/
|
|
319
|
+
HarmCategory["HARM_CATEGORY_IMAGE_HATE"] = "HARM_CATEGORY_IMAGE_HATE";
|
|
320
|
+
/**
|
|
321
|
+
* The harm category is image dangerous content.
|
|
322
|
+
*/
|
|
323
|
+
HarmCategory["HARM_CATEGORY_IMAGE_DANGEROUS_CONTENT"] = "HARM_CATEGORY_IMAGE_DANGEROUS_CONTENT";
|
|
324
|
+
/**
|
|
325
|
+
* The harm category is image harassment.
|
|
326
|
+
*/
|
|
327
|
+
HarmCategory["HARM_CATEGORY_IMAGE_HARASSMENT"] = "HARM_CATEGORY_IMAGE_HARASSMENT";
|
|
328
|
+
/**
|
|
329
|
+
* The harm category is image sexually explicit content.
|
|
330
|
+
*/
|
|
331
|
+
HarmCategory["HARM_CATEGORY_IMAGE_SEXUALLY_EXPLICIT"] = "HARM_CATEGORY_IMAGE_SEXUALLY_EXPLICIT";
|
|
317
332
|
})(exports.HarmCategory || (exports.HarmCategory = {}));
|
|
318
333
|
/** Optional. Specify if the threshold is used for probability or severity score. If not specified, the threshold is used for probability score. */
|
|
319
334
|
exports.HarmBlockMethod = void 0;
|
|
@@ -400,6 +415,50 @@ exports.AuthType = void 0;
|
|
|
400
415
|
*/
|
|
401
416
|
AuthType["OIDC_AUTH"] = "OIDC_AUTH";
|
|
402
417
|
})(exports.AuthType || (exports.AuthType = {}));
|
|
418
|
+
/** The API spec that the external API implements. */
|
|
419
|
+
exports.ApiSpec = void 0;
|
|
420
|
+
(function (ApiSpec) {
|
|
421
|
+
/**
|
|
422
|
+
* Unspecified API spec. This value should not be used.
|
|
423
|
+
*/
|
|
424
|
+
ApiSpec["API_SPEC_UNSPECIFIED"] = "API_SPEC_UNSPECIFIED";
|
|
425
|
+
/**
|
|
426
|
+
* Simple search API spec.
|
|
427
|
+
*/
|
|
428
|
+
ApiSpec["SIMPLE_SEARCH"] = "SIMPLE_SEARCH";
|
|
429
|
+
/**
|
|
430
|
+
* Elastic search API spec.
|
|
431
|
+
*/
|
|
432
|
+
ApiSpec["ELASTIC_SEARCH"] = "ELASTIC_SEARCH";
|
|
433
|
+
})(exports.ApiSpec || (exports.ApiSpec = {}));
|
|
434
|
+
/** Required. The environment being operated. */
|
|
435
|
+
exports.Environment = void 0;
|
|
436
|
+
(function (Environment) {
|
|
437
|
+
/**
|
|
438
|
+
* Defaults to browser.
|
|
439
|
+
*/
|
|
440
|
+
Environment["ENVIRONMENT_UNSPECIFIED"] = "ENVIRONMENT_UNSPECIFIED";
|
|
441
|
+
/**
|
|
442
|
+
* Operates in a web browser.
|
|
443
|
+
*/
|
|
444
|
+
Environment["ENVIRONMENT_BROWSER"] = "ENVIRONMENT_BROWSER";
|
|
445
|
+
})(exports.Environment || (exports.Environment = {}));
|
|
446
|
+
/** Status of the url retrieval. */
|
|
447
|
+
exports.UrlRetrievalStatus = void 0;
|
|
448
|
+
(function (UrlRetrievalStatus) {
|
|
449
|
+
/**
|
|
450
|
+
* Default value. This value is unused
|
|
451
|
+
*/
|
|
452
|
+
UrlRetrievalStatus["URL_RETRIEVAL_STATUS_UNSPECIFIED"] = "URL_RETRIEVAL_STATUS_UNSPECIFIED";
|
|
453
|
+
/**
|
|
454
|
+
* Url retrieval is successful.
|
|
455
|
+
*/
|
|
456
|
+
UrlRetrievalStatus["URL_RETRIEVAL_STATUS_SUCCESS"] = "URL_RETRIEVAL_STATUS_SUCCESS";
|
|
457
|
+
/**
|
|
458
|
+
* Url retrieval is failed due to error.
|
|
459
|
+
*/
|
|
460
|
+
UrlRetrievalStatus["URL_RETRIEVAL_STATUS_ERROR"] = "URL_RETRIEVAL_STATUS_ERROR";
|
|
461
|
+
})(exports.UrlRetrievalStatus || (exports.UrlRetrievalStatus = {}));
|
|
403
462
|
/** Output only. The reason why the model stopped generating tokens.
|
|
404
463
|
|
|
405
464
|
If empty, the model has not stopped generating the tokens.
|
|
@@ -530,6 +589,10 @@ exports.BlockedReason = void 0;
|
|
|
530
589
|
* Candidates blocked due to prohibited content.
|
|
531
590
|
*/
|
|
532
591
|
BlockedReason["PROHIBITED_CONTENT"] = "PROHIBITED_CONTENT";
|
|
592
|
+
/**
|
|
593
|
+
* Candidates blocked due to unsafe image generation content.
|
|
594
|
+
*/
|
|
595
|
+
BlockedReason["IMAGE_SAFETY"] = "IMAGE_SAFETY";
|
|
533
596
|
})(exports.BlockedReason || (exports.BlockedReason = {}));
|
|
534
597
|
/** Output only. Traffic type. This shows whether a request consumes Pay-As-You-Go or Provisioned Throughput quota. */
|
|
535
598
|
exports.TrafficType = void 0;
|
|
@@ -727,22 +790,6 @@ exports.FunctionCallingConfigMode = void 0;
|
|
|
727
790
|
*/
|
|
728
791
|
FunctionCallingConfigMode["NONE"] = "NONE";
|
|
729
792
|
})(exports.FunctionCallingConfigMode || (exports.FunctionCallingConfigMode = {}));
|
|
730
|
-
/** Status of the url retrieval. */
|
|
731
|
-
exports.UrlRetrievalStatus = void 0;
|
|
732
|
-
(function (UrlRetrievalStatus) {
|
|
733
|
-
/**
|
|
734
|
-
* Default value. This value is unused
|
|
735
|
-
*/
|
|
736
|
-
UrlRetrievalStatus["URL_RETRIEVAL_STATUS_UNSPECIFIED"] = "URL_RETRIEVAL_STATUS_UNSPECIFIED";
|
|
737
|
-
/**
|
|
738
|
-
* Url retrieval is successful.
|
|
739
|
-
*/
|
|
740
|
-
UrlRetrievalStatus["URL_RETRIEVAL_STATUS_SUCCESS"] = "URL_RETRIEVAL_STATUS_SUCCESS";
|
|
741
|
-
/**
|
|
742
|
-
* Url retrieval is failed due to error.
|
|
743
|
-
*/
|
|
744
|
-
UrlRetrievalStatus["URL_RETRIEVAL_STATUS_ERROR"] = "URL_RETRIEVAL_STATUS_ERROR";
|
|
745
|
-
})(exports.UrlRetrievalStatus || (exports.UrlRetrievalStatus = {}));
|
|
746
793
|
/** Enum that controls the safety filter level for objectionable content. */
|
|
747
794
|
exports.SafetyFilterLevel = void 0;
|
|
748
795
|
(function (SafetyFilterLevel) {
|
|
@@ -770,11 +817,38 @@ exports.PersonGeneration = void 0;
|
|
|
770
817
|
/** Enum that specifies the language of the text in the prompt. */
|
|
771
818
|
exports.ImagePromptLanguage = void 0;
|
|
772
819
|
(function (ImagePromptLanguage) {
|
|
820
|
+
/**
|
|
821
|
+
* Auto-detect the language.
|
|
822
|
+
*/
|
|
773
823
|
ImagePromptLanguage["auto"] = "auto";
|
|
824
|
+
/**
|
|
825
|
+
* English
|
|
826
|
+
*/
|
|
774
827
|
ImagePromptLanguage["en"] = "en";
|
|
828
|
+
/**
|
|
829
|
+
* Japanese
|
|
830
|
+
*/
|
|
775
831
|
ImagePromptLanguage["ja"] = "ja";
|
|
832
|
+
/**
|
|
833
|
+
* Korean
|
|
834
|
+
*/
|
|
776
835
|
ImagePromptLanguage["ko"] = "ko";
|
|
836
|
+
/**
|
|
837
|
+
* Hindi
|
|
838
|
+
*/
|
|
777
839
|
ImagePromptLanguage["hi"] = "hi";
|
|
840
|
+
/**
|
|
841
|
+
* Chinese
|
|
842
|
+
*/
|
|
843
|
+
ImagePromptLanguage["zh"] = "zh";
|
|
844
|
+
/**
|
|
845
|
+
* Portuguese
|
|
846
|
+
*/
|
|
847
|
+
ImagePromptLanguage["pt"] = "pt";
|
|
848
|
+
/**
|
|
849
|
+
* Spanish
|
|
850
|
+
*/
|
|
851
|
+
ImagePromptLanguage["es"] = "es";
|
|
778
852
|
})(exports.ImagePromptLanguage || (exports.ImagePromptLanguage = {}));
|
|
779
853
|
/** Enum representing the mask mode of a mask reference image. */
|
|
780
854
|
exports.MaskReferenceMode = void 0;
|
|
@@ -1875,133 +1949,12 @@ function tContents(origin) {
|
|
|
1875
1949
|
}
|
|
1876
1950
|
return result;
|
|
1877
1951
|
}
|
|
1878
|
-
// The fields that are supported by JSONSchema. Must be kept in sync with the
|
|
1879
|
-
// JSONSchema interface above.
|
|
1880
|
-
const supportedJsonSchemaFields = new Set([
|
|
1881
|
-
'type',
|
|
1882
|
-
'format',
|
|
1883
|
-
'title',
|
|
1884
|
-
'description',
|
|
1885
|
-
'default',
|
|
1886
|
-
'items',
|
|
1887
|
-
'minItems',
|
|
1888
|
-
'maxItems',
|
|
1889
|
-
'enum',
|
|
1890
|
-
'properties',
|
|
1891
|
-
'required',
|
|
1892
|
-
'minProperties',
|
|
1893
|
-
'maxProperties',
|
|
1894
|
-
'minimum',
|
|
1895
|
-
'maximum',
|
|
1896
|
-
'minLength',
|
|
1897
|
-
'maxLength',
|
|
1898
|
-
'pattern',
|
|
1899
|
-
'anyOf',
|
|
1900
|
-
'propertyOrdering',
|
|
1901
|
-
]);
|
|
1902
|
-
const jsonSchemaTypeValidator = zod.z.enum([
|
|
1903
|
-
'string',
|
|
1904
|
-
'number',
|
|
1905
|
-
'integer',
|
|
1906
|
-
'object',
|
|
1907
|
-
'array',
|
|
1908
|
-
'boolean',
|
|
1909
|
-
'null',
|
|
1910
|
-
]);
|
|
1911
|
-
// Handles all types and arrays of all types.
|
|
1912
|
-
const schemaTypeUnion = zod.z.union([
|
|
1913
|
-
jsonSchemaTypeValidator,
|
|
1914
|
-
zod.z.array(jsonSchemaTypeValidator),
|
|
1915
|
-
]);
|
|
1916
|
-
/**
|
|
1917
|
-
* Creates a zod validator for JSONSchema.
|
|
1918
|
-
*
|
|
1919
|
-
* @param strictMode Whether to enable strict mode, default to true. When
|
|
1920
|
-
* strict mode is enabled, the zod validator will throw error if there
|
|
1921
|
-
* are unrecognized fields in the input data. If strict mode is
|
|
1922
|
-
* disabled, the zod validator will ignore the unrecognized fields, only
|
|
1923
|
-
* populate the fields that are listed in the JSONSchema. Regardless of
|
|
1924
|
-
* the mode the type mismatch will always result in an error, for example
|
|
1925
|
-
* items field should be a single JSONSchema, but for tuple type it would
|
|
1926
|
-
* be an array of JSONSchema, this will always result in an error.
|
|
1927
|
-
* @return The zod validator for JSONSchema.
|
|
1928
|
-
*/
|
|
1929
|
-
function createJsonSchemaValidator(strictMode = true) {
|
|
1930
|
-
const jsonSchemaValidator = zod.z.lazy(() => {
|
|
1931
|
-
// Define the base object shape *inside* the z.lazy callback
|
|
1932
|
-
const baseShape = zod.z.object({
|
|
1933
|
-
// --- Type ---
|
|
1934
|
-
type: schemaTypeUnion.optional(),
|
|
1935
|
-
// --- Annotations ---
|
|
1936
|
-
format: zod.z.string().optional(),
|
|
1937
|
-
title: zod.z.string().optional(),
|
|
1938
|
-
description: zod.z.string().optional(),
|
|
1939
|
-
default: zod.z.unknown().optional(),
|
|
1940
|
-
// --- Array Validations ---
|
|
1941
|
-
items: jsonSchemaValidator.optional(),
|
|
1942
|
-
minItems: zod.z.coerce.string().optional(),
|
|
1943
|
-
maxItems: zod.z.coerce.string().optional(),
|
|
1944
|
-
// --- Generic Validations ---
|
|
1945
|
-
enum: zod.z.array(zod.z.unknown()).optional(),
|
|
1946
|
-
// --- Object Validations ---
|
|
1947
|
-
properties: zod.z.record(zod.z.string(), jsonSchemaValidator).optional(),
|
|
1948
|
-
required: zod.z.array(zod.z.string()).optional(),
|
|
1949
|
-
minProperties: zod.z.coerce.string().optional(),
|
|
1950
|
-
maxProperties: zod.z.coerce.string().optional(),
|
|
1951
|
-
propertyOrdering: zod.z.array(zod.z.string()).optional(),
|
|
1952
|
-
// --- Numeric Validations ---
|
|
1953
|
-
minimum: zod.z.number().optional(),
|
|
1954
|
-
maximum: zod.z.number().optional(),
|
|
1955
|
-
// --- String Validations ---
|
|
1956
|
-
minLength: zod.z.coerce.string().optional(),
|
|
1957
|
-
maxLength: zod.z.coerce.string().optional(),
|
|
1958
|
-
pattern: zod.z.string().optional(),
|
|
1959
|
-
// --- Schema Composition ---
|
|
1960
|
-
anyOf: zod.z.array(jsonSchemaValidator).optional(),
|
|
1961
|
-
// --- Additional Properties --- This field is not included in the
|
|
1962
|
-
// JSONSchema, will not be communicated to the model, it is here purely
|
|
1963
|
-
// for enabling the zod validation strict mode.
|
|
1964
|
-
additionalProperties: zod.z.boolean().optional(),
|
|
1965
|
-
});
|
|
1966
|
-
// Conditionally apply .strict() based on the flag
|
|
1967
|
-
return strictMode ? baseShape.strict() : baseShape;
|
|
1968
|
-
});
|
|
1969
|
-
return jsonSchemaValidator;
|
|
1970
|
-
}
|
|
1971
1952
|
/*
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
zod_to_json_schema will squash the types into an array instead of put them
|
|
1978
|
-
in anyOf fields. Otherwise, it will put the types in anyOf fields.
|
|
1979
|
-
See the following link for more details:
|
|
1980
|
-
https://github.com/zodjs/zod-to-json-schema/blob/main/src/index.ts#L101
|
|
1981
|
-
The logic here is trying to undo that optimization, flattening the array of
|
|
1982
|
-
types to anyOf fields.
|
|
1983
|
-
type field
|
|
1984
|
-
|
|
|
1985
|
-
___________________________
|
|
1986
|
-
/ \
|
|
1987
|
-
/ \
|
|
1988
|
-
/ \
|
|
1989
|
-
Array Type.*
|
|
1990
|
-
/ \ |
|
|
1991
|
-
Include null. Not included null type = Type.*.
|
|
1992
|
-
[null, Type.*, Type.*] multiple types.
|
|
1993
|
-
[null, Type.*] [Type.*, Type.*]
|
|
1994
|
-
/ \
|
|
1995
|
-
remove null \
|
|
1996
|
-
add nullable = true \
|
|
1997
|
-
/ \ \
|
|
1998
|
-
[Type.*] [Type.*, Type.*] \
|
|
1999
|
-
only one type left multiple types left \
|
|
2000
|
-
add type = Type.*. \ /
|
|
2001
|
-
\ /
|
|
2002
|
-
not populate the type field in final result
|
|
2003
|
-
and make the types into anyOf fields
|
|
2004
|
-
anyOf:[{type: 'Type.*'}, {type: 'Type.*'}];
|
|
1953
|
+
Transform the type field from an array of types to an array of anyOf fields.
|
|
1954
|
+
Example:
|
|
1955
|
+
{type: ['STRING', 'NUMBER']}
|
|
1956
|
+
will be transformed to
|
|
1957
|
+
{anyOf: [{type: 'STRING'}, {type: 'NUMBER'}]}
|
|
2005
1958
|
*/
|
|
2006
1959
|
function flattenTypeArrayToAnyOf(typeList, resultingSchema) {
|
|
2007
1960
|
if (typeList.includes('null')) {
|
|
@@ -2147,15 +2100,11 @@ function processJsonSchema(_jsonSchema) {
|
|
|
2147
2100
|
// https://github.com/StefanTerdell/zod-to-json-schema/blob/70525efe555cd226691e093d171370a3b10921d1/src/zodToJsonSchema.ts#L7
|
|
2148
2101
|
// typebox can return unknown, see details in
|
|
2149
2102
|
// https://github.com/sinclairzx81/typebox/blob/5a5431439f7d5ca6b494d0d18fbfd7b1a356d67c/src/type/create/type.ts#L35
|
|
2103
|
+
// Note: proper json schemas with the $schema field set never arrive to this
|
|
2104
|
+
// transformer. Schemas with $schema are routed to the equivalent API json
|
|
2105
|
+
// schema field.
|
|
2150
2106
|
function tSchema(schema) {
|
|
2151
|
-
|
|
2152
|
-
delete schema['$schema'];
|
|
2153
|
-
const validatedJsonSchema = createJsonSchemaValidator().parse(schema);
|
|
2154
|
-
return processJsonSchema(validatedJsonSchema);
|
|
2155
|
-
}
|
|
2156
|
-
else {
|
|
2157
|
-
return processJsonSchema(schema);
|
|
2158
|
-
}
|
|
2107
|
+
return processJsonSchema(schema);
|
|
2159
2108
|
}
|
|
2160
2109
|
function tSpeechConfig(speechConfig) {
|
|
2161
2110
|
if (typeof speechConfig === 'object') {
|
|
@@ -2184,10 +2133,28 @@ function tTool(tool) {
|
|
|
2184
2133
|
if (tool.functionDeclarations) {
|
|
2185
2134
|
for (const functionDeclaration of tool.functionDeclarations) {
|
|
2186
2135
|
if (functionDeclaration.parameters) {
|
|
2187
|
-
|
|
2136
|
+
if (!Object.keys(functionDeclaration.parameters).includes('$schema')) {
|
|
2137
|
+
functionDeclaration.parameters = processJsonSchema(functionDeclaration.parameters);
|
|
2138
|
+
}
|
|
2139
|
+
else {
|
|
2140
|
+
if (!functionDeclaration.parametersJsonSchema) {
|
|
2141
|
+
functionDeclaration.parametersJsonSchema =
|
|
2142
|
+
functionDeclaration.parameters;
|
|
2143
|
+
delete functionDeclaration.parameters;
|
|
2144
|
+
}
|
|
2145
|
+
}
|
|
2188
2146
|
}
|
|
2189
2147
|
if (functionDeclaration.response) {
|
|
2190
|
-
|
|
2148
|
+
if (!Object.keys(functionDeclaration.response).includes('$schema')) {
|
|
2149
|
+
functionDeclaration.response = processJsonSchema(functionDeclaration.response);
|
|
2150
|
+
}
|
|
2151
|
+
else {
|
|
2152
|
+
if (!functionDeclaration.responseJsonSchema) {
|
|
2153
|
+
functionDeclaration.responseJsonSchema =
|
|
2154
|
+
functionDeclaration.response;
|
|
2155
|
+
delete functionDeclaration.response;
|
|
2156
|
+
}
|
|
2157
|
+
}
|
|
2191
2158
|
}
|
|
2192
2159
|
}
|
|
2193
2160
|
}
|
|
@@ -2392,7 +2359,7 @@ function mcpToGeminiTool(mcpTool, config = {}) {
|
|
|
2392
2359
|
const functionDeclaration = {
|
|
2393
2360
|
name: mcpToolSchema['name'],
|
|
2394
2361
|
description: mcpToolSchema['description'],
|
|
2395
|
-
|
|
2362
|
+
parametersJsonSchema: mcpToolSchema['inputSchema'],
|
|
2396
2363
|
};
|
|
2397
2364
|
if (config.behavior) {
|
|
2398
2365
|
functionDeclaration['behavior'] = config.behavior;
|
|
@@ -2424,53 +2391,6 @@ function mcpToolsToGeminiTool(mcpTools, config = {}) {
|
|
|
2424
2391
|
}
|
|
2425
2392
|
return { functionDeclarations: functionDeclarations };
|
|
2426
2393
|
}
|
|
2427
|
-
// Filters the list schema field to only include fields that are supported by
|
|
2428
|
-
// JSONSchema.
|
|
2429
|
-
function filterListSchemaField(fieldValue) {
|
|
2430
|
-
const listSchemaFieldValue = [];
|
|
2431
|
-
for (const listFieldValue of fieldValue) {
|
|
2432
|
-
listSchemaFieldValue.push(filterToJsonSchema(listFieldValue));
|
|
2433
|
-
}
|
|
2434
|
-
return listSchemaFieldValue;
|
|
2435
|
-
}
|
|
2436
|
-
// Filters the dict schema field to only include fields that are supported by
|
|
2437
|
-
// JSONSchema.
|
|
2438
|
-
function filterDictSchemaField(fieldValue) {
|
|
2439
|
-
const dictSchemaFieldValue = {};
|
|
2440
|
-
for (const [key, value] of Object.entries(fieldValue)) {
|
|
2441
|
-
const valueRecord = value;
|
|
2442
|
-
dictSchemaFieldValue[key] = filterToJsonSchema(valueRecord);
|
|
2443
|
-
}
|
|
2444
|
-
return dictSchemaFieldValue;
|
|
2445
|
-
}
|
|
2446
|
-
// Filters the schema to only include fields that are supported by JSONSchema.
|
|
2447
|
-
function filterToJsonSchema(schema) {
|
|
2448
|
-
const schemaFieldNames = new Set(['items']); // 'additional_properties' to come
|
|
2449
|
-
const listSchemaFieldNames = new Set(['anyOf']); // 'one_of', 'all_of', 'not' to come
|
|
2450
|
-
const dictSchemaFieldNames = new Set(['properties']); // 'defs' to come
|
|
2451
|
-
const filteredSchema = {};
|
|
2452
|
-
for (const [fieldName, fieldValue] of Object.entries(schema)) {
|
|
2453
|
-
if (schemaFieldNames.has(fieldName)) {
|
|
2454
|
-
filteredSchema[fieldName] = filterToJsonSchema(fieldValue);
|
|
2455
|
-
}
|
|
2456
|
-
else if (listSchemaFieldNames.has(fieldName)) {
|
|
2457
|
-
filteredSchema[fieldName] = filterListSchemaField(fieldValue);
|
|
2458
|
-
}
|
|
2459
|
-
else if (dictSchemaFieldNames.has(fieldName)) {
|
|
2460
|
-
filteredSchema[fieldName] = filterDictSchemaField(fieldValue);
|
|
2461
|
-
}
|
|
2462
|
-
else if (fieldName === 'type') {
|
|
2463
|
-
const typeValue = fieldValue.toUpperCase();
|
|
2464
|
-
filteredSchema[fieldName] = Object.values(exports.Type).includes(typeValue)
|
|
2465
|
-
? typeValue
|
|
2466
|
-
: exports.Type.TYPE_UNSPECIFIED;
|
|
2467
|
-
}
|
|
2468
|
-
else if (supportedJsonSchemaFields.has(fieldName)) {
|
|
2469
|
-
filteredSchema[fieldName] = fieldValue;
|
|
2470
|
-
}
|
|
2471
|
-
}
|
|
2472
|
-
return filteredSchema;
|
|
2473
|
-
}
|
|
2474
2394
|
// Transforms a source input into a BatchJobSource object with validation.
|
|
2475
2395
|
function tBatchJobSource(apiClient, src) {
|
|
2476
2396
|
if (typeof src !== 'string' && !Array.isArray(src)) {
|
|
@@ -2945,6 +2865,10 @@ function toolToMldev$4(fromObject) {
|
|
|
2945
2865
|
if (fromCodeExecution != null) {
|
|
2946
2866
|
setValueByPath(toObject, ['codeExecution'], fromCodeExecution);
|
|
2947
2867
|
}
|
|
2868
|
+
const fromComputerUse = getValueByPath(fromObject, ['computerUse']);
|
|
2869
|
+
if (fromComputerUse != null) {
|
|
2870
|
+
setValueByPath(toObject, ['computerUse'], fromComputerUse);
|
|
2871
|
+
}
|
|
2948
2872
|
return toObject;
|
|
2949
2873
|
}
|
|
2950
2874
|
function functionCallingConfigToMldev$2(fromObject) {
|
|
@@ -3356,6 +3280,18 @@ function listBatchJobsParametersToMldev(fromObject) {
|
|
|
3356
3280
|
}
|
|
3357
3281
|
return toObject;
|
|
3358
3282
|
}
|
|
3283
|
+
function deleteBatchJobParametersToMldev(apiClient, fromObject) {
|
|
3284
|
+
const toObject = {};
|
|
3285
|
+
const fromName = getValueByPath(fromObject, ['name']);
|
|
3286
|
+
if (fromName != null) {
|
|
3287
|
+
setValueByPath(toObject, ['_url', 'name'], tBatchJobName(apiClient, fromName));
|
|
3288
|
+
}
|
|
3289
|
+
const fromConfig = getValueByPath(fromObject, ['config']);
|
|
3290
|
+
if (fromConfig != null) {
|
|
3291
|
+
setValueByPath(toObject, ['config'], fromConfig);
|
|
3292
|
+
}
|
|
3293
|
+
return toObject;
|
|
3294
|
+
}
|
|
3359
3295
|
function batchJobSourceToVertex(fromObject) {
|
|
3360
3296
|
const toObject = {};
|
|
3361
3297
|
const fromFormat = getValueByPath(fromObject, ['format']);
|
|
@@ -3476,6 +3412,18 @@ function listBatchJobsParametersToVertex(fromObject) {
|
|
|
3476
3412
|
}
|
|
3477
3413
|
return toObject;
|
|
3478
3414
|
}
|
|
3415
|
+
function deleteBatchJobParametersToVertex(apiClient, fromObject) {
|
|
3416
|
+
const toObject = {};
|
|
3417
|
+
const fromName = getValueByPath(fromObject, ['name']);
|
|
3418
|
+
if (fromName != null) {
|
|
3419
|
+
setValueByPath(toObject, ['_url', 'name'], tBatchJobName(apiClient, fromName));
|
|
3420
|
+
}
|
|
3421
|
+
const fromConfig = getValueByPath(fromObject, ['config']);
|
|
3422
|
+
if (fromConfig != null) {
|
|
3423
|
+
setValueByPath(toObject, ['config'], fromConfig);
|
|
3424
|
+
}
|
|
3425
|
+
return toObject;
|
|
3426
|
+
}
|
|
3479
3427
|
function jobErrorFromMldev() {
|
|
3480
3428
|
const toObject = {};
|
|
3481
3429
|
return toObject;
|
|
@@ -3813,6 +3761,22 @@ function listBatchJobsResponseFromMldev(fromObject) {
|
|
|
3813
3761
|
}
|
|
3814
3762
|
return toObject;
|
|
3815
3763
|
}
|
|
3764
|
+
function deleteResourceJobFromMldev(fromObject) {
|
|
3765
|
+
const toObject = {};
|
|
3766
|
+
const fromName = getValueByPath(fromObject, ['name']);
|
|
3767
|
+
if (fromName != null) {
|
|
3768
|
+
setValueByPath(toObject, ['name'], fromName);
|
|
3769
|
+
}
|
|
3770
|
+
const fromDone = getValueByPath(fromObject, ['done']);
|
|
3771
|
+
if (fromDone != null) {
|
|
3772
|
+
setValueByPath(toObject, ['done'], fromDone);
|
|
3773
|
+
}
|
|
3774
|
+
const fromError = getValueByPath(fromObject, ['error']);
|
|
3775
|
+
if (fromError != null) {
|
|
3776
|
+
setValueByPath(toObject, ['error'], jobErrorFromMldev());
|
|
3777
|
+
}
|
|
3778
|
+
return toObject;
|
|
3779
|
+
}
|
|
3816
3780
|
function jobErrorFromVertex(fromObject) {
|
|
3817
3781
|
const toObject = {};
|
|
3818
3782
|
const fromDetails = getValueByPath(fromObject, ['details']);
|
|
@@ -3940,6 +3904,22 @@ function listBatchJobsResponseFromVertex(fromObject) {
|
|
|
3940
3904
|
}
|
|
3941
3905
|
return toObject;
|
|
3942
3906
|
}
|
|
3907
|
+
function deleteResourceJobFromVertex(fromObject) {
|
|
3908
|
+
const toObject = {};
|
|
3909
|
+
const fromName = getValueByPath(fromObject, ['name']);
|
|
3910
|
+
if (fromName != null) {
|
|
3911
|
+
setValueByPath(toObject, ['name'], fromName);
|
|
3912
|
+
}
|
|
3913
|
+
const fromDone = getValueByPath(fromObject, ['done']);
|
|
3914
|
+
if (fromDone != null) {
|
|
3915
|
+
setValueByPath(toObject, ['done'], fromDone);
|
|
3916
|
+
}
|
|
3917
|
+
const fromError = getValueByPath(fromObject, ['error']);
|
|
3918
|
+
if (fromError != null) {
|
|
3919
|
+
setValueByPath(toObject, ['error'], jobErrorFromVertex(fromError));
|
|
3920
|
+
}
|
|
3921
|
+
return toObject;
|
|
3922
|
+
}
|
|
3943
3923
|
|
|
3944
3924
|
/**
|
|
3945
3925
|
* @license
|
|
@@ -4147,20 +4127,23 @@ class Batches extends BaseModule {
|
|
|
4147
4127
|
*/
|
|
4148
4128
|
this.create = async (params) => {
|
|
4149
4129
|
if (this.apiClient.isVertexAI()) {
|
|
4130
|
+
const timestamp = Date.now();
|
|
4131
|
+
const timestampStr = timestamp.toString();
|
|
4150
4132
|
if (Array.isArray(params.src)) {
|
|
4151
4133
|
throw new Error('InlinedRequest[] is not supported in Vertex AI. Please use ' +
|
|
4152
4134
|
'Google Cloud Storage URI or BigQuery URI instead.');
|
|
4153
4135
|
}
|
|
4154
4136
|
params.config = params.config || {};
|
|
4155
4137
|
if (params.config.displayName === undefined) {
|
|
4156
|
-
params.config.displayName = 'genaiBatchJob_';
|
|
4138
|
+
params.config.displayName = 'genaiBatchJob_${timestampStr}';
|
|
4157
4139
|
}
|
|
4158
4140
|
if (params.config.dest === undefined && typeof params.src === 'string') {
|
|
4159
4141
|
if (params.src.startsWith('gs://') && params.src.endsWith('.jsonl')) {
|
|
4160
4142
|
params.config.dest = `${params.src.slice(0, -6)}/dest`;
|
|
4161
4143
|
}
|
|
4162
4144
|
else if (params.src.startsWith('bq://')) {
|
|
4163
|
-
params.config.dest =
|
|
4145
|
+
params.config.dest =
|
|
4146
|
+
`${params.src}_dest_${timestampStr}`;
|
|
4164
4147
|
}
|
|
4165
4148
|
else {
|
|
4166
4149
|
throw new Error('Unsupported source:' + params.src);
|
|
@@ -4419,6 +4402,71 @@ class Batches extends BaseModule {
|
|
|
4419
4402
|
});
|
|
4420
4403
|
}
|
|
4421
4404
|
}
|
|
4405
|
+
/**
|
|
4406
|
+
* Deletes a batch job.
|
|
4407
|
+
*
|
|
4408
|
+
* @param params - The parameters for the delete request.
|
|
4409
|
+
* @return The empty response returned by the API.
|
|
4410
|
+
*
|
|
4411
|
+
* @example
|
|
4412
|
+
* ```ts
|
|
4413
|
+
* await ai.batches.delete({name: '...'}); // The server-generated resource name.
|
|
4414
|
+
* ```
|
|
4415
|
+
*/
|
|
4416
|
+
async delete(params) {
|
|
4417
|
+
var _a, _b, _c, _d;
|
|
4418
|
+
let response;
|
|
4419
|
+
let path = '';
|
|
4420
|
+
let queryParams = {};
|
|
4421
|
+
if (this.apiClient.isVertexAI()) {
|
|
4422
|
+
const body = deleteBatchJobParametersToVertex(this.apiClient, params);
|
|
4423
|
+
path = formatMap('batchPredictionJobs/{name}', body['_url']);
|
|
4424
|
+
queryParams = body['_query'];
|
|
4425
|
+
delete body['config'];
|
|
4426
|
+
delete body['_url'];
|
|
4427
|
+
delete body['_query'];
|
|
4428
|
+
response = this.apiClient
|
|
4429
|
+
.request({
|
|
4430
|
+
path: path,
|
|
4431
|
+
queryParams: queryParams,
|
|
4432
|
+
body: JSON.stringify(body),
|
|
4433
|
+
httpMethod: 'DELETE',
|
|
4434
|
+
httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
|
|
4435
|
+
abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
|
|
4436
|
+
})
|
|
4437
|
+
.then((httpResponse) => {
|
|
4438
|
+
return httpResponse.json();
|
|
4439
|
+
});
|
|
4440
|
+
return response.then((apiResponse) => {
|
|
4441
|
+
const resp = deleteResourceJobFromVertex(apiResponse);
|
|
4442
|
+
return resp;
|
|
4443
|
+
});
|
|
4444
|
+
}
|
|
4445
|
+
else {
|
|
4446
|
+
const body = deleteBatchJobParametersToMldev(this.apiClient, params);
|
|
4447
|
+
path = formatMap('batches/{name}', body['_url']);
|
|
4448
|
+
queryParams = body['_query'];
|
|
4449
|
+
delete body['config'];
|
|
4450
|
+
delete body['_url'];
|
|
4451
|
+
delete body['_query'];
|
|
4452
|
+
response = this.apiClient
|
|
4453
|
+
.request({
|
|
4454
|
+
path: path,
|
|
4455
|
+
queryParams: queryParams,
|
|
4456
|
+
body: JSON.stringify(body),
|
|
4457
|
+
httpMethod: 'DELETE',
|
|
4458
|
+
httpOptions: (_c = params.config) === null || _c === void 0 ? void 0 : _c.httpOptions,
|
|
4459
|
+
abortSignal: (_d = params.config) === null || _d === void 0 ? void 0 : _d.abortSignal,
|
|
4460
|
+
})
|
|
4461
|
+
.then((httpResponse) => {
|
|
4462
|
+
return httpResponse.json();
|
|
4463
|
+
});
|
|
4464
|
+
return response.then((apiResponse) => {
|
|
4465
|
+
const resp = deleteResourceJobFromMldev(apiResponse);
|
|
4466
|
+
return resp;
|
|
4467
|
+
});
|
|
4468
|
+
}
|
|
4469
|
+
}
|
|
4422
4470
|
}
|
|
4423
4471
|
|
|
4424
4472
|
/**
|
|
@@ -4673,6 +4721,10 @@ function toolToMldev$3(fromObject) {
|
|
|
4673
4721
|
if (fromCodeExecution != null) {
|
|
4674
4722
|
setValueByPath(toObject, ['codeExecution'], fromCodeExecution);
|
|
4675
4723
|
}
|
|
4724
|
+
const fromComputerUse = getValueByPath(fromObject, ['computerUse']);
|
|
4725
|
+
if (fromComputerUse != null) {
|
|
4726
|
+
setValueByPath(toObject, ['computerUse'], fromComputerUse);
|
|
4727
|
+
}
|
|
4676
4728
|
return toObject;
|
|
4677
4729
|
}
|
|
4678
4730
|
function functionCallingConfigToMldev$1(fromObject) {
|
|
@@ -5163,6 +5215,10 @@ function toolToVertex$2(fromObject) {
|
|
|
5163
5215
|
if (fromCodeExecution != null) {
|
|
5164
5216
|
setValueByPath(toObject, ['codeExecution'], fromCodeExecution);
|
|
5165
5217
|
}
|
|
5218
|
+
const fromComputerUse = getValueByPath(fromObject, ['computerUse']);
|
|
5219
|
+
if (fromComputerUse != null) {
|
|
5220
|
+
setValueByPath(toObject, ['computerUse'], fromComputerUse);
|
|
5221
|
+
}
|
|
5166
5222
|
return toObject;
|
|
5167
5223
|
}
|
|
5168
5224
|
function functionCallingConfigToVertex$1(fromObject) {
|
|
@@ -7369,6 +7425,10 @@ function toolToMldev$2(fromObject) {
|
|
|
7369
7425
|
if (fromCodeExecution != null) {
|
|
7370
7426
|
setValueByPath(toObject, ['codeExecution'], fromCodeExecution);
|
|
7371
7427
|
}
|
|
7428
|
+
const fromComputerUse = getValueByPath(fromObject, ['computerUse']);
|
|
7429
|
+
if (fromComputerUse != null) {
|
|
7430
|
+
setValueByPath(toObject, ['computerUse'], fromComputerUse);
|
|
7431
|
+
}
|
|
7372
7432
|
return toObject;
|
|
7373
7433
|
}
|
|
7374
7434
|
function toolToVertex$1(fromObject) {
|
|
@@ -7419,6 +7479,10 @@ function toolToVertex$1(fromObject) {
|
|
|
7419
7479
|
if (fromCodeExecution != null) {
|
|
7420
7480
|
setValueByPath(toObject, ['codeExecution'], fromCodeExecution);
|
|
7421
7481
|
}
|
|
7482
|
+
const fromComputerUse = getValueByPath(fromObject, ['computerUse']);
|
|
7483
|
+
if (fromComputerUse != null) {
|
|
7484
|
+
setValueByPath(toObject, ['computerUse'], fromComputerUse);
|
|
7485
|
+
}
|
|
7422
7486
|
return toObject;
|
|
7423
7487
|
}
|
|
7424
7488
|
function sessionResumptionConfigToMldev$1(fromObject) {
|
|
@@ -7914,8 +7978,9 @@ function liveSendRealtimeInputParametersToVertex(fromObject) {
|
|
|
7914
7978
|
if (fromMedia != null) {
|
|
7915
7979
|
setValueByPath(toObject, ['mediaChunks'], tBlobs(fromMedia));
|
|
7916
7980
|
}
|
|
7917
|
-
|
|
7918
|
-
|
|
7981
|
+
const fromAudio = getValueByPath(fromObject, ['audio']);
|
|
7982
|
+
if (fromAudio != null) {
|
|
7983
|
+
setValueByPath(toObject, ['audio'], tAudioBlob(fromAudio));
|
|
7919
7984
|
}
|
|
7920
7985
|
const fromAudioStreamEnd = getValueByPath(fromObject, [
|
|
7921
7986
|
'audioStreamEnd',
|
|
@@ -7923,11 +7988,13 @@ function liveSendRealtimeInputParametersToVertex(fromObject) {
|
|
|
7923
7988
|
if (fromAudioStreamEnd != null) {
|
|
7924
7989
|
setValueByPath(toObject, ['audioStreamEnd'], fromAudioStreamEnd);
|
|
7925
7990
|
}
|
|
7926
|
-
|
|
7927
|
-
|
|
7991
|
+
const fromVideo = getValueByPath(fromObject, ['video']);
|
|
7992
|
+
if (fromVideo != null) {
|
|
7993
|
+
setValueByPath(toObject, ['video'], tImageBlob(fromVideo));
|
|
7928
7994
|
}
|
|
7929
|
-
|
|
7930
|
-
|
|
7995
|
+
const fromText = getValueByPath(fromObject, ['text']);
|
|
7996
|
+
if (fromText != null) {
|
|
7997
|
+
setValueByPath(toObject, ['text'], fromText);
|
|
7931
7998
|
}
|
|
7932
7999
|
const fromActivityStart = getValueByPath(fromObject, [
|
|
7933
8000
|
'activityStart',
|
|
@@ -8083,8 +8150,12 @@ function liveServerSetupCompleteFromMldev() {
|
|
|
8083
8150
|
const toObject = {};
|
|
8084
8151
|
return toObject;
|
|
8085
8152
|
}
|
|
8086
|
-
function liveServerSetupCompleteFromVertex() {
|
|
8153
|
+
function liveServerSetupCompleteFromVertex(fromObject) {
|
|
8087
8154
|
const toObject = {};
|
|
8155
|
+
const fromSessionId = getValueByPath(fromObject, ['sessionId']);
|
|
8156
|
+
if (fromSessionId != null) {
|
|
8157
|
+
setValueByPath(toObject, ['sessionId'], fromSessionId);
|
|
8158
|
+
}
|
|
8088
8159
|
return toObject;
|
|
8089
8160
|
}
|
|
8090
8161
|
function videoMetadataFromMldev$1(fromObject) {
|
|
@@ -8837,7 +8908,7 @@ function liveServerMessageFromVertex(fromObject) {
|
|
|
8837
8908
|
'setupComplete',
|
|
8838
8909
|
]);
|
|
8839
8910
|
if (fromSetupComplete != null) {
|
|
8840
|
-
setValueByPath(toObject, ['setupComplete'], liveServerSetupCompleteFromVertex());
|
|
8911
|
+
setValueByPath(toObject, ['setupComplete'], liveServerSetupCompleteFromVertex(fromSetupComplete));
|
|
8841
8912
|
}
|
|
8842
8913
|
const fromServerContent = getValueByPath(fromObject, [
|
|
8843
8914
|
'serverContent',
|
|
@@ -9405,6 +9476,10 @@ function toolToMldev$1(fromObject) {
|
|
|
9405
9476
|
if (fromCodeExecution != null) {
|
|
9406
9477
|
setValueByPath(toObject, ['codeExecution'], fromCodeExecution);
|
|
9407
9478
|
}
|
|
9479
|
+
const fromComputerUse = getValueByPath(fromObject, ['computerUse']);
|
|
9480
|
+
if (fromComputerUse != null) {
|
|
9481
|
+
setValueByPath(toObject, ['computerUse'], fromComputerUse);
|
|
9482
|
+
}
|
|
9408
9483
|
return toObject;
|
|
9409
9484
|
}
|
|
9410
9485
|
function functionCallingConfigToMldev(fromObject) {
|
|
@@ -10494,6 +10569,10 @@ function toolToVertex(fromObject) {
|
|
|
10494
10569
|
if (fromCodeExecution != null) {
|
|
10495
10570
|
setValueByPath(toObject, ['codeExecution'], fromCodeExecution);
|
|
10496
10571
|
}
|
|
10572
|
+
const fromComputerUse = getValueByPath(fromObject, ['computerUse']);
|
|
10573
|
+
if (fromComputerUse != null) {
|
|
10574
|
+
setValueByPath(toObject, ['computerUse'], fromComputerUse);
|
|
10575
|
+
}
|
|
10497
10576
|
return toObject;
|
|
10498
10577
|
}
|
|
10499
10578
|
function functionCallingConfigToVertex(fromObject) {
|
|
@@ -11877,7 +11956,7 @@ function modelFromMldev(fromObject) {
|
|
|
11877
11956
|
}
|
|
11878
11957
|
return toObject;
|
|
11879
11958
|
}
|
|
11880
|
-
function listModelsResponseFromMldev(
|
|
11959
|
+
function listModelsResponseFromMldev(fromObject) {
|
|
11881
11960
|
const toObject = {};
|
|
11882
11961
|
const fromNextPageToken = getValueByPath(fromObject, [
|
|
11883
11962
|
'nextPageToken',
|
|
@@ -12521,7 +12600,7 @@ function modelFromVertex(fromObject) {
|
|
|
12521
12600
|
}
|
|
12522
12601
|
return toObject;
|
|
12523
12602
|
}
|
|
12524
|
-
function listModelsResponseFromVertex(
|
|
12603
|
+
function listModelsResponseFromVertex(fromObject) {
|
|
12525
12604
|
const toObject = {};
|
|
12526
12605
|
const fromNextPageToken = getValueByPath(fromObject, [
|
|
12527
12606
|
'nextPageToken',
|
|
@@ -12647,7 +12726,7 @@ const CONTENT_TYPE_HEADER = 'Content-Type';
|
|
|
12647
12726
|
const SERVER_TIMEOUT_HEADER = 'X-Server-Timeout';
|
|
12648
12727
|
const USER_AGENT_HEADER = 'User-Agent';
|
|
12649
12728
|
const GOOGLE_API_CLIENT_HEADER = 'x-goog-api-client';
|
|
12650
|
-
const SDK_VERSION = '1.
|
|
12729
|
+
const SDK_VERSION = '1.9.0'; // x-release-please-version
|
|
12651
12730
|
const LIBRARY_LABEL = `google-genai-sdk/${SDK_VERSION}`;
|
|
12652
12731
|
const VERTEX_AI_API_DEFAULT_VERSION = 'v1beta1';
|
|
12653
12732
|
const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
|
|
@@ -12878,7 +12957,14 @@ class ApiClient {
|
|
|
12878
12957
|
const abortController = new AbortController();
|
|
12879
12958
|
const signal = abortController.signal;
|
|
12880
12959
|
if (httpOptions.timeout && (httpOptions === null || httpOptions === void 0 ? void 0 : httpOptions.timeout) > 0) {
|
|
12881
|
-
setTimeout(() => abortController.abort(), httpOptions.timeout);
|
|
12960
|
+
const timeoutHandle = setTimeout(() => abortController.abort(), httpOptions.timeout);
|
|
12961
|
+
if (timeoutHandle &&
|
|
12962
|
+
typeof timeoutHandle.unref ===
|
|
12963
|
+
'function') {
|
|
12964
|
+
// call unref to prevent nodejs process from hanging, see
|
|
12965
|
+
// https://nodejs.org/api/timers.html#timeoutunref
|
|
12966
|
+
timeoutHandle.unref();
|
|
12967
|
+
}
|
|
12882
12968
|
}
|
|
12883
12969
|
if (abortSignal) {
|
|
12884
12970
|
abortSignal.addEventListener('abort', () => {
|
|
@@ -12941,7 +13027,7 @@ class ApiClient {
|
|
|
12941
13027
|
}
|
|
12942
13028
|
break;
|
|
12943
13029
|
}
|
|
12944
|
-
const chunkString = decoder.decode(value);
|
|
13030
|
+
const chunkString = decoder.decode(value, { stream: true });
|
|
12945
13031
|
// Parse and throw an error if the chunk contains an error.
|
|
12946
13032
|
try {
|
|
12947
13033
|
const chunkJson = JSON.parse(chunkString);
|
|
@@ -13698,7 +13784,7 @@ class Live {
|
|
|
13698
13784
|
if (GOOGLE_GENAI_USE_VERTEXAI) {
|
|
13699
13785
|
model = 'gemini-2.0-flash-live-preview-04-09';
|
|
13700
13786
|
} else {
|
|
13701
|
-
model = 'gemini-2.
|
|
13787
|
+
model = 'gemini-live-2.5-flash-preview';
|
|
13702
13788
|
}
|
|
13703
13789
|
const session = await ai.live.connect({
|
|
13704
13790
|
model: model,
|
|
@@ -13744,6 +13830,9 @@ class Live {
|
|
|
13744
13830
|
let keyName = 'key';
|
|
13745
13831
|
if (apiKey === null || apiKey === void 0 ? void 0 : apiKey.startsWith('auth_tokens/')) {
|
|
13746
13832
|
console.warn('Warning: Ephemeral token support is experimental and may change in future versions.');
|
|
13833
|
+
if (apiVersion !== 'v1alpha') {
|
|
13834
|
+
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.");
|
|
13835
|
+
}
|
|
13747
13836
|
method = 'BidiGenerateContentConstrained';
|
|
13748
13837
|
keyName = 'access_token';
|
|
13749
13838
|
}
|
|
@@ -14019,7 +14108,7 @@ class Session {
|
|
|
14019
14108
|
if (GOOGLE_GENAI_USE_VERTEXAI) {
|
|
14020
14109
|
model = 'gemini-2.0-flash-live-preview-04-09';
|
|
14021
14110
|
} else {
|
|
14022
|
-
model = 'gemini-2.
|
|
14111
|
+
model = 'gemini-live-2.5-flash-preview';
|
|
14023
14112
|
}
|
|
14024
14113
|
const session = await ai.live.connect({
|
|
14025
14114
|
model: model,
|
|
@@ -14148,6 +14237,7 @@ class Models extends BaseModule {
|
|
|
14148
14237
|
this.generateContent = async (params) => {
|
|
14149
14238
|
var _a, _b, _c, _d, _e;
|
|
14150
14239
|
const transformedParams = await this.processParamsForMcpUsage(params);
|
|
14240
|
+
this.maybeMoveToResponseJsonSchem(params);
|
|
14151
14241
|
if (!hasMcpClientTools(params) || shouldDisableAfc(params.config)) {
|
|
14152
14242
|
return await this.generateContentInternal(transformedParams);
|
|
14153
14243
|
}
|
|
@@ -14234,6 +14324,7 @@ class Models extends BaseModule {
|
|
|
14234
14324
|
* ```
|
|
14235
14325
|
*/
|
|
14236
14326
|
this.generateContentStream = async (params) => {
|
|
14327
|
+
this.maybeMoveToResponseJsonSchem(params);
|
|
14237
14328
|
if (shouldDisableAfc(params.config)) {
|
|
14238
14329
|
const transformedParams = await this.processParamsForMcpUsage(params);
|
|
14239
14330
|
return await this.generateContentStreamInternal(transformedParams);
|
|
@@ -14385,6 +14476,24 @@ class Models extends BaseModule {
|
|
|
14385
14476
|
return await this.upscaleImageInternal(apiParams);
|
|
14386
14477
|
};
|
|
14387
14478
|
}
|
|
14479
|
+
/**
|
|
14480
|
+
* This logic is needed for GenerateContentConfig only.
|
|
14481
|
+
* Previously we made GenerateContentConfig.responseSchema field to accept
|
|
14482
|
+
* unknown. Since v1.9.0, we switch to use backend JSON schema support.
|
|
14483
|
+
* To maintain backward compatibility, we move the data that was treated as
|
|
14484
|
+
* JSON schema from the responseSchema field to the responseJsonSchema field.
|
|
14485
|
+
*/
|
|
14486
|
+
maybeMoveToResponseJsonSchem(params) {
|
|
14487
|
+
if (params.config && params.config.responseSchema) {
|
|
14488
|
+
if (!params.config.responseJsonSchema) {
|
|
14489
|
+
if (Object.keys(params.config.responseSchema).includes('$schema')) {
|
|
14490
|
+
params.config.responseJsonSchema = params.config.responseSchema;
|
|
14491
|
+
delete params.config.responseSchema;
|
|
14492
|
+
}
|
|
14493
|
+
}
|
|
14494
|
+
}
|
|
14495
|
+
return;
|
|
14496
|
+
}
|
|
14388
14497
|
/**
|
|
14389
14498
|
* Transforms the CallableTools in the parameters to be simply Tools, it
|
|
14390
14499
|
* copies the params into a new object and replaces the tools, it does not
|
|
@@ -14981,7 +15090,7 @@ class Models extends BaseModule {
|
|
|
14981
15090
|
return httpResponse.json();
|
|
14982
15091
|
});
|
|
14983
15092
|
return response.then((apiResponse) => {
|
|
14984
|
-
const resp = listModelsResponseFromVertex(
|
|
15093
|
+
const resp = listModelsResponseFromVertex(apiResponse);
|
|
14985
15094
|
const typedResp = new ListModelsResponse();
|
|
14986
15095
|
Object.assign(typedResp, resp);
|
|
14987
15096
|
return typedResp;
|
|
@@ -15007,7 +15116,7 @@ class Models extends BaseModule {
|
|
|
15007
15116
|
return httpResponse.json();
|
|
15008
15117
|
});
|
|
15009
15118
|
return response.then((apiResponse) => {
|
|
15010
|
-
const resp = listModelsResponseFromMldev(
|
|
15119
|
+
const resp = listModelsResponseFromMldev(apiResponse);
|
|
15011
15120
|
const typedResp = new ListModelsResponse();
|
|
15012
15121
|
Object.assign(typedResp, resp);
|
|
15013
15122
|
return typedResp;
|
|
@@ -16017,6 +16126,10 @@ function toolToMldev(fromObject) {
|
|
|
16017
16126
|
if (fromCodeExecution != null) {
|
|
16018
16127
|
setValueByPath(toObject, ['codeExecution'], fromCodeExecution);
|
|
16019
16128
|
}
|
|
16129
|
+
const fromComputerUse = getValueByPath(fromObject, ['computerUse']);
|
|
16130
|
+
if (fromComputerUse != null) {
|
|
16131
|
+
setValueByPath(toObject, ['computerUse'], fromComputerUse);
|
|
16132
|
+
}
|
|
16020
16133
|
return toObject;
|
|
16021
16134
|
}
|
|
16022
16135
|
function sessionResumptionConfigToMldev(fromObject) {
|
|
@@ -16441,14 +16554,20 @@ class Tokens extends BaseModule {
|
|
|
16441
16554
|
* @experimental
|
|
16442
16555
|
*
|
|
16443
16556
|
* @remarks
|
|
16444
|
-
*
|
|
16557
|
+
* Ephemeral auth tokens is only supported in the Gemini Developer API.
|
|
16445
16558
|
* It can be used for the session connection to the Live constrained API.
|
|
16559
|
+
* Support in v1alpha only.
|
|
16446
16560
|
*
|
|
16447
16561
|
* @param params - The parameters for the create request.
|
|
16448
16562
|
* @return The created auth token.
|
|
16449
16563
|
*
|
|
16450
16564
|
* @example
|
|
16451
16565
|
* ```ts
|
|
16566
|
+
* const ai = new GoogleGenAI({
|
|
16567
|
+
* apiKey: token.name,
|
|
16568
|
+
* httpOptions: { apiVersion: 'v1alpha' } // Support in v1alpha only.
|
|
16569
|
+
* });
|
|
16570
|
+
*
|
|
16452
16571
|
* // Case 1: If LiveEphemeralParameters is unset, unlock LiveConnectConfig
|
|
16453
16572
|
* // when using the token in Live API sessions. Each session connection can
|
|
16454
16573
|
* // use a different configuration.
|
|
@@ -16781,6 +16900,9 @@ function tuningDatasetToMldev(fromObject) {
|
|
|
16781
16900
|
if (getValueByPath(fromObject, ['gcsUri']) !== undefined) {
|
|
16782
16901
|
throw new Error('gcsUri parameter is not supported in Gemini API.');
|
|
16783
16902
|
}
|
|
16903
|
+
if (getValueByPath(fromObject, ['vertexDatasetResource']) !== undefined) {
|
|
16904
|
+
throw new Error('vertexDatasetResource parameter is not supported in Gemini API.');
|
|
16905
|
+
}
|
|
16784
16906
|
const fromExamples = getValueByPath(fromObject, ['examples']);
|
|
16785
16907
|
if (fromExamples != null) {
|
|
16786
16908
|
let transformedList = fromExamples;
|
|
@@ -16894,17 +17016,29 @@ function tuningDatasetToVertex(fromObject, parentObject) {
|
|
|
16894
17016
|
if (parentObject !== undefined && fromGcsUri != null) {
|
|
16895
17017
|
setValueByPath(parentObject, ['supervisedTuningSpec', 'trainingDatasetUri'], fromGcsUri);
|
|
16896
17018
|
}
|
|
17019
|
+
const fromVertexDatasetResource = getValueByPath(fromObject, [
|
|
17020
|
+
'vertexDatasetResource',
|
|
17021
|
+
]);
|
|
17022
|
+
if (parentObject !== undefined && fromVertexDatasetResource != null) {
|
|
17023
|
+
setValueByPath(parentObject, ['supervisedTuningSpec', 'trainingDatasetUri'], fromVertexDatasetResource);
|
|
17024
|
+
}
|
|
16897
17025
|
if (getValueByPath(fromObject, ['examples']) !== undefined) {
|
|
16898
17026
|
throw new Error('examples parameter is not supported in Vertex AI.');
|
|
16899
17027
|
}
|
|
16900
17028
|
return toObject;
|
|
16901
17029
|
}
|
|
16902
|
-
function tuningValidationDatasetToVertex(fromObject) {
|
|
17030
|
+
function tuningValidationDatasetToVertex(fromObject, parentObject) {
|
|
16903
17031
|
const toObject = {};
|
|
16904
17032
|
const fromGcsUri = getValueByPath(fromObject, ['gcsUri']);
|
|
16905
17033
|
if (fromGcsUri != null) {
|
|
16906
17034
|
setValueByPath(toObject, ['validationDatasetUri'], fromGcsUri);
|
|
16907
17035
|
}
|
|
17036
|
+
const fromVertexDatasetResource = getValueByPath(fromObject, [
|
|
17037
|
+
'vertexDatasetResource',
|
|
17038
|
+
]);
|
|
17039
|
+
if (parentObject !== undefined && fromVertexDatasetResource != null) {
|
|
17040
|
+
setValueByPath(parentObject, ['supervisedTuningSpec', 'trainingDatasetUri'], fromVertexDatasetResource);
|
|
17041
|
+
}
|
|
16908
17042
|
return toObject;
|
|
16909
17043
|
}
|
|
16910
17044
|
function createTuningJobConfigToVertex(fromObject, parentObject) {
|
|
@@ -16913,7 +17047,7 @@ function createTuningJobConfigToVertex(fromObject, parentObject) {
|
|
|
16913
17047
|
'validationDataset',
|
|
16914
17048
|
]);
|
|
16915
17049
|
if (parentObject !== undefined && fromValidationDataset != null) {
|
|
16916
|
-
setValueByPath(parentObject, ['supervisedTuningSpec'], tuningValidationDatasetToVertex(fromValidationDataset));
|
|
17050
|
+
setValueByPath(parentObject, ['supervisedTuningSpec'], tuningValidationDatasetToVertex(fromValidationDataset, toObject));
|
|
16917
17051
|
}
|
|
16918
17052
|
const fromTunedModelDisplayName = getValueByPath(fromObject, [
|
|
16919
17053
|
'tunedModelDisplayName',
|
|
@@ -17045,6 +17179,14 @@ function tuningJobFromMldev(fromObject) {
|
|
|
17045
17179
|
if (fromPipelineJob != null) {
|
|
17046
17180
|
setValueByPath(toObject, ['pipelineJob'], fromPipelineJob);
|
|
17047
17181
|
}
|
|
17182
|
+
const fromSatisfiesPzi = getValueByPath(fromObject, ['satisfiesPzi']);
|
|
17183
|
+
if (fromSatisfiesPzi != null) {
|
|
17184
|
+
setValueByPath(toObject, ['satisfiesPzi'], fromSatisfiesPzi);
|
|
17185
|
+
}
|
|
17186
|
+
const fromSatisfiesPzs = getValueByPath(fromObject, ['satisfiesPzs']);
|
|
17187
|
+
if (fromSatisfiesPzs != null) {
|
|
17188
|
+
setValueByPath(toObject, ['satisfiesPzs'], fromSatisfiesPzs);
|
|
17189
|
+
}
|
|
17048
17190
|
const fromServiceAccount = getValueByPath(fromObject, [
|
|
17049
17191
|
'serviceAccount',
|
|
17050
17192
|
]);
|
|
@@ -17225,6 +17367,14 @@ function tuningJobFromVertex(fromObject) {
|
|
|
17225
17367
|
if (fromPipelineJob != null) {
|
|
17226
17368
|
setValueByPath(toObject, ['pipelineJob'], fromPipelineJob);
|
|
17227
17369
|
}
|
|
17370
|
+
const fromSatisfiesPzi = getValueByPath(fromObject, ['satisfiesPzi']);
|
|
17371
|
+
if (fromSatisfiesPzi != null) {
|
|
17372
|
+
setValueByPath(toObject, ['satisfiesPzi'], fromSatisfiesPzi);
|
|
17373
|
+
}
|
|
17374
|
+
const fromSatisfiesPzs = getValueByPath(fromObject, ['satisfiesPzs']);
|
|
17375
|
+
if (fromSatisfiesPzs != null) {
|
|
17376
|
+
setValueByPath(toObject, ['satisfiesPzs'], fromSatisfiesPzs);
|
|
17377
|
+
}
|
|
17228
17378
|
const fromServiceAccount = getValueByPath(fromObject, [
|
|
17229
17379
|
'serviceAccount',
|
|
17230
17380
|
]);
|