@google/genai 1.7.0 → 1.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +43 -0
- package/dist/genai.d.ts +240 -22
- package/dist/index.cjs +373 -224
- package/dist/index.mjs +374 -225
- package/dist/index.mjs.map +1 -1
- package/dist/node/index.cjs +373 -223
- package/dist/node/index.mjs +374 -224
- package/dist/node/index.mjs.map +1 -1
- package/dist/node/node.d.ts +240 -22
- package/dist/web/index.mjs +374 -225
- package/dist/web/index.mjs.map +1 -1
- package/dist/web/web.d.ts +240 -22
- package/package.json +5 -5
package/dist/node/index.mjs
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
1
|
import { GoogleAuth } from 'google-auth-library';
|
|
3
2
|
import { createWriteStream, writeFile } from 'fs';
|
|
4
3
|
import { Readable } from 'node:stream';
|
|
@@ -292,6 +291,22 @@ var HarmCategory;
|
|
|
292
291
|
* Deprecated: Election filter is not longer supported. The harm category is civic integrity.
|
|
293
292
|
*/
|
|
294
293
|
HarmCategory["HARM_CATEGORY_CIVIC_INTEGRITY"] = "HARM_CATEGORY_CIVIC_INTEGRITY";
|
|
294
|
+
/**
|
|
295
|
+
* The harm category is image hate.
|
|
296
|
+
*/
|
|
297
|
+
HarmCategory["HARM_CATEGORY_IMAGE_HATE"] = "HARM_CATEGORY_IMAGE_HATE";
|
|
298
|
+
/**
|
|
299
|
+
* The harm category is image dangerous content.
|
|
300
|
+
*/
|
|
301
|
+
HarmCategory["HARM_CATEGORY_IMAGE_DANGEROUS_CONTENT"] = "HARM_CATEGORY_IMAGE_DANGEROUS_CONTENT";
|
|
302
|
+
/**
|
|
303
|
+
* The harm category is image harassment.
|
|
304
|
+
*/
|
|
305
|
+
HarmCategory["HARM_CATEGORY_IMAGE_HARASSMENT"] = "HARM_CATEGORY_IMAGE_HARASSMENT";
|
|
306
|
+
/**
|
|
307
|
+
* The harm category is image sexually explicit content.
|
|
308
|
+
*/
|
|
309
|
+
HarmCategory["HARM_CATEGORY_IMAGE_SEXUALLY_EXPLICIT"] = "HARM_CATEGORY_IMAGE_SEXUALLY_EXPLICIT";
|
|
295
310
|
})(HarmCategory || (HarmCategory = {}));
|
|
296
311
|
/** Optional. Specify if the threshold is used for probability or severity score. If not specified, the threshold is used for probability score. */
|
|
297
312
|
var HarmBlockMethod;
|
|
@@ -378,6 +393,50 @@ var AuthType;
|
|
|
378
393
|
*/
|
|
379
394
|
AuthType["OIDC_AUTH"] = "OIDC_AUTH";
|
|
380
395
|
})(AuthType || (AuthType = {}));
|
|
396
|
+
/** The API spec that the external API implements. */
|
|
397
|
+
var ApiSpec;
|
|
398
|
+
(function (ApiSpec) {
|
|
399
|
+
/**
|
|
400
|
+
* Unspecified API spec. This value should not be used.
|
|
401
|
+
*/
|
|
402
|
+
ApiSpec["API_SPEC_UNSPECIFIED"] = "API_SPEC_UNSPECIFIED";
|
|
403
|
+
/**
|
|
404
|
+
* Simple search API spec.
|
|
405
|
+
*/
|
|
406
|
+
ApiSpec["SIMPLE_SEARCH"] = "SIMPLE_SEARCH";
|
|
407
|
+
/**
|
|
408
|
+
* Elastic search API spec.
|
|
409
|
+
*/
|
|
410
|
+
ApiSpec["ELASTIC_SEARCH"] = "ELASTIC_SEARCH";
|
|
411
|
+
})(ApiSpec || (ApiSpec = {}));
|
|
412
|
+
/** Required. The environment being operated. */
|
|
413
|
+
var Environment;
|
|
414
|
+
(function (Environment) {
|
|
415
|
+
/**
|
|
416
|
+
* Defaults to browser.
|
|
417
|
+
*/
|
|
418
|
+
Environment["ENVIRONMENT_UNSPECIFIED"] = "ENVIRONMENT_UNSPECIFIED";
|
|
419
|
+
/**
|
|
420
|
+
* Operates in a web browser.
|
|
421
|
+
*/
|
|
422
|
+
Environment["ENVIRONMENT_BROWSER"] = "ENVIRONMENT_BROWSER";
|
|
423
|
+
})(Environment || (Environment = {}));
|
|
424
|
+
/** Status of the url retrieval. */
|
|
425
|
+
var UrlRetrievalStatus;
|
|
426
|
+
(function (UrlRetrievalStatus) {
|
|
427
|
+
/**
|
|
428
|
+
* Default value. This value is unused
|
|
429
|
+
*/
|
|
430
|
+
UrlRetrievalStatus["URL_RETRIEVAL_STATUS_UNSPECIFIED"] = "URL_RETRIEVAL_STATUS_UNSPECIFIED";
|
|
431
|
+
/**
|
|
432
|
+
* Url retrieval is successful.
|
|
433
|
+
*/
|
|
434
|
+
UrlRetrievalStatus["URL_RETRIEVAL_STATUS_SUCCESS"] = "URL_RETRIEVAL_STATUS_SUCCESS";
|
|
435
|
+
/**
|
|
436
|
+
* Url retrieval is failed due to error.
|
|
437
|
+
*/
|
|
438
|
+
UrlRetrievalStatus["URL_RETRIEVAL_STATUS_ERROR"] = "URL_RETRIEVAL_STATUS_ERROR";
|
|
439
|
+
})(UrlRetrievalStatus || (UrlRetrievalStatus = {}));
|
|
381
440
|
/** Output only. The reason why the model stopped generating tokens.
|
|
382
441
|
|
|
383
442
|
If empty, the model has not stopped generating the tokens.
|
|
@@ -508,6 +567,10 @@ var BlockedReason;
|
|
|
508
567
|
* Candidates blocked due to prohibited content.
|
|
509
568
|
*/
|
|
510
569
|
BlockedReason["PROHIBITED_CONTENT"] = "PROHIBITED_CONTENT";
|
|
570
|
+
/**
|
|
571
|
+
* Candidates blocked due to unsafe image generation content.
|
|
572
|
+
*/
|
|
573
|
+
BlockedReason["IMAGE_SAFETY"] = "IMAGE_SAFETY";
|
|
511
574
|
})(BlockedReason || (BlockedReason = {}));
|
|
512
575
|
/** Output only. Traffic type. This shows whether a request consumes Pay-As-You-Go or Provisioned Throughput quota. */
|
|
513
576
|
var TrafficType;
|
|
@@ -705,22 +768,6 @@ var FunctionCallingConfigMode;
|
|
|
705
768
|
*/
|
|
706
769
|
FunctionCallingConfigMode["NONE"] = "NONE";
|
|
707
770
|
})(FunctionCallingConfigMode || (FunctionCallingConfigMode = {}));
|
|
708
|
-
/** Status of the url retrieval. */
|
|
709
|
-
var UrlRetrievalStatus;
|
|
710
|
-
(function (UrlRetrievalStatus) {
|
|
711
|
-
/**
|
|
712
|
-
* Default value. This value is unused
|
|
713
|
-
*/
|
|
714
|
-
UrlRetrievalStatus["URL_RETRIEVAL_STATUS_UNSPECIFIED"] = "URL_RETRIEVAL_STATUS_UNSPECIFIED";
|
|
715
|
-
/**
|
|
716
|
-
* Url retrieval is successful.
|
|
717
|
-
*/
|
|
718
|
-
UrlRetrievalStatus["URL_RETRIEVAL_STATUS_SUCCESS"] = "URL_RETRIEVAL_STATUS_SUCCESS";
|
|
719
|
-
/**
|
|
720
|
-
* Url retrieval is failed due to error.
|
|
721
|
-
*/
|
|
722
|
-
UrlRetrievalStatus["URL_RETRIEVAL_STATUS_ERROR"] = "URL_RETRIEVAL_STATUS_ERROR";
|
|
723
|
-
})(UrlRetrievalStatus || (UrlRetrievalStatus = {}));
|
|
724
771
|
/** Enum that controls the safety filter level for objectionable content. */
|
|
725
772
|
var SafetyFilterLevel;
|
|
726
773
|
(function (SafetyFilterLevel) {
|
|
@@ -748,11 +795,38 @@ var PersonGeneration;
|
|
|
748
795
|
/** Enum that specifies the language of the text in the prompt. */
|
|
749
796
|
var ImagePromptLanguage;
|
|
750
797
|
(function (ImagePromptLanguage) {
|
|
798
|
+
/**
|
|
799
|
+
* Auto-detect the language.
|
|
800
|
+
*/
|
|
751
801
|
ImagePromptLanguage["auto"] = "auto";
|
|
802
|
+
/**
|
|
803
|
+
* English
|
|
804
|
+
*/
|
|
752
805
|
ImagePromptLanguage["en"] = "en";
|
|
806
|
+
/**
|
|
807
|
+
* Japanese
|
|
808
|
+
*/
|
|
753
809
|
ImagePromptLanguage["ja"] = "ja";
|
|
810
|
+
/**
|
|
811
|
+
* Korean
|
|
812
|
+
*/
|
|
754
813
|
ImagePromptLanguage["ko"] = "ko";
|
|
814
|
+
/**
|
|
815
|
+
* Hindi
|
|
816
|
+
*/
|
|
755
817
|
ImagePromptLanguage["hi"] = "hi";
|
|
818
|
+
/**
|
|
819
|
+
* Chinese
|
|
820
|
+
*/
|
|
821
|
+
ImagePromptLanguage["zh"] = "zh";
|
|
822
|
+
/**
|
|
823
|
+
* Portuguese
|
|
824
|
+
*/
|
|
825
|
+
ImagePromptLanguage["pt"] = "pt";
|
|
826
|
+
/**
|
|
827
|
+
* Spanish
|
|
828
|
+
*/
|
|
829
|
+
ImagePromptLanguage["es"] = "es";
|
|
756
830
|
})(ImagePromptLanguage || (ImagePromptLanguage = {}));
|
|
757
831
|
/** Enum representing the mask mode of a mask reference image. */
|
|
758
832
|
var MaskReferenceMode;
|
|
@@ -1853,133 +1927,12 @@ function tContents(origin) {
|
|
|
1853
1927
|
}
|
|
1854
1928
|
return result;
|
|
1855
1929
|
}
|
|
1856
|
-
// The fields that are supported by JSONSchema. Must be kept in sync with the
|
|
1857
|
-
// JSONSchema interface above.
|
|
1858
|
-
const supportedJsonSchemaFields = new Set([
|
|
1859
|
-
'type',
|
|
1860
|
-
'format',
|
|
1861
|
-
'title',
|
|
1862
|
-
'description',
|
|
1863
|
-
'default',
|
|
1864
|
-
'items',
|
|
1865
|
-
'minItems',
|
|
1866
|
-
'maxItems',
|
|
1867
|
-
'enum',
|
|
1868
|
-
'properties',
|
|
1869
|
-
'required',
|
|
1870
|
-
'minProperties',
|
|
1871
|
-
'maxProperties',
|
|
1872
|
-
'minimum',
|
|
1873
|
-
'maximum',
|
|
1874
|
-
'minLength',
|
|
1875
|
-
'maxLength',
|
|
1876
|
-
'pattern',
|
|
1877
|
-
'anyOf',
|
|
1878
|
-
'propertyOrdering',
|
|
1879
|
-
]);
|
|
1880
|
-
const jsonSchemaTypeValidator = z.enum([
|
|
1881
|
-
'string',
|
|
1882
|
-
'number',
|
|
1883
|
-
'integer',
|
|
1884
|
-
'object',
|
|
1885
|
-
'array',
|
|
1886
|
-
'boolean',
|
|
1887
|
-
'null',
|
|
1888
|
-
]);
|
|
1889
|
-
// Handles all types and arrays of all types.
|
|
1890
|
-
const schemaTypeUnion = z.union([
|
|
1891
|
-
jsonSchemaTypeValidator,
|
|
1892
|
-
z.array(jsonSchemaTypeValidator),
|
|
1893
|
-
]);
|
|
1894
|
-
/**
|
|
1895
|
-
* Creates a zod validator for JSONSchema.
|
|
1896
|
-
*
|
|
1897
|
-
* @param strictMode Whether to enable strict mode, default to true. When
|
|
1898
|
-
* strict mode is enabled, the zod validator will throw error if there
|
|
1899
|
-
* are unrecognized fields in the input data. If strict mode is
|
|
1900
|
-
* disabled, the zod validator will ignore the unrecognized fields, only
|
|
1901
|
-
* populate the fields that are listed in the JSONSchema. Regardless of
|
|
1902
|
-
* the mode the type mismatch will always result in an error, for example
|
|
1903
|
-
* items field should be a single JSONSchema, but for tuple type it would
|
|
1904
|
-
* be an array of JSONSchema, this will always result in an error.
|
|
1905
|
-
* @return The zod validator for JSONSchema.
|
|
1906
|
-
*/
|
|
1907
|
-
function createJsonSchemaValidator(strictMode = true) {
|
|
1908
|
-
const jsonSchemaValidator = z.lazy(() => {
|
|
1909
|
-
// Define the base object shape *inside* the z.lazy callback
|
|
1910
|
-
const baseShape = z.object({
|
|
1911
|
-
// --- Type ---
|
|
1912
|
-
type: schemaTypeUnion.optional(),
|
|
1913
|
-
// --- Annotations ---
|
|
1914
|
-
format: z.string().optional(),
|
|
1915
|
-
title: z.string().optional(),
|
|
1916
|
-
description: z.string().optional(),
|
|
1917
|
-
default: z.unknown().optional(),
|
|
1918
|
-
// --- Array Validations ---
|
|
1919
|
-
items: jsonSchemaValidator.optional(),
|
|
1920
|
-
minItems: z.coerce.string().optional(),
|
|
1921
|
-
maxItems: z.coerce.string().optional(),
|
|
1922
|
-
// --- Generic Validations ---
|
|
1923
|
-
enum: z.array(z.unknown()).optional(),
|
|
1924
|
-
// --- Object Validations ---
|
|
1925
|
-
properties: z.record(z.string(), jsonSchemaValidator).optional(),
|
|
1926
|
-
required: z.array(z.string()).optional(),
|
|
1927
|
-
minProperties: z.coerce.string().optional(),
|
|
1928
|
-
maxProperties: z.coerce.string().optional(),
|
|
1929
|
-
propertyOrdering: z.array(z.string()).optional(),
|
|
1930
|
-
// --- Numeric Validations ---
|
|
1931
|
-
minimum: z.number().optional(),
|
|
1932
|
-
maximum: z.number().optional(),
|
|
1933
|
-
// --- String Validations ---
|
|
1934
|
-
minLength: z.coerce.string().optional(),
|
|
1935
|
-
maxLength: z.coerce.string().optional(),
|
|
1936
|
-
pattern: z.string().optional(),
|
|
1937
|
-
// --- Schema Composition ---
|
|
1938
|
-
anyOf: z.array(jsonSchemaValidator).optional(),
|
|
1939
|
-
// --- Additional Properties --- This field is not included in the
|
|
1940
|
-
// JSONSchema, will not be communicated to the model, it is here purely
|
|
1941
|
-
// for enabling the zod validation strict mode.
|
|
1942
|
-
additionalProperties: z.boolean().optional(),
|
|
1943
|
-
});
|
|
1944
|
-
// Conditionally apply .strict() based on the flag
|
|
1945
|
-
return strictMode ? baseShape.strict() : baseShape;
|
|
1946
|
-
});
|
|
1947
|
-
return jsonSchemaValidator;
|
|
1948
|
-
}
|
|
1949
1930
|
/*
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
zod_to_json_schema will squash the types into an array instead of put them
|
|
1956
|
-
in anyOf fields. Otherwise, it will put the types in anyOf fields.
|
|
1957
|
-
See the following link for more details:
|
|
1958
|
-
https://github.com/zodjs/zod-to-json-schema/blob/main/src/index.ts#L101
|
|
1959
|
-
The logic here is trying to undo that optimization, flattening the array of
|
|
1960
|
-
types to anyOf fields.
|
|
1961
|
-
type field
|
|
1962
|
-
|
|
|
1963
|
-
___________________________
|
|
1964
|
-
/ \
|
|
1965
|
-
/ \
|
|
1966
|
-
/ \
|
|
1967
|
-
Array Type.*
|
|
1968
|
-
/ \ |
|
|
1969
|
-
Include null. Not included null type = Type.*.
|
|
1970
|
-
[null, Type.*, Type.*] multiple types.
|
|
1971
|
-
[null, Type.*] [Type.*, Type.*]
|
|
1972
|
-
/ \
|
|
1973
|
-
remove null \
|
|
1974
|
-
add nullable = true \
|
|
1975
|
-
/ \ \
|
|
1976
|
-
[Type.*] [Type.*, Type.*] \
|
|
1977
|
-
only one type left multiple types left \
|
|
1978
|
-
add type = Type.*. \ /
|
|
1979
|
-
\ /
|
|
1980
|
-
not populate the type field in final result
|
|
1981
|
-
and make the types into anyOf fields
|
|
1982
|
-
anyOf:[{type: 'Type.*'}, {type: 'Type.*'}];
|
|
1931
|
+
Transform the type field from an array of types to an array of anyOf fields.
|
|
1932
|
+
Example:
|
|
1933
|
+
{type: ['STRING', 'NUMBER']}
|
|
1934
|
+
will be transformed to
|
|
1935
|
+
{anyOf: [{type: 'STRING'}, {type: 'NUMBER'}]}
|
|
1983
1936
|
*/
|
|
1984
1937
|
function flattenTypeArrayToAnyOf(typeList, resultingSchema) {
|
|
1985
1938
|
if (typeList.includes('null')) {
|
|
@@ -2125,15 +2078,11 @@ function processJsonSchema(_jsonSchema) {
|
|
|
2125
2078
|
// https://github.com/StefanTerdell/zod-to-json-schema/blob/70525efe555cd226691e093d171370a3b10921d1/src/zodToJsonSchema.ts#L7
|
|
2126
2079
|
// typebox can return unknown, see details in
|
|
2127
2080
|
// https://github.com/sinclairzx81/typebox/blob/5a5431439f7d5ca6b494d0d18fbfd7b1a356d67c/src/type/create/type.ts#L35
|
|
2081
|
+
// Note: proper json schemas with the $schema field set never arrive to this
|
|
2082
|
+
// transformer. Schemas with $schema are routed to the equivalent API json
|
|
2083
|
+
// schema field.
|
|
2128
2084
|
function tSchema(schema) {
|
|
2129
|
-
|
|
2130
|
-
delete schema['$schema'];
|
|
2131
|
-
const validatedJsonSchema = createJsonSchemaValidator().parse(schema);
|
|
2132
|
-
return processJsonSchema(validatedJsonSchema);
|
|
2133
|
-
}
|
|
2134
|
-
else {
|
|
2135
|
-
return processJsonSchema(schema);
|
|
2136
|
-
}
|
|
2085
|
+
return processJsonSchema(schema);
|
|
2137
2086
|
}
|
|
2138
2087
|
function tSpeechConfig(speechConfig) {
|
|
2139
2088
|
if (typeof speechConfig === 'object') {
|
|
@@ -2162,10 +2111,28 @@ function tTool(tool) {
|
|
|
2162
2111
|
if (tool.functionDeclarations) {
|
|
2163
2112
|
for (const functionDeclaration of tool.functionDeclarations) {
|
|
2164
2113
|
if (functionDeclaration.parameters) {
|
|
2165
|
-
|
|
2114
|
+
if (!Object.keys(functionDeclaration.parameters).includes('$schema')) {
|
|
2115
|
+
functionDeclaration.parameters = processJsonSchema(functionDeclaration.parameters);
|
|
2116
|
+
}
|
|
2117
|
+
else {
|
|
2118
|
+
if (!functionDeclaration.parametersJsonSchema) {
|
|
2119
|
+
functionDeclaration.parametersJsonSchema =
|
|
2120
|
+
functionDeclaration.parameters;
|
|
2121
|
+
delete functionDeclaration.parameters;
|
|
2122
|
+
}
|
|
2123
|
+
}
|
|
2166
2124
|
}
|
|
2167
2125
|
if (functionDeclaration.response) {
|
|
2168
|
-
|
|
2126
|
+
if (!Object.keys(functionDeclaration.response).includes('$schema')) {
|
|
2127
|
+
functionDeclaration.response = processJsonSchema(functionDeclaration.response);
|
|
2128
|
+
}
|
|
2129
|
+
else {
|
|
2130
|
+
if (!functionDeclaration.responseJsonSchema) {
|
|
2131
|
+
functionDeclaration.responseJsonSchema =
|
|
2132
|
+
functionDeclaration.response;
|
|
2133
|
+
delete functionDeclaration.response;
|
|
2134
|
+
}
|
|
2135
|
+
}
|
|
2169
2136
|
}
|
|
2170
2137
|
}
|
|
2171
2138
|
}
|
|
@@ -2370,7 +2337,7 @@ function mcpToGeminiTool(mcpTool, config = {}) {
|
|
|
2370
2337
|
const functionDeclaration = {
|
|
2371
2338
|
name: mcpToolSchema['name'],
|
|
2372
2339
|
description: mcpToolSchema['description'],
|
|
2373
|
-
|
|
2340
|
+
parametersJsonSchema: mcpToolSchema['inputSchema'],
|
|
2374
2341
|
};
|
|
2375
2342
|
if (config.behavior) {
|
|
2376
2343
|
functionDeclaration['behavior'] = config.behavior;
|
|
@@ -2402,53 +2369,6 @@ function mcpToolsToGeminiTool(mcpTools, config = {}) {
|
|
|
2402
2369
|
}
|
|
2403
2370
|
return { functionDeclarations: functionDeclarations };
|
|
2404
2371
|
}
|
|
2405
|
-
// Filters the list schema field to only include fields that are supported by
|
|
2406
|
-
// JSONSchema.
|
|
2407
|
-
function filterListSchemaField(fieldValue) {
|
|
2408
|
-
const listSchemaFieldValue = [];
|
|
2409
|
-
for (const listFieldValue of fieldValue) {
|
|
2410
|
-
listSchemaFieldValue.push(filterToJsonSchema(listFieldValue));
|
|
2411
|
-
}
|
|
2412
|
-
return listSchemaFieldValue;
|
|
2413
|
-
}
|
|
2414
|
-
// Filters the dict schema field to only include fields that are supported by
|
|
2415
|
-
// JSONSchema.
|
|
2416
|
-
function filterDictSchemaField(fieldValue) {
|
|
2417
|
-
const dictSchemaFieldValue = {};
|
|
2418
|
-
for (const [key, value] of Object.entries(fieldValue)) {
|
|
2419
|
-
const valueRecord = value;
|
|
2420
|
-
dictSchemaFieldValue[key] = filterToJsonSchema(valueRecord);
|
|
2421
|
-
}
|
|
2422
|
-
return dictSchemaFieldValue;
|
|
2423
|
-
}
|
|
2424
|
-
// Filters the schema to only include fields that are supported by JSONSchema.
|
|
2425
|
-
function filterToJsonSchema(schema) {
|
|
2426
|
-
const schemaFieldNames = new Set(['items']); // 'additional_properties' to come
|
|
2427
|
-
const listSchemaFieldNames = new Set(['anyOf']); // 'one_of', 'all_of', 'not' to come
|
|
2428
|
-
const dictSchemaFieldNames = new Set(['properties']); // 'defs' to come
|
|
2429
|
-
const filteredSchema = {};
|
|
2430
|
-
for (const [fieldName, fieldValue] of Object.entries(schema)) {
|
|
2431
|
-
if (schemaFieldNames.has(fieldName)) {
|
|
2432
|
-
filteredSchema[fieldName] = filterToJsonSchema(fieldValue);
|
|
2433
|
-
}
|
|
2434
|
-
else if (listSchemaFieldNames.has(fieldName)) {
|
|
2435
|
-
filteredSchema[fieldName] = filterListSchemaField(fieldValue);
|
|
2436
|
-
}
|
|
2437
|
-
else if (dictSchemaFieldNames.has(fieldName)) {
|
|
2438
|
-
filteredSchema[fieldName] = filterDictSchemaField(fieldValue);
|
|
2439
|
-
}
|
|
2440
|
-
else if (fieldName === 'type') {
|
|
2441
|
-
const typeValue = fieldValue.toUpperCase();
|
|
2442
|
-
filteredSchema[fieldName] = Object.values(Type).includes(typeValue)
|
|
2443
|
-
? typeValue
|
|
2444
|
-
: Type.TYPE_UNSPECIFIED;
|
|
2445
|
-
}
|
|
2446
|
-
else if (supportedJsonSchemaFields.has(fieldName)) {
|
|
2447
|
-
filteredSchema[fieldName] = fieldValue;
|
|
2448
|
-
}
|
|
2449
|
-
}
|
|
2450
|
-
return filteredSchema;
|
|
2451
|
-
}
|
|
2452
2372
|
// Transforms a source input into a BatchJobSource object with validation.
|
|
2453
2373
|
function tBatchJobSource(apiClient, src) {
|
|
2454
2374
|
if (typeof src !== 'string' && !Array.isArray(src)) {
|
|
@@ -2923,6 +2843,10 @@ function toolToMldev$4(fromObject) {
|
|
|
2923
2843
|
if (fromCodeExecution != null) {
|
|
2924
2844
|
setValueByPath(toObject, ['codeExecution'], fromCodeExecution);
|
|
2925
2845
|
}
|
|
2846
|
+
const fromComputerUse = getValueByPath(fromObject, ['computerUse']);
|
|
2847
|
+
if (fromComputerUse != null) {
|
|
2848
|
+
setValueByPath(toObject, ['computerUse'], fromComputerUse);
|
|
2849
|
+
}
|
|
2926
2850
|
return toObject;
|
|
2927
2851
|
}
|
|
2928
2852
|
function functionCallingConfigToMldev$2(fromObject) {
|
|
@@ -3334,6 +3258,18 @@ function listBatchJobsParametersToMldev(fromObject) {
|
|
|
3334
3258
|
}
|
|
3335
3259
|
return toObject;
|
|
3336
3260
|
}
|
|
3261
|
+
function deleteBatchJobParametersToMldev(apiClient, fromObject) {
|
|
3262
|
+
const toObject = {};
|
|
3263
|
+
const fromName = getValueByPath(fromObject, ['name']);
|
|
3264
|
+
if (fromName != null) {
|
|
3265
|
+
setValueByPath(toObject, ['_url', 'name'], tBatchJobName(apiClient, fromName));
|
|
3266
|
+
}
|
|
3267
|
+
const fromConfig = getValueByPath(fromObject, ['config']);
|
|
3268
|
+
if (fromConfig != null) {
|
|
3269
|
+
setValueByPath(toObject, ['config'], fromConfig);
|
|
3270
|
+
}
|
|
3271
|
+
return toObject;
|
|
3272
|
+
}
|
|
3337
3273
|
function batchJobSourceToVertex(fromObject) {
|
|
3338
3274
|
const toObject = {};
|
|
3339
3275
|
const fromFormat = getValueByPath(fromObject, ['format']);
|
|
@@ -3454,6 +3390,18 @@ function listBatchJobsParametersToVertex(fromObject) {
|
|
|
3454
3390
|
}
|
|
3455
3391
|
return toObject;
|
|
3456
3392
|
}
|
|
3393
|
+
function deleteBatchJobParametersToVertex(apiClient, fromObject) {
|
|
3394
|
+
const toObject = {};
|
|
3395
|
+
const fromName = getValueByPath(fromObject, ['name']);
|
|
3396
|
+
if (fromName != null) {
|
|
3397
|
+
setValueByPath(toObject, ['_url', 'name'], tBatchJobName(apiClient, fromName));
|
|
3398
|
+
}
|
|
3399
|
+
const fromConfig = getValueByPath(fromObject, ['config']);
|
|
3400
|
+
if (fromConfig != null) {
|
|
3401
|
+
setValueByPath(toObject, ['config'], fromConfig);
|
|
3402
|
+
}
|
|
3403
|
+
return toObject;
|
|
3404
|
+
}
|
|
3457
3405
|
function jobErrorFromMldev() {
|
|
3458
3406
|
const toObject = {};
|
|
3459
3407
|
return toObject;
|
|
@@ -3791,6 +3739,22 @@ function listBatchJobsResponseFromMldev(fromObject) {
|
|
|
3791
3739
|
}
|
|
3792
3740
|
return toObject;
|
|
3793
3741
|
}
|
|
3742
|
+
function deleteResourceJobFromMldev(fromObject) {
|
|
3743
|
+
const toObject = {};
|
|
3744
|
+
const fromName = getValueByPath(fromObject, ['name']);
|
|
3745
|
+
if (fromName != null) {
|
|
3746
|
+
setValueByPath(toObject, ['name'], fromName);
|
|
3747
|
+
}
|
|
3748
|
+
const fromDone = getValueByPath(fromObject, ['done']);
|
|
3749
|
+
if (fromDone != null) {
|
|
3750
|
+
setValueByPath(toObject, ['done'], fromDone);
|
|
3751
|
+
}
|
|
3752
|
+
const fromError = getValueByPath(fromObject, ['error']);
|
|
3753
|
+
if (fromError != null) {
|
|
3754
|
+
setValueByPath(toObject, ['error'], jobErrorFromMldev());
|
|
3755
|
+
}
|
|
3756
|
+
return toObject;
|
|
3757
|
+
}
|
|
3794
3758
|
function jobErrorFromVertex(fromObject) {
|
|
3795
3759
|
const toObject = {};
|
|
3796
3760
|
const fromDetails = getValueByPath(fromObject, ['details']);
|
|
@@ -3918,6 +3882,22 @@ function listBatchJobsResponseFromVertex(fromObject) {
|
|
|
3918
3882
|
}
|
|
3919
3883
|
return toObject;
|
|
3920
3884
|
}
|
|
3885
|
+
function deleteResourceJobFromVertex(fromObject) {
|
|
3886
|
+
const toObject = {};
|
|
3887
|
+
const fromName = getValueByPath(fromObject, ['name']);
|
|
3888
|
+
if (fromName != null) {
|
|
3889
|
+
setValueByPath(toObject, ['name'], fromName);
|
|
3890
|
+
}
|
|
3891
|
+
const fromDone = getValueByPath(fromObject, ['done']);
|
|
3892
|
+
if (fromDone != null) {
|
|
3893
|
+
setValueByPath(toObject, ['done'], fromDone);
|
|
3894
|
+
}
|
|
3895
|
+
const fromError = getValueByPath(fromObject, ['error']);
|
|
3896
|
+
if (fromError != null) {
|
|
3897
|
+
setValueByPath(toObject, ['error'], jobErrorFromVertex(fromError));
|
|
3898
|
+
}
|
|
3899
|
+
return toObject;
|
|
3900
|
+
}
|
|
3921
3901
|
|
|
3922
3902
|
/**
|
|
3923
3903
|
* @license
|
|
@@ -4125,20 +4105,23 @@ class Batches extends BaseModule {
|
|
|
4125
4105
|
*/
|
|
4126
4106
|
this.create = async (params) => {
|
|
4127
4107
|
if (this.apiClient.isVertexAI()) {
|
|
4108
|
+
const timestamp = Date.now();
|
|
4109
|
+
const timestampStr = timestamp.toString();
|
|
4128
4110
|
if (Array.isArray(params.src)) {
|
|
4129
4111
|
throw new Error('InlinedRequest[] is not supported in Vertex AI. Please use ' +
|
|
4130
4112
|
'Google Cloud Storage URI or BigQuery URI instead.');
|
|
4131
4113
|
}
|
|
4132
4114
|
params.config = params.config || {};
|
|
4133
4115
|
if (params.config.displayName === undefined) {
|
|
4134
|
-
params.config.displayName = 'genaiBatchJob_';
|
|
4116
|
+
params.config.displayName = 'genaiBatchJob_${timestampStr}';
|
|
4135
4117
|
}
|
|
4136
4118
|
if (params.config.dest === undefined && typeof params.src === 'string') {
|
|
4137
4119
|
if (params.src.startsWith('gs://') && params.src.endsWith('.jsonl')) {
|
|
4138
4120
|
params.config.dest = `${params.src.slice(0, -6)}/dest`;
|
|
4139
4121
|
}
|
|
4140
4122
|
else if (params.src.startsWith('bq://')) {
|
|
4141
|
-
params.config.dest =
|
|
4123
|
+
params.config.dest =
|
|
4124
|
+
`${params.src}_dest_${timestampStr}`;
|
|
4142
4125
|
}
|
|
4143
4126
|
else {
|
|
4144
4127
|
throw new Error('Unsupported source:' + params.src);
|
|
@@ -4397,6 +4380,71 @@ class Batches extends BaseModule {
|
|
|
4397
4380
|
});
|
|
4398
4381
|
}
|
|
4399
4382
|
}
|
|
4383
|
+
/**
|
|
4384
|
+
* Deletes a batch job.
|
|
4385
|
+
*
|
|
4386
|
+
* @param params - The parameters for the delete request.
|
|
4387
|
+
* @return The empty response returned by the API.
|
|
4388
|
+
*
|
|
4389
|
+
* @example
|
|
4390
|
+
* ```ts
|
|
4391
|
+
* await ai.batches.delete({name: '...'}); // The server-generated resource name.
|
|
4392
|
+
* ```
|
|
4393
|
+
*/
|
|
4394
|
+
async delete(params) {
|
|
4395
|
+
var _a, _b, _c, _d;
|
|
4396
|
+
let response;
|
|
4397
|
+
let path = '';
|
|
4398
|
+
let queryParams = {};
|
|
4399
|
+
if (this.apiClient.isVertexAI()) {
|
|
4400
|
+
const body = deleteBatchJobParametersToVertex(this.apiClient, params);
|
|
4401
|
+
path = formatMap('batchPredictionJobs/{name}', body['_url']);
|
|
4402
|
+
queryParams = body['_query'];
|
|
4403
|
+
delete body['config'];
|
|
4404
|
+
delete body['_url'];
|
|
4405
|
+
delete body['_query'];
|
|
4406
|
+
response = this.apiClient
|
|
4407
|
+
.request({
|
|
4408
|
+
path: path,
|
|
4409
|
+
queryParams: queryParams,
|
|
4410
|
+
body: JSON.stringify(body),
|
|
4411
|
+
httpMethod: 'DELETE',
|
|
4412
|
+
httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
|
|
4413
|
+
abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
|
|
4414
|
+
})
|
|
4415
|
+
.then((httpResponse) => {
|
|
4416
|
+
return httpResponse.json();
|
|
4417
|
+
});
|
|
4418
|
+
return response.then((apiResponse) => {
|
|
4419
|
+
const resp = deleteResourceJobFromVertex(apiResponse);
|
|
4420
|
+
return resp;
|
|
4421
|
+
});
|
|
4422
|
+
}
|
|
4423
|
+
else {
|
|
4424
|
+
const body = deleteBatchJobParametersToMldev(this.apiClient, params);
|
|
4425
|
+
path = formatMap('batches/{name}', body['_url']);
|
|
4426
|
+
queryParams = body['_query'];
|
|
4427
|
+
delete body['config'];
|
|
4428
|
+
delete body['_url'];
|
|
4429
|
+
delete body['_query'];
|
|
4430
|
+
response = this.apiClient
|
|
4431
|
+
.request({
|
|
4432
|
+
path: path,
|
|
4433
|
+
queryParams: queryParams,
|
|
4434
|
+
body: JSON.stringify(body),
|
|
4435
|
+
httpMethod: 'DELETE',
|
|
4436
|
+
httpOptions: (_c = params.config) === null || _c === void 0 ? void 0 : _c.httpOptions,
|
|
4437
|
+
abortSignal: (_d = params.config) === null || _d === void 0 ? void 0 : _d.abortSignal,
|
|
4438
|
+
})
|
|
4439
|
+
.then((httpResponse) => {
|
|
4440
|
+
return httpResponse.json();
|
|
4441
|
+
});
|
|
4442
|
+
return response.then((apiResponse) => {
|
|
4443
|
+
const resp = deleteResourceJobFromMldev(apiResponse);
|
|
4444
|
+
return resp;
|
|
4445
|
+
});
|
|
4446
|
+
}
|
|
4447
|
+
}
|
|
4400
4448
|
}
|
|
4401
4449
|
|
|
4402
4450
|
/**
|
|
@@ -4651,6 +4699,10 @@ function toolToMldev$3(fromObject) {
|
|
|
4651
4699
|
if (fromCodeExecution != null) {
|
|
4652
4700
|
setValueByPath(toObject, ['codeExecution'], fromCodeExecution);
|
|
4653
4701
|
}
|
|
4702
|
+
const fromComputerUse = getValueByPath(fromObject, ['computerUse']);
|
|
4703
|
+
if (fromComputerUse != null) {
|
|
4704
|
+
setValueByPath(toObject, ['computerUse'], fromComputerUse);
|
|
4705
|
+
}
|
|
4654
4706
|
return toObject;
|
|
4655
4707
|
}
|
|
4656
4708
|
function functionCallingConfigToMldev$1(fromObject) {
|
|
@@ -5141,6 +5193,10 @@ function toolToVertex$2(fromObject) {
|
|
|
5141
5193
|
if (fromCodeExecution != null) {
|
|
5142
5194
|
setValueByPath(toObject, ['codeExecution'], fromCodeExecution);
|
|
5143
5195
|
}
|
|
5196
|
+
const fromComputerUse = getValueByPath(fromObject, ['computerUse']);
|
|
5197
|
+
if (fromComputerUse != null) {
|
|
5198
|
+
setValueByPath(toObject, ['computerUse'], fromComputerUse);
|
|
5199
|
+
}
|
|
5144
5200
|
return toObject;
|
|
5145
5201
|
}
|
|
5146
5202
|
function functionCallingConfigToVertex$1(fromObject) {
|
|
@@ -7347,6 +7403,10 @@ function toolToMldev$2(fromObject) {
|
|
|
7347
7403
|
if (fromCodeExecution != null) {
|
|
7348
7404
|
setValueByPath(toObject, ['codeExecution'], fromCodeExecution);
|
|
7349
7405
|
}
|
|
7406
|
+
const fromComputerUse = getValueByPath(fromObject, ['computerUse']);
|
|
7407
|
+
if (fromComputerUse != null) {
|
|
7408
|
+
setValueByPath(toObject, ['computerUse'], fromComputerUse);
|
|
7409
|
+
}
|
|
7350
7410
|
return toObject;
|
|
7351
7411
|
}
|
|
7352
7412
|
function toolToVertex$1(fromObject) {
|
|
@@ -7397,6 +7457,10 @@ function toolToVertex$1(fromObject) {
|
|
|
7397
7457
|
if (fromCodeExecution != null) {
|
|
7398
7458
|
setValueByPath(toObject, ['codeExecution'], fromCodeExecution);
|
|
7399
7459
|
}
|
|
7460
|
+
const fromComputerUse = getValueByPath(fromObject, ['computerUse']);
|
|
7461
|
+
if (fromComputerUse != null) {
|
|
7462
|
+
setValueByPath(toObject, ['computerUse'], fromComputerUse);
|
|
7463
|
+
}
|
|
7400
7464
|
return toObject;
|
|
7401
7465
|
}
|
|
7402
7466
|
function sessionResumptionConfigToMldev$1(fromObject) {
|
|
@@ -7892,8 +7956,9 @@ function liveSendRealtimeInputParametersToVertex(fromObject) {
|
|
|
7892
7956
|
if (fromMedia != null) {
|
|
7893
7957
|
setValueByPath(toObject, ['mediaChunks'], tBlobs(fromMedia));
|
|
7894
7958
|
}
|
|
7895
|
-
|
|
7896
|
-
|
|
7959
|
+
const fromAudio = getValueByPath(fromObject, ['audio']);
|
|
7960
|
+
if (fromAudio != null) {
|
|
7961
|
+
setValueByPath(toObject, ['audio'], tAudioBlob(fromAudio));
|
|
7897
7962
|
}
|
|
7898
7963
|
const fromAudioStreamEnd = getValueByPath(fromObject, [
|
|
7899
7964
|
'audioStreamEnd',
|
|
@@ -7901,11 +7966,13 @@ function liveSendRealtimeInputParametersToVertex(fromObject) {
|
|
|
7901
7966
|
if (fromAudioStreamEnd != null) {
|
|
7902
7967
|
setValueByPath(toObject, ['audioStreamEnd'], fromAudioStreamEnd);
|
|
7903
7968
|
}
|
|
7904
|
-
|
|
7905
|
-
|
|
7969
|
+
const fromVideo = getValueByPath(fromObject, ['video']);
|
|
7970
|
+
if (fromVideo != null) {
|
|
7971
|
+
setValueByPath(toObject, ['video'], tImageBlob(fromVideo));
|
|
7906
7972
|
}
|
|
7907
|
-
|
|
7908
|
-
|
|
7973
|
+
const fromText = getValueByPath(fromObject, ['text']);
|
|
7974
|
+
if (fromText != null) {
|
|
7975
|
+
setValueByPath(toObject, ['text'], fromText);
|
|
7909
7976
|
}
|
|
7910
7977
|
const fromActivityStart = getValueByPath(fromObject, [
|
|
7911
7978
|
'activityStart',
|
|
@@ -8061,8 +8128,12 @@ function liveServerSetupCompleteFromMldev() {
|
|
|
8061
8128
|
const toObject = {};
|
|
8062
8129
|
return toObject;
|
|
8063
8130
|
}
|
|
8064
|
-
function liveServerSetupCompleteFromVertex() {
|
|
8131
|
+
function liveServerSetupCompleteFromVertex(fromObject) {
|
|
8065
8132
|
const toObject = {};
|
|
8133
|
+
const fromSessionId = getValueByPath(fromObject, ['sessionId']);
|
|
8134
|
+
if (fromSessionId != null) {
|
|
8135
|
+
setValueByPath(toObject, ['sessionId'], fromSessionId);
|
|
8136
|
+
}
|
|
8066
8137
|
return toObject;
|
|
8067
8138
|
}
|
|
8068
8139
|
function videoMetadataFromMldev$1(fromObject) {
|
|
@@ -8815,7 +8886,7 @@ function liveServerMessageFromVertex(fromObject) {
|
|
|
8815
8886
|
'setupComplete',
|
|
8816
8887
|
]);
|
|
8817
8888
|
if (fromSetupComplete != null) {
|
|
8818
|
-
setValueByPath(toObject, ['setupComplete'], liveServerSetupCompleteFromVertex());
|
|
8889
|
+
setValueByPath(toObject, ['setupComplete'], liveServerSetupCompleteFromVertex(fromSetupComplete));
|
|
8819
8890
|
}
|
|
8820
8891
|
const fromServerContent = getValueByPath(fromObject, [
|
|
8821
8892
|
'serverContent',
|
|
@@ -9383,6 +9454,10 @@ function toolToMldev$1(fromObject) {
|
|
|
9383
9454
|
if (fromCodeExecution != null) {
|
|
9384
9455
|
setValueByPath(toObject, ['codeExecution'], fromCodeExecution);
|
|
9385
9456
|
}
|
|
9457
|
+
const fromComputerUse = getValueByPath(fromObject, ['computerUse']);
|
|
9458
|
+
if (fromComputerUse != null) {
|
|
9459
|
+
setValueByPath(toObject, ['computerUse'], fromComputerUse);
|
|
9460
|
+
}
|
|
9386
9461
|
return toObject;
|
|
9387
9462
|
}
|
|
9388
9463
|
function functionCallingConfigToMldev(fromObject) {
|
|
@@ -10472,6 +10547,10 @@ function toolToVertex(fromObject) {
|
|
|
10472
10547
|
if (fromCodeExecution != null) {
|
|
10473
10548
|
setValueByPath(toObject, ['codeExecution'], fromCodeExecution);
|
|
10474
10549
|
}
|
|
10550
|
+
const fromComputerUse = getValueByPath(fromObject, ['computerUse']);
|
|
10551
|
+
if (fromComputerUse != null) {
|
|
10552
|
+
setValueByPath(toObject, ['computerUse'], fromComputerUse);
|
|
10553
|
+
}
|
|
10475
10554
|
return toObject;
|
|
10476
10555
|
}
|
|
10477
10556
|
function functionCallingConfigToVertex(fromObject) {
|
|
@@ -11855,7 +11934,7 @@ function modelFromMldev(fromObject) {
|
|
|
11855
11934
|
}
|
|
11856
11935
|
return toObject;
|
|
11857
11936
|
}
|
|
11858
|
-
function listModelsResponseFromMldev(
|
|
11937
|
+
function listModelsResponseFromMldev(fromObject) {
|
|
11859
11938
|
const toObject = {};
|
|
11860
11939
|
const fromNextPageToken = getValueByPath(fromObject, [
|
|
11861
11940
|
'nextPageToken',
|
|
@@ -12499,7 +12578,7 @@ function modelFromVertex(fromObject) {
|
|
|
12499
12578
|
}
|
|
12500
12579
|
return toObject;
|
|
12501
12580
|
}
|
|
12502
|
-
function listModelsResponseFromVertex(
|
|
12581
|
+
function listModelsResponseFromVertex(fromObject) {
|
|
12503
12582
|
const toObject = {};
|
|
12504
12583
|
const fromNextPageToken = getValueByPath(fromObject, [
|
|
12505
12584
|
'nextPageToken',
|
|
@@ -12625,7 +12704,7 @@ const CONTENT_TYPE_HEADER = 'Content-Type';
|
|
|
12625
12704
|
const SERVER_TIMEOUT_HEADER = 'X-Server-Timeout';
|
|
12626
12705
|
const USER_AGENT_HEADER = 'User-Agent';
|
|
12627
12706
|
const GOOGLE_API_CLIENT_HEADER = 'x-goog-api-client';
|
|
12628
|
-
const SDK_VERSION = '1.
|
|
12707
|
+
const SDK_VERSION = '1.9.0'; // x-release-please-version
|
|
12629
12708
|
const LIBRARY_LABEL = `google-genai-sdk/${SDK_VERSION}`;
|
|
12630
12709
|
const VERTEX_AI_API_DEFAULT_VERSION = 'v1beta1';
|
|
12631
12710
|
const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
|
|
@@ -12856,7 +12935,14 @@ class ApiClient {
|
|
|
12856
12935
|
const abortController = new AbortController();
|
|
12857
12936
|
const signal = abortController.signal;
|
|
12858
12937
|
if (httpOptions.timeout && (httpOptions === null || httpOptions === void 0 ? void 0 : httpOptions.timeout) > 0) {
|
|
12859
|
-
setTimeout(() => abortController.abort(), httpOptions.timeout);
|
|
12938
|
+
const timeoutHandle = setTimeout(() => abortController.abort(), httpOptions.timeout);
|
|
12939
|
+
if (timeoutHandle &&
|
|
12940
|
+
typeof timeoutHandle.unref ===
|
|
12941
|
+
'function') {
|
|
12942
|
+
// call unref to prevent nodejs process from hanging, see
|
|
12943
|
+
// https://nodejs.org/api/timers.html#timeoutunref
|
|
12944
|
+
timeoutHandle.unref();
|
|
12945
|
+
}
|
|
12860
12946
|
}
|
|
12861
12947
|
if (abortSignal) {
|
|
12862
12948
|
abortSignal.addEventListener('abort', () => {
|
|
@@ -12919,7 +13005,7 @@ class ApiClient {
|
|
|
12919
13005
|
}
|
|
12920
13006
|
break;
|
|
12921
13007
|
}
|
|
12922
|
-
const chunkString = decoder.decode(value);
|
|
13008
|
+
const chunkString = decoder.decode(value, { stream: true });
|
|
12923
13009
|
// Parse and throw an error if the chunk contains an error.
|
|
12924
13010
|
try {
|
|
12925
13011
|
const chunkJson = JSON.parse(chunkString);
|
|
@@ -13676,7 +13762,7 @@ class Live {
|
|
|
13676
13762
|
if (GOOGLE_GENAI_USE_VERTEXAI) {
|
|
13677
13763
|
model = 'gemini-2.0-flash-live-preview-04-09';
|
|
13678
13764
|
} else {
|
|
13679
|
-
model = 'gemini-2.
|
|
13765
|
+
model = 'gemini-live-2.5-flash-preview';
|
|
13680
13766
|
}
|
|
13681
13767
|
const session = await ai.live.connect({
|
|
13682
13768
|
model: model,
|
|
@@ -13722,6 +13808,9 @@ class Live {
|
|
|
13722
13808
|
let keyName = 'key';
|
|
13723
13809
|
if (apiKey === null || apiKey === void 0 ? void 0 : apiKey.startsWith('auth_tokens/')) {
|
|
13724
13810
|
console.warn('Warning: Ephemeral token support is experimental and may change in future versions.');
|
|
13811
|
+
if (apiVersion !== 'v1alpha') {
|
|
13812
|
+
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.");
|
|
13813
|
+
}
|
|
13725
13814
|
method = 'BidiGenerateContentConstrained';
|
|
13726
13815
|
keyName = 'access_token';
|
|
13727
13816
|
}
|
|
@@ -13997,7 +14086,7 @@ class Session {
|
|
|
13997
14086
|
if (GOOGLE_GENAI_USE_VERTEXAI) {
|
|
13998
14087
|
model = 'gemini-2.0-flash-live-preview-04-09';
|
|
13999
14088
|
} else {
|
|
14000
|
-
model = 'gemini-2.
|
|
14089
|
+
model = 'gemini-live-2.5-flash-preview';
|
|
14001
14090
|
}
|
|
14002
14091
|
const session = await ai.live.connect({
|
|
14003
14092
|
model: model,
|
|
@@ -14126,6 +14215,7 @@ class Models extends BaseModule {
|
|
|
14126
14215
|
this.generateContent = async (params) => {
|
|
14127
14216
|
var _a, _b, _c, _d, _e;
|
|
14128
14217
|
const transformedParams = await this.processParamsForMcpUsage(params);
|
|
14218
|
+
this.maybeMoveToResponseJsonSchem(params);
|
|
14129
14219
|
if (!hasMcpClientTools(params) || shouldDisableAfc(params.config)) {
|
|
14130
14220
|
return await this.generateContentInternal(transformedParams);
|
|
14131
14221
|
}
|
|
@@ -14212,6 +14302,7 @@ class Models extends BaseModule {
|
|
|
14212
14302
|
* ```
|
|
14213
14303
|
*/
|
|
14214
14304
|
this.generateContentStream = async (params) => {
|
|
14305
|
+
this.maybeMoveToResponseJsonSchem(params);
|
|
14215
14306
|
if (shouldDisableAfc(params.config)) {
|
|
14216
14307
|
const transformedParams = await this.processParamsForMcpUsage(params);
|
|
14217
14308
|
return await this.generateContentStreamInternal(transformedParams);
|
|
@@ -14363,6 +14454,24 @@ class Models extends BaseModule {
|
|
|
14363
14454
|
return await this.upscaleImageInternal(apiParams);
|
|
14364
14455
|
};
|
|
14365
14456
|
}
|
|
14457
|
+
/**
|
|
14458
|
+
* This logic is needed for GenerateContentConfig only.
|
|
14459
|
+
* Previously we made GenerateContentConfig.responseSchema field to accept
|
|
14460
|
+
* unknown. Since v1.9.0, we switch to use backend JSON schema support.
|
|
14461
|
+
* To maintain backward compatibility, we move the data that was treated as
|
|
14462
|
+
* JSON schema from the responseSchema field to the responseJsonSchema field.
|
|
14463
|
+
*/
|
|
14464
|
+
maybeMoveToResponseJsonSchem(params) {
|
|
14465
|
+
if (params.config && params.config.responseSchema) {
|
|
14466
|
+
if (!params.config.responseJsonSchema) {
|
|
14467
|
+
if (Object.keys(params.config.responseSchema).includes('$schema')) {
|
|
14468
|
+
params.config.responseJsonSchema = params.config.responseSchema;
|
|
14469
|
+
delete params.config.responseSchema;
|
|
14470
|
+
}
|
|
14471
|
+
}
|
|
14472
|
+
}
|
|
14473
|
+
return;
|
|
14474
|
+
}
|
|
14366
14475
|
/**
|
|
14367
14476
|
* Transforms the CallableTools in the parameters to be simply Tools, it
|
|
14368
14477
|
* copies the params into a new object and replaces the tools, it does not
|
|
@@ -14959,7 +15068,7 @@ class Models extends BaseModule {
|
|
|
14959
15068
|
return httpResponse.json();
|
|
14960
15069
|
});
|
|
14961
15070
|
return response.then((apiResponse) => {
|
|
14962
|
-
const resp = listModelsResponseFromVertex(
|
|
15071
|
+
const resp = listModelsResponseFromVertex(apiResponse);
|
|
14963
15072
|
const typedResp = new ListModelsResponse();
|
|
14964
15073
|
Object.assign(typedResp, resp);
|
|
14965
15074
|
return typedResp;
|
|
@@ -14985,7 +15094,7 @@ class Models extends BaseModule {
|
|
|
14985
15094
|
return httpResponse.json();
|
|
14986
15095
|
});
|
|
14987
15096
|
return response.then((apiResponse) => {
|
|
14988
|
-
const resp = listModelsResponseFromMldev(
|
|
15097
|
+
const resp = listModelsResponseFromMldev(apiResponse);
|
|
14989
15098
|
const typedResp = new ListModelsResponse();
|
|
14990
15099
|
Object.assign(typedResp, resp);
|
|
14991
15100
|
return typedResp;
|
|
@@ -15995,6 +16104,10 @@ function toolToMldev(fromObject) {
|
|
|
15995
16104
|
if (fromCodeExecution != null) {
|
|
15996
16105
|
setValueByPath(toObject, ['codeExecution'], fromCodeExecution);
|
|
15997
16106
|
}
|
|
16107
|
+
const fromComputerUse = getValueByPath(fromObject, ['computerUse']);
|
|
16108
|
+
if (fromComputerUse != null) {
|
|
16109
|
+
setValueByPath(toObject, ['computerUse'], fromComputerUse);
|
|
16110
|
+
}
|
|
15998
16111
|
return toObject;
|
|
15999
16112
|
}
|
|
16000
16113
|
function sessionResumptionConfigToMldev(fromObject) {
|
|
@@ -16419,14 +16532,20 @@ class Tokens extends BaseModule {
|
|
|
16419
16532
|
* @experimental
|
|
16420
16533
|
*
|
|
16421
16534
|
* @remarks
|
|
16422
|
-
*
|
|
16535
|
+
* Ephemeral auth tokens is only supported in the Gemini Developer API.
|
|
16423
16536
|
* It can be used for the session connection to the Live constrained API.
|
|
16537
|
+
* Support in v1alpha only.
|
|
16424
16538
|
*
|
|
16425
16539
|
* @param params - The parameters for the create request.
|
|
16426
16540
|
* @return The created auth token.
|
|
16427
16541
|
*
|
|
16428
16542
|
* @example
|
|
16429
16543
|
* ```ts
|
|
16544
|
+
* const ai = new GoogleGenAI({
|
|
16545
|
+
* apiKey: token.name,
|
|
16546
|
+
* httpOptions: { apiVersion: 'v1alpha' } // Support in v1alpha only.
|
|
16547
|
+
* });
|
|
16548
|
+
*
|
|
16430
16549
|
* // Case 1: If LiveEphemeralParameters is unset, unlock LiveConnectConfig
|
|
16431
16550
|
* // when using the token in Live API sessions. Each session connection can
|
|
16432
16551
|
* // use a different configuration.
|
|
@@ -16759,6 +16878,9 @@ function tuningDatasetToMldev(fromObject) {
|
|
|
16759
16878
|
if (getValueByPath(fromObject, ['gcsUri']) !== undefined) {
|
|
16760
16879
|
throw new Error('gcsUri parameter is not supported in Gemini API.');
|
|
16761
16880
|
}
|
|
16881
|
+
if (getValueByPath(fromObject, ['vertexDatasetResource']) !== undefined) {
|
|
16882
|
+
throw new Error('vertexDatasetResource parameter is not supported in Gemini API.');
|
|
16883
|
+
}
|
|
16762
16884
|
const fromExamples = getValueByPath(fromObject, ['examples']);
|
|
16763
16885
|
if (fromExamples != null) {
|
|
16764
16886
|
let transformedList = fromExamples;
|
|
@@ -16872,17 +16994,29 @@ function tuningDatasetToVertex(fromObject, parentObject) {
|
|
|
16872
16994
|
if (parentObject !== undefined && fromGcsUri != null) {
|
|
16873
16995
|
setValueByPath(parentObject, ['supervisedTuningSpec', 'trainingDatasetUri'], fromGcsUri);
|
|
16874
16996
|
}
|
|
16997
|
+
const fromVertexDatasetResource = getValueByPath(fromObject, [
|
|
16998
|
+
'vertexDatasetResource',
|
|
16999
|
+
]);
|
|
17000
|
+
if (parentObject !== undefined && fromVertexDatasetResource != null) {
|
|
17001
|
+
setValueByPath(parentObject, ['supervisedTuningSpec', 'trainingDatasetUri'], fromVertexDatasetResource);
|
|
17002
|
+
}
|
|
16875
17003
|
if (getValueByPath(fromObject, ['examples']) !== undefined) {
|
|
16876
17004
|
throw new Error('examples parameter is not supported in Vertex AI.');
|
|
16877
17005
|
}
|
|
16878
17006
|
return toObject;
|
|
16879
17007
|
}
|
|
16880
|
-
function tuningValidationDatasetToVertex(fromObject) {
|
|
17008
|
+
function tuningValidationDatasetToVertex(fromObject, parentObject) {
|
|
16881
17009
|
const toObject = {};
|
|
16882
17010
|
const fromGcsUri = getValueByPath(fromObject, ['gcsUri']);
|
|
16883
17011
|
if (fromGcsUri != null) {
|
|
16884
17012
|
setValueByPath(toObject, ['validationDatasetUri'], fromGcsUri);
|
|
16885
17013
|
}
|
|
17014
|
+
const fromVertexDatasetResource = getValueByPath(fromObject, [
|
|
17015
|
+
'vertexDatasetResource',
|
|
17016
|
+
]);
|
|
17017
|
+
if (parentObject !== undefined && fromVertexDatasetResource != null) {
|
|
17018
|
+
setValueByPath(parentObject, ['supervisedTuningSpec', 'trainingDatasetUri'], fromVertexDatasetResource);
|
|
17019
|
+
}
|
|
16886
17020
|
return toObject;
|
|
16887
17021
|
}
|
|
16888
17022
|
function createTuningJobConfigToVertex(fromObject, parentObject) {
|
|
@@ -16891,7 +17025,7 @@ function createTuningJobConfigToVertex(fromObject, parentObject) {
|
|
|
16891
17025
|
'validationDataset',
|
|
16892
17026
|
]);
|
|
16893
17027
|
if (parentObject !== undefined && fromValidationDataset != null) {
|
|
16894
|
-
setValueByPath(parentObject, ['supervisedTuningSpec'], tuningValidationDatasetToVertex(fromValidationDataset));
|
|
17028
|
+
setValueByPath(parentObject, ['supervisedTuningSpec'], tuningValidationDatasetToVertex(fromValidationDataset, toObject));
|
|
16895
17029
|
}
|
|
16896
17030
|
const fromTunedModelDisplayName = getValueByPath(fromObject, [
|
|
16897
17031
|
'tunedModelDisplayName',
|
|
@@ -17023,6 +17157,14 @@ function tuningJobFromMldev(fromObject) {
|
|
|
17023
17157
|
if (fromPipelineJob != null) {
|
|
17024
17158
|
setValueByPath(toObject, ['pipelineJob'], fromPipelineJob);
|
|
17025
17159
|
}
|
|
17160
|
+
const fromSatisfiesPzi = getValueByPath(fromObject, ['satisfiesPzi']);
|
|
17161
|
+
if (fromSatisfiesPzi != null) {
|
|
17162
|
+
setValueByPath(toObject, ['satisfiesPzi'], fromSatisfiesPzi);
|
|
17163
|
+
}
|
|
17164
|
+
const fromSatisfiesPzs = getValueByPath(fromObject, ['satisfiesPzs']);
|
|
17165
|
+
if (fromSatisfiesPzs != null) {
|
|
17166
|
+
setValueByPath(toObject, ['satisfiesPzs'], fromSatisfiesPzs);
|
|
17167
|
+
}
|
|
17026
17168
|
const fromServiceAccount = getValueByPath(fromObject, [
|
|
17027
17169
|
'serviceAccount',
|
|
17028
17170
|
]);
|
|
@@ -17203,6 +17345,14 @@ function tuningJobFromVertex(fromObject) {
|
|
|
17203
17345
|
if (fromPipelineJob != null) {
|
|
17204
17346
|
setValueByPath(toObject, ['pipelineJob'], fromPipelineJob);
|
|
17205
17347
|
}
|
|
17348
|
+
const fromSatisfiesPzi = getValueByPath(fromObject, ['satisfiesPzi']);
|
|
17349
|
+
if (fromSatisfiesPzi != null) {
|
|
17350
|
+
setValueByPath(toObject, ['satisfiesPzi'], fromSatisfiesPzi);
|
|
17351
|
+
}
|
|
17352
|
+
const fromSatisfiesPzs = getValueByPath(fromObject, ['satisfiesPzs']);
|
|
17353
|
+
if (fromSatisfiesPzs != null) {
|
|
17354
|
+
setValueByPath(toObject, ['satisfiesPzs'], fromSatisfiesPzs);
|
|
17355
|
+
}
|
|
17206
17356
|
const fromServiceAccount = getValueByPath(fromObject, [
|
|
17207
17357
|
'serviceAccount',
|
|
17208
17358
|
]);
|
|
@@ -17889,5 +18039,5 @@ function getApiKeyFromEnv() {
|
|
|
17889
18039
|
return envGoogleApiKey || envGeminiApiKey;
|
|
17890
18040
|
}
|
|
17891
18041
|
|
|
17892
|
-
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 };
|
|
18042
|
+
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 };
|
|
17893
18043
|
//# sourceMappingURL=index.mjs.map
|