@google/genai 1.7.0 → 1.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +43 -0
- package/dist/genai.d.ts +240 -22
- package/dist/index.cjs +373 -224
- package/dist/index.mjs +374 -225
- package/dist/index.mjs.map +1 -1
- package/dist/node/index.cjs +373 -223
- package/dist/node/index.mjs +374 -224
- package/dist/node/index.mjs.map +1 -1
- package/dist/node/node.d.ts +240 -22
- package/dist/web/index.mjs +374 -225
- package/dist/web/index.mjs.map +1 -1
- package/dist/web/web.d.ts +240 -22
- package/package.json +5 -5
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
2
|
* @license
|
|
5
3
|
* Copyright 2025 Google LLC
|
|
@@ -257,6 +255,22 @@ var HarmCategory;
|
|
|
257
255
|
* Deprecated: Election filter is not longer supported. The harm category is civic integrity.
|
|
258
256
|
*/
|
|
259
257
|
HarmCategory["HARM_CATEGORY_CIVIC_INTEGRITY"] = "HARM_CATEGORY_CIVIC_INTEGRITY";
|
|
258
|
+
/**
|
|
259
|
+
* The harm category is image hate.
|
|
260
|
+
*/
|
|
261
|
+
HarmCategory["HARM_CATEGORY_IMAGE_HATE"] = "HARM_CATEGORY_IMAGE_HATE";
|
|
262
|
+
/**
|
|
263
|
+
* The harm category is image dangerous content.
|
|
264
|
+
*/
|
|
265
|
+
HarmCategory["HARM_CATEGORY_IMAGE_DANGEROUS_CONTENT"] = "HARM_CATEGORY_IMAGE_DANGEROUS_CONTENT";
|
|
266
|
+
/**
|
|
267
|
+
* The harm category is image harassment.
|
|
268
|
+
*/
|
|
269
|
+
HarmCategory["HARM_CATEGORY_IMAGE_HARASSMENT"] = "HARM_CATEGORY_IMAGE_HARASSMENT";
|
|
270
|
+
/**
|
|
271
|
+
* The harm category is image sexually explicit content.
|
|
272
|
+
*/
|
|
273
|
+
HarmCategory["HARM_CATEGORY_IMAGE_SEXUALLY_EXPLICIT"] = "HARM_CATEGORY_IMAGE_SEXUALLY_EXPLICIT";
|
|
260
274
|
})(HarmCategory || (HarmCategory = {}));
|
|
261
275
|
/** Optional. Specify if the threshold is used for probability or severity score. If not specified, the threshold is used for probability score. */
|
|
262
276
|
var HarmBlockMethod;
|
|
@@ -343,6 +357,50 @@ var AuthType;
|
|
|
343
357
|
*/
|
|
344
358
|
AuthType["OIDC_AUTH"] = "OIDC_AUTH";
|
|
345
359
|
})(AuthType || (AuthType = {}));
|
|
360
|
+
/** The API spec that the external API implements. */
|
|
361
|
+
var ApiSpec;
|
|
362
|
+
(function (ApiSpec) {
|
|
363
|
+
/**
|
|
364
|
+
* Unspecified API spec. This value should not be used.
|
|
365
|
+
*/
|
|
366
|
+
ApiSpec["API_SPEC_UNSPECIFIED"] = "API_SPEC_UNSPECIFIED";
|
|
367
|
+
/**
|
|
368
|
+
* Simple search API spec.
|
|
369
|
+
*/
|
|
370
|
+
ApiSpec["SIMPLE_SEARCH"] = "SIMPLE_SEARCH";
|
|
371
|
+
/**
|
|
372
|
+
* Elastic search API spec.
|
|
373
|
+
*/
|
|
374
|
+
ApiSpec["ELASTIC_SEARCH"] = "ELASTIC_SEARCH";
|
|
375
|
+
})(ApiSpec || (ApiSpec = {}));
|
|
376
|
+
/** Required. The environment being operated. */
|
|
377
|
+
var Environment;
|
|
378
|
+
(function (Environment) {
|
|
379
|
+
/**
|
|
380
|
+
* Defaults to browser.
|
|
381
|
+
*/
|
|
382
|
+
Environment["ENVIRONMENT_UNSPECIFIED"] = "ENVIRONMENT_UNSPECIFIED";
|
|
383
|
+
/**
|
|
384
|
+
* Operates in a web browser.
|
|
385
|
+
*/
|
|
386
|
+
Environment["ENVIRONMENT_BROWSER"] = "ENVIRONMENT_BROWSER";
|
|
387
|
+
})(Environment || (Environment = {}));
|
|
388
|
+
/** Status of the url retrieval. */
|
|
389
|
+
var UrlRetrievalStatus;
|
|
390
|
+
(function (UrlRetrievalStatus) {
|
|
391
|
+
/**
|
|
392
|
+
* Default value. This value is unused
|
|
393
|
+
*/
|
|
394
|
+
UrlRetrievalStatus["URL_RETRIEVAL_STATUS_UNSPECIFIED"] = "URL_RETRIEVAL_STATUS_UNSPECIFIED";
|
|
395
|
+
/**
|
|
396
|
+
* Url retrieval is successful.
|
|
397
|
+
*/
|
|
398
|
+
UrlRetrievalStatus["URL_RETRIEVAL_STATUS_SUCCESS"] = "URL_RETRIEVAL_STATUS_SUCCESS";
|
|
399
|
+
/**
|
|
400
|
+
* Url retrieval is failed due to error.
|
|
401
|
+
*/
|
|
402
|
+
UrlRetrievalStatus["URL_RETRIEVAL_STATUS_ERROR"] = "URL_RETRIEVAL_STATUS_ERROR";
|
|
403
|
+
})(UrlRetrievalStatus || (UrlRetrievalStatus = {}));
|
|
346
404
|
/** Output only. The reason why the model stopped generating tokens.
|
|
347
405
|
|
|
348
406
|
If empty, the model has not stopped generating the tokens.
|
|
@@ -473,6 +531,10 @@ var BlockedReason;
|
|
|
473
531
|
* Candidates blocked due to prohibited content.
|
|
474
532
|
*/
|
|
475
533
|
BlockedReason["PROHIBITED_CONTENT"] = "PROHIBITED_CONTENT";
|
|
534
|
+
/**
|
|
535
|
+
* Candidates blocked due to unsafe image generation content.
|
|
536
|
+
*/
|
|
537
|
+
BlockedReason["IMAGE_SAFETY"] = "IMAGE_SAFETY";
|
|
476
538
|
})(BlockedReason || (BlockedReason = {}));
|
|
477
539
|
/** Output only. Traffic type. This shows whether a request consumes Pay-As-You-Go or Provisioned Throughput quota. */
|
|
478
540
|
var TrafficType;
|
|
@@ -670,22 +732,6 @@ var FunctionCallingConfigMode;
|
|
|
670
732
|
*/
|
|
671
733
|
FunctionCallingConfigMode["NONE"] = "NONE";
|
|
672
734
|
})(FunctionCallingConfigMode || (FunctionCallingConfigMode = {}));
|
|
673
|
-
/** Status of the url retrieval. */
|
|
674
|
-
var UrlRetrievalStatus;
|
|
675
|
-
(function (UrlRetrievalStatus) {
|
|
676
|
-
/**
|
|
677
|
-
* Default value. This value is unused
|
|
678
|
-
*/
|
|
679
|
-
UrlRetrievalStatus["URL_RETRIEVAL_STATUS_UNSPECIFIED"] = "URL_RETRIEVAL_STATUS_UNSPECIFIED";
|
|
680
|
-
/**
|
|
681
|
-
* Url retrieval is successful.
|
|
682
|
-
*/
|
|
683
|
-
UrlRetrievalStatus["URL_RETRIEVAL_STATUS_SUCCESS"] = "URL_RETRIEVAL_STATUS_SUCCESS";
|
|
684
|
-
/**
|
|
685
|
-
* Url retrieval is failed due to error.
|
|
686
|
-
*/
|
|
687
|
-
UrlRetrievalStatus["URL_RETRIEVAL_STATUS_ERROR"] = "URL_RETRIEVAL_STATUS_ERROR";
|
|
688
|
-
})(UrlRetrievalStatus || (UrlRetrievalStatus = {}));
|
|
689
735
|
/** Enum that controls the safety filter level for objectionable content. */
|
|
690
736
|
var SafetyFilterLevel;
|
|
691
737
|
(function (SafetyFilterLevel) {
|
|
@@ -713,11 +759,38 @@ var PersonGeneration;
|
|
|
713
759
|
/** Enum that specifies the language of the text in the prompt. */
|
|
714
760
|
var ImagePromptLanguage;
|
|
715
761
|
(function (ImagePromptLanguage) {
|
|
762
|
+
/**
|
|
763
|
+
* Auto-detect the language.
|
|
764
|
+
*/
|
|
716
765
|
ImagePromptLanguage["auto"] = "auto";
|
|
766
|
+
/**
|
|
767
|
+
* English
|
|
768
|
+
*/
|
|
717
769
|
ImagePromptLanguage["en"] = "en";
|
|
770
|
+
/**
|
|
771
|
+
* Japanese
|
|
772
|
+
*/
|
|
718
773
|
ImagePromptLanguage["ja"] = "ja";
|
|
774
|
+
/**
|
|
775
|
+
* Korean
|
|
776
|
+
*/
|
|
719
777
|
ImagePromptLanguage["ko"] = "ko";
|
|
778
|
+
/**
|
|
779
|
+
* Hindi
|
|
780
|
+
*/
|
|
720
781
|
ImagePromptLanguage["hi"] = "hi";
|
|
782
|
+
/**
|
|
783
|
+
* Chinese
|
|
784
|
+
*/
|
|
785
|
+
ImagePromptLanguage["zh"] = "zh";
|
|
786
|
+
/**
|
|
787
|
+
* Portuguese
|
|
788
|
+
*/
|
|
789
|
+
ImagePromptLanguage["pt"] = "pt";
|
|
790
|
+
/**
|
|
791
|
+
* Spanish
|
|
792
|
+
*/
|
|
793
|
+
ImagePromptLanguage["es"] = "es";
|
|
721
794
|
})(ImagePromptLanguage || (ImagePromptLanguage = {}));
|
|
722
795
|
/** Enum representing the mask mode of a mask reference image. */
|
|
723
796
|
var MaskReferenceMode;
|
|
@@ -1818,133 +1891,12 @@ function tContents(origin) {
|
|
|
1818
1891
|
}
|
|
1819
1892
|
return result;
|
|
1820
1893
|
}
|
|
1821
|
-
// The fields that are supported by JSONSchema. Must be kept in sync with the
|
|
1822
|
-
// JSONSchema interface above.
|
|
1823
|
-
const supportedJsonSchemaFields = new Set([
|
|
1824
|
-
'type',
|
|
1825
|
-
'format',
|
|
1826
|
-
'title',
|
|
1827
|
-
'description',
|
|
1828
|
-
'default',
|
|
1829
|
-
'items',
|
|
1830
|
-
'minItems',
|
|
1831
|
-
'maxItems',
|
|
1832
|
-
'enum',
|
|
1833
|
-
'properties',
|
|
1834
|
-
'required',
|
|
1835
|
-
'minProperties',
|
|
1836
|
-
'maxProperties',
|
|
1837
|
-
'minimum',
|
|
1838
|
-
'maximum',
|
|
1839
|
-
'minLength',
|
|
1840
|
-
'maxLength',
|
|
1841
|
-
'pattern',
|
|
1842
|
-
'anyOf',
|
|
1843
|
-
'propertyOrdering',
|
|
1844
|
-
]);
|
|
1845
|
-
const jsonSchemaTypeValidator = z.enum([
|
|
1846
|
-
'string',
|
|
1847
|
-
'number',
|
|
1848
|
-
'integer',
|
|
1849
|
-
'object',
|
|
1850
|
-
'array',
|
|
1851
|
-
'boolean',
|
|
1852
|
-
'null',
|
|
1853
|
-
]);
|
|
1854
|
-
// Handles all types and arrays of all types.
|
|
1855
|
-
const schemaTypeUnion = z.union([
|
|
1856
|
-
jsonSchemaTypeValidator,
|
|
1857
|
-
z.array(jsonSchemaTypeValidator),
|
|
1858
|
-
]);
|
|
1859
|
-
/**
|
|
1860
|
-
* Creates a zod validator for JSONSchema.
|
|
1861
|
-
*
|
|
1862
|
-
* @param strictMode Whether to enable strict mode, default to true. When
|
|
1863
|
-
* strict mode is enabled, the zod validator will throw error if there
|
|
1864
|
-
* are unrecognized fields in the input data. If strict mode is
|
|
1865
|
-
* disabled, the zod validator will ignore the unrecognized fields, only
|
|
1866
|
-
* populate the fields that are listed in the JSONSchema. Regardless of
|
|
1867
|
-
* the mode the type mismatch will always result in an error, for example
|
|
1868
|
-
* items field should be a single JSONSchema, but for tuple type it would
|
|
1869
|
-
* be an array of JSONSchema, this will always result in an error.
|
|
1870
|
-
* @return The zod validator for JSONSchema.
|
|
1871
|
-
*/
|
|
1872
|
-
function createJsonSchemaValidator(strictMode = true) {
|
|
1873
|
-
const jsonSchemaValidator = z.lazy(() => {
|
|
1874
|
-
// Define the base object shape *inside* the z.lazy callback
|
|
1875
|
-
const baseShape = z.object({
|
|
1876
|
-
// --- Type ---
|
|
1877
|
-
type: schemaTypeUnion.optional(),
|
|
1878
|
-
// --- Annotations ---
|
|
1879
|
-
format: z.string().optional(),
|
|
1880
|
-
title: z.string().optional(),
|
|
1881
|
-
description: z.string().optional(),
|
|
1882
|
-
default: z.unknown().optional(),
|
|
1883
|
-
// --- Array Validations ---
|
|
1884
|
-
items: jsonSchemaValidator.optional(),
|
|
1885
|
-
minItems: z.coerce.string().optional(),
|
|
1886
|
-
maxItems: z.coerce.string().optional(),
|
|
1887
|
-
// --- Generic Validations ---
|
|
1888
|
-
enum: z.array(z.unknown()).optional(),
|
|
1889
|
-
// --- Object Validations ---
|
|
1890
|
-
properties: z.record(z.string(), jsonSchemaValidator).optional(),
|
|
1891
|
-
required: z.array(z.string()).optional(),
|
|
1892
|
-
minProperties: z.coerce.string().optional(),
|
|
1893
|
-
maxProperties: z.coerce.string().optional(),
|
|
1894
|
-
propertyOrdering: z.array(z.string()).optional(),
|
|
1895
|
-
// --- Numeric Validations ---
|
|
1896
|
-
minimum: z.number().optional(),
|
|
1897
|
-
maximum: z.number().optional(),
|
|
1898
|
-
// --- String Validations ---
|
|
1899
|
-
minLength: z.coerce.string().optional(),
|
|
1900
|
-
maxLength: z.coerce.string().optional(),
|
|
1901
|
-
pattern: z.string().optional(),
|
|
1902
|
-
// --- Schema Composition ---
|
|
1903
|
-
anyOf: z.array(jsonSchemaValidator).optional(),
|
|
1904
|
-
// --- Additional Properties --- This field is not included in the
|
|
1905
|
-
// JSONSchema, will not be communicated to the model, it is here purely
|
|
1906
|
-
// for enabling the zod validation strict mode.
|
|
1907
|
-
additionalProperties: z.boolean().optional(),
|
|
1908
|
-
});
|
|
1909
|
-
// Conditionally apply .strict() based on the flag
|
|
1910
|
-
return strictMode ? baseShape.strict() : baseShape;
|
|
1911
|
-
});
|
|
1912
|
-
return jsonSchemaValidator;
|
|
1913
|
-
}
|
|
1914
1894
|
/*
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
zod_to_json_schema will squash the types into an array instead of put them
|
|
1921
|
-
in anyOf fields. Otherwise, it will put the types in anyOf fields.
|
|
1922
|
-
See the following link for more details:
|
|
1923
|
-
https://github.com/zodjs/zod-to-json-schema/blob/main/src/index.ts#L101
|
|
1924
|
-
The logic here is trying to undo that optimization, flattening the array of
|
|
1925
|
-
types to anyOf fields.
|
|
1926
|
-
type field
|
|
1927
|
-
|
|
|
1928
|
-
___________________________
|
|
1929
|
-
/ \
|
|
1930
|
-
/ \
|
|
1931
|
-
/ \
|
|
1932
|
-
Array Type.*
|
|
1933
|
-
/ \ |
|
|
1934
|
-
Include null. Not included null type = Type.*.
|
|
1935
|
-
[null, Type.*, Type.*] multiple types.
|
|
1936
|
-
[null, Type.*] [Type.*, Type.*]
|
|
1937
|
-
/ \
|
|
1938
|
-
remove null \
|
|
1939
|
-
add nullable = true \
|
|
1940
|
-
/ \ \
|
|
1941
|
-
[Type.*] [Type.*, Type.*] \
|
|
1942
|
-
only one type left multiple types left \
|
|
1943
|
-
add type = Type.*. \ /
|
|
1944
|
-
\ /
|
|
1945
|
-
not populate the type field in final result
|
|
1946
|
-
and make the types into anyOf fields
|
|
1947
|
-
anyOf:[{type: 'Type.*'}, {type: 'Type.*'}];
|
|
1895
|
+
Transform the type field from an array of types to an array of anyOf fields.
|
|
1896
|
+
Example:
|
|
1897
|
+
{type: ['STRING', 'NUMBER']}
|
|
1898
|
+
will be transformed to
|
|
1899
|
+
{anyOf: [{type: 'STRING'}, {type: 'NUMBER'}]}
|
|
1948
1900
|
*/
|
|
1949
1901
|
function flattenTypeArrayToAnyOf(typeList, resultingSchema) {
|
|
1950
1902
|
if (typeList.includes('null')) {
|
|
@@ -2090,15 +2042,11 @@ function processJsonSchema(_jsonSchema) {
|
|
|
2090
2042
|
// https://github.com/StefanTerdell/zod-to-json-schema/blob/70525efe555cd226691e093d171370a3b10921d1/src/zodToJsonSchema.ts#L7
|
|
2091
2043
|
// typebox can return unknown, see details in
|
|
2092
2044
|
// https://github.com/sinclairzx81/typebox/blob/5a5431439f7d5ca6b494d0d18fbfd7b1a356d67c/src/type/create/type.ts#L35
|
|
2045
|
+
// Note: proper json schemas with the $schema field set never arrive to this
|
|
2046
|
+
// transformer. Schemas with $schema are routed to the equivalent API json
|
|
2047
|
+
// schema field.
|
|
2093
2048
|
function tSchema(schema) {
|
|
2094
|
-
|
|
2095
|
-
delete schema['$schema'];
|
|
2096
|
-
const validatedJsonSchema = createJsonSchemaValidator().parse(schema);
|
|
2097
|
-
return processJsonSchema(validatedJsonSchema);
|
|
2098
|
-
}
|
|
2099
|
-
else {
|
|
2100
|
-
return processJsonSchema(schema);
|
|
2101
|
-
}
|
|
2049
|
+
return processJsonSchema(schema);
|
|
2102
2050
|
}
|
|
2103
2051
|
function tSpeechConfig(speechConfig) {
|
|
2104
2052
|
if (typeof speechConfig === 'object') {
|
|
@@ -2127,10 +2075,28 @@ function tTool(tool) {
|
|
|
2127
2075
|
if (tool.functionDeclarations) {
|
|
2128
2076
|
for (const functionDeclaration of tool.functionDeclarations) {
|
|
2129
2077
|
if (functionDeclaration.parameters) {
|
|
2130
|
-
|
|
2078
|
+
if (!Object.keys(functionDeclaration.parameters).includes('$schema')) {
|
|
2079
|
+
functionDeclaration.parameters = processJsonSchema(functionDeclaration.parameters);
|
|
2080
|
+
}
|
|
2081
|
+
else {
|
|
2082
|
+
if (!functionDeclaration.parametersJsonSchema) {
|
|
2083
|
+
functionDeclaration.parametersJsonSchema =
|
|
2084
|
+
functionDeclaration.parameters;
|
|
2085
|
+
delete functionDeclaration.parameters;
|
|
2086
|
+
}
|
|
2087
|
+
}
|
|
2131
2088
|
}
|
|
2132
2089
|
if (functionDeclaration.response) {
|
|
2133
|
-
|
|
2090
|
+
if (!Object.keys(functionDeclaration.response).includes('$schema')) {
|
|
2091
|
+
functionDeclaration.response = processJsonSchema(functionDeclaration.response);
|
|
2092
|
+
}
|
|
2093
|
+
else {
|
|
2094
|
+
if (!functionDeclaration.responseJsonSchema) {
|
|
2095
|
+
functionDeclaration.responseJsonSchema =
|
|
2096
|
+
functionDeclaration.response;
|
|
2097
|
+
delete functionDeclaration.response;
|
|
2098
|
+
}
|
|
2099
|
+
}
|
|
2134
2100
|
}
|
|
2135
2101
|
}
|
|
2136
2102
|
}
|
|
@@ -2335,7 +2301,7 @@ function mcpToGeminiTool(mcpTool, config = {}) {
|
|
|
2335
2301
|
const functionDeclaration = {
|
|
2336
2302
|
name: mcpToolSchema['name'],
|
|
2337
2303
|
description: mcpToolSchema['description'],
|
|
2338
|
-
|
|
2304
|
+
parametersJsonSchema: mcpToolSchema['inputSchema'],
|
|
2339
2305
|
};
|
|
2340
2306
|
if (config.behavior) {
|
|
2341
2307
|
functionDeclaration['behavior'] = config.behavior;
|
|
@@ -2367,53 +2333,6 @@ function mcpToolsToGeminiTool(mcpTools, config = {}) {
|
|
|
2367
2333
|
}
|
|
2368
2334
|
return { functionDeclarations: functionDeclarations };
|
|
2369
2335
|
}
|
|
2370
|
-
// Filters the list schema field to only include fields that are supported by
|
|
2371
|
-
// JSONSchema.
|
|
2372
|
-
function filterListSchemaField(fieldValue) {
|
|
2373
|
-
const listSchemaFieldValue = [];
|
|
2374
|
-
for (const listFieldValue of fieldValue) {
|
|
2375
|
-
listSchemaFieldValue.push(filterToJsonSchema(listFieldValue));
|
|
2376
|
-
}
|
|
2377
|
-
return listSchemaFieldValue;
|
|
2378
|
-
}
|
|
2379
|
-
// Filters the dict schema field to only include fields that are supported by
|
|
2380
|
-
// JSONSchema.
|
|
2381
|
-
function filterDictSchemaField(fieldValue) {
|
|
2382
|
-
const dictSchemaFieldValue = {};
|
|
2383
|
-
for (const [key, value] of Object.entries(fieldValue)) {
|
|
2384
|
-
const valueRecord = value;
|
|
2385
|
-
dictSchemaFieldValue[key] = filterToJsonSchema(valueRecord);
|
|
2386
|
-
}
|
|
2387
|
-
return dictSchemaFieldValue;
|
|
2388
|
-
}
|
|
2389
|
-
// Filters the schema to only include fields that are supported by JSONSchema.
|
|
2390
|
-
function filterToJsonSchema(schema) {
|
|
2391
|
-
const schemaFieldNames = new Set(['items']); // 'additional_properties' to come
|
|
2392
|
-
const listSchemaFieldNames = new Set(['anyOf']); // 'one_of', 'all_of', 'not' to come
|
|
2393
|
-
const dictSchemaFieldNames = new Set(['properties']); // 'defs' to come
|
|
2394
|
-
const filteredSchema = {};
|
|
2395
|
-
for (const [fieldName, fieldValue] of Object.entries(schema)) {
|
|
2396
|
-
if (schemaFieldNames.has(fieldName)) {
|
|
2397
|
-
filteredSchema[fieldName] = filterToJsonSchema(fieldValue);
|
|
2398
|
-
}
|
|
2399
|
-
else if (listSchemaFieldNames.has(fieldName)) {
|
|
2400
|
-
filteredSchema[fieldName] = filterListSchemaField(fieldValue);
|
|
2401
|
-
}
|
|
2402
|
-
else if (dictSchemaFieldNames.has(fieldName)) {
|
|
2403
|
-
filteredSchema[fieldName] = filterDictSchemaField(fieldValue);
|
|
2404
|
-
}
|
|
2405
|
-
else if (fieldName === 'type') {
|
|
2406
|
-
const typeValue = fieldValue.toUpperCase();
|
|
2407
|
-
filteredSchema[fieldName] = Object.values(Type).includes(typeValue)
|
|
2408
|
-
? typeValue
|
|
2409
|
-
: Type.TYPE_UNSPECIFIED;
|
|
2410
|
-
}
|
|
2411
|
-
else if (supportedJsonSchemaFields.has(fieldName)) {
|
|
2412
|
-
filteredSchema[fieldName] = fieldValue;
|
|
2413
|
-
}
|
|
2414
|
-
}
|
|
2415
|
-
return filteredSchema;
|
|
2416
|
-
}
|
|
2417
2336
|
// Transforms a source input into a BatchJobSource object with validation.
|
|
2418
2337
|
function tBatchJobSource(apiClient, src) {
|
|
2419
2338
|
if (typeof src !== 'string' && !Array.isArray(src)) {
|
|
@@ -2888,6 +2807,10 @@ function toolToMldev$4(fromObject) {
|
|
|
2888
2807
|
if (fromCodeExecution != null) {
|
|
2889
2808
|
setValueByPath(toObject, ['codeExecution'], fromCodeExecution);
|
|
2890
2809
|
}
|
|
2810
|
+
const fromComputerUse = getValueByPath(fromObject, ['computerUse']);
|
|
2811
|
+
if (fromComputerUse != null) {
|
|
2812
|
+
setValueByPath(toObject, ['computerUse'], fromComputerUse);
|
|
2813
|
+
}
|
|
2891
2814
|
return toObject;
|
|
2892
2815
|
}
|
|
2893
2816
|
function functionCallingConfigToMldev$2(fromObject) {
|
|
@@ -3299,6 +3222,18 @@ function listBatchJobsParametersToMldev(fromObject) {
|
|
|
3299
3222
|
}
|
|
3300
3223
|
return toObject;
|
|
3301
3224
|
}
|
|
3225
|
+
function deleteBatchJobParametersToMldev(apiClient, fromObject) {
|
|
3226
|
+
const toObject = {};
|
|
3227
|
+
const fromName = getValueByPath(fromObject, ['name']);
|
|
3228
|
+
if (fromName != null) {
|
|
3229
|
+
setValueByPath(toObject, ['_url', 'name'], tBatchJobName(apiClient, fromName));
|
|
3230
|
+
}
|
|
3231
|
+
const fromConfig = getValueByPath(fromObject, ['config']);
|
|
3232
|
+
if (fromConfig != null) {
|
|
3233
|
+
setValueByPath(toObject, ['config'], fromConfig);
|
|
3234
|
+
}
|
|
3235
|
+
return toObject;
|
|
3236
|
+
}
|
|
3302
3237
|
function batchJobSourceToVertex(fromObject) {
|
|
3303
3238
|
const toObject = {};
|
|
3304
3239
|
const fromFormat = getValueByPath(fromObject, ['format']);
|
|
@@ -3419,6 +3354,18 @@ function listBatchJobsParametersToVertex(fromObject) {
|
|
|
3419
3354
|
}
|
|
3420
3355
|
return toObject;
|
|
3421
3356
|
}
|
|
3357
|
+
function deleteBatchJobParametersToVertex(apiClient, fromObject) {
|
|
3358
|
+
const toObject = {};
|
|
3359
|
+
const fromName = getValueByPath(fromObject, ['name']);
|
|
3360
|
+
if (fromName != null) {
|
|
3361
|
+
setValueByPath(toObject, ['_url', 'name'], tBatchJobName(apiClient, fromName));
|
|
3362
|
+
}
|
|
3363
|
+
const fromConfig = getValueByPath(fromObject, ['config']);
|
|
3364
|
+
if (fromConfig != null) {
|
|
3365
|
+
setValueByPath(toObject, ['config'], fromConfig);
|
|
3366
|
+
}
|
|
3367
|
+
return toObject;
|
|
3368
|
+
}
|
|
3422
3369
|
function jobErrorFromMldev() {
|
|
3423
3370
|
const toObject = {};
|
|
3424
3371
|
return toObject;
|
|
@@ -3756,6 +3703,22 @@ function listBatchJobsResponseFromMldev(fromObject) {
|
|
|
3756
3703
|
}
|
|
3757
3704
|
return toObject;
|
|
3758
3705
|
}
|
|
3706
|
+
function deleteResourceJobFromMldev(fromObject) {
|
|
3707
|
+
const toObject = {};
|
|
3708
|
+
const fromName = getValueByPath(fromObject, ['name']);
|
|
3709
|
+
if (fromName != null) {
|
|
3710
|
+
setValueByPath(toObject, ['name'], fromName);
|
|
3711
|
+
}
|
|
3712
|
+
const fromDone = getValueByPath(fromObject, ['done']);
|
|
3713
|
+
if (fromDone != null) {
|
|
3714
|
+
setValueByPath(toObject, ['done'], fromDone);
|
|
3715
|
+
}
|
|
3716
|
+
const fromError = getValueByPath(fromObject, ['error']);
|
|
3717
|
+
if (fromError != null) {
|
|
3718
|
+
setValueByPath(toObject, ['error'], jobErrorFromMldev());
|
|
3719
|
+
}
|
|
3720
|
+
return toObject;
|
|
3721
|
+
}
|
|
3759
3722
|
function jobErrorFromVertex(fromObject) {
|
|
3760
3723
|
const toObject = {};
|
|
3761
3724
|
const fromDetails = getValueByPath(fromObject, ['details']);
|
|
@@ -3883,6 +3846,22 @@ function listBatchJobsResponseFromVertex(fromObject) {
|
|
|
3883
3846
|
}
|
|
3884
3847
|
return toObject;
|
|
3885
3848
|
}
|
|
3849
|
+
function deleteResourceJobFromVertex(fromObject) {
|
|
3850
|
+
const toObject = {};
|
|
3851
|
+
const fromName = getValueByPath(fromObject, ['name']);
|
|
3852
|
+
if (fromName != null) {
|
|
3853
|
+
setValueByPath(toObject, ['name'], fromName);
|
|
3854
|
+
}
|
|
3855
|
+
const fromDone = getValueByPath(fromObject, ['done']);
|
|
3856
|
+
if (fromDone != null) {
|
|
3857
|
+
setValueByPath(toObject, ['done'], fromDone);
|
|
3858
|
+
}
|
|
3859
|
+
const fromError = getValueByPath(fromObject, ['error']);
|
|
3860
|
+
if (fromError != null) {
|
|
3861
|
+
setValueByPath(toObject, ['error'], jobErrorFromVertex(fromError));
|
|
3862
|
+
}
|
|
3863
|
+
return toObject;
|
|
3864
|
+
}
|
|
3886
3865
|
|
|
3887
3866
|
/**
|
|
3888
3867
|
* @license
|
|
@@ -4090,20 +4069,23 @@ class Batches extends BaseModule {
|
|
|
4090
4069
|
*/
|
|
4091
4070
|
this.create = async (params) => {
|
|
4092
4071
|
if (this.apiClient.isVertexAI()) {
|
|
4072
|
+
const timestamp = Date.now();
|
|
4073
|
+
const timestampStr = timestamp.toString();
|
|
4093
4074
|
if (Array.isArray(params.src)) {
|
|
4094
4075
|
throw new Error('InlinedRequest[] is not supported in Vertex AI. Please use ' +
|
|
4095
4076
|
'Google Cloud Storage URI or BigQuery URI instead.');
|
|
4096
4077
|
}
|
|
4097
4078
|
params.config = params.config || {};
|
|
4098
4079
|
if (params.config.displayName === undefined) {
|
|
4099
|
-
params.config.displayName = 'genaiBatchJob_';
|
|
4080
|
+
params.config.displayName = 'genaiBatchJob_${timestampStr}';
|
|
4100
4081
|
}
|
|
4101
4082
|
if (params.config.dest === undefined && typeof params.src === 'string') {
|
|
4102
4083
|
if (params.src.startsWith('gs://') && params.src.endsWith('.jsonl')) {
|
|
4103
4084
|
params.config.dest = `${params.src.slice(0, -6)}/dest`;
|
|
4104
4085
|
}
|
|
4105
4086
|
else if (params.src.startsWith('bq://')) {
|
|
4106
|
-
params.config.dest =
|
|
4087
|
+
params.config.dest =
|
|
4088
|
+
`${params.src}_dest_${timestampStr}`;
|
|
4107
4089
|
}
|
|
4108
4090
|
else {
|
|
4109
4091
|
throw new Error('Unsupported source:' + params.src);
|
|
@@ -4362,6 +4344,71 @@ class Batches extends BaseModule {
|
|
|
4362
4344
|
});
|
|
4363
4345
|
}
|
|
4364
4346
|
}
|
|
4347
|
+
/**
|
|
4348
|
+
* Deletes a batch job.
|
|
4349
|
+
*
|
|
4350
|
+
* @param params - The parameters for the delete request.
|
|
4351
|
+
* @return The empty response returned by the API.
|
|
4352
|
+
*
|
|
4353
|
+
* @example
|
|
4354
|
+
* ```ts
|
|
4355
|
+
* await ai.batches.delete({name: '...'}); // The server-generated resource name.
|
|
4356
|
+
* ```
|
|
4357
|
+
*/
|
|
4358
|
+
async delete(params) {
|
|
4359
|
+
var _a, _b, _c, _d;
|
|
4360
|
+
let response;
|
|
4361
|
+
let path = '';
|
|
4362
|
+
let queryParams = {};
|
|
4363
|
+
if (this.apiClient.isVertexAI()) {
|
|
4364
|
+
const body = deleteBatchJobParametersToVertex(this.apiClient, params);
|
|
4365
|
+
path = formatMap('batchPredictionJobs/{name}', body['_url']);
|
|
4366
|
+
queryParams = body['_query'];
|
|
4367
|
+
delete body['config'];
|
|
4368
|
+
delete body['_url'];
|
|
4369
|
+
delete body['_query'];
|
|
4370
|
+
response = this.apiClient
|
|
4371
|
+
.request({
|
|
4372
|
+
path: path,
|
|
4373
|
+
queryParams: queryParams,
|
|
4374
|
+
body: JSON.stringify(body),
|
|
4375
|
+
httpMethod: 'DELETE',
|
|
4376
|
+
httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
|
|
4377
|
+
abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
|
|
4378
|
+
})
|
|
4379
|
+
.then((httpResponse) => {
|
|
4380
|
+
return httpResponse.json();
|
|
4381
|
+
});
|
|
4382
|
+
return response.then((apiResponse) => {
|
|
4383
|
+
const resp = deleteResourceJobFromVertex(apiResponse);
|
|
4384
|
+
return resp;
|
|
4385
|
+
});
|
|
4386
|
+
}
|
|
4387
|
+
else {
|
|
4388
|
+
const body = deleteBatchJobParametersToMldev(this.apiClient, params);
|
|
4389
|
+
path = formatMap('batches/{name}', body['_url']);
|
|
4390
|
+
queryParams = body['_query'];
|
|
4391
|
+
delete body['config'];
|
|
4392
|
+
delete body['_url'];
|
|
4393
|
+
delete body['_query'];
|
|
4394
|
+
response = this.apiClient
|
|
4395
|
+
.request({
|
|
4396
|
+
path: path,
|
|
4397
|
+
queryParams: queryParams,
|
|
4398
|
+
body: JSON.stringify(body),
|
|
4399
|
+
httpMethod: 'DELETE',
|
|
4400
|
+
httpOptions: (_c = params.config) === null || _c === void 0 ? void 0 : _c.httpOptions,
|
|
4401
|
+
abortSignal: (_d = params.config) === null || _d === void 0 ? void 0 : _d.abortSignal,
|
|
4402
|
+
})
|
|
4403
|
+
.then((httpResponse) => {
|
|
4404
|
+
return httpResponse.json();
|
|
4405
|
+
});
|
|
4406
|
+
return response.then((apiResponse) => {
|
|
4407
|
+
const resp = deleteResourceJobFromMldev(apiResponse);
|
|
4408
|
+
return resp;
|
|
4409
|
+
});
|
|
4410
|
+
}
|
|
4411
|
+
}
|
|
4365
4412
|
}
|
|
4366
4413
|
|
|
4367
4414
|
/**
|
|
@@ -4616,6 +4663,10 @@ function toolToMldev$3(fromObject) {
|
|
|
4616
4663
|
if (fromCodeExecution != null) {
|
|
4617
4664
|
setValueByPath(toObject, ['codeExecution'], fromCodeExecution);
|
|
4618
4665
|
}
|
|
4666
|
+
const fromComputerUse = getValueByPath(fromObject, ['computerUse']);
|
|
4667
|
+
if (fromComputerUse != null) {
|
|
4668
|
+
setValueByPath(toObject, ['computerUse'], fromComputerUse);
|
|
4669
|
+
}
|
|
4619
4670
|
return toObject;
|
|
4620
4671
|
}
|
|
4621
4672
|
function functionCallingConfigToMldev$1(fromObject) {
|
|
@@ -5106,6 +5157,10 @@ function toolToVertex$2(fromObject) {
|
|
|
5106
5157
|
if (fromCodeExecution != null) {
|
|
5107
5158
|
setValueByPath(toObject, ['codeExecution'], fromCodeExecution);
|
|
5108
5159
|
}
|
|
5160
|
+
const fromComputerUse = getValueByPath(fromObject, ['computerUse']);
|
|
5161
|
+
if (fromComputerUse != null) {
|
|
5162
|
+
setValueByPath(toObject, ['computerUse'], fromComputerUse);
|
|
5163
|
+
}
|
|
5109
5164
|
return toObject;
|
|
5110
5165
|
}
|
|
5111
5166
|
function functionCallingConfigToVertex$1(fromObject) {
|
|
@@ -6193,7 +6248,7 @@ const CONTENT_TYPE_HEADER = 'Content-Type';
|
|
|
6193
6248
|
const SERVER_TIMEOUT_HEADER = 'X-Server-Timeout';
|
|
6194
6249
|
const USER_AGENT_HEADER = 'User-Agent';
|
|
6195
6250
|
const GOOGLE_API_CLIENT_HEADER = 'x-goog-api-client';
|
|
6196
|
-
const SDK_VERSION = '1.
|
|
6251
|
+
const SDK_VERSION = '1.9.0'; // x-release-please-version
|
|
6197
6252
|
const LIBRARY_LABEL = `google-genai-sdk/${SDK_VERSION}`;
|
|
6198
6253
|
const VERTEX_AI_API_DEFAULT_VERSION = 'v1beta1';
|
|
6199
6254
|
const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
|
|
@@ -6424,7 +6479,14 @@ class ApiClient {
|
|
|
6424
6479
|
const abortController = new AbortController();
|
|
6425
6480
|
const signal = abortController.signal;
|
|
6426
6481
|
if (httpOptions.timeout && (httpOptions === null || httpOptions === void 0 ? void 0 : httpOptions.timeout) > 0) {
|
|
6427
|
-
setTimeout(() => abortController.abort(), httpOptions.timeout);
|
|
6482
|
+
const timeoutHandle = setTimeout(() => abortController.abort(), httpOptions.timeout);
|
|
6483
|
+
if (timeoutHandle &&
|
|
6484
|
+
typeof timeoutHandle.unref ===
|
|
6485
|
+
'function') {
|
|
6486
|
+
// call unref to prevent nodejs process from hanging, see
|
|
6487
|
+
// https://nodejs.org/api/timers.html#timeoutunref
|
|
6488
|
+
timeoutHandle.unref();
|
|
6489
|
+
}
|
|
6428
6490
|
}
|
|
6429
6491
|
if (abortSignal) {
|
|
6430
6492
|
abortSignal.addEventListener('abort', () => {
|
|
@@ -6487,7 +6549,7 @@ class ApiClient {
|
|
|
6487
6549
|
}
|
|
6488
6550
|
break;
|
|
6489
6551
|
}
|
|
6490
|
-
const chunkString = decoder.decode(value);
|
|
6552
|
+
const chunkString = decoder.decode(value, { stream: true });
|
|
6491
6553
|
// Parse and throw an error if the chunk contains an error.
|
|
6492
6554
|
try {
|
|
6493
6555
|
const chunkJson = JSON.parse(chunkString);
|
|
@@ -8002,6 +8064,10 @@ function toolToMldev$2(fromObject) {
|
|
|
8002
8064
|
if (fromCodeExecution != null) {
|
|
8003
8065
|
setValueByPath(toObject, ['codeExecution'], fromCodeExecution);
|
|
8004
8066
|
}
|
|
8067
|
+
const fromComputerUse = getValueByPath(fromObject, ['computerUse']);
|
|
8068
|
+
if (fromComputerUse != null) {
|
|
8069
|
+
setValueByPath(toObject, ['computerUse'], fromComputerUse);
|
|
8070
|
+
}
|
|
8005
8071
|
return toObject;
|
|
8006
8072
|
}
|
|
8007
8073
|
function toolToVertex$1(fromObject) {
|
|
@@ -8052,6 +8118,10 @@ function toolToVertex$1(fromObject) {
|
|
|
8052
8118
|
if (fromCodeExecution != null) {
|
|
8053
8119
|
setValueByPath(toObject, ['codeExecution'], fromCodeExecution);
|
|
8054
8120
|
}
|
|
8121
|
+
const fromComputerUse = getValueByPath(fromObject, ['computerUse']);
|
|
8122
|
+
if (fromComputerUse != null) {
|
|
8123
|
+
setValueByPath(toObject, ['computerUse'], fromComputerUse);
|
|
8124
|
+
}
|
|
8055
8125
|
return toObject;
|
|
8056
8126
|
}
|
|
8057
8127
|
function sessionResumptionConfigToMldev$1(fromObject) {
|
|
@@ -8547,8 +8617,9 @@ function liveSendRealtimeInputParametersToVertex(fromObject) {
|
|
|
8547
8617
|
if (fromMedia != null) {
|
|
8548
8618
|
setValueByPath(toObject, ['mediaChunks'], tBlobs(fromMedia));
|
|
8549
8619
|
}
|
|
8550
|
-
|
|
8551
|
-
|
|
8620
|
+
const fromAudio = getValueByPath(fromObject, ['audio']);
|
|
8621
|
+
if (fromAudio != null) {
|
|
8622
|
+
setValueByPath(toObject, ['audio'], tAudioBlob(fromAudio));
|
|
8552
8623
|
}
|
|
8553
8624
|
const fromAudioStreamEnd = getValueByPath(fromObject, [
|
|
8554
8625
|
'audioStreamEnd',
|
|
@@ -8556,11 +8627,13 @@ function liveSendRealtimeInputParametersToVertex(fromObject) {
|
|
|
8556
8627
|
if (fromAudioStreamEnd != null) {
|
|
8557
8628
|
setValueByPath(toObject, ['audioStreamEnd'], fromAudioStreamEnd);
|
|
8558
8629
|
}
|
|
8559
|
-
|
|
8560
|
-
|
|
8630
|
+
const fromVideo = getValueByPath(fromObject, ['video']);
|
|
8631
|
+
if (fromVideo != null) {
|
|
8632
|
+
setValueByPath(toObject, ['video'], tImageBlob(fromVideo));
|
|
8561
8633
|
}
|
|
8562
|
-
|
|
8563
|
-
|
|
8634
|
+
const fromText = getValueByPath(fromObject, ['text']);
|
|
8635
|
+
if (fromText != null) {
|
|
8636
|
+
setValueByPath(toObject, ['text'], fromText);
|
|
8564
8637
|
}
|
|
8565
8638
|
const fromActivityStart = getValueByPath(fromObject, [
|
|
8566
8639
|
'activityStart',
|
|
@@ -8716,8 +8789,12 @@ function liveServerSetupCompleteFromMldev() {
|
|
|
8716
8789
|
const toObject = {};
|
|
8717
8790
|
return toObject;
|
|
8718
8791
|
}
|
|
8719
|
-
function liveServerSetupCompleteFromVertex() {
|
|
8792
|
+
function liveServerSetupCompleteFromVertex(fromObject) {
|
|
8720
8793
|
const toObject = {};
|
|
8794
|
+
const fromSessionId = getValueByPath(fromObject, ['sessionId']);
|
|
8795
|
+
if (fromSessionId != null) {
|
|
8796
|
+
setValueByPath(toObject, ['sessionId'], fromSessionId);
|
|
8797
|
+
}
|
|
8721
8798
|
return toObject;
|
|
8722
8799
|
}
|
|
8723
8800
|
function videoMetadataFromMldev$1(fromObject) {
|
|
@@ -9470,7 +9547,7 @@ function liveServerMessageFromVertex(fromObject) {
|
|
|
9470
9547
|
'setupComplete',
|
|
9471
9548
|
]);
|
|
9472
9549
|
if (fromSetupComplete != null) {
|
|
9473
|
-
setValueByPath(toObject, ['setupComplete'], liveServerSetupCompleteFromVertex());
|
|
9550
|
+
setValueByPath(toObject, ['setupComplete'], liveServerSetupCompleteFromVertex(fromSetupComplete));
|
|
9474
9551
|
}
|
|
9475
9552
|
const fromServerContent = getValueByPath(fromObject, [
|
|
9476
9553
|
'serverContent',
|
|
@@ -10038,6 +10115,10 @@ function toolToMldev$1(fromObject) {
|
|
|
10038
10115
|
if (fromCodeExecution != null) {
|
|
10039
10116
|
setValueByPath(toObject, ['codeExecution'], fromCodeExecution);
|
|
10040
10117
|
}
|
|
10118
|
+
const fromComputerUse = getValueByPath(fromObject, ['computerUse']);
|
|
10119
|
+
if (fromComputerUse != null) {
|
|
10120
|
+
setValueByPath(toObject, ['computerUse'], fromComputerUse);
|
|
10121
|
+
}
|
|
10041
10122
|
return toObject;
|
|
10042
10123
|
}
|
|
10043
10124
|
function functionCallingConfigToMldev(fromObject) {
|
|
@@ -11127,6 +11208,10 @@ function toolToVertex(fromObject) {
|
|
|
11127
11208
|
if (fromCodeExecution != null) {
|
|
11128
11209
|
setValueByPath(toObject, ['codeExecution'], fromCodeExecution);
|
|
11129
11210
|
}
|
|
11211
|
+
const fromComputerUse = getValueByPath(fromObject, ['computerUse']);
|
|
11212
|
+
if (fromComputerUse != null) {
|
|
11213
|
+
setValueByPath(toObject, ['computerUse'], fromComputerUse);
|
|
11214
|
+
}
|
|
11130
11215
|
return toObject;
|
|
11131
11216
|
}
|
|
11132
11217
|
function functionCallingConfigToVertex(fromObject) {
|
|
@@ -12510,7 +12595,7 @@ function modelFromMldev(fromObject) {
|
|
|
12510
12595
|
}
|
|
12511
12596
|
return toObject;
|
|
12512
12597
|
}
|
|
12513
|
-
function listModelsResponseFromMldev(
|
|
12598
|
+
function listModelsResponseFromMldev(fromObject) {
|
|
12514
12599
|
const toObject = {};
|
|
12515
12600
|
const fromNextPageToken = getValueByPath(fromObject, [
|
|
12516
12601
|
'nextPageToken',
|
|
@@ -13154,7 +13239,7 @@ function modelFromVertex(fromObject) {
|
|
|
13154
13239
|
}
|
|
13155
13240
|
return toObject;
|
|
13156
13241
|
}
|
|
13157
|
-
function listModelsResponseFromVertex(
|
|
13242
|
+
function listModelsResponseFromVertex(fromObject) {
|
|
13158
13243
|
const toObject = {};
|
|
13159
13244
|
const fromNextPageToken = getValueByPath(fromObject, [
|
|
13160
13245
|
'nextPageToken',
|
|
@@ -13764,7 +13849,7 @@ class Live {
|
|
|
13764
13849
|
if (GOOGLE_GENAI_USE_VERTEXAI) {
|
|
13765
13850
|
model = 'gemini-2.0-flash-live-preview-04-09';
|
|
13766
13851
|
} else {
|
|
13767
|
-
model = 'gemini-2.
|
|
13852
|
+
model = 'gemini-live-2.5-flash-preview';
|
|
13768
13853
|
}
|
|
13769
13854
|
const session = await ai.live.connect({
|
|
13770
13855
|
model: model,
|
|
@@ -13810,6 +13895,9 @@ class Live {
|
|
|
13810
13895
|
let keyName = 'key';
|
|
13811
13896
|
if (apiKey === null || apiKey === void 0 ? void 0 : apiKey.startsWith('auth_tokens/')) {
|
|
13812
13897
|
console.warn('Warning: Ephemeral token support is experimental and may change in future versions.');
|
|
13898
|
+
if (apiVersion !== 'v1alpha') {
|
|
13899
|
+
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.");
|
|
13900
|
+
}
|
|
13813
13901
|
method = 'BidiGenerateContentConstrained';
|
|
13814
13902
|
keyName = 'access_token';
|
|
13815
13903
|
}
|
|
@@ -14085,7 +14173,7 @@ class Session {
|
|
|
14085
14173
|
if (GOOGLE_GENAI_USE_VERTEXAI) {
|
|
14086
14174
|
model = 'gemini-2.0-flash-live-preview-04-09';
|
|
14087
14175
|
} else {
|
|
14088
|
-
model = 'gemini-2.
|
|
14176
|
+
model = 'gemini-live-2.5-flash-preview';
|
|
14089
14177
|
}
|
|
14090
14178
|
const session = await ai.live.connect({
|
|
14091
14179
|
model: model,
|
|
@@ -14214,6 +14302,7 @@ class Models extends BaseModule {
|
|
|
14214
14302
|
this.generateContent = async (params) => {
|
|
14215
14303
|
var _a, _b, _c, _d, _e;
|
|
14216
14304
|
const transformedParams = await this.processParamsForMcpUsage(params);
|
|
14305
|
+
this.maybeMoveToResponseJsonSchem(params);
|
|
14217
14306
|
if (!hasMcpClientTools(params) || shouldDisableAfc(params.config)) {
|
|
14218
14307
|
return await this.generateContentInternal(transformedParams);
|
|
14219
14308
|
}
|
|
@@ -14300,6 +14389,7 @@ class Models extends BaseModule {
|
|
|
14300
14389
|
* ```
|
|
14301
14390
|
*/
|
|
14302
14391
|
this.generateContentStream = async (params) => {
|
|
14392
|
+
this.maybeMoveToResponseJsonSchem(params);
|
|
14303
14393
|
if (shouldDisableAfc(params.config)) {
|
|
14304
14394
|
const transformedParams = await this.processParamsForMcpUsage(params);
|
|
14305
14395
|
return await this.generateContentStreamInternal(transformedParams);
|
|
@@ -14451,6 +14541,24 @@ class Models extends BaseModule {
|
|
|
14451
14541
|
return await this.upscaleImageInternal(apiParams);
|
|
14452
14542
|
};
|
|
14453
14543
|
}
|
|
14544
|
+
/**
|
|
14545
|
+
* This logic is needed for GenerateContentConfig only.
|
|
14546
|
+
* Previously we made GenerateContentConfig.responseSchema field to accept
|
|
14547
|
+
* unknown. Since v1.9.0, we switch to use backend JSON schema support.
|
|
14548
|
+
* To maintain backward compatibility, we move the data that was treated as
|
|
14549
|
+
* JSON schema from the responseSchema field to the responseJsonSchema field.
|
|
14550
|
+
*/
|
|
14551
|
+
maybeMoveToResponseJsonSchem(params) {
|
|
14552
|
+
if (params.config && params.config.responseSchema) {
|
|
14553
|
+
if (!params.config.responseJsonSchema) {
|
|
14554
|
+
if (Object.keys(params.config.responseSchema).includes('$schema')) {
|
|
14555
|
+
params.config.responseJsonSchema = params.config.responseSchema;
|
|
14556
|
+
delete params.config.responseSchema;
|
|
14557
|
+
}
|
|
14558
|
+
}
|
|
14559
|
+
}
|
|
14560
|
+
return;
|
|
14561
|
+
}
|
|
14454
14562
|
/**
|
|
14455
14563
|
* Transforms the CallableTools in the parameters to be simply Tools, it
|
|
14456
14564
|
* copies the params into a new object and replaces the tools, it does not
|
|
@@ -15047,7 +15155,7 @@ class Models extends BaseModule {
|
|
|
15047
15155
|
return httpResponse.json();
|
|
15048
15156
|
});
|
|
15049
15157
|
return response.then((apiResponse) => {
|
|
15050
|
-
const resp = listModelsResponseFromVertex(
|
|
15158
|
+
const resp = listModelsResponseFromVertex(apiResponse);
|
|
15051
15159
|
const typedResp = new ListModelsResponse();
|
|
15052
15160
|
Object.assign(typedResp, resp);
|
|
15053
15161
|
return typedResp;
|
|
@@ -15073,7 +15181,7 @@ class Models extends BaseModule {
|
|
|
15073
15181
|
return httpResponse.json();
|
|
15074
15182
|
});
|
|
15075
15183
|
return response.then((apiResponse) => {
|
|
15076
|
-
const resp = listModelsResponseFromMldev(
|
|
15184
|
+
const resp = listModelsResponseFromMldev(apiResponse);
|
|
15077
15185
|
const typedResp = new ListModelsResponse();
|
|
15078
15186
|
Object.assign(typedResp, resp);
|
|
15079
15187
|
return typedResp;
|
|
@@ -16083,6 +16191,10 @@ function toolToMldev(fromObject) {
|
|
|
16083
16191
|
if (fromCodeExecution != null) {
|
|
16084
16192
|
setValueByPath(toObject, ['codeExecution'], fromCodeExecution);
|
|
16085
16193
|
}
|
|
16194
|
+
const fromComputerUse = getValueByPath(fromObject, ['computerUse']);
|
|
16195
|
+
if (fromComputerUse != null) {
|
|
16196
|
+
setValueByPath(toObject, ['computerUse'], fromComputerUse);
|
|
16197
|
+
}
|
|
16086
16198
|
return toObject;
|
|
16087
16199
|
}
|
|
16088
16200
|
function sessionResumptionConfigToMldev(fromObject) {
|
|
@@ -16507,14 +16619,20 @@ class Tokens extends BaseModule {
|
|
|
16507
16619
|
* @experimental
|
|
16508
16620
|
*
|
|
16509
16621
|
* @remarks
|
|
16510
|
-
*
|
|
16622
|
+
* Ephemeral auth tokens is only supported in the Gemini Developer API.
|
|
16511
16623
|
* It can be used for the session connection to the Live constrained API.
|
|
16624
|
+
* Support in v1alpha only.
|
|
16512
16625
|
*
|
|
16513
16626
|
* @param params - The parameters for the create request.
|
|
16514
16627
|
* @return The created auth token.
|
|
16515
16628
|
*
|
|
16516
16629
|
* @example
|
|
16517
16630
|
* ```ts
|
|
16631
|
+
* const ai = new GoogleGenAI({
|
|
16632
|
+
* apiKey: token.name,
|
|
16633
|
+
* httpOptions: { apiVersion: 'v1alpha' } // Support in v1alpha only.
|
|
16634
|
+
* });
|
|
16635
|
+
*
|
|
16518
16636
|
* // Case 1: If LiveEphemeralParameters is unset, unlock LiveConnectConfig
|
|
16519
16637
|
* // when using the token in Live API sessions. Each session connection can
|
|
16520
16638
|
* // use a different configuration.
|
|
@@ -16673,6 +16791,9 @@ function tuningDatasetToMldev(fromObject) {
|
|
|
16673
16791
|
if (getValueByPath(fromObject, ['gcsUri']) !== undefined) {
|
|
16674
16792
|
throw new Error('gcsUri parameter is not supported in Gemini API.');
|
|
16675
16793
|
}
|
|
16794
|
+
if (getValueByPath(fromObject, ['vertexDatasetResource']) !== undefined) {
|
|
16795
|
+
throw new Error('vertexDatasetResource parameter is not supported in Gemini API.');
|
|
16796
|
+
}
|
|
16676
16797
|
const fromExamples = getValueByPath(fromObject, ['examples']);
|
|
16677
16798
|
if (fromExamples != null) {
|
|
16678
16799
|
let transformedList = fromExamples;
|
|
@@ -16786,17 +16907,29 @@ function tuningDatasetToVertex(fromObject, parentObject) {
|
|
|
16786
16907
|
if (parentObject !== undefined && fromGcsUri != null) {
|
|
16787
16908
|
setValueByPath(parentObject, ['supervisedTuningSpec', 'trainingDatasetUri'], fromGcsUri);
|
|
16788
16909
|
}
|
|
16910
|
+
const fromVertexDatasetResource = getValueByPath(fromObject, [
|
|
16911
|
+
'vertexDatasetResource',
|
|
16912
|
+
]);
|
|
16913
|
+
if (parentObject !== undefined && fromVertexDatasetResource != null) {
|
|
16914
|
+
setValueByPath(parentObject, ['supervisedTuningSpec', 'trainingDatasetUri'], fromVertexDatasetResource);
|
|
16915
|
+
}
|
|
16789
16916
|
if (getValueByPath(fromObject, ['examples']) !== undefined) {
|
|
16790
16917
|
throw new Error('examples parameter is not supported in Vertex AI.');
|
|
16791
16918
|
}
|
|
16792
16919
|
return toObject;
|
|
16793
16920
|
}
|
|
16794
|
-
function tuningValidationDatasetToVertex(fromObject) {
|
|
16921
|
+
function tuningValidationDatasetToVertex(fromObject, parentObject) {
|
|
16795
16922
|
const toObject = {};
|
|
16796
16923
|
const fromGcsUri = getValueByPath(fromObject, ['gcsUri']);
|
|
16797
16924
|
if (fromGcsUri != null) {
|
|
16798
16925
|
setValueByPath(toObject, ['validationDatasetUri'], fromGcsUri);
|
|
16799
16926
|
}
|
|
16927
|
+
const fromVertexDatasetResource = getValueByPath(fromObject, [
|
|
16928
|
+
'vertexDatasetResource',
|
|
16929
|
+
]);
|
|
16930
|
+
if (parentObject !== undefined && fromVertexDatasetResource != null) {
|
|
16931
|
+
setValueByPath(parentObject, ['supervisedTuningSpec', 'trainingDatasetUri'], fromVertexDatasetResource);
|
|
16932
|
+
}
|
|
16800
16933
|
return toObject;
|
|
16801
16934
|
}
|
|
16802
16935
|
function createTuningJobConfigToVertex(fromObject, parentObject) {
|
|
@@ -16805,7 +16938,7 @@ function createTuningJobConfigToVertex(fromObject, parentObject) {
|
|
|
16805
16938
|
'validationDataset',
|
|
16806
16939
|
]);
|
|
16807
16940
|
if (parentObject !== undefined && fromValidationDataset != null) {
|
|
16808
|
-
setValueByPath(parentObject, ['supervisedTuningSpec'], tuningValidationDatasetToVertex(fromValidationDataset));
|
|
16941
|
+
setValueByPath(parentObject, ['supervisedTuningSpec'], tuningValidationDatasetToVertex(fromValidationDataset, toObject));
|
|
16809
16942
|
}
|
|
16810
16943
|
const fromTunedModelDisplayName = getValueByPath(fromObject, [
|
|
16811
16944
|
'tunedModelDisplayName',
|
|
@@ -16937,6 +17070,14 @@ function tuningJobFromMldev(fromObject) {
|
|
|
16937
17070
|
if (fromPipelineJob != null) {
|
|
16938
17071
|
setValueByPath(toObject, ['pipelineJob'], fromPipelineJob);
|
|
16939
17072
|
}
|
|
17073
|
+
const fromSatisfiesPzi = getValueByPath(fromObject, ['satisfiesPzi']);
|
|
17074
|
+
if (fromSatisfiesPzi != null) {
|
|
17075
|
+
setValueByPath(toObject, ['satisfiesPzi'], fromSatisfiesPzi);
|
|
17076
|
+
}
|
|
17077
|
+
const fromSatisfiesPzs = getValueByPath(fromObject, ['satisfiesPzs']);
|
|
17078
|
+
if (fromSatisfiesPzs != null) {
|
|
17079
|
+
setValueByPath(toObject, ['satisfiesPzs'], fromSatisfiesPzs);
|
|
17080
|
+
}
|
|
16940
17081
|
const fromServiceAccount = getValueByPath(fromObject, [
|
|
16941
17082
|
'serviceAccount',
|
|
16942
17083
|
]);
|
|
@@ -17117,6 +17258,14 @@ function tuningJobFromVertex(fromObject) {
|
|
|
17117
17258
|
if (fromPipelineJob != null) {
|
|
17118
17259
|
setValueByPath(toObject, ['pipelineJob'], fromPipelineJob);
|
|
17119
17260
|
}
|
|
17261
|
+
const fromSatisfiesPzi = getValueByPath(fromObject, ['satisfiesPzi']);
|
|
17262
|
+
if (fromSatisfiesPzi != null) {
|
|
17263
|
+
setValueByPath(toObject, ['satisfiesPzi'], fromSatisfiesPzi);
|
|
17264
|
+
}
|
|
17265
|
+
const fromSatisfiesPzs = getValueByPath(fromObject, ['satisfiesPzs']);
|
|
17266
|
+
if (fromSatisfiesPzs != null) {
|
|
17267
|
+
setValueByPath(toObject, ['satisfiesPzs'], fromSatisfiesPzs);
|
|
17268
|
+
}
|
|
17120
17269
|
const fromServiceAccount = getValueByPath(fromObject, [
|
|
17121
17270
|
'serviceAccount',
|
|
17122
17271
|
]);
|
|
@@ -17492,5 +17641,5 @@ class GoogleGenAI {
|
|
|
17492
17641
|
}
|
|
17493
17642
|
}
|
|
17494
17643
|
|
|
17495
|
-
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 };
|
|
17644
|
+
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 };
|
|
17496
17645
|
//# sourceMappingURL=index.mjs.map
|