@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/web/index.mjs
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
2
|
* @license
|
|
5
3
|
* Copyright 2025 Google LLC
|
|
@@ -287,6 +285,22 @@ var HarmCategory;
|
|
|
287
285
|
* Deprecated: Election filter is not longer supported. The harm category is civic integrity.
|
|
288
286
|
*/
|
|
289
287
|
HarmCategory["HARM_CATEGORY_CIVIC_INTEGRITY"] = "HARM_CATEGORY_CIVIC_INTEGRITY";
|
|
288
|
+
/**
|
|
289
|
+
* The harm category is image hate.
|
|
290
|
+
*/
|
|
291
|
+
HarmCategory["HARM_CATEGORY_IMAGE_HATE"] = "HARM_CATEGORY_IMAGE_HATE";
|
|
292
|
+
/**
|
|
293
|
+
* The harm category is image dangerous content.
|
|
294
|
+
*/
|
|
295
|
+
HarmCategory["HARM_CATEGORY_IMAGE_DANGEROUS_CONTENT"] = "HARM_CATEGORY_IMAGE_DANGEROUS_CONTENT";
|
|
296
|
+
/**
|
|
297
|
+
* The harm category is image harassment.
|
|
298
|
+
*/
|
|
299
|
+
HarmCategory["HARM_CATEGORY_IMAGE_HARASSMENT"] = "HARM_CATEGORY_IMAGE_HARASSMENT";
|
|
300
|
+
/**
|
|
301
|
+
* The harm category is image sexually explicit content.
|
|
302
|
+
*/
|
|
303
|
+
HarmCategory["HARM_CATEGORY_IMAGE_SEXUALLY_EXPLICIT"] = "HARM_CATEGORY_IMAGE_SEXUALLY_EXPLICIT";
|
|
290
304
|
})(HarmCategory || (HarmCategory = {}));
|
|
291
305
|
/** Optional. Specify if the threshold is used for probability or severity score. If not specified, the threshold is used for probability score. */
|
|
292
306
|
var HarmBlockMethod;
|
|
@@ -373,6 +387,50 @@ var AuthType;
|
|
|
373
387
|
*/
|
|
374
388
|
AuthType["OIDC_AUTH"] = "OIDC_AUTH";
|
|
375
389
|
})(AuthType || (AuthType = {}));
|
|
390
|
+
/** The API spec that the external API implements. */
|
|
391
|
+
var ApiSpec;
|
|
392
|
+
(function (ApiSpec) {
|
|
393
|
+
/**
|
|
394
|
+
* Unspecified API spec. This value should not be used.
|
|
395
|
+
*/
|
|
396
|
+
ApiSpec["API_SPEC_UNSPECIFIED"] = "API_SPEC_UNSPECIFIED";
|
|
397
|
+
/**
|
|
398
|
+
* Simple search API spec.
|
|
399
|
+
*/
|
|
400
|
+
ApiSpec["SIMPLE_SEARCH"] = "SIMPLE_SEARCH";
|
|
401
|
+
/**
|
|
402
|
+
* Elastic search API spec.
|
|
403
|
+
*/
|
|
404
|
+
ApiSpec["ELASTIC_SEARCH"] = "ELASTIC_SEARCH";
|
|
405
|
+
})(ApiSpec || (ApiSpec = {}));
|
|
406
|
+
/** Required. The environment being operated. */
|
|
407
|
+
var Environment;
|
|
408
|
+
(function (Environment) {
|
|
409
|
+
/**
|
|
410
|
+
* Defaults to browser.
|
|
411
|
+
*/
|
|
412
|
+
Environment["ENVIRONMENT_UNSPECIFIED"] = "ENVIRONMENT_UNSPECIFIED";
|
|
413
|
+
/**
|
|
414
|
+
* Operates in a web browser.
|
|
415
|
+
*/
|
|
416
|
+
Environment["ENVIRONMENT_BROWSER"] = "ENVIRONMENT_BROWSER";
|
|
417
|
+
})(Environment || (Environment = {}));
|
|
418
|
+
/** Status of the url retrieval. */
|
|
419
|
+
var UrlRetrievalStatus;
|
|
420
|
+
(function (UrlRetrievalStatus) {
|
|
421
|
+
/**
|
|
422
|
+
* Default value. This value is unused
|
|
423
|
+
*/
|
|
424
|
+
UrlRetrievalStatus["URL_RETRIEVAL_STATUS_UNSPECIFIED"] = "URL_RETRIEVAL_STATUS_UNSPECIFIED";
|
|
425
|
+
/**
|
|
426
|
+
* Url retrieval is successful.
|
|
427
|
+
*/
|
|
428
|
+
UrlRetrievalStatus["URL_RETRIEVAL_STATUS_SUCCESS"] = "URL_RETRIEVAL_STATUS_SUCCESS";
|
|
429
|
+
/**
|
|
430
|
+
* Url retrieval is failed due to error.
|
|
431
|
+
*/
|
|
432
|
+
UrlRetrievalStatus["URL_RETRIEVAL_STATUS_ERROR"] = "URL_RETRIEVAL_STATUS_ERROR";
|
|
433
|
+
})(UrlRetrievalStatus || (UrlRetrievalStatus = {}));
|
|
376
434
|
/** Output only. The reason why the model stopped generating tokens.
|
|
377
435
|
|
|
378
436
|
If empty, the model has not stopped generating the tokens.
|
|
@@ -503,6 +561,10 @@ var BlockedReason;
|
|
|
503
561
|
* Candidates blocked due to prohibited content.
|
|
504
562
|
*/
|
|
505
563
|
BlockedReason["PROHIBITED_CONTENT"] = "PROHIBITED_CONTENT";
|
|
564
|
+
/**
|
|
565
|
+
* Candidates blocked due to unsafe image generation content.
|
|
566
|
+
*/
|
|
567
|
+
BlockedReason["IMAGE_SAFETY"] = "IMAGE_SAFETY";
|
|
506
568
|
})(BlockedReason || (BlockedReason = {}));
|
|
507
569
|
/** Output only. Traffic type. This shows whether a request consumes Pay-As-You-Go or Provisioned Throughput quota. */
|
|
508
570
|
var TrafficType;
|
|
@@ -700,22 +762,6 @@ var FunctionCallingConfigMode;
|
|
|
700
762
|
*/
|
|
701
763
|
FunctionCallingConfigMode["NONE"] = "NONE";
|
|
702
764
|
})(FunctionCallingConfigMode || (FunctionCallingConfigMode = {}));
|
|
703
|
-
/** Status of the url retrieval. */
|
|
704
|
-
var UrlRetrievalStatus;
|
|
705
|
-
(function (UrlRetrievalStatus) {
|
|
706
|
-
/**
|
|
707
|
-
* Default value. This value is unused
|
|
708
|
-
*/
|
|
709
|
-
UrlRetrievalStatus["URL_RETRIEVAL_STATUS_UNSPECIFIED"] = "URL_RETRIEVAL_STATUS_UNSPECIFIED";
|
|
710
|
-
/**
|
|
711
|
-
* Url retrieval is successful.
|
|
712
|
-
*/
|
|
713
|
-
UrlRetrievalStatus["URL_RETRIEVAL_STATUS_SUCCESS"] = "URL_RETRIEVAL_STATUS_SUCCESS";
|
|
714
|
-
/**
|
|
715
|
-
* Url retrieval is failed due to error.
|
|
716
|
-
*/
|
|
717
|
-
UrlRetrievalStatus["URL_RETRIEVAL_STATUS_ERROR"] = "URL_RETRIEVAL_STATUS_ERROR";
|
|
718
|
-
})(UrlRetrievalStatus || (UrlRetrievalStatus = {}));
|
|
719
765
|
/** Enum that controls the safety filter level for objectionable content. */
|
|
720
766
|
var SafetyFilterLevel;
|
|
721
767
|
(function (SafetyFilterLevel) {
|
|
@@ -743,11 +789,38 @@ var PersonGeneration;
|
|
|
743
789
|
/** Enum that specifies the language of the text in the prompt. */
|
|
744
790
|
var ImagePromptLanguage;
|
|
745
791
|
(function (ImagePromptLanguage) {
|
|
792
|
+
/**
|
|
793
|
+
* Auto-detect the language.
|
|
794
|
+
*/
|
|
746
795
|
ImagePromptLanguage["auto"] = "auto";
|
|
796
|
+
/**
|
|
797
|
+
* English
|
|
798
|
+
*/
|
|
747
799
|
ImagePromptLanguage["en"] = "en";
|
|
800
|
+
/**
|
|
801
|
+
* Japanese
|
|
802
|
+
*/
|
|
748
803
|
ImagePromptLanguage["ja"] = "ja";
|
|
804
|
+
/**
|
|
805
|
+
* Korean
|
|
806
|
+
*/
|
|
749
807
|
ImagePromptLanguage["ko"] = "ko";
|
|
808
|
+
/**
|
|
809
|
+
* Hindi
|
|
810
|
+
*/
|
|
750
811
|
ImagePromptLanguage["hi"] = "hi";
|
|
812
|
+
/**
|
|
813
|
+
* Chinese
|
|
814
|
+
*/
|
|
815
|
+
ImagePromptLanguage["zh"] = "zh";
|
|
816
|
+
/**
|
|
817
|
+
* Portuguese
|
|
818
|
+
*/
|
|
819
|
+
ImagePromptLanguage["pt"] = "pt";
|
|
820
|
+
/**
|
|
821
|
+
* Spanish
|
|
822
|
+
*/
|
|
823
|
+
ImagePromptLanguage["es"] = "es";
|
|
751
824
|
})(ImagePromptLanguage || (ImagePromptLanguage = {}));
|
|
752
825
|
/** Enum representing the mask mode of a mask reference image. */
|
|
753
826
|
var MaskReferenceMode;
|
|
@@ -1848,133 +1921,12 @@ function tContents(origin) {
|
|
|
1848
1921
|
}
|
|
1849
1922
|
return result;
|
|
1850
1923
|
}
|
|
1851
|
-
// The fields that are supported by JSONSchema. Must be kept in sync with the
|
|
1852
|
-
// JSONSchema interface above.
|
|
1853
|
-
const supportedJsonSchemaFields = new Set([
|
|
1854
|
-
'type',
|
|
1855
|
-
'format',
|
|
1856
|
-
'title',
|
|
1857
|
-
'description',
|
|
1858
|
-
'default',
|
|
1859
|
-
'items',
|
|
1860
|
-
'minItems',
|
|
1861
|
-
'maxItems',
|
|
1862
|
-
'enum',
|
|
1863
|
-
'properties',
|
|
1864
|
-
'required',
|
|
1865
|
-
'minProperties',
|
|
1866
|
-
'maxProperties',
|
|
1867
|
-
'minimum',
|
|
1868
|
-
'maximum',
|
|
1869
|
-
'minLength',
|
|
1870
|
-
'maxLength',
|
|
1871
|
-
'pattern',
|
|
1872
|
-
'anyOf',
|
|
1873
|
-
'propertyOrdering',
|
|
1874
|
-
]);
|
|
1875
|
-
const jsonSchemaTypeValidator = z.enum([
|
|
1876
|
-
'string',
|
|
1877
|
-
'number',
|
|
1878
|
-
'integer',
|
|
1879
|
-
'object',
|
|
1880
|
-
'array',
|
|
1881
|
-
'boolean',
|
|
1882
|
-
'null',
|
|
1883
|
-
]);
|
|
1884
|
-
// Handles all types and arrays of all types.
|
|
1885
|
-
const schemaTypeUnion = z.union([
|
|
1886
|
-
jsonSchemaTypeValidator,
|
|
1887
|
-
z.array(jsonSchemaTypeValidator),
|
|
1888
|
-
]);
|
|
1889
|
-
/**
|
|
1890
|
-
* Creates a zod validator for JSONSchema.
|
|
1891
|
-
*
|
|
1892
|
-
* @param strictMode Whether to enable strict mode, default to true. When
|
|
1893
|
-
* strict mode is enabled, the zod validator will throw error if there
|
|
1894
|
-
* are unrecognized fields in the input data. If strict mode is
|
|
1895
|
-
* disabled, the zod validator will ignore the unrecognized fields, only
|
|
1896
|
-
* populate the fields that are listed in the JSONSchema. Regardless of
|
|
1897
|
-
* the mode the type mismatch will always result in an error, for example
|
|
1898
|
-
* items field should be a single JSONSchema, but for tuple type it would
|
|
1899
|
-
* be an array of JSONSchema, this will always result in an error.
|
|
1900
|
-
* @return The zod validator for JSONSchema.
|
|
1901
|
-
*/
|
|
1902
|
-
function createJsonSchemaValidator(strictMode = true) {
|
|
1903
|
-
const jsonSchemaValidator = z.lazy(() => {
|
|
1904
|
-
// Define the base object shape *inside* the z.lazy callback
|
|
1905
|
-
const baseShape = z.object({
|
|
1906
|
-
// --- Type ---
|
|
1907
|
-
type: schemaTypeUnion.optional(),
|
|
1908
|
-
// --- Annotations ---
|
|
1909
|
-
format: z.string().optional(),
|
|
1910
|
-
title: z.string().optional(),
|
|
1911
|
-
description: z.string().optional(),
|
|
1912
|
-
default: z.unknown().optional(),
|
|
1913
|
-
// --- Array Validations ---
|
|
1914
|
-
items: jsonSchemaValidator.optional(),
|
|
1915
|
-
minItems: z.coerce.string().optional(),
|
|
1916
|
-
maxItems: z.coerce.string().optional(),
|
|
1917
|
-
// --- Generic Validations ---
|
|
1918
|
-
enum: z.array(z.unknown()).optional(),
|
|
1919
|
-
// --- Object Validations ---
|
|
1920
|
-
properties: z.record(z.string(), jsonSchemaValidator).optional(),
|
|
1921
|
-
required: z.array(z.string()).optional(),
|
|
1922
|
-
minProperties: z.coerce.string().optional(),
|
|
1923
|
-
maxProperties: z.coerce.string().optional(),
|
|
1924
|
-
propertyOrdering: z.array(z.string()).optional(),
|
|
1925
|
-
// --- Numeric Validations ---
|
|
1926
|
-
minimum: z.number().optional(),
|
|
1927
|
-
maximum: z.number().optional(),
|
|
1928
|
-
// --- String Validations ---
|
|
1929
|
-
minLength: z.coerce.string().optional(),
|
|
1930
|
-
maxLength: z.coerce.string().optional(),
|
|
1931
|
-
pattern: z.string().optional(),
|
|
1932
|
-
// --- Schema Composition ---
|
|
1933
|
-
anyOf: z.array(jsonSchemaValidator).optional(),
|
|
1934
|
-
// --- Additional Properties --- This field is not included in the
|
|
1935
|
-
// JSONSchema, will not be communicated to the model, it is here purely
|
|
1936
|
-
// for enabling the zod validation strict mode.
|
|
1937
|
-
additionalProperties: z.boolean().optional(),
|
|
1938
|
-
});
|
|
1939
|
-
// Conditionally apply .strict() based on the flag
|
|
1940
|
-
return strictMode ? baseShape.strict() : baseShape;
|
|
1941
|
-
});
|
|
1942
|
-
return jsonSchemaValidator;
|
|
1943
|
-
}
|
|
1944
1924
|
/*
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
zod_to_json_schema will squash the types into an array instead of put them
|
|
1951
|
-
in anyOf fields. Otherwise, it will put the types in anyOf fields.
|
|
1952
|
-
See the following link for more details:
|
|
1953
|
-
https://github.com/zodjs/zod-to-json-schema/blob/main/src/index.ts#L101
|
|
1954
|
-
The logic here is trying to undo that optimization, flattening the array of
|
|
1955
|
-
types to anyOf fields.
|
|
1956
|
-
type field
|
|
1957
|
-
|
|
|
1958
|
-
___________________________
|
|
1959
|
-
/ \
|
|
1960
|
-
/ \
|
|
1961
|
-
/ \
|
|
1962
|
-
Array Type.*
|
|
1963
|
-
/ \ |
|
|
1964
|
-
Include null. Not included null type = Type.*.
|
|
1965
|
-
[null, Type.*, Type.*] multiple types.
|
|
1966
|
-
[null, Type.*] [Type.*, Type.*]
|
|
1967
|
-
/ \
|
|
1968
|
-
remove null \
|
|
1969
|
-
add nullable = true \
|
|
1970
|
-
/ \ \
|
|
1971
|
-
[Type.*] [Type.*, Type.*] \
|
|
1972
|
-
only one type left multiple types left \
|
|
1973
|
-
add type = Type.*. \ /
|
|
1974
|
-
\ /
|
|
1975
|
-
not populate the type field in final result
|
|
1976
|
-
and make the types into anyOf fields
|
|
1977
|
-
anyOf:[{type: 'Type.*'}, {type: 'Type.*'}];
|
|
1925
|
+
Transform the type field from an array of types to an array of anyOf fields.
|
|
1926
|
+
Example:
|
|
1927
|
+
{type: ['STRING', 'NUMBER']}
|
|
1928
|
+
will be transformed to
|
|
1929
|
+
{anyOf: [{type: 'STRING'}, {type: 'NUMBER'}]}
|
|
1978
1930
|
*/
|
|
1979
1931
|
function flattenTypeArrayToAnyOf(typeList, resultingSchema) {
|
|
1980
1932
|
if (typeList.includes('null')) {
|
|
@@ -2120,15 +2072,11 @@ function processJsonSchema(_jsonSchema) {
|
|
|
2120
2072
|
// https://github.com/StefanTerdell/zod-to-json-schema/blob/70525efe555cd226691e093d171370a3b10921d1/src/zodToJsonSchema.ts#L7
|
|
2121
2073
|
// typebox can return unknown, see details in
|
|
2122
2074
|
// https://github.com/sinclairzx81/typebox/blob/5a5431439f7d5ca6b494d0d18fbfd7b1a356d67c/src/type/create/type.ts#L35
|
|
2075
|
+
// Note: proper json schemas with the $schema field set never arrive to this
|
|
2076
|
+
// transformer. Schemas with $schema are routed to the equivalent API json
|
|
2077
|
+
// schema field.
|
|
2123
2078
|
function tSchema(schema) {
|
|
2124
|
-
|
|
2125
|
-
delete schema['$schema'];
|
|
2126
|
-
const validatedJsonSchema = createJsonSchemaValidator().parse(schema);
|
|
2127
|
-
return processJsonSchema(validatedJsonSchema);
|
|
2128
|
-
}
|
|
2129
|
-
else {
|
|
2130
|
-
return processJsonSchema(schema);
|
|
2131
|
-
}
|
|
2079
|
+
return processJsonSchema(schema);
|
|
2132
2080
|
}
|
|
2133
2081
|
function tSpeechConfig(speechConfig) {
|
|
2134
2082
|
if (typeof speechConfig === 'object') {
|
|
@@ -2157,10 +2105,28 @@ function tTool(tool) {
|
|
|
2157
2105
|
if (tool.functionDeclarations) {
|
|
2158
2106
|
for (const functionDeclaration of tool.functionDeclarations) {
|
|
2159
2107
|
if (functionDeclaration.parameters) {
|
|
2160
|
-
|
|
2108
|
+
if (!Object.keys(functionDeclaration.parameters).includes('$schema')) {
|
|
2109
|
+
functionDeclaration.parameters = processJsonSchema(functionDeclaration.parameters);
|
|
2110
|
+
}
|
|
2111
|
+
else {
|
|
2112
|
+
if (!functionDeclaration.parametersJsonSchema) {
|
|
2113
|
+
functionDeclaration.parametersJsonSchema =
|
|
2114
|
+
functionDeclaration.parameters;
|
|
2115
|
+
delete functionDeclaration.parameters;
|
|
2116
|
+
}
|
|
2117
|
+
}
|
|
2161
2118
|
}
|
|
2162
2119
|
if (functionDeclaration.response) {
|
|
2163
|
-
|
|
2120
|
+
if (!Object.keys(functionDeclaration.response).includes('$schema')) {
|
|
2121
|
+
functionDeclaration.response = processJsonSchema(functionDeclaration.response);
|
|
2122
|
+
}
|
|
2123
|
+
else {
|
|
2124
|
+
if (!functionDeclaration.responseJsonSchema) {
|
|
2125
|
+
functionDeclaration.responseJsonSchema =
|
|
2126
|
+
functionDeclaration.response;
|
|
2127
|
+
delete functionDeclaration.response;
|
|
2128
|
+
}
|
|
2129
|
+
}
|
|
2164
2130
|
}
|
|
2165
2131
|
}
|
|
2166
2132
|
}
|
|
@@ -2365,7 +2331,7 @@ function mcpToGeminiTool(mcpTool, config = {}) {
|
|
|
2365
2331
|
const functionDeclaration = {
|
|
2366
2332
|
name: mcpToolSchema['name'],
|
|
2367
2333
|
description: mcpToolSchema['description'],
|
|
2368
|
-
|
|
2334
|
+
parametersJsonSchema: mcpToolSchema['inputSchema'],
|
|
2369
2335
|
};
|
|
2370
2336
|
if (config.behavior) {
|
|
2371
2337
|
functionDeclaration['behavior'] = config.behavior;
|
|
@@ -2397,53 +2363,6 @@ function mcpToolsToGeminiTool(mcpTools, config = {}) {
|
|
|
2397
2363
|
}
|
|
2398
2364
|
return { functionDeclarations: functionDeclarations };
|
|
2399
2365
|
}
|
|
2400
|
-
// Filters the list schema field to only include fields that are supported by
|
|
2401
|
-
// JSONSchema.
|
|
2402
|
-
function filterListSchemaField(fieldValue) {
|
|
2403
|
-
const listSchemaFieldValue = [];
|
|
2404
|
-
for (const listFieldValue of fieldValue) {
|
|
2405
|
-
listSchemaFieldValue.push(filterToJsonSchema(listFieldValue));
|
|
2406
|
-
}
|
|
2407
|
-
return listSchemaFieldValue;
|
|
2408
|
-
}
|
|
2409
|
-
// Filters the dict schema field to only include fields that are supported by
|
|
2410
|
-
// JSONSchema.
|
|
2411
|
-
function filterDictSchemaField(fieldValue) {
|
|
2412
|
-
const dictSchemaFieldValue = {};
|
|
2413
|
-
for (const [key, value] of Object.entries(fieldValue)) {
|
|
2414
|
-
const valueRecord = value;
|
|
2415
|
-
dictSchemaFieldValue[key] = filterToJsonSchema(valueRecord);
|
|
2416
|
-
}
|
|
2417
|
-
return dictSchemaFieldValue;
|
|
2418
|
-
}
|
|
2419
|
-
// Filters the schema to only include fields that are supported by JSONSchema.
|
|
2420
|
-
function filterToJsonSchema(schema) {
|
|
2421
|
-
const schemaFieldNames = new Set(['items']); // 'additional_properties' to come
|
|
2422
|
-
const listSchemaFieldNames = new Set(['anyOf']); // 'one_of', 'all_of', 'not' to come
|
|
2423
|
-
const dictSchemaFieldNames = new Set(['properties']); // 'defs' to come
|
|
2424
|
-
const filteredSchema = {};
|
|
2425
|
-
for (const [fieldName, fieldValue] of Object.entries(schema)) {
|
|
2426
|
-
if (schemaFieldNames.has(fieldName)) {
|
|
2427
|
-
filteredSchema[fieldName] = filterToJsonSchema(fieldValue);
|
|
2428
|
-
}
|
|
2429
|
-
else if (listSchemaFieldNames.has(fieldName)) {
|
|
2430
|
-
filteredSchema[fieldName] = filterListSchemaField(fieldValue);
|
|
2431
|
-
}
|
|
2432
|
-
else if (dictSchemaFieldNames.has(fieldName)) {
|
|
2433
|
-
filteredSchema[fieldName] = filterDictSchemaField(fieldValue);
|
|
2434
|
-
}
|
|
2435
|
-
else if (fieldName === 'type') {
|
|
2436
|
-
const typeValue = fieldValue.toUpperCase();
|
|
2437
|
-
filteredSchema[fieldName] = Object.values(Type).includes(typeValue)
|
|
2438
|
-
? typeValue
|
|
2439
|
-
: Type.TYPE_UNSPECIFIED;
|
|
2440
|
-
}
|
|
2441
|
-
else if (supportedJsonSchemaFields.has(fieldName)) {
|
|
2442
|
-
filteredSchema[fieldName] = fieldValue;
|
|
2443
|
-
}
|
|
2444
|
-
}
|
|
2445
|
-
return filteredSchema;
|
|
2446
|
-
}
|
|
2447
2366
|
// Transforms a source input into a BatchJobSource object with validation.
|
|
2448
2367
|
function tBatchJobSource(apiClient, src) {
|
|
2449
2368
|
if (typeof src !== 'string' && !Array.isArray(src)) {
|
|
@@ -2918,6 +2837,10 @@ function toolToMldev$4(fromObject) {
|
|
|
2918
2837
|
if (fromCodeExecution != null) {
|
|
2919
2838
|
setValueByPath(toObject, ['codeExecution'], fromCodeExecution);
|
|
2920
2839
|
}
|
|
2840
|
+
const fromComputerUse = getValueByPath(fromObject, ['computerUse']);
|
|
2841
|
+
if (fromComputerUse != null) {
|
|
2842
|
+
setValueByPath(toObject, ['computerUse'], fromComputerUse);
|
|
2843
|
+
}
|
|
2921
2844
|
return toObject;
|
|
2922
2845
|
}
|
|
2923
2846
|
function functionCallingConfigToMldev$2(fromObject) {
|
|
@@ -3329,6 +3252,18 @@ function listBatchJobsParametersToMldev(fromObject) {
|
|
|
3329
3252
|
}
|
|
3330
3253
|
return toObject;
|
|
3331
3254
|
}
|
|
3255
|
+
function deleteBatchJobParametersToMldev(apiClient, fromObject) {
|
|
3256
|
+
const toObject = {};
|
|
3257
|
+
const fromName = getValueByPath(fromObject, ['name']);
|
|
3258
|
+
if (fromName != null) {
|
|
3259
|
+
setValueByPath(toObject, ['_url', 'name'], tBatchJobName(apiClient, fromName));
|
|
3260
|
+
}
|
|
3261
|
+
const fromConfig = getValueByPath(fromObject, ['config']);
|
|
3262
|
+
if (fromConfig != null) {
|
|
3263
|
+
setValueByPath(toObject, ['config'], fromConfig);
|
|
3264
|
+
}
|
|
3265
|
+
return toObject;
|
|
3266
|
+
}
|
|
3332
3267
|
function batchJobSourceToVertex(fromObject) {
|
|
3333
3268
|
const toObject = {};
|
|
3334
3269
|
const fromFormat = getValueByPath(fromObject, ['format']);
|
|
@@ -3449,6 +3384,18 @@ function listBatchJobsParametersToVertex(fromObject) {
|
|
|
3449
3384
|
}
|
|
3450
3385
|
return toObject;
|
|
3451
3386
|
}
|
|
3387
|
+
function deleteBatchJobParametersToVertex(apiClient, fromObject) {
|
|
3388
|
+
const toObject = {};
|
|
3389
|
+
const fromName = getValueByPath(fromObject, ['name']);
|
|
3390
|
+
if (fromName != null) {
|
|
3391
|
+
setValueByPath(toObject, ['_url', 'name'], tBatchJobName(apiClient, fromName));
|
|
3392
|
+
}
|
|
3393
|
+
const fromConfig = getValueByPath(fromObject, ['config']);
|
|
3394
|
+
if (fromConfig != null) {
|
|
3395
|
+
setValueByPath(toObject, ['config'], fromConfig);
|
|
3396
|
+
}
|
|
3397
|
+
return toObject;
|
|
3398
|
+
}
|
|
3452
3399
|
function jobErrorFromMldev() {
|
|
3453
3400
|
const toObject = {};
|
|
3454
3401
|
return toObject;
|
|
@@ -3786,6 +3733,22 @@ function listBatchJobsResponseFromMldev(fromObject) {
|
|
|
3786
3733
|
}
|
|
3787
3734
|
return toObject;
|
|
3788
3735
|
}
|
|
3736
|
+
function deleteResourceJobFromMldev(fromObject) {
|
|
3737
|
+
const toObject = {};
|
|
3738
|
+
const fromName = getValueByPath(fromObject, ['name']);
|
|
3739
|
+
if (fromName != null) {
|
|
3740
|
+
setValueByPath(toObject, ['name'], fromName);
|
|
3741
|
+
}
|
|
3742
|
+
const fromDone = getValueByPath(fromObject, ['done']);
|
|
3743
|
+
if (fromDone != null) {
|
|
3744
|
+
setValueByPath(toObject, ['done'], fromDone);
|
|
3745
|
+
}
|
|
3746
|
+
const fromError = getValueByPath(fromObject, ['error']);
|
|
3747
|
+
if (fromError != null) {
|
|
3748
|
+
setValueByPath(toObject, ['error'], jobErrorFromMldev());
|
|
3749
|
+
}
|
|
3750
|
+
return toObject;
|
|
3751
|
+
}
|
|
3789
3752
|
function jobErrorFromVertex(fromObject) {
|
|
3790
3753
|
const toObject = {};
|
|
3791
3754
|
const fromDetails = getValueByPath(fromObject, ['details']);
|
|
@@ -3913,6 +3876,22 @@ function listBatchJobsResponseFromVertex(fromObject) {
|
|
|
3913
3876
|
}
|
|
3914
3877
|
return toObject;
|
|
3915
3878
|
}
|
|
3879
|
+
function deleteResourceJobFromVertex(fromObject) {
|
|
3880
|
+
const toObject = {};
|
|
3881
|
+
const fromName = getValueByPath(fromObject, ['name']);
|
|
3882
|
+
if (fromName != null) {
|
|
3883
|
+
setValueByPath(toObject, ['name'], fromName);
|
|
3884
|
+
}
|
|
3885
|
+
const fromDone = getValueByPath(fromObject, ['done']);
|
|
3886
|
+
if (fromDone != null) {
|
|
3887
|
+
setValueByPath(toObject, ['done'], fromDone);
|
|
3888
|
+
}
|
|
3889
|
+
const fromError = getValueByPath(fromObject, ['error']);
|
|
3890
|
+
if (fromError != null) {
|
|
3891
|
+
setValueByPath(toObject, ['error'], jobErrorFromVertex(fromError));
|
|
3892
|
+
}
|
|
3893
|
+
return toObject;
|
|
3894
|
+
}
|
|
3916
3895
|
|
|
3917
3896
|
/**
|
|
3918
3897
|
* @license
|
|
@@ -4120,20 +4099,23 @@ class Batches extends BaseModule {
|
|
|
4120
4099
|
*/
|
|
4121
4100
|
this.create = async (params) => {
|
|
4122
4101
|
if (this.apiClient.isVertexAI()) {
|
|
4102
|
+
const timestamp = Date.now();
|
|
4103
|
+
const timestampStr = timestamp.toString();
|
|
4123
4104
|
if (Array.isArray(params.src)) {
|
|
4124
4105
|
throw new Error('InlinedRequest[] is not supported in Vertex AI. Please use ' +
|
|
4125
4106
|
'Google Cloud Storage URI or BigQuery URI instead.');
|
|
4126
4107
|
}
|
|
4127
4108
|
params.config = params.config || {};
|
|
4128
4109
|
if (params.config.displayName === undefined) {
|
|
4129
|
-
params.config.displayName = 'genaiBatchJob_';
|
|
4110
|
+
params.config.displayName = 'genaiBatchJob_${timestampStr}';
|
|
4130
4111
|
}
|
|
4131
4112
|
if (params.config.dest === undefined && typeof params.src === 'string') {
|
|
4132
4113
|
if (params.src.startsWith('gs://') && params.src.endsWith('.jsonl')) {
|
|
4133
4114
|
params.config.dest = `${params.src.slice(0, -6)}/dest`;
|
|
4134
4115
|
}
|
|
4135
4116
|
else if (params.src.startsWith('bq://')) {
|
|
4136
|
-
params.config.dest =
|
|
4117
|
+
params.config.dest =
|
|
4118
|
+
`${params.src}_dest_${timestampStr}`;
|
|
4137
4119
|
}
|
|
4138
4120
|
else {
|
|
4139
4121
|
throw new Error('Unsupported source:' + params.src);
|
|
@@ -4392,6 +4374,71 @@ class Batches extends BaseModule {
|
|
|
4392
4374
|
});
|
|
4393
4375
|
}
|
|
4394
4376
|
}
|
|
4377
|
+
/**
|
|
4378
|
+
* Deletes a batch job.
|
|
4379
|
+
*
|
|
4380
|
+
* @param params - The parameters for the delete request.
|
|
4381
|
+
* @return The empty response returned by the API.
|
|
4382
|
+
*
|
|
4383
|
+
* @example
|
|
4384
|
+
* ```ts
|
|
4385
|
+
* await ai.batches.delete({name: '...'}); // The server-generated resource name.
|
|
4386
|
+
* ```
|
|
4387
|
+
*/
|
|
4388
|
+
async delete(params) {
|
|
4389
|
+
var _a, _b, _c, _d;
|
|
4390
|
+
let response;
|
|
4391
|
+
let path = '';
|
|
4392
|
+
let queryParams = {};
|
|
4393
|
+
if (this.apiClient.isVertexAI()) {
|
|
4394
|
+
const body = deleteBatchJobParametersToVertex(this.apiClient, params);
|
|
4395
|
+
path = formatMap('batchPredictionJobs/{name}', body['_url']);
|
|
4396
|
+
queryParams = body['_query'];
|
|
4397
|
+
delete body['config'];
|
|
4398
|
+
delete body['_url'];
|
|
4399
|
+
delete body['_query'];
|
|
4400
|
+
response = this.apiClient
|
|
4401
|
+
.request({
|
|
4402
|
+
path: path,
|
|
4403
|
+
queryParams: queryParams,
|
|
4404
|
+
body: JSON.stringify(body),
|
|
4405
|
+
httpMethod: 'DELETE',
|
|
4406
|
+
httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
|
|
4407
|
+
abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
|
|
4408
|
+
})
|
|
4409
|
+
.then((httpResponse) => {
|
|
4410
|
+
return httpResponse.json();
|
|
4411
|
+
});
|
|
4412
|
+
return response.then((apiResponse) => {
|
|
4413
|
+
const resp = deleteResourceJobFromVertex(apiResponse);
|
|
4414
|
+
return resp;
|
|
4415
|
+
});
|
|
4416
|
+
}
|
|
4417
|
+
else {
|
|
4418
|
+
const body = deleteBatchJobParametersToMldev(this.apiClient, params);
|
|
4419
|
+
path = formatMap('batches/{name}', body['_url']);
|
|
4420
|
+
queryParams = body['_query'];
|
|
4421
|
+
delete body['config'];
|
|
4422
|
+
delete body['_url'];
|
|
4423
|
+
delete body['_query'];
|
|
4424
|
+
response = this.apiClient
|
|
4425
|
+
.request({
|
|
4426
|
+
path: path,
|
|
4427
|
+
queryParams: queryParams,
|
|
4428
|
+
body: JSON.stringify(body),
|
|
4429
|
+
httpMethod: 'DELETE',
|
|
4430
|
+
httpOptions: (_c = params.config) === null || _c === void 0 ? void 0 : _c.httpOptions,
|
|
4431
|
+
abortSignal: (_d = params.config) === null || _d === void 0 ? void 0 : _d.abortSignal,
|
|
4432
|
+
})
|
|
4433
|
+
.then((httpResponse) => {
|
|
4434
|
+
return httpResponse.json();
|
|
4435
|
+
});
|
|
4436
|
+
return response.then((apiResponse) => {
|
|
4437
|
+
const resp = deleteResourceJobFromMldev(apiResponse);
|
|
4438
|
+
return resp;
|
|
4439
|
+
});
|
|
4440
|
+
}
|
|
4441
|
+
}
|
|
4395
4442
|
}
|
|
4396
4443
|
|
|
4397
4444
|
/**
|
|
@@ -4646,6 +4693,10 @@ function toolToMldev$3(fromObject) {
|
|
|
4646
4693
|
if (fromCodeExecution != null) {
|
|
4647
4694
|
setValueByPath(toObject, ['codeExecution'], fromCodeExecution);
|
|
4648
4695
|
}
|
|
4696
|
+
const fromComputerUse = getValueByPath(fromObject, ['computerUse']);
|
|
4697
|
+
if (fromComputerUse != null) {
|
|
4698
|
+
setValueByPath(toObject, ['computerUse'], fromComputerUse);
|
|
4699
|
+
}
|
|
4649
4700
|
return toObject;
|
|
4650
4701
|
}
|
|
4651
4702
|
function functionCallingConfigToMldev$1(fromObject) {
|
|
@@ -5136,6 +5187,10 @@ function toolToVertex$2(fromObject) {
|
|
|
5136
5187
|
if (fromCodeExecution != null) {
|
|
5137
5188
|
setValueByPath(toObject, ['codeExecution'], fromCodeExecution);
|
|
5138
5189
|
}
|
|
5190
|
+
const fromComputerUse = getValueByPath(fromObject, ['computerUse']);
|
|
5191
|
+
if (fromComputerUse != null) {
|
|
5192
|
+
setValueByPath(toObject, ['computerUse'], fromComputerUse);
|
|
5193
|
+
}
|
|
5139
5194
|
return toObject;
|
|
5140
5195
|
}
|
|
5141
5196
|
function functionCallingConfigToVertex$1(fromObject) {
|
|
@@ -7342,6 +7397,10 @@ function toolToMldev$2(fromObject) {
|
|
|
7342
7397
|
if (fromCodeExecution != null) {
|
|
7343
7398
|
setValueByPath(toObject, ['codeExecution'], fromCodeExecution);
|
|
7344
7399
|
}
|
|
7400
|
+
const fromComputerUse = getValueByPath(fromObject, ['computerUse']);
|
|
7401
|
+
if (fromComputerUse != null) {
|
|
7402
|
+
setValueByPath(toObject, ['computerUse'], fromComputerUse);
|
|
7403
|
+
}
|
|
7345
7404
|
return toObject;
|
|
7346
7405
|
}
|
|
7347
7406
|
function toolToVertex$1(fromObject) {
|
|
@@ -7392,6 +7451,10 @@ function toolToVertex$1(fromObject) {
|
|
|
7392
7451
|
if (fromCodeExecution != null) {
|
|
7393
7452
|
setValueByPath(toObject, ['codeExecution'], fromCodeExecution);
|
|
7394
7453
|
}
|
|
7454
|
+
const fromComputerUse = getValueByPath(fromObject, ['computerUse']);
|
|
7455
|
+
if (fromComputerUse != null) {
|
|
7456
|
+
setValueByPath(toObject, ['computerUse'], fromComputerUse);
|
|
7457
|
+
}
|
|
7395
7458
|
return toObject;
|
|
7396
7459
|
}
|
|
7397
7460
|
function sessionResumptionConfigToMldev$1(fromObject) {
|
|
@@ -7887,8 +7950,9 @@ function liveSendRealtimeInputParametersToVertex(fromObject) {
|
|
|
7887
7950
|
if (fromMedia != null) {
|
|
7888
7951
|
setValueByPath(toObject, ['mediaChunks'], tBlobs(fromMedia));
|
|
7889
7952
|
}
|
|
7890
|
-
|
|
7891
|
-
|
|
7953
|
+
const fromAudio = getValueByPath(fromObject, ['audio']);
|
|
7954
|
+
if (fromAudio != null) {
|
|
7955
|
+
setValueByPath(toObject, ['audio'], tAudioBlob(fromAudio));
|
|
7892
7956
|
}
|
|
7893
7957
|
const fromAudioStreamEnd = getValueByPath(fromObject, [
|
|
7894
7958
|
'audioStreamEnd',
|
|
@@ -7896,11 +7960,13 @@ function liveSendRealtimeInputParametersToVertex(fromObject) {
|
|
|
7896
7960
|
if (fromAudioStreamEnd != null) {
|
|
7897
7961
|
setValueByPath(toObject, ['audioStreamEnd'], fromAudioStreamEnd);
|
|
7898
7962
|
}
|
|
7899
|
-
|
|
7900
|
-
|
|
7963
|
+
const fromVideo = getValueByPath(fromObject, ['video']);
|
|
7964
|
+
if (fromVideo != null) {
|
|
7965
|
+
setValueByPath(toObject, ['video'], tImageBlob(fromVideo));
|
|
7901
7966
|
}
|
|
7902
|
-
|
|
7903
|
-
|
|
7967
|
+
const fromText = getValueByPath(fromObject, ['text']);
|
|
7968
|
+
if (fromText != null) {
|
|
7969
|
+
setValueByPath(toObject, ['text'], fromText);
|
|
7904
7970
|
}
|
|
7905
7971
|
const fromActivityStart = getValueByPath(fromObject, [
|
|
7906
7972
|
'activityStart',
|
|
@@ -8056,8 +8122,12 @@ function liveServerSetupCompleteFromMldev() {
|
|
|
8056
8122
|
const toObject = {};
|
|
8057
8123
|
return toObject;
|
|
8058
8124
|
}
|
|
8059
|
-
function liveServerSetupCompleteFromVertex() {
|
|
8125
|
+
function liveServerSetupCompleteFromVertex(fromObject) {
|
|
8060
8126
|
const toObject = {};
|
|
8127
|
+
const fromSessionId = getValueByPath(fromObject, ['sessionId']);
|
|
8128
|
+
if (fromSessionId != null) {
|
|
8129
|
+
setValueByPath(toObject, ['sessionId'], fromSessionId);
|
|
8130
|
+
}
|
|
8061
8131
|
return toObject;
|
|
8062
8132
|
}
|
|
8063
8133
|
function videoMetadataFromMldev$1(fromObject) {
|
|
@@ -8810,7 +8880,7 @@ function liveServerMessageFromVertex(fromObject) {
|
|
|
8810
8880
|
'setupComplete',
|
|
8811
8881
|
]);
|
|
8812
8882
|
if (fromSetupComplete != null) {
|
|
8813
|
-
setValueByPath(toObject, ['setupComplete'], liveServerSetupCompleteFromVertex());
|
|
8883
|
+
setValueByPath(toObject, ['setupComplete'], liveServerSetupCompleteFromVertex(fromSetupComplete));
|
|
8814
8884
|
}
|
|
8815
8885
|
const fromServerContent = getValueByPath(fromObject, [
|
|
8816
8886
|
'serverContent',
|
|
@@ -9378,6 +9448,10 @@ function toolToMldev$1(fromObject) {
|
|
|
9378
9448
|
if (fromCodeExecution != null) {
|
|
9379
9449
|
setValueByPath(toObject, ['codeExecution'], fromCodeExecution);
|
|
9380
9450
|
}
|
|
9451
|
+
const fromComputerUse = getValueByPath(fromObject, ['computerUse']);
|
|
9452
|
+
if (fromComputerUse != null) {
|
|
9453
|
+
setValueByPath(toObject, ['computerUse'], fromComputerUse);
|
|
9454
|
+
}
|
|
9381
9455
|
return toObject;
|
|
9382
9456
|
}
|
|
9383
9457
|
function functionCallingConfigToMldev(fromObject) {
|
|
@@ -10467,6 +10541,10 @@ function toolToVertex(fromObject) {
|
|
|
10467
10541
|
if (fromCodeExecution != null) {
|
|
10468
10542
|
setValueByPath(toObject, ['codeExecution'], fromCodeExecution);
|
|
10469
10543
|
}
|
|
10544
|
+
const fromComputerUse = getValueByPath(fromObject, ['computerUse']);
|
|
10545
|
+
if (fromComputerUse != null) {
|
|
10546
|
+
setValueByPath(toObject, ['computerUse'], fromComputerUse);
|
|
10547
|
+
}
|
|
10470
10548
|
return toObject;
|
|
10471
10549
|
}
|
|
10472
10550
|
function functionCallingConfigToVertex(fromObject) {
|
|
@@ -11850,7 +11928,7 @@ function modelFromMldev(fromObject) {
|
|
|
11850
11928
|
}
|
|
11851
11929
|
return toObject;
|
|
11852
11930
|
}
|
|
11853
|
-
function listModelsResponseFromMldev(
|
|
11931
|
+
function listModelsResponseFromMldev(fromObject) {
|
|
11854
11932
|
const toObject = {};
|
|
11855
11933
|
const fromNextPageToken = getValueByPath(fromObject, [
|
|
11856
11934
|
'nextPageToken',
|
|
@@ -12494,7 +12572,7 @@ function modelFromVertex(fromObject) {
|
|
|
12494
12572
|
}
|
|
12495
12573
|
return toObject;
|
|
12496
12574
|
}
|
|
12497
|
-
function listModelsResponseFromVertex(
|
|
12575
|
+
function listModelsResponseFromVertex(fromObject) {
|
|
12498
12576
|
const toObject = {};
|
|
12499
12577
|
const fromNextPageToken = getValueByPath(fromObject, [
|
|
12500
12578
|
'nextPageToken',
|
|
@@ -12620,7 +12698,7 @@ const CONTENT_TYPE_HEADER = 'Content-Type';
|
|
|
12620
12698
|
const SERVER_TIMEOUT_HEADER = 'X-Server-Timeout';
|
|
12621
12699
|
const USER_AGENT_HEADER = 'User-Agent';
|
|
12622
12700
|
const GOOGLE_API_CLIENT_HEADER = 'x-goog-api-client';
|
|
12623
|
-
const SDK_VERSION = '1.
|
|
12701
|
+
const SDK_VERSION = '1.9.0'; // x-release-please-version
|
|
12624
12702
|
const LIBRARY_LABEL = `google-genai-sdk/${SDK_VERSION}`;
|
|
12625
12703
|
const VERTEX_AI_API_DEFAULT_VERSION = 'v1beta1';
|
|
12626
12704
|
const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
|
|
@@ -12851,7 +12929,14 @@ class ApiClient {
|
|
|
12851
12929
|
const abortController = new AbortController();
|
|
12852
12930
|
const signal = abortController.signal;
|
|
12853
12931
|
if (httpOptions.timeout && (httpOptions === null || httpOptions === void 0 ? void 0 : httpOptions.timeout) > 0) {
|
|
12854
|
-
setTimeout(() => abortController.abort(), httpOptions.timeout);
|
|
12932
|
+
const timeoutHandle = setTimeout(() => abortController.abort(), httpOptions.timeout);
|
|
12933
|
+
if (timeoutHandle &&
|
|
12934
|
+
typeof timeoutHandle.unref ===
|
|
12935
|
+
'function') {
|
|
12936
|
+
// call unref to prevent nodejs process from hanging, see
|
|
12937
|
+
// https://nodejs.org/api/timers.html#timeoutunref
|
|
12938
|
+
timeoutHandle.unref();
|
|
12939
|
+
}
|
|
12855
12940
|
}
|
|
12856
12941
|
if (abortSignal) {
|
|
12857
12942
|
abortSignal.addEventListener('abort', () => {
|
|
@@ -12914,7 +12999,7 @@ class ApiClient {
|
|
|
12914
12999
|
}
|
|
12915
13000
|
break;
|
|
12916
13001
|
}
|
|
12917
|
-
const chunkString = decoder.decode(value);
|
|
13002
|
+
const chunkString = decoder.decode(value, { stream: true });
|
|
12918
13003
|
// Parse and throw an error if the chunk contains an error.
|
|
12919
13004
|
try {
|
|
12920
13005
|
const chunkJson = JSON.parse(chunkString);
|
|
@@ -13671,7 +13756,7 @@ class Live {
|
|
|
13671
13756
|
if (GOOGLE_GENAI_USE_VERTEXAI) {
|
|
13672
13757
|
model = 'gemini-2.0-flash-live-preview-04-09';
|
|
13673
13758
|
} else {
|
|
13674
|
-
model = 'gemini-2.
|
|
13759
|
+
model = 'gemini-live-2.5-flash-preview';
|
|
13675
13760
|
}
|
|
13676
13761
|
const session = await ai.live.connect({
|
|
13677
13762
|
model: model,
|
|
@@ -13717,6 +13802,9 @@ class Live {
|
|
|
13717
13802
|
let keyName = 'key';
|
|
13718
13803
|
if (apiKey === null || apiKey === void 0 ? void 0 : apiKey.startsWith('auth_tokens/')) {
|
|
13719
13804
|
console.warn('Warning: Ephemeral token support is experimental and may change in future versions.');
|
|
13805
|
+
if (apiVersion !== 'v1alpha') {
|
|
13806
|
+
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.");
|
|
13807
|
+
}
|
|
13720
13808
|
method = 'BidiGenerateContentConstrained';
|
|
13721
13809
|
keyName = 'access_token';
|
|
13722
13810
|
}
|
|
@@ -13992,7 +14080,7 @@ class Session {
|
|
|
13992
14080
|
if (GOOGLE_GENAI_USE_VERTEXAI) {
|
|
13993
14081
|
model = 'gemini-2.0-flash-live-preview-04-09';
|
|
13994
14082
|
} else {
|
|
13995
|
-
model = 'gemini-2.
|
|
14083
|
+
model = 'gemini-live-2.5-flash-preview';
|
|
13996
14084
|
}
|
|
13997
14085
|
const session = await ai.live.connect({
|
|
13998
14086
|
model: model,
|
|
@@ -14121,6 +14209,7 @@ class Models extends BaseModule {
|
|
|
14121
14209
|
this.generateContent = async (params) => {
|
|
14122
14210
|
var _a, _b, _c, _d, _e;
|
|
14123
14211
|
const transformedParams = await this.processParamsForMcpUsage(params);
|
|
14212
|
+
this.maybeMoveToResponseJsonSchem(params);
|
|
14124
14213
|
if (!hasMcpClientTools(params) || shouldDisableAfc(params.config)) {
|
|
14125
14214
|
return await this.generateContentInternal(transformedParams);
|
|
14126
14215
|
}
|
|
@@ -14207,6 +14296,7 @@ class Models extends BaseModule {
|
|
|
14207
14296
|
* ```
|
|
14208
14297
|
*/
|
|
14209
14298
|
this.generateContentStream = async (params) => {
|
|
14299
|
+
this.maybeMoveToResponseJsonSchem(params);
|
|
14210
14300
|
if (shouldDisableAfc(params.config)) {
|
|
14211
14301
|
const transformedParams = await this.processParamsForMcpUsage(params);
|
|
14212
14302
|
return await this.generateContentStreamInternal(transformedParams);
|
|
@@ -14358,6 +14448,24 @@ class Models extends BaseModule {
|
|
|
14358
14448
|
return await this.upscaleImageInternal(apiParams);
|
|
14359
14449
|
};
|
|
14360
14450
|
}
|
|
14451
|
+
/**
|
|
14452
|
+
* This logic is needed for GenerateContentConfig only.
|
|
14453
|
+
* Previously we made GenerateContentConfig.responseSchema field to accept
|
|
14454
|
+
* unknown. Since v1.9.0, we switch to use backend JSON schema support.
|
|
14455
|
+
* To maintain backward compatibility, we move the data that was treated as
|
|
14456
|
+
* JSON schema from the responseSchema field to the responseJsonSchema field.
|
|
14457
|
+
*/
|
|
14458
|
+
maybeMoveToResponseJsonSchem(params) {
|
|
14459
|
+
if (params.config && params.config.responseSchema) {
|
|
14460
|
+
if (!params.config.responseJsonSchema) {
|
|
14461
|
+
if (Object.keys(params.config.responseSchema).includes('$schema')) {
|
|
14462
|
+
params.config.responseJsonSchema = params.config.responseSchema;
|
|
14463
|
+
delete params.config.responseSchema;
|
|
14464
|
+
}
|
|
14465
|
+
}
|
|
14466
|
+
}
|
|
14467
|
+
return;
|
|
14468
|
+
}
|
|
14361
14469
|
/**
|
|
14362
14470
|
* Transforms the CallableTools in the parameters to be simply Tools, it
|
|
14363
14471
|
* copies the params into a new object and replaces the tools, it does not
|
|
@@ -14954,7 +15062,7 @@ class Models extends BaseModule {
|
|
|
14954
15062
|
return httpResponse.json();
|
|
14955
15063
|
});
|
|
14956
15064
|
return response.then((apiResponse) => {
|
|
14957
|
-
const resp = listModelsResponseFromVertex(
|
|
15065
|
+
const resp = listModelsResponseFromVertex(apiResponse);
|
|
14958
15066
|
const typedResp = new ListModelsResponse();
|
|
14959
15067
|
Object.assign(typedResp, resp);
|
|
14960
15068
|
return typedResp;
|
|
@@ -14980,7 +15088,7 @@ class Models extends BaseModule {
|
|
|
14980
15088
|
return httpResponse.json();
|
|
14981
15089
|
});
|
|
14982
15090
|
return response.then((apiResponse) => {
|
|
14983
|
-
const resp = listModelsResponseFromMldev(
|
|
15091
|
+
const resp = listModelsResponseFromMldev(apiResponse);
|
|
14984
15092
|
const typedResp = new ListModelsResponse();
|
|
14985
15093
|
Object.assign(typedResp, resp);
|
|
14986
15094
|
return typedResp;
|
|
@@ -15990,6 +16098,10 @@ function toolToMldev(fromObject) {
|
|
|
15990
16098
|
if (fromCodeExecution != null) {
|
|
15991
16099
|
setValueByPath(toObject, ['codeExecution'], fromCodeExecution);
|
|
15992
16100
|
}
|
|
16101
|
+
const fromComputerUse = getValueByPath(fromObject, ['computerUse']);
|
|
16102
|
+
if (fromComputerUse != null) {
|
|
16103
|
+
setValueByPath(toObject, ['computerUse'], fromComputerUse);
|
|
16104
|
+
}
|
|
15993
16105
|
return toObject;
|
|
15994
16106
|
}
|
|
15995
16107
|
function sessionResumptionConfigToMldev(fromObject) {
|
|
@@ -16414,14 +16526,20 @@ class Tokens extends BaseModule {
|
|
|
16414
16526
|
* @experimental
|
|
16415
16527
|
*
|
|
16416
16528
|
* @remarks
|
|
16417
|
-
*
|
|
16529
|
+
* Ephemeral auth tokens is only supported in the Gemini Developer API.
|
|
16418
16530
|
* It can be used for the session connection to the Live constrained API.
|
|
16531
|
+
* Support in v1alpha only.
|
|
16419
16532
|
*
|
|
16420
16533
|
* @param params - The parameters for the create request.
|
|
16421
16534
|
* @return The created auth token.
|
|
16422
16535
|
*
|
|
16423
16536
|
* @example
|
|
16424
16537
|
* ```ts
|
|
16538
|
+
* const ai = new GoogleGenAI({
|
|
16539
|
+
* apiKey: token.name,
|
|
16540
|
+
* httpOptions: { apiVersion: 'v1alpha' } // Support in v1alpha only.
|
|
16541
|
+
* });
|
|
16542
|
+
*
|
|
16425
16543
|
* // Case 1: If LiveEphemeralParameters is unset, unlock LiveConnectConfig
|
|
16426
16544
|
* // when using the token in Live API sessions. Each session connection can
|
|
16427
16545
|
* // use a different configuration.
|
|
@@ -16580,6 +16698,9 @@ function tuningDatasetToMldev(fromObject) {
|
|
|
16580
16698
|
if (getValueByPath(fromObject, ['gcsUri']) !== undefined) {
|
|
16581
16699
|
throw new Error('gcsUri parameter is not supported in Gemini API.');
|
|
16582
16700
|
}
|
|
16701
|
+
if (getValueByPath(fromObject, ['vertexDatasetResource']) !== undefined) {
|
|
16702
|
+
throw new Error('vertexDatasetResource parameter is not supported in Gemini API.');
|
|
16703
|
+
}
|
|
16583
16704
|
const fromExamples = getValueByPath(fromObject, ['examples']);
|
|
16584
16705
|
if (fromExamples != null) {
|
|
16585
16706
|
let transformedList = fromExamples;
|
|
@@ -16693,17 +16814,29 @@ function tuningDatasetToVertex(fromObject, parentObject) {
|
|
|
16693
16814
|
if (parentObject !== undefined && fromGcsUri != null) {
|
|
16694
16815
|
setValueByPath(parentObject, ['supervisedTuningSpec', 'trainingDatasetUri'], fromGcsUri);
|
|
16695
16816
|
}
|
|
16817
|
+
const fromVertexDatasetResource = getValueByPath(fromObject, [
|
|
16818
|
+
'vertexDatasetResource',
|
|
16819
|
+
]);
|
|
16820
|
+
if (parentObject !== undefined && fromVertexDatasetResource != null) {
|
|
16821
|
+
setValueByPath(parentObject, ['supervisedTuningSpec', 'trainingDatasetUri'], fromVertexDatasetResource);
|
|
16822
|
+
}
|
|
16696
16823
|
if (getValueByPath(fromObject, ['examples']) !== undefined) {
|
|
16697
16824
|
throw new Error('examples parameter is not supported in Vertex AI.');
|
|
16698
16825
|
}
|
|
16699
16826
|
return toObject;
|
|
16700
16827
|
}
|
|
16701
|
-
function tuningValidationDatasetToVertex(fromObject) {
|
|
16828
|
+
function tuningValidationDatasetToVertex(fromObject, parentObject) {
|
|
16702
16829
|
const toObject = {};
|
|
16703
16830
|
const fromGcsUri = getValueByPath(fromObject, ['gcsUri']);
|
|
16704
16831
|
if (fromGcsUri != null) {
|
|
16705
16832
|
setValueByPath(toObject, ['validationDatasetUri'], fromGcsUri);
|
|
16706
16833
|
}
|
|
16834
|
+
const fromVertexDatasetResource = getValueByPath(fromObject, [
|
|
16835
|
+
'vertexDatasetResource',
|
|
16836
|
+
]);
|
|
16837
|
+
if (parentObject !== undefined && fromVertexDatasetResource != null) {
|
|
16838
|
+
setValueByPath(parentObject, ['supervisedTuningSpec', 'trainingDatasetUri'], fromVertexDatasetResource);
|
|
16839
|
+
}
|
|
16707
16840
|
return toObject;
|
|
16708
16841
|
}
|
|
16709
16842
|
function createTuningJobConfigToVertex(fromObject, parentObject) {
|
|
@@ -16712,7 +16845,7 @@ function createTuningJobConfigToVertex(fromObject, parentObject) {
|
|
|
16712
16845
|
'validationDataset',
|
|
16713
16846
|
]);
|
|
16714
16847
|
if (parentObject !== undefined && fromValidationDataset != null) {
|
|
16715
|
-
setValueByPath(parentObject, ['supervisedTuningSpec'], tuningValidationDatasetToVertex(fromValidationDataset));
|
|
16848
|
+
setValueByPath(parentObject, ['supervisedTuningSpec'], tuningValidationDatasetToVertex(fromValidationDataset, toObject));
|
|
16716
16849
|
}
|
|
16717
16850
|
const fromTunedModelDisplayName = getValueByPath(fromObject, [
|
|
16718
16851
|
'tunedModelDisplayName',
|
|
@@ -16844,6 +16977,14 @@ function tuningJobFromMldev(fromObject) {
|
|
|
16844
16977
|
if (fromPipelineJob != null) {
|
|
16845
16978
|
setValueByPath(toObject, ['pipelineJob'], fromPipelineJob);
|
|
16846
16979
|
}
|
|
16980
|
+
const fromSatisfiesPzi = getValueByPath(fromObject, ['satisfiesPzi']);
|
|
16981
|
+
if (fromSatisfiesPzi != null) {
|
|
16982
|
+
setValueByPath(toObject, ['satisfiesPzi'], fromSatisfiesPzi);
|
|
16983
|
+
}
|
|
16984
|
+
const fromSatisfiesPzs = getValueByPath(fromObject, ['satisfiesPzs']);
|
|
16985
|
+
if (fromSatisfiesPzs != null) {
|
|
16986
|
+
setValueByPath(toObject, ['satisfiesPzs'], fromSatisfiesPzs);
|
|
16987
|
+
}
|
|
16847
16988
|
const fromServiceAccount = getValueByPath(fromObject, [
|
|
16848
16989
|
'serviceAccount',
|
|
16849
16990
|
]);
|
|
@@ -17024,6 +17165,14 @@ function tuningJobFromVertex(fromObject) {
|
|
|
17024
17165
|
if (fromPipelineJob != null) {
|
|
17025
17166
|
setValueByPath(toObject, ['pipelineJob'], fromPipelineJob);
|
|
17026
17167
|
}
|
|
17168
|
+
const fromSatisfiesPzi = getValueByPath(fromObject, ['satisfiesPzi']);
|
|
17169
|
+
if (fromSatisfiesPzi != null) {
|
|
17170
|
+
setValueByPath(toObject, ['satisfiesPzi'], fromSatisfiesPzi);
|
|
17171
|
+
}
|
|
17172
|
+
const fromSatisfiesPzs = getValueByPath(fromObject, ['satisfiesPzs']);
|
|
17173
|
+
if (fromSatisfiesPzs != null) {
|
|
17174
|
+
setValueByPath(toObject, ['satisfiesPzs'], fromSatisfiesPzs);
|
|
17175
|
+
}
|
|
17027
17176
|
const fromServiceAccount = getValueByPath(fromObject, [
|
|
17028
17177
|
'serviceAccount',
|
|
17029
17178
|
]);
|
|
@@ -17552,5 +17701,5 @@ class GoogleGenAI {
|
|
|
17552
17701
|
}
|
|
17553
17702
|
}
|
|
17554
17703
|
|
|
17555
|
-
export { ActivityHandling, AdapterSize, ApiError, AuthType, Batches, Behavior, BlockedReason, Caches, Chat, Chats, ComputeTokensResponse, ControlReferenceImage, ControlReferenceType, CountTokensResponse, CreateFileResponse, DeleteCachedContentResponse, DeleteFileResponse, DeleteModelResponse, DynamicRetrievalConfigMode, EditImageResponse, EditMode, EmbedContentResponse, EndSensitivity, FeatureSelectionPreference, FileSource, FileState, Files, FinishReason, FunctionCallingConfigMode, FunctionResponse, FunctionResponseScheduling, GenerateContentResponse, GenerateContentResponsePromptFeedback, GenerateContentResponseUsageMetadata, GenerateImagesResponse, GenerateVideosResponse, GoogleGenAI, HarmBlockMethod, HarmBlockThreshold, HarmCategory, HarmProbability, HarmSeverity, HttpResponse, ImagePromptLanguage, InlinedResponse, JobState, Language, ListBatchJobsResponse, ListCachedContentsResponse, ListFilesResponse, ListModelsResponse, ListTuningJobsResponse, Live, LiveClientToolResponse, LiveMusicPlaybackControl, LiveMusicServerMessage, LiveSendToolResponseParameters, LiveServerMessage, MaskReferenceImage, MaskReferenceMode, MediaModality, MediaResolution, Modality, Mode, Models, Operations, Outcome, PagedItem, Pager, PersonGeneration, RawReferenceImage, ReplayResponse, SafetyFilterLevel, Scale, Session, StartSensitivity, StyleReferenceImage, SubjectReferenceImage, SubjectReferenceType, Tokens, TrafficType, TurnCoverage, Type, UpscaleImageResponse, UrlRetrievalStatus, VideoCompressionQuality, createModelContent, createPartFromBase64, createPartFromCodeExecutionResult, createPartFromExecutableCode, createPartFromFunctionCall, createPartFromFunctionResponse, createPartFromText, createPartFromUri, createUserContent, mcpToTool, setDefaultBaseUrls };
|
|
17704
|
+
export { ActivityHandling, AdapterSize, ApiError, ApiSpec, AuthType, Batches, Behavior, BlockedReason, Caches, Chat, Chats, ComputeTokensResponse, ControlReferenceImage, ControlReferenceType, CountTokensResponse, CreateFileResponse, DeleteCachedContentResponse, DeleteFileResponse, DeleteModelResponse, DynamicRetrievalConfigMode, EditImageResponse, EditMode, EmbedContentResponse, EndSensitivity, Environment, FeatureSelectionPreference, FileSource, FileState, Files, FinishReason, FunctionCallingConfigMode, FunctionResponse, FunctionResponseScheduling, GenerateContentResponse, GenerateContentResponsePromptFeedback, GenerateContentResponseUsageMetadata, GenerateImagesResponse, GenerateVideosResponse, GoogleGenAI, HarmBlockMethod, HarmBlockThreshold, HarmCategory, HarmProbability, HarmSeverity, HttpResponse, ImagePromptLanguage, InlinedResponse, JobState, Language, ListBatchJobsResponse, ListCachedContentsResponse, ListFilesResponse, ListModelsResponse, ListTuningJobsResponse, Live, LiveClientToolResponse, LiveMusicPlaybackControl, LiveMusicServerMessage, LiveSendToolResponseParameters, LiveServerMessage, MaskReferenceImage, MaskReferenceMode, MediaModality, MediaResolution, Modality, Mode, Models, Operations, Outcome, PagedItem, Pager, PersonGeneration, RawReferenceImage, ReplayResponse, SafetyFilterLevel, Scale, Session, StartSensitivity, StyleReferenceImage, SubjectReferenceImage, SubjectReferenceType, Tokens, TrafficType, TurnCoverage, Type, UpscaleImageResponse, UrlRetrievalStatus, VideoCompressionQuality, createModelContent, createPartFromBase64, createPartFromCodeExecutionResult, createPartFromExecutableCode, createPartFromFunctionCall, createPartFromFunctionResponse, createPartFromText, createPartFromUri, createUserContent, mcpToTool, setDefaultBaseUrls };
|
|
17556
17705
|
//# sourceMappingURL=index.mjs.map
|