@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/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
|
|
@@ -259,6 +257,22 @@ exports.HarmCategory = void 0;
|
|
|
259
257
|
* Deprecated: Election filter is not longer supported. The harm category is civic integrity.
|
|
260
258
|
*/
|
|
261
259
|
HarmCategory["HARM_CATEGORY_CIVIC_INTEGRITY"] = "HARM_CATEGORY_CIVIC_INTEGRITY";
|
|
260
|
+
/**
|
|
261
|
+
* The harm category is image hate.
|
|
262
|
+
*/
|
|
263
|
+
HarmCategory["HARM_CATEGORY_IMAGE_HATE"] = "HARM_CATEGORY_IMAGE_HATE";
|
|
264
|
+
/**
|
|
265
|
+
* The harm category is image dangerous content.
|
|
266
|
+
*/
|
|
267
|
+
HarmCategory["HARM_CATEGORY_IMAGE_DANGEROUS_CONTENT"] = "HARM_CATEGORY_IMAGE_DANGEROUS_CONTENT";
|
|
268
|
+
/**
|
|
269
|
+
* The harm category is image harassment.
|
|
270
|
+
*/
|
|
271
|
+
HarmCategory["HARM_CATEGORY_IMAGE_HARASSMENT"] = "HARM_CATEGORY_IMAGE_HARASSMENT";
|
|
272
|
+
/**
|
|
273
|
+
* The harm category is image sexually explicit content.
|
|
274
|
+
*/
|
|
275
|
+
HarmCategory["HARM_CATEGORY_IMAGE_SEXUALLY_EXPLICIT"] = "HARM_CATEGORY_IMAGE_SEXUALLY_EXPLICIT";
|
|
262
276
|
})(exports.HarmCategory || (exports.HarmCategory = {}));
|
|
263
277
|
/** Optional. Specify if the threshold is used for probability or severity score. If not specified, the threshold is used for probability score. */
|
|
264
278
|
exports.HarmBlockMethod = void 0;
|
|
@@ -345,6 +359,50 @@ exports.AuthType = void 0;
|
|
|
345
359
|
*/
|
|
346
360
|
AuthType["OIDC_AUTH"] = "OIDC_AUTH";
|
|
347
361
|
})(exports.AuthType || (exports.AuthType = {}));
|
|
362
|
+
/** The API spec that the external API implements. */
|
|
363
|
+
exports.ApiSpec = void 0;
|
|
364
|
+
(function (ApiSpec) {
|
|
365
|
+
/**
|
|
366
|
+
* Unspecified API spec. This value should not be used.
|
|
367
|
+
*/
|
|
368
|
+
ApiSpec["API_SPEC_UNSPECIFIED"] = "API_SPEC_UNSPECIFIED";
|
|
369
|
+
/**
|
|
370
|
+
* Simple search API spec.
|
|
371
|
+
*/
|
|
372
|
+
ApiSpec["SIMPLE_SEARCH"] = "SIMPLE_SEARCH";
|
|
373
|
+
/**
|
|
374
|
+
* Elastic search API spec.
|
|
375
|
+
*/
|
|
376
|
+
ApiSpec["ELASTIC_SEARCH"] = "ELASTIC_SEARCH";
|
|
377
|
+
})(exports.ApiSpec || (exports.ApiSpec = {}));
|
|
378
|
+
/** Required. The environment being operated. */
|
|
379
|
+
exports.Environment = void 0;
|
|
380
|
+
(function (Environment) {
|
|
381
|
+
/**
|
|
382
|
+
* Defaults to browser.
|
|
383
|
+
*/
|
|
384
|
+
Environment["ENVIRONMENT_UNSPECIFIED"] = "ENVIRONMENT_UNSPECIFIED";
|
|
385
|
+
/**
|
|
386
|
+
* Operates in a web browser.
|
|
387
|
+
*/
|
|
388
|
+
Environment["ENVIRONMENT_BROWSER"] = "ENVIRONMENT_BROWSER";
|
|
389
|
+
})(exports.Environment || (exports.Environment = {}));
|
|
390
|
+
/** Status of the url retrieval. */
|
|
391
|
+
exports.UrlRetrievalStatus = void 0;
|
|
392
|
+
(function (UrlRetrievalStatus) {
|
|
393
|
+
/**
|
|
394
|
+
* Default value. This value is unused
|
|
395
|
+
*/
|
|
396
|
+
UrlRetrievalStatus["URL_RETRIEVAL_STATUS_UNSPECIFIED"] = "URL_RETRIEVAL_STATUS_UNSPECIFIED";
|
|
397
|
+
/**
|
|
398
|
+
* Url retrieval is successful.
|
|
399
|
+
*/
|
|
400
|
+
UrlRetrievalStatus["URL_RETRIEVAL_STATUS_SUCCESS"] = "URL_RETRIEVAL_STATUS_SUCCESS";
|
|
401
|
+
/**
|
|
402
|
+
* Url retrieval is failed due to error.
|
|
403
|
+
*/
|
|
404
|
+
UrlRetrievalStatus["URL_RETRIEVAL_STATUS_ERROR"] = "URL_RETRIEVAL_STATUS_ERROR";
|
|
405
|
+
})(exports.UrlRetrievalStatus || (exports.UrlRetrievalStatus = {}));
|
|
348
406
|
/** Output only. The reason why the model stopped generating tokens.
|
|
349
407
|
|
|
350
408
|
If empty, the model has not stopped generating the tokens.
|
|
@@ -475,6 +533,10 @@ exports.BlockedReason = void 0;
|
|
|
475
533
|
* Candidates blocked due to prohibited content.
|
|
476
534
|
*/
|
|
477
535
|
BlockedReason["PROHIBITED_CONTENT"] = "PROHIBITED_CONTENT";
|
|
536
|
+
/**
|
|
537
|
+
* Candidates blocked due to unsafe image generation content.
|
|
538
|
+
*/
|
|
539
|
+
BlockedReason["IMAGE_SAFETY"] = "IMAGE_SAFETY";
|
|
478
540
|
})(exports.BlockedReason || (exports.BlockedReason = {}));
|
|
479
541
|
/** Output only. Traffic type. This shows whether a request consumes Pay-As-You-Go or Provisioned Throughput quota. */
|
|
480
542
|
exports.TrafficType = void 0;
|
|
@@ -672,22 +734,6 @@ exports.FunctionCallingConfigMode = void 0;
|
|
|
672
734
|
*/
|
|
673
735
|
FunctionCallingConfigMode["NONE"] = "NONE";
|
|
674
736
|
})(exports.FunctionCallingConfigMode || (exports.FunctionCallingConfigMode = {}));
|
|
675
|
-
/** Status of the url retrieval. */
|
|
676
|
-
exports.UrlRetrievalStatus = void 0;
|
|
677
|
-
(function (UrlRetrievalStatus) {
|
|
678
|
-
/**
|
|
679
|
-
* Default value. This value is unused
|
|
680
|
-
*/
|
|
681
|
-
UrlRetrievalStatus["URL_RETRIEVAL_STATUS_UNSPECIFIED"] = "URL_RETRIEVAL_STATUS_UNSPECIFIED";
|
|
682
|
-
/**
|
|
683
|
-
* Url retrieval is successful.
|
|
684
|
-
*/
|
|
685
|
-
UrlRetrievalStatus["URL_RETRIEVAL_STATUS_SUCCESS"] = "URL_RETRIEVAL_STATUS_SUCCESS";
|
|
686
|
-
/**
|
|
687
|
-
* Url retrieval is failed due to error.
|
|
688
|
-
*/
|
|
689
|
-
UrlRetrievalStatus["URL_RETRIEVAL_STATUS_ERROR"] = "URL_RETRIEVAL_STATUS_ERROR";
|
|
690
|
-
})(exports.UrlRetrievalStatus || (exports.UrlRetrievalStatus = {}));
|
|
691
737
|
/** Enum that controls the safety filter level for objectionable content. */
|
|
692
738
|
exports.SafetyFilterLevel = void 0;
|
|
693
739
|
(function (SafetyFilterLevel) {
|
|
@@ -715,11 +761,38 @@ exports.PersonGeneration = void 0;
|
|
|
715
761
|
/** Enum that specifies the language of the text in the prompt. */
|
|
716
762
|
exports.ImagePromptLanguage = void 0;
|
|
717
763
|
(function (ImagePromptLanguage) {
|
|
764
|
+
/**
|
|
765
|
+
* Auto-detect the language.
|
|
766
|
+
*/
|
|
718
767
|
ImagePromptLanguage["auto"] = "auto";
|
|
768
|
+
/**
|
|
769
|
+
* English
|
|
770
|
+
*/
|
|
719
771
|
ImagePromptLanguage["en"] = "en";
|
|
772
|
+
/**
|
|
773
|
+
* Japanese
|
|
774
|
+
*/
|
|
720
775
|
ImagePromptLanguage["ja"] = "ja";
|
|
776
|
+
/**
|
|
777
|
+
* Korean
|
|
778
|
+
*/
|
|
721
779
|
ImagePromptLanguage["ko"] = "ko";
|
|
780
|
+
/**
|
|
781
|
+
* Hindi
|
|
782
|
+
*/
|
|
722
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";
|
|
723
796
|
})(exports.ImagePromptLanguage || (exports.ImagePromptLanguage = {}));
|
|
724
797
|
/** Enum representing the mask mode of a mask reference image. */
|
|
725
798
|
exports.MaskReferenceMode = void 0;
|
|
@@ -1820,133 +1893,12 @@ function tContents(origin) {
|
|
|
1820
1893
|
}
|
|
1821
1894
|
return result;
|
|
1822
1895
|
}
|
|
1823
|
-
// The fields that are supported by JSONSchema. Must be kept in sync with the
|
|
1824
|
-
// JSONSchema interface above.
|
|
1825
|
-
const supportedJsonSchemaFields = new Set([
|
|
1826
|
-
'type',
|
|
1827
|
-
'format',
|
|
1828
|
-
'title',
|
|
1829
|
-
'description',
|
|
1830
|
-
'default',
|
|
1831
|
-
'items',
|
|
1832
|
-
'minItems',
|
|
1833
|
-
'maxItems',
|
|
1834
|
-
'enum',
|
|
1835
|
-
'properties',
|
|
1836
|
-
'required',
|
|
1837
|
-
'minProperties',
|
|
1838
|
-
'maxProperties',
|
|
1839
|
-
'minimum',
|
|
1840
|
-
'maximum',
|
|
1841
|
-
'minLength',
|
|
1842
|
-
'maxLength',
|
|
1843
|
-
'pattern',
|
|
1844
|
-
'anyOf',
|
|
1845
|
-
'propertyOrdering',
|
|
1846
|
-
]);
|
|
1847
|
-
const jsonSchemaTypeValidator = zod.z.enum([
|
|
1848
|
-
'string',
|
|
1849
|
-
'number',
|
|
1850
|
-
'integer',
|
|
1851
|
-
'object',
|
|
1852
|
-
'array',
|
|
1853
|
-
'boolean',
|
|
1854
|
-
'null',
|
|
1855
|
-
]);
|
|
1856
|
-
// Handles all types and arrays of all types.
|
|
1857
|
-
const schemaTypeUnion = zod.z.union([
|
|
1858
|
-
jsonSchemaTypeValidator,
|
|
1859
|
-
zod.z.array(jsonSchemaTypeValidator),
|
|
1860
|
-
]);
|
|
1861
|
-
/**
|
|
1862
|
-
* Creates a zod validator for JSONSchema.
|
|
1863
|
-
*
|
|
1864
|
-
* @param strictMode Whether to enable strict mode, default to true. When
|
|
1865
|
-
* strict mode is enabled, the zod validator will throw error if there
|
|
1866
|
-
* are unrecognized fields in the input data. If strict mode is
|
|
1867
|
-
* disabled, the zod validator will ignore the unrecognized fields, only
|
|
1868
|
-
* populate the fields that are listed in the JSONSchema. Regardless of
|
|
1869
|
-
* the mode the type mismatch will always result in an error, for example
|
|
1870
|
-
* items field should be a single JSONSchema, but for tuple type it would
|
|
1871
|
-
* be an array of JSONSchema, this will always result in an error.
|
|
1872
|
-
* @return The zod validator for JSONSchema.
|
|
1873
|
-
*/
|
|
1874
|
-
function createJsonSchemaValidator(strictMode = true) {
|
|
1875
|
-
const jsonSchemaValidator = zod.z.lazy(() => {
|
|
1876
|
-
// Define the base object shape *inside* the z.lazy callback
|
|
1877
|
-
const baseShape = zod.z.object({
|
|
1878
|
-
// --- Type ---
|
|
1879
|
-
type: schemaTypeUnion.optional(),
|
|
1880
|
-
// --- Annotations ---
|
|
1881
|
-
format: zod.z.string().optional(),
|
|
1882
|
-
title: zod.z.string().optional(),
|
|
1883
|
-
description: zod.z.string().optional(),
|
|
1884
|
-
default: zod.z.unknown().optional(),
|
|
1885
|
-
// --- Array Validations ---
|
|
1886
|
-
items: jsonSchemaValidator.optional(),
|
|
1887
|
-
minItems: zod.z.coerce.string().optional(),
|
|
1888
|
-
maxItems: zod.z.coerce.string().optional(),
|
|
1889
|
-
// --- Generic Validations ---
|
|
1890
|
-
enum: zod.z.array(zod.z.unknown()).optional(),
|
|
1891
|
-
// --- Object Validations ---
|
|
1892
|
-
properties: zod.z.record(zod.z.string(), jsonSchemaValidator).optional(),
|
|
1893
|
-
required: zod.z.array(zod.z.string()).optional(),
|
|
1894
|
-
minProperties: zod.z.coerce.string().optional(),
|
|
1895
|
-
maxProperties: zod.z.coerce.string().optional(),
|
|
1896
|
-
propertyOrdering: zod.z.array(zod.z.string()).optional(),
|
|
1897
|
-
// --- Numeric Validations ---
|
|
1898
|
-
minimum: zod.z.number().optional(),
|
|
1899
|
-
maximum: zod.z.number().optional(),
|
|
1900
|
-
// --- String Validations ---
|
|
1901
|
-
minLength: zod.z.coerce.string().optional(),
|
|
1902
|
-
maxLength: zod.z.coerce.string().optional(),
|
|
1903
|
-
pattern: zod.z.string().optional(),
|
|
1904
|
-
// --- Schema Composition ---
|
|
1905
|
-
anyOf: zod.z.array(jsonSchemaValidator).optional(),
|
|
1906
|
-
// --- Additional Properties --- This field is not included in the
|
|
1907
|
-
// JSONSchema, will not be communicated to the model, it is here purely
|
|
1908
|
-
// for enabling the zod validation strict mode.
|
|
1909
|
-
additionalProperties: zod.z.boolean().optional(),
|
|
1910
|
-
});
|
|
1911
|
-
// Conditionally apply .strict() based on the flag
|
|
1912
|
-
return strictMode ? baseShape.strict() : baseShape;
|
|
1913
|
-
});
|
|
1914
|
-
return jsonSchemaValidator;
|
|
1915
|
-
}
|
|
1916
1896
|
/*
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
zod_to_json_schema will squash the types into an array instead of put them
|
|
1923
|
-
in anyOf fields. Otherwise, it will put the types in anyOf fields.
|
|
1924
|
-
See the following link for more details:
|
|
1925
|
-
https://github.com/zodjs/zod-to-json-schema/blob/main/src/index.ts#L101
|
|
1926
|
-
The logic here is trying to undo that optimization, flattening the array of
|
|
1927
|
-
types to anyOf fields.
|
|
1928
|
-
type field
|
|
1929
|
-
|
|
|
1930
|
-
___________________________
|
|
1931
|
-
/ \
|
|
1932
|
-
/ \
|
|
1933
|
-
/ \
|
|
1934
|
-
Array Type.*
|
|
1935
|
-
/ \ |
|
|
1936
|
-
Include null. Not included null type = Type.*.
|
|
1937
|
-
[null, Type.*, Type.*] multiple types.
|
|
1938
|
-
[null, Type.*] [Type.*, Type.*]
|
|
1939
|
-
/ \
|
|
1940
|
-
remove null \
|
|
1941
|
-
add nullable = true \
|
|
1942
|
-
/ \ \
|
|
1943
|
-
[Type.*] [Type.*, Type.*] \
|
|
1944
|
-
only one type left multiple types left \
|
|
1945
|
-
add type = Type.*. \ /
|
|
1946
|
-
\ /
|
|
1947
|
-
not populate the type field in final result
|
|
1948
|
-
and make the types into anyOf fields
|
|
1949
|
-
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'}]}
|
|
1950
1902
|
*/
|
|
1951
1903
|
function flattenTypeArrayToAnyOf(typeList, resultingSchema) {
|
|
1952
1904
|
if (typeList.includes('null')) {
|
|
@@ -2092,15 +2044,11 @@ function processJsonSchema(_jsonSchema) {
|
|
|
2092
2044
|
// https://github.com/StefanTerdell/zod-to-json-schema/blob/70525efe555cd226691e093d171370a3b10921d1/src/zodToJsonSchema.ts#L7
|
|
2093
2045
|
// typebox can return unknown, see details in
|
|
2094
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.
|
|
2095
2050
|
function tSchema(schema) {
|
|
2096
|
-
|
|
2097
|
-
delete schema['$schema'];
|
|
2098
|
-
const validatedJsonSchema = createJsonSchemaValidator().parse(schema);
|
|
2099
|
-
return processJsonSchema(validatedJsonSchema);
|
|
2100
|
-
}
|
|
2101
|
-
else {
|
|
2102
|
-
return processJsonSchema(schema);
|
|
2103
|
-
}
|
|
2051
|
+
return processJsonSchema(schema);
|
|
2104
2052
|
}
|
|
2105
2053
|
function tSpeechConfig(speechConfig) {
|
|
2106
2054
|
if (typeof speechConfig === 'object') {
|
|
@@ -2129,10 +2077,28 @@ function tTool(tool) {
|
|
|
2129
2077
|
if (tool.functionDeclarations) {
|
|
2130
2078
|
for (const functionDeclaration of tool.functionDeclarations) {
|
|
2131
2079
|
if (functionDeclaration.parameters) {
|
|
2132
|
-
|
|
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
|
+
}
|
|
2133
2090
|
}
|
|
2134
2091
|
if (functionDeclaration.response) {
|
|
2135
|
-
|
|
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
|
+
}
|
|
2136
2102
|
}
|
|
2137
2103
|
}
|
|
2138
2104
|
}
|
|
@@ -2337,7 +2303,7 @@ function mcpToGeminiTool(mcpTool, config = {}) {
|
|
|
2337
2303
|
const functionDeclaration = {
|
|
2338
2304
|
name: mcpToolSchema['name'],
|
|
2339
2305
|
description: mcpToolSchema['description'],
|
|
2340
|
-
|
|
2306
|
+
parametersJsonSchema: mcpToolSchema['inputSchema'],
|
|
2341
2307
|
};
|
|
2342
2308
|
if (config.behavior) {
|
|
2343
2309
|
functionDeclaration['behavior'] = config.behavior;
|
|
@@ -2369,53 +2335,6 @@ function mcpToolsToGeminiTool(mcpTools, config = {}) {
|
|
|
2369
2335
|
}
|
|
2370
2336
|
return { functionDeclarations: functionDeclarations };
|
|
2371
2337
|
}
|
|
2372
|
-
// Filters the list schema field to only include fields that are supported by
|
|
2373
|
-
// JSONSchema.
|
|
2374
|
-
function filterListSchemaField(fieldValue) {
|
|
2375
|
-
const listSchemaFieldValue = [];
|
|
2376
|
-
for (const listFieldValue of fieldValue) {
|
|
2377
|
-
listSchemaFieldValue.push(filterToJsonSchema(listFieldValue));
|
|
2378
|
-
}
|
|
2379
|
-
return listSchemaFieldValue;
|
|
2380
|
-
}
|
|
2381
|
-
// Filters the dict schema field to only include fields that are supported by
|
|
2382
|
-
// JSONSchema.
|
|
2383
|
-
function filterDictSchemaField(fieldValue) {
|
|
2384
|
-
const dictSchemaFieldValue = {};
|
|
2385
|
-
for (const [key, value] of Object.entries(fieldValue)) {
|
|
2386
|
-
const valueRecord = value;
|
|
2387
|
-
dictSchemaFieldValue[key] = filterToJsonSchema(valueRecord);
|
|
2388
|
-
}
|
|
2389
|
-
return dictSchemaFieldValue;
|
|
2390
|
-
}
|
|
2391
|
-
// Filters the schema to only include fields that are supported by JSONSchema.
|
|
2392
|
-
function filterToJsonSchema(schema) {
|
|
2393
|
-
const schemaFieldNames = new Set(['items']); // 'additional_properties' to come
|
|
2394
|
-
const listSchemaFieldNames = new Set(['anyOf']); // 'one_of', 'all_of', 'not' to come
|
|
2395
|
-
const dictSchemaFieldNames = new Set(['properties']); // 'defs' to come
|
|
2396
|
-
const filteredSchema = {};
|
|
2397
|
-
for (const [fieldName, fieldValue] of Object.entries(schema)) {
|
|
2398
|
-
if (schemaFieldNames.has(fieldName)) {
|
|
2399
|
-
filteredSchema[fieldName] = filterToJsonSchema(fieldValue);
|
|
2400
|
-
}
|
|
2401
|
-
else if (listSchemaFieldNames.has(fieldName)) {
|
|
2402
|
-
filteredSchema[fieldName] = filterListSchemaField(fieldValue);
|
|
2403
|
-
}
|
|
2404
|
-
else if (dictSchemaFieldNames.has(fieldName)) {
|
|
2405
|
-
filteredSchema[fieldName] = filterDictSchemaField(fieldValue);
|
|
2406
|
-
}
|
|
2407
|
-
else if (fieldName === 'type') {
|
|
2408
|
-
const typeValue = fieldValue.toUpperCase();
|
|
2409
|
-
filteredSchema[fieldName] = Object.values(exports.Type).includes(typeValue)
|
|
2410
|
-
? typeValue
|
|
2411
|
-
: exports.Type.TYPE_UNSPECIFIED;
|
|
2412
|
-
}
|
|
2413
|
-
else if (supportedJsonSchemaFields.has(fieldName)) {
|
|
2414
|
-
filteredSchema[fieldName] = fieldValue;
|
|
2415
|
-
}
|
|
2416
|
-
}
|
|
2417
|
-
return filteredSchema;
|
|
2418
|
-
}
|
|
2419
2338
|
// Transforms a source input into a BatchJobSource object with validation.
|
|
2420
2339
|
function tBatchJobSource(apiClient, src) {
|
|
2421
2340
|
if (typeof src !== 'string' && !Array.isArray(src)) {
|
|
@@ -2890,6 +2809,10 @@ function toolToMldev$4(fromObject) {
|
|
|
2890
2809
|
if (fromCodeExecution != null) {
|
|
2891
2810
|
setValueByPath(toObject, ['codeExecution'], fromCodeExecution);
|
|
2892
2811
|
}
|
|
2812
|
+
const fromComputerUse = getValueByPath(fromObject, ['computerUse']);
|
|
2813
|
+
if (fromComputerUse != null) {
|
|
2814
|
+
setValueByPath(toObject, ['computerUse'], fromComputerUse);
|
|
2815
|
+
}
|
|
2893
2816
|
return toObject;
|
|
2894
2817
|
}
|
|
2895
2818
|
function functionCallingConfigToMldev$2(fromObject) {
|
|
@@ -3301,6 +3224,18 @@ function listBatchJobsParametersToMldev(fromObject) {
|
|
|
3301
3224
|
}
|
|
3302
3225
|
return toObject;
|
|
3303
3226
|
}
|
|
3227
|
+
function deleteBatchJobParametersToMldev(apiClient, fromObject) {
|
|
3228
|
+
const toObject = {};
|
|
3229
|
+
const fromName = getValueByPath(fromObject, ['name']);
|
|
3230
|
+
if (fromName != null) {
|
|
3231
|
+
setValueByPath(toObject, ['_url', 'name'], tBatchJobName(apiClient, fromName));
|
|
3232
|
+
}
|
|
3233
|
+
const fromConfig = getValueByPath(fromObject, ['config']);
|
|
3234
|
+
if (fromConfig != null) {
|
|
3235
|
+
setValueByPath(toObject, ['config'], fromConfig);
|
|
3236
|
+
}
|
|
3237
|
+
return toObject;
|
|
3238
|
+
}
|
|
3304
3239
|
function batchJobSourceToVertex(fromObject) {
|
|
3305
3240
|
const toObject = {};
|
|
3306
3241
|
const fromFormat = getValueByPath(fromObject, ['format']);
|
|
@@ -3421,6 +3356,18 @@ function listBatchJobsParametersToVertex(fromObject) {
|
|
|
3421
3356
|
}
|
|
3422
3357
|
return toObject;
|
|
3423
3358
|
}
|
|
3359
|
+
function deleteBatchJobParametersToVertex(apiClient, fromObject) {
|
|
3360
|
+
const toObject = {};
|
|
3361
|
+
const fromName = getValueByPath(fromObject, ['name']);
|
|
3362
|
+
if (fromName != null) {
|
|
3363
|
+
setValueByPath(toObject, ['_url', 'name'], tBatchJobName(apiClient, fromName));
|
|
3364
|
+
}
|
|
3365
|
+
const fromConfig = getValueByPath(fromObject, ['config']);
|
|
3366
|
+
if (fromConfig != null) {
|
|
3367
|
+
setValueByPath(toObject, ['config'], fromConfig);
|
|
3368
|
+
}
|
|
3369
|
+
return toObject;
|
|
3370
|
+
}
|
|
3424
3371
|
function jobErrorFromMldev() {
|
|
3425
3372
|
const toObject = {};
|
|
3426
3373
|
return toObject;
|
|
@@ -3758,6 +3705,22 @@ function listBatchJobsResponseFromMldev(fromObject) {
|
|
|
3758
3705
|
}
|
|
3759
3706
|
return toObject;
|
|
3760
3707
|
}
|
|
3708
|
+
function deleteResourceJobFromMldev(fromObject) {
|
|
3709
|
+
const toObject = {};
|
|
3710
|
+
const fromName = getValueByPath(fromObject, ['name']);
|
|
3711
|
+
if (fromName != null) {
|
|
3712
|
+
setValueByPath(toObject, ['name'], fromName);
|
|
3713
|
+
}
|
|
3714
|
+
const fromDone = getValueByPath(fromObject, ['done']);
|
|
3715
|
+
if (fromDone != null) {
|
|
3716
|
+
setValueByPath(toObject, ['done'], fromDone);
|
|
3717
|
+
}
|
|
3718
|
+
const fromError = getValueByPath(fromObject, ['error']);
|
|
3719
|
+
if (fromError != null) {
|
|
3720
|
+
setValueByPath(toObject, ['error'], jobErrorFromMldev());
|
|
3721
|
+
}
|
|
3722
|
+
return toObject;
|
|
3723
|
+
}
|
|
3761
3724
|
function jobErrorFromVertex(fromObject) {
|
|
3762
3725
|
const toObject = {};
|
|
3763
3726
|
const fromDetails = getValueByPath(fromObject, ['details']);
|
|
@@ -3885,6 +3848,22 @@ function listBatchJobsResponseFromVertex(fromObject) {
|
|
|
3885
3848
|
}
|
|
3886
3849
|
return toObject;
|
|
3887
3850
|
}
|
|
3851
|
+
function deleteResourceJobFromVertex(fromObject) {
|
|
3852
|
+
const toObject = {};
|
|
3853
|
+
const fromName = getValueByPath(fromObject, ['name']);
|
|
3854
|
+
if (fromName != null) {
|
|
3855
|
+
setValueByPath(toObject, ['name'], fromName);
|
|
3856
|
+
}
|
|
3857
|
+
const fromDone = getValueByPath(fromObject, ['done']);
|
|
3858
|
+
if (fromDone != null) {
|
|
3859
|
+
setValueByPath(toObject, ['done'], fromDone);
|
|
3860
|
+
}
|
|
3861
|
+
const fromError = getValueByPath(fromObject, ['error']);
|
|
3862
|
+
if (fromError != null) {
|
|
3863
|
+
setValueByPath(toObject, ['error'], jobErrorFromVertex(fromError));
|
|
3864
|
+
}
|
|
3865
|
+
return toObject;
|
|
3866
|
+
}
|
|
3888
3867
|
|
|
3889
3868
|
/**
|
|
3890
3869
|
* @license
|
|
@@ -4092,20 +4071,23 @@ class Batches extends BaseModule {
|
|
|
4092
4071
|
*/
|
|
4093
4072
|
this.create = async (params) => {
|
|
4094
4073
|
if (this.apiClient.isVertexAI()) {
|
|
4074
|
+
const timestamp = Date.now();
|
|
4075
|
+
const timestampStr = timestamp.toString();
|
|
4095
4076
|
if (Array.isArray(params.src)) {
|
|
4096
4077
|
throw new Error('InlinedRequest[] is not supported in Vertex AI. Please use ' +
|
|
4097
4078
|
'Google Cloud Storage URI or BigQuery URI instead.');
|
|
4098
4079
|
}
|
|
4099
4080
|
params.config = params.config || {};
|
|
4100
4081
|
if (params.config.displayName === undefined) {
|
|
4101
|
-
params.config.displayName = 'genaiBatchJob_';
|
|
4082
|
+
params.config.displayName = 'genaiBatchJob_${timestampStr}';
|
|
4102
4083
|
}
|
|
4103
4084
|
if (params.config.dest === undefined && typeof params.src === 'string') {
|
|
4104
4085
|
if (params.src.startsWith('gs://') && params.src.endsWith('.jsonl')) {
|
|
4105
4086
|
params.config.dest = `${params.src.slice(0, -6)}/dest`;
|
|
4106
4087
|
}
|
|
4107
4088
|
else if (params.src.startsWith('bq://')) {
|
|
4108
|
-
params.config.dest =
|
|
4089
|
+
params.config.dest =
|
|
4090
|
+
`${params.src}_dest_${timestampStr}`;
|
|
4109
4091
|
}
|
|
4110
4092
|
else {
|
|
4111
4093
|
throw new Error('Unsupported source:' + params.src);
|
|
@@ -4364,6 +4346,71 @@ class Batches extends BaseModule {
|
|
|
4364
4346
|
});
|
|
4365
4347
|
}
|
|
4366
4348
|
}
|
|
4349
|
+
/**
|
|
4350
|
+
* Deletes a batch job.
|
|
4351
|
+
*
|
|
4352
|
+
* @param params - The parameters for the delete request.
|
|
4353
|
+
* @return The empty response returned by the API.
|
|
4354
|
+
*
|
|
4355
|
+
* @example
|
|
4356
|
+
* ```ts
|
|
4357
|
+
* await ai.batches.delete({name: '...'}); // The server-generated resource name.
|
|
4358
|
+
* ```
|
|
4359
|
+
*/
|
|
4360
|
+
async delete(params) {
|
|
4361
|
+
var _a, _b, _c, _d;
|
|
4362
|
+
let response;
|
|
4363
|
+
let path = '';
|
|
4364
|
+
let queryParams = {};
|
|
4365
|
+
if (this.apiClient.isVertexAI()) {
|
|
4366
|
+
const body = deleteBatchJobParametersToVertex(this.apiClient, params);
|
|
4367
|
+
path = formatMap('batchPredictionJobs/{name}', body['_url']);
|
|
4368
|
+
queryParams = body['_query'];
|
|
4369
|
+
delete body['config'];
|
|
4370
|
+
delete body['_url'];
|
|
4371
|
+
delete body['_query'];
|
|
4372
|
+
response = this.apiClient
|
|
4373
|
+
.request({
|
|
4374
|
+
path: path,
|
|
4375
|
+
queryParams: queryParams,
|
|
4376
|
+
body: JSON.stringify(body),
|
|
4377
|
+
httpMethod: 'DELETE',
|
|
4378
|
+
httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
|
|
4379
|
+
abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
|
|
4380
|
+
})
|
|
4381
|
+
.then((httpResponse) => {
|
|
4382
|
+
return httpResponse.json();
|
|
4383
|
+
});
|
|
4384
|
+
return response.then((apiResponse) => {
|
|
4385
|
+
const resp = deleteResourceJobFromVertex(apiResponse);
|
|
4386
|
+
return resp;
|
|
4387
|
+
});
|
|
4388
|
+
}
|
|
4389
|
+
else {
|
|
4390
|
+
const body = deleteBatchJobParametersToMldev(this.apiClient, params);
|
|
4391
|
+
path = formatMap('batches/{name}', body['_url']);
|
|
4392
|
+
queryParams = body['_query'];
|
|
4393
|
+
delete body['config'];
|
|
4394
|
+
delete body['_url'];
|
|
4395
|
+
delete body['_query'];
|
|
4396
|
+
response = this.apiClient
|
|
4397
|
+
.request({
|
|
4398
|
+
path: path,
|
|
4399
|
+
queryParams: queryParams,
|
|
4400
|
+
body: JSON.stringify(body),
|
|
4401
|
+
httpMethod: 'DELETE',
|
|
4402
|
+
httpOptions: (_c = params.config) === null || _c === void 0 ? void 0 : _c.httpOptions,
|
|
4403
|
+
abortSignal: (_d = params.config) === null || _d === void 0 ? void 0 : _d.abortSignal,
|
|
4404
|
+
})
|
|
4405
|
+
.then((httpResponse) => {
|
|
4406
|
+
return httpResponse.json();
|
|
4407
|
+
});
|
|
4408
|
+
return response.then((apiResponse) => {
|
|
4409
|
+
const resp = deleteResourceJobFromMldev(apiResponse);
|
|
4410
|
+
return resp;
|
|
4411
|
+
});
|
|
4412
|
+
}
|
|
4413
|
+
}
|
|
4367
4414
|
}
|
|
4368
4415
|
|
|
4369
4416
|
/**
|
|
@@ -4618,6 +4665,10 @@ function toolToMldev$3(fromObject) {
|
|
|
4618
4665
|
if (fromCodeExecution != null) {
|
|
4619
4666
|
setValueByPath(toObject, ['codeExecution'], fromCodeExecution);
|
|
4620
4667
|
}
|
|
4668
|
+
const fromComputerUse = getValueByPath(fromObject, ['computerUse']);
|
|
4669
|
+
if (fromComputerUse != null) {
|
|
4670
|
+
setValueByPath(toObject, ['computerUse'], fromComputerUse);
|
|
4671
|
+
}
|
|
4621
4672
|
return toObject;
|
|
4622
4673
|
}
|
|
4623
4674
|
function functionCallingConfigToMldev$1(fromObject) {
|
|
@@ -5108,6 +5159,10 @@ function toolToVertex$2(fromObject) {
|
|
|
5108
5159
|
if (fromCodeExecution != null) {
|
|
5109
5160
|
setValueByPath(toObject, ['codeExecution'], fromCodeExecution);
|
|
5110
5161
|
}
|
|
5162
|
+
const fromComputerUse = getValueByPath(fromObject, ['computerUse']);
|
|
5163
|
+
if (fromComputerUse != null) {
|
|
5164
|
+
setValueByPath(toObject, ['computerUse'], fromComputerUse);
|
|
5165
|
+
}
|
|
5111
5166
|
return toObject;
|
|
5112
5167
|
}
|
|
5113
5168
|
function functionCallingConfigToVertex$1(fromObject) {
|
|
@@ -6195,7 +6250,7 @@ const CONTENT_TYPE_HEADER = 'Content-Type';
|
|
|
6195
6250
|
const SERVER_TIMEOUT_HEADER = 'X-Server-Timeout';
|
|
6196
6251
|
const USER_AGENT_HEADER = 'User-Agent';
|
|
6197
6252
|
const GOOGLE_API_CLIENT_HEADER = 'x-goog-api-client';
|
|
6198
|
-
const SDK_VERSION = '1.
|
|
6253
|
+
const SDK_VERSION = '1.9.0'; // x-release-please-version
|
|
6199
6254
|
const LIBRARY_LABEL = `google-genai-sdk/${SDK_VERSION}`;
|
|
6200
6255
|
const VERTEX_AI_API_DEFAULT_VERSION = 'v1beta1';
|
|
6201
6256
|
const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
|
|
@@ -6426,7 +6481,14 @@ class ApiClient {
|
|
|
6426
6481
|
const abortController = new AbortController();
|
|
6427
6482
|
const signal = abortController.signal;
|
|
6428
6483
|
if (httpOptions.timeout && (httpOptions === null || httpOptions === void 0 ? void 0 : httpOptions.timeout) > 0) {
|
|
6429
|
-
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
|
+
}
|
|
6430
6492
|
}
|
|
6431
6493
|
if (abortSignal) {
|
|
6432
6494
|
abortSignal.addEventListener('abort', () => {
|
|
@@ -6489,7 +6551,7 @@ class ApiClient {
|
|
|
6489
6551
|
}
|
|
6490
6552
|
break;
|
|
6491
6553
|
}
|
|
6492
|
-
const chunkString = decoder.decode(value);
|
|
6554
|
+
const chunkString = decoder.decode(value, { stream: true });
|
|
6493
6555
|
// Parse and throw an error if the chunk contains an error.
|
|
6494
6556
|
try {
|
|
6495
6557
|
const chunkJson = JSON.parse(chunkString);
|
|
@@ -8004,6 +8066,10 @@ function toolToMldev$2(fromObject) {
|
|
|
8004
8066
|
if (fromCodeExecution != null) {
|
|
8005
8067
|
setValueByPath(toObject, ['codeExecution'], fromCodeExecution);
|
|
8006
8068
|
}
|
|
8069
|
+
const fromComputerUse = getValueByPath(fromObject, ['computerUse']);
|
|
8070
|
+
if (fromComputerUse != null) {
|
|
8071
|
+
setValueByPath(toObject, ['computerUse'], fromComputerUse);
|
|
8072
|
+
}
|
|
8007
8073
|
return toObject;
|
|
8008
8074
|
}
|
|
8009
8075
|
function toolToVertex$1(fromObject) {
|
|
@@ -8054,6 +8120,10 @@ function toolToVertex$1(fromObject) {
|
|
|
8054
8120
|
if (fromCodeExecution != null) {
|
|
8055
8121
|
setValueByPath(toObject, ['codeExecution'], fromCodeExecution);
|
|
8056
8122
|
}
|
|
8123
|
+
const fromComputerUse = getValueByPath(fromObject, ['computerUse']);
|
|
8124
|
+
if (fromComputerUse != null) {
|
|
8125
|
+
setValueByPath(toObject, ['computerUse'], fromComputerUse);
|
|
8126
|
+
}
|
|
8057
8127
|
return toObject;
|
|
8058
8128
|
}
|
|
8059
8129
|
function sessionResumptionConfigToMldev$1(fromObject) {
|
|
@@ -8549,8 +8619,9 @@ function liveSendRealtimeInputParametersToVertex(fromObject) {
|
|
|
8549
8619
|
if (fromMedia != null) {
|
|
8550
8620
|
setValueByPath(toObject, ['mediaChunks'], tBlobs(fromMedia));
|
|
8551
8621
|
}
|
|
8552
|
-
|
|
8553
|
-
|
|
8622
|
+
const fromAudio = getValueByPath(fromObject, ['audio']);
|
|
8623
|
+
if (fromAudio != null) {
|
|
8624
|
+
setValueByPath(toObject, ['audio'], tAudioBlob(fromAudio));
|
|
8554
8625
|
}
|
|
8555
8626
|
const fromAudioStreamEnd = getValueByPath(fromObject, [
|
|
8556
8627
|
'audioStreamEnd',
|
|
@@ -8558,11 +8629,13 @@ function liveSendRealtimeInputParametersToVertex(fromObject) {
|
|
|
8558
8629
|
if (fromAudioStreamEnd != null) {
|
|
8559
8630
|
setValueByPath(toObject, ['audioStreamEnd'], fromAudioStreamEnd);
|
|
8560
8631
|
}
|
|
8561
|
-
|
|
8562
|
-
|
|
8632
|
+
const fromVideo = getValueByPath(fromObject, ['video']);
|
|
8633
|
+
if (fromVideo != null) {
|
|
8634
|
+
setValueByPath(toObject, ['video'], tImageBlob(fromVideo));
|
|
8563
8635
|
}
|
|
8564
|
-
|
|
8565
|
-
|
|
8636
|
+
const fromText = getValueByPath(fromObject, ['text']);
|
|
8637
|
+
if (fromText != null) {
|
|
8638
|
+
setValueByPath(toObject, ['text'], fromText);
|
|
8566
8639
|
}
|
|
8567
8640
|
const fromActivityStart = getValueByPath(fromObject, [
|
|
8568
8641
|
'activityStart',
|
|
@@ -8718,8 +8791,12 @@ function liveServerSetupCompleteFromMldev() {
|
|
|
8718
8791
|
const toObject = {};
|
|
8719
8792
|
return toObject;
|
|
8720
8793
|
}
|
|
8721
|
-
function liveServerSetupCompleteFromVertex() {
|
|
8794
|
+
function liveServerSetupCompleteFromVertex(fromObject) {
|
|
8722
8795
|
const toObject = {};
|
|
8796
|
+
const fromSessionId = getValueByPath(fromObject, ['sessionId']);
|
|
8797
|
+
if (fromSessionId != null) {
|
|
8798
|
+
setValueByPath(toObject, ['sessionId'], fromSessionId);
|
|
8799
|
+
}
|
|
8723
8800
|
return toObject;
|
|
8724
8801
|
}
|
|
8725
8802
|
function videoMetadataFromMldev$1(fromObject) {
|
|
@@ -9472,7 +9549,7 @@ function liveServerMessageFromVertex(fromObject) {
|
|
|
9472
9549
|
'setupComplete',
|
|
9473
9550
|
]);
|
|
9474
9551
|
if (fromSetupComplete != null) {
|
|
9475
|
-
setValueByPath(toObject, ['setupComplete'], liveServerSetupCompleteFromVertex());
|
|
9552
|
+
setValueByPath(toObject, ['setupComplete'], liveServerSetupCompleteFromVertex(fromSetupComplete));
|
|
9476
9553
|
}
|
|
9477
9554
|
const fromServerContent = getValueByPath(fromObject, [
|
|
9478
9555
|
'serverContent',
|
|
@@ -10040,6 +10117,10 @@ function toolToMldev$1(fromObject) {
|
|
|
10040
10117
|
if (fromCodeExecution != null) {
|
|
10041
10118
|
setValueByPath(toObject, ['codeExecution'], fromCodeExecution);
|
|
10042
10119
|
}
|
|
10120
|
+
const fromComputerUse = getValueByPath(fromObject, ['computerUse']);
|
|
10121
|
+
if (fromComputerUse != null) {
|
|
10122
|
+
setValueByPath(toObject, ['computerUse'], fromComputerUse);
|
|
10123
|
+
}
|
|
10043
10124
|
return toObject;
|
|
10044
10125
|
}
|
|
10045
10126
|
function functionCallingConfigToMldev(fromObject) {
|
|
@@ -11129,6 +11210,10 @@ function toolToVertex(fromObject) {
|
|
|
11129
11210
|
if (fromCodeExecution != null) {
|
|
11130
11211
|
setValueByPath(toObject, ['codeExecution'], fromCodeExecution);
|
|
11131
11212
|
}
|
|
11213
|
+
const fromComputerUse = getValueByPath(fromObject, ['computerUse']);
|
|
11214
|
+
if (fromComputerUse != null) {
|
|
11215
|
+
setValueByPath(toObject, ['computerUse'], fromComputerUse);
|
|
11216
|
+
}
|
|
11132
11217
|
return toObject;
|
|
11133
11218
|
}
|
|
11134
11219
|
function functionCallingConfigToVertex(fromObject) {
|
|
@@ -12512,7 +12597,7 @@ function modelFromMldev(fromObject) {
|
|
|
12512
12597
|
}
|
|
12513
12598
|
return toObject;
|
|
12514
12599
|
}
|
|
12515
|
-
function listModelsResponseFromMldev(
|
|
12600
|
+
function listModelsResponseFromMldev(fromObject) {
|
|
12516
12601
|
const toObject = {};
|
|
12517
12602
|
const fromNextPageToken = getValueByPath(fromObject, [
|
|
12518
12603
|
'nextPageToken',
|
|
@@ -13156,7 +13241,7 @@ function modelFromVertex(fromObject) {
|
|
|
13156
13241
|
}
|
|
13157
13242
|
return toObject;
|
|
13158
13243
|
}
|
|
13159
|
-
function listModelsResponseFromVertex(
|
|
13244
|
+
function listModelsResponseFromVertex(fromObject) {
|
|
13160
13245
|
const toObject = {};
|
|
13161
13246
|
const fromNextPageToken = getValueByPath(fromObject, [
|
|
13162
13247
|
'nextPageToken',
|
|
@@ -13766,7 +13851,7 @@ class Live {
|
|
|
13766
13851
|
if (GOOGLE_GENAI_USE_VERTEXAI) {
|
|
13767
13852
|
model = 'gemini-2.0-flash-live-preview-04-09';
|
|
13768
13853
|
} else {
|
|
13769
|
-
model = 'gemini-2.
|
|
13854
|
+
model = 'gemini-live-2.5-flash-preview';
|
|
13770
13855
|
}
|
|
13771
13856
|
const session = await ai.live.connect({
|
|
13772
13857
|
model: model,
|
|
@@ -13812,6 +13897,9 @@ class Live {
|
|
|
13812
13897
|
let keyName = 'key';
|
|
13813
13898
|
if (apiKey === null || apiKey === void 0 ? void 0 : apiKey.startsWith('auth_tokens/')) {
|
|
13814
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
|
+
}
|
|
13815
13903
|
method = 'BidiGenerateContentConstrained';
|
|
13816
13904
|
keyName = 'access_token';
|
|
13817
13905
|
}
|
|
@@ -14087,7 +14175,7 @@ class Session {
|
|
|
14087
14175
|
if (GOOGLE_GENAI_USE_VERTEXAI) {
|
|
14088
14176
|
model = 'gemini-2.0-flash-live-preview-04-09';
|
|
14089
14177
|
} else {
|
|
14090
|
-
model = 'gemini-2.
|
|
14178
|
+
model = 'gemini-live-2.5-flash-preview';
|
|
14091
14179
|
}
|
|
14092
14180
|
const session = await ai.live.connect({
|
|
14093
14181
|
model: model,
|
|
@@ -14216,6 +14304,7 @@ class Models extends BaseModule {
|
|
|
14216
14304
|
this.generateContent = async (params) => {
|
|
14217
14305
|
var _a, _b, _c, _d, _e;
|
|
14218
14306
|
const transformedParams = await this.processParamsForMcpUsage(params);
|
|
14307
|
+
this.maybeMoveToResponseJsonSchem(params);
|
|
14219
14308
|
if (!hasMcpClientTools(params) || shouldDisableAfc(params.config)) {
|
|
14220
14309
|
return await this.generateContentInternal(transformedParams);
|
|
14221
14310
|
}
|
|
@@ -14302,6 +14391,7 @@ class Models extends BaseModule {
|
|
|
14302
14391
|
* ```
|
|
14303
14392
|
*/
|
|
14304
14393
|
this.generateContentStream = async (params) => {
|
|
14394
|
+
this.maybeMoveToResponseJsonSchem(params);
|
|
14305
14395
|
if (shouldDisableAfc(params.config)) {
|
|
14306
14396
|
const transformedParams = await this.processParamsForMcpUsage(params);
|
|
14307
14397
|
return await this.generateContentStreamInternal(transformedParams);
|
|
@@ -14453,6 +14543,24 @@ class Models extends BaseModule {
|
|
|
14453
14543
|
return await this.upscaleImageInternal(apiParams);
|
|
14454
14544
|
};
|
|
14455
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
|
+
}
|
|
14456
14564
|
/**
|
|
14457
14565
|
* Transforms the CallableTools in the parameters to be simply Tools, it
|
|
14458
14566
|
* copies the params into a new object and replaces the tools, it does not
|
|
@@ -15049,7 +15157,7 @@ class Models extends BaseModule {
|
|
|
15049
15157
|
return httpResponse.json();
|
|
15050
15158
|
});
|
|
15051
15159
|
return response.then((apiResponse) => {
|
|
15052
|
-
const resp = listModelsResponseFromVertex(
|
|
15160
|
+
const resp = listModelsResponseFromVertex(apiResponse);
|
|
15053
15161
|
const typedResp = new ListModelsResponse();
|
|
15054
15162
|
Object.assign(typedResp, resp);
|
|
15055
15163
|
return typedResp;
|
|
@@ -15075,7 +15183,7 @@ class Models extends BaseModule {
|
|
|
15075
15183
|
return httpResponse.json();
|
|
15076
15184
|
});
|
|
15077
15185
|
return response.then((apiResponse) => {
|
|
15078
|
-
const resp = listModelsResponseFromMldev(
|
|
15186
|
+
const resp = listModelsResponseFromMldev(apiResponse);
|
|
15079
15187
|
const typedResp = new ListModelsResponse();
|
|
15080
15188
|
Object.assign(typedResp, resp);
|
|
15081
15189
|
return typedResp;
|
|
@@ -16085,6 +16193,10 @@ function toolToMldev(fromObject) {
|
|
|
16085
16193
|
if (fromCodeExecution != null) {
|
|
16086
16194
|
setValueByPath(toObject, ['codeExecution'], fromCodeExecution);
|
|
16087
16195
|
}
|
|
16196
|
+
const fromComputerUse = getValueByPath(fromObject, ['computerUse']);
|
|
16197
|
+
if (fromComputerUse != null) {
|
|
16198
|
+
setValueByPath(toObject, ['computerUse'], fromComputerUse);
|
|
16199
|
+
}
|
|
16088
16200
|
return toObject;
|
|
16089
16201
|
}
|
|
16090
16202
|
function sessionResumptionConfigToMldev(fromObject) {
|
|
@@ -16509,14 +16621,20 @@ class Tokens extends BaseModule {
|
|
|
16509
16621
|
* @experimental
|
|
16510
16622
|
*
|
|
16511
16623
|
* @remarks
|
|
16512
|
-
*
|
|
16624
|
+
* Ephemeral auth tokens is only supported in the Gemini Developer API.
|
|
16513
16625
|
* It can be used for the session connection to the Live constrained API.
|
|
16626
|
+
* Support in v1alpha only.
|
|
16514
16627
|
*
|
|
16515
16628
|
* @param params - The parameters for the create request.
|
|
16516
16629
|
* @return The created auth token.
|
|
16517
16630
|
*
|
|
16518
16631
|
* @example
|
|
16519
16632
|
* ```ts
|
|
16633
|
+
* const ai = new GoogleGenAI({
|
|
16634
|
+
* apiKey: token.name,
|
|
16635
|
+
* httpOptions: { apiVersion: 'v1alpha' } // Support in v1alpha only.
|
|
16636
|
+
* });
|
|
16637
|
+
*
|
|
16520
16638
|
* // Case 1: If LiveEphemeralParameters is unset, unlock LiveConnectConfig
|
|
16521
16639
|
* // when using the token in Live API sessions. Each session connection can
|
|
16522
16640
|
* // use a different configuration.
|
|
@@ -16675,6 +16793,9 @@ function tuningDatasetToMldev(fromObject) {
|
|
|
16675
16793
|
if (getValueByPath(fromObject, ['gcsUri']) !== undefined) {
|
|
16676
16794
|
throw new Error('gcsUri parameter is not supported in Gemini API.');
|
|
16677
16795
|
}
|
|
16796
|
+
if (getValueByPath(fromObject, ['vertexDatasetResource']) !== undefined) {
|
|
16797
|
+
throw new Error('vertexDatasetResource parameter is not supported in Gemini API.');
|
|
16798
|
+
}
|
|
16678
16799
|
const fromExamples = getValueByPath(fromObject, ['examples']);
|
|
16679
16800
|
if (fromExamples != null) {
|
|
16680
16801
|
let transformedList = fromExamples;
|
|
@@ -16788,17 +16909,29 @@ function tuningDatasetToVertex(fromObject, parentObject) {
|
|
|
16788
16909
|
if (parentObject !== undefined && fromGcsUri != null) {
|
|
16789
16910
|
setValueByPath(parentObject, ['supervisedTuningSpec', 'trainingDatasetUri'], fromGcsUri);
|
|
16790
16911
|
}
|
|
16912
|
+
const fromVertexDatasetResource = getValueByPath(fromObject, [
|
|
16913
|
+
'vertexDatasetResource',
|
|
16914
|
+
]);
|
|
16915
|
+
if (parentObject !== undefined && fromVertexDatasetResource != null) {
|
|
16916
|
+
setValueByPath(parentObject, ['supervisedTuningSpec', 'trainingDatasetUri'], fromVertexDatasetResource);
|
|
16917
|
+
}
|
|
16791
16918
|
if (getValueByPath(fromObject, ['examples']) !== undefined) {
|
|
16792
16919
|
throw new Error('examples parameter is not supported in Vertex AI.');
|
|
16793
16920
|
}
|
|
16794
16921
|
return toObject;
|
|
16795
16922
|
}
|
|
16796
|
-
function tuningValidationDatasetToVertex(fromObject) {
|
|
16923
|
+
function tuningValidationDatasetToVertex(fromObject, parentObject) {
|
|
16797
16924
|
const toObject = {};
|
|
16798
16925
|
const fromGcsUri = getValueByPath(fromObject, ['gcsUri']);
|
|
16799
16926
|
if (fromGcsUri != null) {
|
|
16800
16927
|
setValueByPath(toObject, ['validationDatasetUri'], fromGcsUri);
|
|
16801
16928
|
}
|
|
16929
|
+
const fromVertexDatasetResource = getValueByPath(fromObject, [
|
|
16930
|
+
'vertexDatasetResource',
|
|
16931
|
+
]);
|
|
16932
|
+
if (parentObject !== undefined && fromVertexDatasetResource != null) {
|
|
16933
|
+
setValueByPath(parentObject, ['supervisedTuningSpec', 'trainingDatasetUri'], fromVertexDatasetResource);
|
|
16934
|
+
}
|
|
16802
16935
|
return toObject;
|
|
16803
16936
|
}
|
|
16804
16937
|
function createTuningJobConfigToVertex(fromObject, parentObject) {
|
|
@@ -16807,7 +16940,7 @@ function createTuningJobConfigToVertex(fromObject, parentObject) {
|
|
|
16807
16940
|
'validationDataset',
|
|
16808
16941
|
]);
|
|
16809
16942
|
if (parentObject !== undefined && fromValidationDataset != null) {
|
|
16810
|
-
setValueByPath(parentObject, ['supervisedTuningSpec'], tuningValidationDatasetToVertex(fromValidationDataset));
|
|
16943
|
+
setValueByPath(parentObject, ['supervisedTuningSpec'], tuningValidationDatasetToVertex(fromValidationDataset, toObject));
|
|
16811
16944
|
}
|
|
16812
16945
|
const fromTunedModelDisplayName = getValueByPath(fromObject, [
|
|
16813
16946
|
'tunedModelDisplayName',
|
|
@@ -16939,6 +17072,14 @@ function tuningJobFromMldev(fromObject) {
|
|
|
16939
17072
|
if (fromPipelineJob != null) {
|
|
16940
17073
|
setValueByPath(toObject, ['pipelineJob'], fromPipelineJob);
|
|
16941
17074
|
}
|
|
17075
|
+
const fromSatisfiesPzi = getValueByPath(fromObject, ['satisfiesPzi']);
|
|
17076
|
+
if (fromSatisfiesPzi != null) {
|
|
17077
|
+
setValueByPath(toObject, ['satisfiesPzi'], fromSatisfiesPzi);
|
|
17078
|
+
}
|
|
17079
|
+
const fromSatisfiesPzs = getValueByPath(fromObject, ['satisfiesPzs']);
|
|
17080
|
+
if (fromSatisfiesPzs != null) {
|
|
17081
|
+
setValueByPath(toObject, ['satisfiesPzs'], fromSatisfiesPzs);
|
|
17082
|
+
}
|
|
16942
17083
|
const fromServiceAccount = getValueByPath(fromObject, [
|
|
16943
17084
|
'serviceAccount',
|
|
16944
17085
|
]);
|
|
@@ -17119,6 +17260,14 @@ function tuningJobFromVertex(fromObject) {
|
|
|
17119
17260
|
if (fromPipelineJob != null) {
|
|
17120
17261
|
setValueByPath(toObject, ['pipelineJob'], fromPipelineJob);
|
|
17121
17262
|
}
|
|
17263
|
+
const fromSatisfiesPzi = getValueByPath(fromObject, ['satisfiesPzi']);
|
|
17264
|
+
if (fromSatisfiesPzi != null) {
|
|
17265
|
+
setValueByPath(toObject, ['satisfiesPzi'], fromSatisfiesPzi);
|
|
17266
|
+
}
|
|
17267
|
+
const fromSatisfiesPzs = getValueByPath(fromObject, ['satisfiesPzs']);
|
|
17268
|
+
if (fromSatisfiesPzs != null) {
|
|
17269
|
+
setValueByPath(toObject, ['satisfiesPzs'], fromSatisfiesPzs);
|
|
17270
|
+
}
|
|
17122
17271
|
const fromServiceAccount = getValueByPath(fromObject, [
|
|
17123
17272
|
'serviceAccount',
|
|
17124
17273
|
]);
|