@google/genai 0.9.0 → 0.10.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 +30 -5
- package/dist/genai.d.ts +229 -2
- package/dist/index.js +297 -86
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +297 -87
- package/dist/index.mjs.map +1 -1
- package/dist/node/index.js +336 -86
- package/dist/node/index.js.map +1 -1
- package/dist/node/node.d.ts +229 -2
- package/dist/web/index.mjs +338 -87
- package/dist/web/index.mjs.map +1 -1
- package/dist/web/web.d.ts +229 -2
- package/package.json +1 -1
package/dist/node/index.js
CHANGED
|
@@ -24,6 +24,66 @@ function _interopNamespaceDefault(e) {
|
|
|
24
24
|
var NodeWs__namespace = /*#__PURE__*/_interopNamespaceDefault(NodeWs);
|
|
25
25
|
var fs__namespace = /*#__PURE__*/_interopNamespaceDefault(fs);
|
|
26
26
|
|
|
27
|
+
/**
|
|
28
|
+
* @license
|
|
29
|
+
* Copyright 2025 Google LLC
|
|
30
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
31
|
+
*/
|
|
32
|
+
let _defaultBaseGeminiUrl = undefined;
|
|
33
|
+
let _defaultBaseVertexUrl = undefined;
|
|
34
|
+
/**
|
|
35
|
+
* Overrides the base URLs for the Gemini API and Vertex AI API.
|
|
36
|
+
*
|
|
37
|
+
* @remarks This function should be called before initializing the SDK. If the
|
|
38
|
+
* base URLs are set after initializing the SDK, the base URLs will not be
|
|
39
|
+
* updated. Base URLs provided in the HttpOptions will also take precedence over
|
|
40
|
+
* URLs set here.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* import {GoogleGenAI, setDefaultBaseUrls} from '@google/genai';
|
|
45
|
+
* // Override the base URL for the Gemini API.
|
|
46
|
+
* setDefaultBaseUrls({geminiUrl:'https://gemini.google.com'});
|
|
47
|
+
*
|
|
48
|
+
* // Override the base URL for the Vertex AI API.
|
|
49
|
+
* setDefaultBaseUrls({vertexUrl: 'https://vertexai.googleapis.com'});
|
|
50
|
+
*
|
|
51
|
+
* const ai = new GoogleGenAI({apiKey: 'GEMINI_API_KEY'});
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
function setDefaultBaseUrls(baseUrlParams) {
|
|
55
|
+
_defaultBaseGeminiUrl = baseUrlParams.geminiUrl;
|
|
56
|
+
_defaultBaseVertexUrl = baseUrlParams.vertexUrl;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Returns the default base URLs for the Gemini API and Vertex AI API.
|
|
60
|
+
*/
|
|
61
|
+
function getDefaultBaseUrls() {
|
|
62
|
+
return {
|
|
63
|
+
geminiUrl: _defaultBaseGeminiUrl,
|
|
64
|
+
vertexUrl: _defaultBaseVertexUrl,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Returns the default base URL based on the following priority:
|
|
69
|
+
* 1. Base URLs set via HttpOptions.
|
|
70
|
+
* 2. Base URLs set via the latest call to setDefaultBaseUrls.
|
|
71
|
+
* 3. Base URLs set via environment variables.
|
|
72
|
+
*/
|
|
73
|
+
function getBaseUrl(options, vertexBaseUrlFromEnv, geminiBaseUrlFromEnv) {
|
|
74
|
+
var _a, _b, _c;
|
|
75
|
+
if (!((_a = options.httpOptions) === null || _a === void 0 ? void 0 : _a.baseUrl)) {
|
|
76
|
+
const defaultBaseUrls = getDefaultBaseUrls();
|
|
77
|
+
if (options.vertexai) {
|
|
78
|
+
return (_b = defaultBaseUrls.vertexUrl) !== null && _b !== void 0 ? _b : vertexBaseUrlFromEnv;
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
return (_c = defaultBaseUrls.geminiUrl) !== null && _c !== void 0 ? _c : geminiBaseUrlFromEnv;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return options.httpOptions.baseUrl;
|
|
85
|
+
}
|
|
86
|
+
|
|
27
87
|
/**
|
|
28
88
|
* @license
|
|
29
89
|
* Copyright 2025 Google LLC
|
|
@@ -199,6 +259,36 @@ function tCachesModel(apiClient, model) {
|
|
|
199
259
|
return transformedModel;
|
|
200
260
|
}
|
|
201
261
|
}
|
|
262
|
+
function tBlobs(apiClient, blobs) {
|
|
263
|
+
if (Array.isArray(blobs)) {
|
|
264
|
+
return blobs.map((blob) => tBlob(apiClient, blob));
|
|
265
|
+
}
|
|
266
|
+
else {
|
|
267
|
+
return [tBlob(apiClient, blobs)];
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
function tBlob(apiClient, blob) {
|
|
271
|
+
if (typeof blob === 'object' && blob !== null) {
|
|
272
|
+
return blob;
|
|
273
|
+
}
|
|
274
|
+
throw new Error(`Could not parse input as Blob. Unsupported blob type: ${typeof blob}`);
|
|
275
|
+
}
|
|
276
|
+
function tImageBlob(apiClient, blob) {
|
|
277
|
+
const transformedBlob = tBlob(apiClient, blob);
|
|
278
|
+
if (transformedBlob.mimeType &&
|
|
279
|
+
transformedBlob.mimeType.startsWith('image/')) {
|
|
280
|
+
return transformedBlob;
|
|
281
|
+
}
|
|
282
|
+
throw new Error(`Unsupported mime type: ${transformedBlob.mimeType}`);
|
|
283
|
+
}
|
|
284
|
+
function tAudioBlob(apiClient, blob) {
|
|
285
|
+
const transformedBlob = tBlob(apiClient, blob);
|
|
286
|
+
if (transformedBlob.mimeType &&
|
|
287
|
+
transformedBlob.mimeType.startsWith('audio/')) {
|
|
288
|
+
return transformedBlob;
|
|
289
|
+
}
|
|
290
|
+
throw new Error(`Unsupported mime type: ${transformedBlob.mimeType}`);
|
|
291
|
+
}
|
|
202
292
|
function tPart(apiClient, origin) {
|
|
203
293
|
if (origin === null || origin === undefined) {
|
|
204
294
|
throw new Error('PartUnion is required');
|
|
@@ -322,38 +412,11 @@ function tContents(apiClient, origin) {
|
|
|
322
412
|
}
|
|
323
413
|
return result;
|
|
324
414
|
}
|
|
325
|
-
function processSchema(apiClient, schema) {
|
|
326
|
-
if (!apiClient.isVertexAI()) {
|
|
327
|
-
if ('default' in schema) {
|
|
328
|
-
throw new Error('Default value is not supported in the response schema for the Gemini API.');
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
if ('anyOf' in schema) {
|
|
332
|
-
if (schema['anyOf'] !== undefined) {
|
|
333
|
-
for (const subSchema of schema['anyOf']) {
|
|
334
|
-
processSchema(apiClient, subSchema);
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
if ('items' in schema) {
|
|
339
|
-
if (schema['items'] !== undefined) {
|
|
340
|
-
processSchema(apiClient, schema['items']);
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
if ('properties' in schema) {
|
|
344
|
-
if (schema['properties'] !== undefined) {
|
|
345
|
-
for (const subSchema of Object.values(schema['properties'])) {
|
|
346
|
-
processSchema(apiClient, subSchema);
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
415
|
function tSchema(apiClient, schema) {
|
|
352
|
-
processSchema(apiClient, schema);
|
|
353
416
|
return schema;
|
|
354
417
|
}
|
|
355
418
|
function tSpeechConfig(apiClient, speechConfig) {
|
|
356
|
-
if (typeof speechConfig === 'object'
|
|
419
|
+
if (typeof speechConfig === 'object') {
|
|
357
420
|
return speechConfig;
|
|
358
421
|
}
|
|
359
422
|
else if (typeof speechConfig === 'string') {
|
|
@@ -1560,6 +1623,7 @@ exports.FinishReason = void 0;
|
|
|
1560
1623
|
FinishReason["MAX_TOKENS"] = "MAX_TOKENS";
|
|
1561
1624
|
FinishReason["SAFETY"] = "SAFETY";
|
|
1562
1625
|
FinishReason["RECITATION"] = "RECITATION";
|
|
1626
|
+
FinishReason["LANGUAGE"] = "LANGUAGE";
|
|
1563
1627
|
FinishReason["OTHER"] = "OTHER";
|
|
1564
1628
|
FinishReason["BLOCKLIST"] = "BLOCKLIST";
|
|
1565
1629
|
FinishReason["PROHIBITED_CONTENT"] = "PROHIBITED_CONTENT";
|
|
@@ -1942,6 +2006,42 @@ class GenerateContentResponse {
|
|
|
1942
2006
|
// part.text === '' is different from part.text is null
|
|
1943
2007
|
return anyTextPartText ? text : undefined;
|
|
1944
2008
|
}
|
|
2009
|
+
/**
|
|
2010
|
+
* Returns the concatenation of all inline data parts from the first candidate
|
|
2011
|
+
* in the response.
|
|
2012
|
+
*
|
|
2013
|
+
* @remarks
|
|
2014
|
+
* If there are multiple candidates in the response, the inline data from the
|
|
2015
|
+
* first one will be returned. If there are non-inline data parts in the
|
|
2016
|
+
* response, the concatenation of all inline data parts will be returned, and
|
|
2017
|
+
* a warning will be logged.
|
|
2018
|
+
*/
|
|
2019
|
+
get data() {
|
|
2020
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
2021
|
+
if (((_d = (_c = (_b = (_a = this.candidates) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.content) === null || _c === void 0 ? void 0 : _c.parts) === null || _d === void 0 ? void 0 : _d.length) === 0) {
|
|
2022
|
+
return undefined;
|
|
2023
|
+
}
|
|
2024
|
+
if (this.candidates && this.candidates.length > 1) {
|
|
2025
|
+
console.warn('there are multiple candidates in the response, returning data from the first one.');
|
|
2026
|
+
}
|
|
2027
|
+
let data = '';
|
|
2028
|
+
const nonDataParts = [];
|
|
2029
|
+
for (const part of (_h = (_g = (_f = (_e = this.candidates) === null || _e === void 0 ? void 0 : _e[0]) === null || _f === void 0 ? void 0 : _f.content) === null || _g === void 0 ? void 0 : _g.parts) !== null && _h !== void 0 ? _h : []) {
|
|
2030
|
+
for (const [fieldName, fieldValue] of Object.entries(part)) {
|
|
2031
|
+
if (fieldName !== 'inlineData' &&
|
|
2032
|
+
(fieldValue !== null || fieldValue !== undefined)) {
|
|
2033
|
+
nonDataParts.push(fieldName);
|
|
2034
|
+
}
|
|
2035
|
+
}
|
|
2036
|
+
if (part.inlineData && typeof part.inlineData.data === 'string') {
|
|
2037
|
+
data += atob(part.inlineData.data);
|
|
2038
|
+
}
|
|
2039
|
+
}
|
|
2040
|
+
if (nonDataParts.length > 0) {
|
|
2041
|
+
console.warn(`there are non-data parts ${nonDataParts} in the response, returning concatenation of all data parts. Please refer to the non data parts for a full response from model.`);
|
|
2042
|
+
}
|
|
2043
|
+
return data.length > 0 ? btoa(data) : undefined;
|
|
2044
|
+
}
|
|
1945
2045
|
/**
|
|
1946
2046
|
* Returns the function calls from the first candidate in the response.
|
|
1947
2047
|
*
|
|
@@ -2197,7 +2297,7 @@ class Caches extends BaseModule {
|
|
|
2197
2297
|
* ```
|
|
2198
2298
|
*/
|
|
2199
2299
|
async create(params) {
|
|
2200
|
-
var _a, _b;
|
|
2300
|
+
var _a, _b, _c, _d;
|
|
2201
2301
|
let response;
|
|
2202
2302
|
let path = '';
|
|
2203
2303
|
let queryParams = {};
|
|
@@ -2215,6 +2315,7 @@ class Caches extends BaseModule {
|
|
|
2215
2315
|
body: JSON.stringify(body),
|
|
2216
2316
|
httpMethod: 'POST',
|
|
2217
2317
|
httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
|
|
2318
|
+
abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
|
|
2218
2319
|
})
|
|
2219
2320
|
.then((httpResponse) => {
|
|
2220
2321
|
return httpResponse.json();
|
|
@@ -2237,7 +2338,8 @@ class Caches extends BaseModule {
|
|
|
2237
2338
|
queryParams: queryParams,
|
|
2238
2339
|
body: JSON.stringify(body),
|
|
2239
2340
|
httpMethod: 'POST',
|
|
2240
|
-
httpOptions: (
|
|
2341
|
+
httpOptions: (_c = params.config) === null || _c === void 0 ? void 0 : _c.httpOptions,
|
|
2342
|
+
abortSignal: (_d = params.config) === null || _d === void 0 ? void 0 : _d.abortSignal,
|
|
2241
2343
|
})
|
|
2242
2344
|
.then((httpResponse) => {
|
|
2243
2345
|
return httpResponse.json();
|
|
@@ -2260,7 +2362,7 @@ class Caches extends BaseModule {
|
|
|
2260
2362
|
* ```
|
|
2261
2363
|
*/
|
|
2262
2364
|
async get(params) {
|
|
2263
|
-
var _a, _b;
|
|
2365
|
+
var _a, _b, _c, _d;
|
|
2264
2366
|
let response;
|
|
2265
2367
|
let path = '';
|
|
2266
2368
|
let queryParams = {};
|
|
@@ -2278,6 +2380,7 @@ class Caches extends BaseModule {
|
|
|
2278
2380
|
body: JSON.stringify(body),
|
|
2279
2381
|
httpMethod: 'GET',
|
|
2280
2382
|
httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
|
|
2383
|
+
abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
|
|
2281
2384
|
})
|
|
2282
2385
|
.then((httpResponse) => {
|
|
2283
2386
|
return httpResponse.json();
|
|
@@ -2300,7 +2403,8 @@ class Caches extends BaseModule {
|
|
|
2300
2403
|
queryParams: queryParams,
|
|
2301
2404
|
body: JSON.stringify(body),
|
|
2302
2405
|
httpMethod: 'GET',
|
|
2303
|
-
httpOptions: (
|
|
2406
|
+
httpOptions: (_c = params.config) === null || _c === void 0 ? void 0 : _c.httpOptions,
|
|
2407
|
+
abortSignal: (_d = params.config) === null || _d === void 0 ? void 0 : _d.abortSignal,
|
|
2304
2408
|
})
|
|
2305
2409
|
.then((httpResponse) => {
|
|
2306
2410
|
return httpResponse.json();
|
|
@@ -2323,7 +2427,7 @@ class Caches extends BaseModule {
|
|
|
2323
2427
|
* ```
|
|
2324
2428
|
*/
|
|
2325
2429
|
async delete(params) {
|
|
2326
|
-
var _a, _b;
|
|
2430
|
+
var _a, _b, _c, _d;
|
|
2327
2431
|
let response;
|
|
2328
2432
|
let path = '';
|
|
2329
2433
|
let queryParams = {};
|
|
@@ -2341,6 +2445,7 @@ class Caches extends BaseModule {
|
|
|
2341
2445
|
body: JSON.stringify(body),
|
|
2342
2446
|
httpMethod: 'DELETE',
|
|
2343
2447
|
httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
|
|
2448
|
+
abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
|
|
2344
2449
|
})
|
|
2345
2450
|
.then((httpResponse) => {
|
|
2346
2451
|
return httpResponse.json();
|
|
@@ -2365,7 +2470,8 @@ class Caches extends BaseModule {
|
|
|
2365
2470
|
queryParams: queryParams,
|
|
2366
2471
|
body: JSON.stringify(body),
|
|
2367
2472
|
httpMethod: 'DELETE',
|
|
2368
|
-
httpOptions: (
|
|
2473
|
+
httpOptions: (_c = params.config) === null || _c === void 0 ? void 0 : _c.httpOptions,
|
|
2474
|
+
abortSignal: (_d = params.config) === null || _d === void 0 ? void 0 : _d.abortSignal,
|
|
2369
2475
|
})
|
|
2370
2476
|
.then((httpResponse) => {
|
|
2371
2477
|
return httpResponse.json();
|
|
@@ -2393,7 +2499,7 @@ class Caches extends BaseModule {
|
|
|
2393
2499
|
* ```
|
|
2394
2500
|
*/
|
|
2395
2501
|
async update(params) {
|
|
2396
|
-
var _a, _b;
|
|
2502
|
+
var _a, _b, _c, _d;
|
|
2397
2503
|
let response;
|
|
2398
2504
|
let path = '';
|
|
2399
2505
|
let queryParams = {};
|
|
@@ -2411,6 +2517,7 @@ class Caches extends BaseModule {
|
|
|
2411
2517
|
body: JSON.stringify(body),
|
|
2412
2518
|
httpMethod: 'PATCH',
|
|
2413
2519
|
httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
|
|
2520
|
+
abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
|
|
2414
2521
|
})
|
|
2415
2522
|
.then((httpResponse) => {
|
|
2416
2523
|
return httpResponse.json();
|
|
@@ -2433,7 +2540,8 @@ class Caches extends BaseModule {
|
|
|
2433
2540
|
queryParams: queryParams,
|
|
2434
2541
|
body: JSON.stringify(body),
|
|
2435
2542
|
httpMethod: 'PATCH',
|
|
2436
|
-
httpOptions: (
|
|
2543
|
+
httpOptions: (_c = params.config) === null || _c === void 0 ? void 0 : _c.httpOptions,
|
|
2544
|
+
abortSignal: (_d = params.config) === null || _d === void 0 ? void 0 : _d.abortSignal,
|
|
2437
2545
|
})
|
|
2438
2546
|
.then((httpResponse) => {
|
|
2439
2547
|
return httpResponse.json();
|
|
@@ -2445,7 +2553,7 @@ class Caches extends BaseModule {
|
|
|
2445
2553
|
}
|
|
2446
2554
|
}
|
|
2447
2555
|
async listInternal(params) {
|
|
2448
|
-
var _a, _b;
|
|
2556
|
+
var _a, _b, _c, _d;
|
|
2449
2557
|
let response;
|
|
2450
2558
|
let path = '';
|
|
2451
2559
|
let queryParams = {};
|
|
@@ -2463,6 +2571,7 @@ class Caches extends BaseModule {
|
|
|
2463
2571
|
body: JSON.stringify(body),
|
|
2464
2572
|
httpMethod: 'GET',
|
|
2465
2573
|
httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
|
|
2574
|
+
abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
|
|
2466
2575
|
})
|
|
2467
2576
|
.then((httpResponse) => {
|
|
2468
2577
|
return httpResponse.json();
|
|
@@ -2487,7 +2596,8 @@ class Caches extends BaseModule {
|
|
|
2487
2596
|
queryParams: queryParams,
|
|
2488
2597
|
body: JSON.stringify(body),
|
|
2489
2598
|
httpMethod: 'GET',
|
|
2490
|
-
httpOptions: (
|
|
2599
|
+
httpOptions: (_c = params.config) === null || _c === void 0 ? void 0 : _c.httpOptions,
|
|
2600
|
+
abortSignal: (_d = params.config) === null || _d === void 0 ? void 0 : _d.abortSignal,
|
|
2491
2601
|
})
|
|
2492
2602
|
.then((httpResponse) => {
|
|
2493
2603
|
return httpResponse.json();
|
|
@@ -3196,7 +3306,7 @@ class Files extends BaseModule {
|
|
|
3196
3306
|
});
|
|
3197
3307
|
}
|
|
3198
3308
|
async listInternal(params) {
|
|
3199
|
-
var _a;
|
|
3309
|
+
var _a, _b;
|
|
3200
3310
|
let response;
|
|
3201
3311
|
let path = '';
|
|
3202
3312
|
let queryParams = {};
|
|
@@ -3217,6 +3327,7 @@ class Files extends BaseModule {
|
|
|
3217
3327
|
body: JSON.stringify(body),
|
|
3218
3328
|
httpMethod: 'GET',
|
|
3219
3329
|
httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
|
|
3330
|
+
abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
|
|
3220
3331
|
})
|
|
3221
3332
|
.then((httpResponse) => {
|
|
3222
3333
|
return httpResponse.json();
|
|
@@ -3230,7 +3341,7 @@ class Files extends BaseModule {
|
|
|
3230
3341
|
}
|
|
3231
3342
|
}
|
|
3232
3343
|
async createInternal(params) {
|
|
3233
|
-
var _a;
|
|
3344
|
+
var _a, _b;
|
|
3234
3345
|
let response;
|
|
3235
3346
|
let path = '';
|
|
3236
3347
|
let queryParams = {};
|
|
@@ -3251,6 +3362,7 @@ class Files extends BaseModule {
|
|
|
3251
3362
|
body: JSON.stringify(body),
|
|
3252
3363
|
httpMethod: 'POST',
|
|
3253
3364
|
httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
|
|
3365
|
+
abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
|
|
3254
3366
|
})
|
|
3255
3367
|
.then((httpResponse) => {
|
|
3256
3368
|
return httpResponse.json();
|
|
@@ -3279,7 +3391,7 @@ class Files extends BaseModule {
|
|
|
3279
3391
|
* ```
|
|
3280
3392
|
*/
|
|
3281
3393
|
async get(params) {
|
|
3282
|
-
var _a;
|
|
3394
|
+
var _a, _b;
|
|
3283
3395
|
let response;
|
|
3284
3396
|
let path = '';
|
|
3285
3397
|
let queryParams = {};
|
|
@@ -3300,6 +3412,7 @@ class Files extends BaseModule {
|
|
|
3300
3412
|
body: JSON.stringify(body),
|
|
3301
3413
|
httpMethod: 'GET',
|
|
3302
3414
|
httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
|
|
3415
|
+
abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
|
|
3303
3416
|
})
|
|
3304
3417
|
.then((httpResponse) => {
|
|
3305
3418
|
return httpResponse.json();
|
|
@@ -3324,7 +3437,7 @@ class Files extends BaseModule {
|
|
|
3324
3437
|
* ```
|
|
3325
3438
|
*/
|
|
3326
3439
|
async delete(params) {
|
|
3327
|
-
var _a;
|
|
3440
|
+
var _a, _b;
|
|
3328
3441
|
let response;
|
|
3329
3442
|
let path = '';
|
|
3330
3443
|
let queryParams = {};
|
|
@@ -3345,6 +3458,7 @@ class Files extends BaseModule {
|
|
|
3345
3458
|
body: JSON.stringify(body),
|
|
3346
3459
|
httpMethod: 'DELETE',
|
|
3347
3460
|
httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
|
|
3461
|
+
abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
|
|
3348
3462
|
})
|
|
3349
3463
|
.then((httpResponse) => {
|
|
3350
3464
|
return httpResponse.json();
|
|
@@ -4155,6 +4269,91 @@ function liveConnectParametersToVertex(apiClient, fromObject) {
|
|
|
4155
4269
|
}
|
|
4156
4270
|
return toObject;
|
|
4157
4271
|
}
|
|
4272
|
+
function activityStartToMldev() {
|
|
4273
|
+
const toObject = {};
|
|
4274
|
+
return toObject;
|
|
4275
|
+
}
|
|
4276
|
+
function activityStartToVertex() {
|
|
4277
|
+
const toObject = {};
|
|
4278
|
+
return toObject;
|
|
4279
|
+
}
|
|
4280
|
+
function activityEndToMldev() {
|
|
4281
|
+
const toObject = {};
|
|
4282
|
+
return toObject;
|
|
4283
|
+
}
|
|
4284
|
+
function activityEndToVertex() {
|
|
4285
|
+
const toObject = {};
|
|
4286
|
+
return toObject;
|
|
4287
|
+
}
|
|
4288
|
+
function liveSendRealtimeInputParametersToMldev(apiClient, fromObject) {
|
|
4289
|
+
const toObject = {};
|
|
4290
|
+
const fromMedia = getValueByPath(fromObject, ['media']);
|
|
4291
|
+
if (fromMedia != null) {
|
|
4292
|
+
setValueByPath(toObject, ['mediaChunks'], tBlobs(apiClient, fromMedia));
|
|
4293
|
+
}
|
|
4294
|
+
const fromAudio = getValueByPath(fromObject, ['audio']);
|
|
4295
|
+
if (fromAudio != null) {
|
|
4296
|
+
setValueByPath(toObject, ['audio'], tAudioBlob(apiClient, fromAudio));
|
|
4297
|
+
}
|
|
4298
|
+
const fromAudioStreamEnd = getValueByPath(fromObject, [
|
|
4299
|
+
'audioStreamEnd',
|
|
4300
|
+
]);
|
|
4301
|
+
if (fromAudioStreamEnd != null) {
|
|
4302
|
+
setValueByPath(toObject, ['audioStreamEnd'], fromAudioStreamEnd);
|
|
4303
|
+
}
|
|
4304
|
+
const fromVideo = getValueByPath(fromObject, ['video']);
|
|
4305
|
+
if (fromVideo != null) {
|
|
4306
|
+
setValueByPath(toObject, ['video'], tImageBlob(apiClient, fromVideo));
|
|
4307
|
+
}
|
|
4308
|
+
const fromText = getValueByPath(fromObject, ['text']);
|
|
4309
|
+
if (fromText != null) {
|
|
4310
|
+
setValueByPath(toObject, ['text'], fromText);
|
|
4311
|
+
}
|
|
4312
|
+
const fromActivityStart = getValueByPath(fromObject, [
|
|
4313
|
+
'activityStart',
|
|
4314
|
+
]);
|
|
4315
|
+
if (fromActivityStart != null) {
|
|
4316
|
+
setValueByPath(toObject, ['activityStart'], activityStartToMldev());
|
|
4317
|
+
}
|
|
4318
|
+
const fromActivityEnd = getValueByPath(fromObject, ['activityEnd']);
|
|
4319
|
+
if (fromActivityEnd != null) {
|
|
4320
|
+
setValueByPath(toObject, ['activityEnd'], activityEndToMldev());
|
|
4321
|
+
}
|
|
4322
|
+
return toObject;
|
|
4323
|
+
}
|
|
4324
|
+
function liveSendRealtimeInputParametersToVertex(apiClient, fromObject) {
|
|
4325
|
+
const toObject = {};
|
|
4326
|
+
const fromMedia = getValueByPath(fromObject, ['media']);
|
|
4327
|
+
if (fromMedia != null) {
|
|
4328
|
+
setValueByPath(toObject, ['mediaChunks'], tBlobs(apiClient, fromMedia));
|
|
4329
|
+
}
|
|
4330
|
+
if (getValueByPath(fromObject, ['audio']) !== undefined) {
|
|
4331
|
+
throw new Error('audio parameter is not supported in Vertex AI.');
|
|
4332
|
+
}
|
|
4333
|
+
const fromAudioStreamEnd = getValueByPath(fromObject, [
|
|
4334
|
+
'audioStreamEnd',
|
|
4335
|
+
]);
|
|
4336
|
+
if (fromAudioStreamEnd != null) {
|
|
4337
|
+
setValueByPath(toObject, ['audioStreamEnd'], fromAudioStreamEnd);
|
|
4338
|
+
}
|
|
4339
|
+
if (getValueByPath(fromObject, ['video']) !== undefined) {
|
|
4340
|
+
throw new Error('video parameter is not supported in Vertex AI.');
|
|
4341
|
+
}
|
|
4342
|
+
if (getValueByPath(fromObject, ['text']) !== undefined) {
|
|
4343
|
+
throw new Error('text parameter is not supported in Vertex AI.');
|
|
4344
|
+
}
|
|
4345
|
+
const fromActivityStart = getValueByPath(fromObject, [
|
|
4346
|
+
'activityStart',
|
|
4347
|
+
]);
|
|
4348
|
+
if (fromActivityStart != null) {
|
|
4349
|
+
setValueByPath(toObject, ['activityStart'], activityStartToVertex());
|
|
4350
|
+
}
|
|
4351
|
+
const fromActivityEnd = getValueByPath(fromObject, ['activityEnd']);
|
|
4352
|
+
if (fromActivityEnd != null) {
|
|
4353
|
+
setValueByPath(toObject, ['activityEnd'], activityEndToVertex());
|
|
4354
|
+
}
|
|
4355
|
+
return toObject;
|
|
4356
|
+
}
|
|
4158
4357
|
function liveServerSetupCompleteFromMldev() {
|
|
4159
4358
|
const toObject = {};
|
|
4160
4359
|
return toObject;
|
|
@@ -7502,21 +7701,6 @@ class Session {
|
|
|
7502
7701
|
clientContent: { turnComplete: params.turnComplete },
|
|
7503
7702
|
};
|
|
7504
7703
|
}
|
|
7505
|
-
tLiveClientRealtimeInput(apiClient, params) {
|
|
7506
|
-
let clientMessage = {};
|
|
7507
|
-
if (!('media' in params) || !params.media) {
|
|
7508
|
-
throw new Error(`Failed to convert realtime input "media", type: '${typeof params.media}'`);
|
|
7509
|
-
}
|
|
7510
|
-
// LiveClientRealtimeInput
|
|
7511
|
-
clientMessage = {
|
|
7512
|
-
realtimeInput: {
|
|
7513
|
-
mediaChunks: [params.media],
|
|
7514
|
-
activityStart: params.activityStart,
|
|
7515
|
-
activityEnd: params.activityEnd,
|
|
7516
|
-
},
|
|
7517
|
-
};
|
|
7518
|
-
return clientMessage;
|
|
7519
|
-
}
|
|
7520
7704
|
tLiveClienttToolResponse(apiClient, params) {
|
|
7521
7705
|
let functionResponses = [];
|
|
7522
7706
|
if (params.functionResponses == null) {
|
|
@@ -7624,10 +7808,17 @@ class Session {
|
|
|
7624
7808
|
of audio and image mimetypes are allowed.
|
|
7625
7809
|
*/
|
|
7626
7810
|
sendRealtimeInput(params) {
|
|
7627
|
-
|
|
7628
|
-
|
|
7811
|
+
let clientMessage = {};
|
|
7812
|
+
if (this.apiClient.isVertexAI()) {
|
|
7813
|
+
clientMessage = {
|
|
7814
|
+
'realtimeInput': liveSendRealtimeInputParametersToVertex(this.apiClient, params),
|
|
7815
|
+
};
|
|
7816
|
+
}
|
|
7817
|
+
else {
|
|
7818
|
+
clientMessage = {
|
|
7819
|
+
'realtimeInput': liveSendRealtimeInputParametersToMldev(this.apiClient, params),
|
|
7820
|
+
};
|
|
7629
7821
|
}
|
|
7630
|
-
const clientMessage = this.tLiveClientRealtimeInput(this.apiClient, params);
|
|
7631
7822
|
this.conn.send(JSON.stringify(clientMessage));
|
|
7632
7823
|
}
|
|
7633
7824
|
/**
|
|
@@ -7848,7 +8039,7 @@ class Models extends BaseModule {
|
|
|
7848
8039
|
};
|
|
7849
8040
|
}
|
|
7850
8041
|
async generateContentInternal(params) {
|
|
7851
|
-
var _a, _b;
|
|
8042
|
+
var _a, _b, _c, _d;
|
|
7852
8043
|
let response;
|
|
7853
8044
|
let path = '';
|
|
7854
8045
|
let queryParams = {};
|
|
@@ -7866,6 +8057,7 @@ class Models extends BaseModule {
|
|
|
7866
8057
|
body: JSON.stringify(body),
|
|
7867
8058
|
httpMethod: 'POST',
|
|
7868
8059
|
httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
|
|
8060
|
+
abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
|
|
7869
8061
|
})
|
|
7870
8062
|
.then((httpResponse) => {
|
|
7871
8063
|
return httpResponse.json();
|
|
@@ -7890,7 +8082,8 @@ class Models extends BaseModule {
|
|
|
7890
8082
|
queryParams: queryParams,
|
|
7891
8083
|
body: JSON.stringify(body),
|
|
7892
8084
|
httpMethod: 'POST',
|
|
7893
|
-
httpOptions: (
|
|
8085
|
+
httpOptions: (_c = params.config) === null || _c === void 0 ? void 0 : _c.httpOptions,
|
|
8086
|
+
abortSignal: (_d = params.config) === null || _d === void 0 ? void 0 : _d.abortSignal,
|
|
7894
8087
|
})
|
|
7895
8088
|
.then((httpResponse) => {
|
|
7896
8089
|
return httpResponse.json();
|
|
@@ -7904,7 +8097,7 @@ class Models extends BaseModule {
|
|
|
7904
8097
|
}
|
|
7905
8098
|
}
|
|
7906
8099
|
async generateContentStreamInternal(params) {
|
|
7907
|
-
var _a, _b;
|
|
8100
|
+
var _a, _b, _c, _d;
|
|
7908
8101
|
let response;
|
|
7909
8102
|
let path = '';
|
|
7910
8103
|
let queryParams = {};
|
|
@@ -7922,6 +8115,7 @@ class Models extends BaseModule {
|
|
|
7922
8115
|
body: JSON.stringify(body),
|
|
7923
8116
|
httpMethod: 'POST',
|
|
7924
8117
|
httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
|
|
8118
|
+
abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
|
|
7925
8119
|
});
|
|
7926
8120
|
return response.then(function (apiResponse) {
|
|
7927
8121
|
return __asyncGenerator(this, arguments, function* () {
|
|
@@ -7960,7 +8154,8 @@ class Models extends BaseModule {
|
|
|
7960
8154
|
queryParams: queryParams,
|
|
7961
8155
|
body: JSON.stringify(body),
|
|
7962
8156
|
httpMethod: 'POST',
|
|
7963
|
-
httpOptions: (
|
|
8157
|
+
httpOptions: (_c = params.config) === null || _c === void 0 ? void 0 : _c.httpOptions,
|
|
8158
|
+
abortSignal: (_d = params.config) === null || _d === void 0 ? void 0 : _d.abortSignal,
|
|
7964
8159
|
});
|
|
7965
8160
|
return response.then(function (apiResponse) {
|
|
7966
8161
|
return __asyncGenerator(this, arguments, function* () {
|
|
@@ -8009,7 +8204,7 @@ class Models extends BaseModule {
|
|
|
8009
8204
|
* ```
|
|
8010
8205
|
*/
|
|
8011
8206
|
async embedContent(params) {
|
|
8012
|
-
var _a, _b;
|
|
8207
|
+
var _a, _b, _c, _d;
|
|
8013
8208
|
let response;
|
|
8014
8209
|
let path = '';
|
|
8015
8210
|
let queryParams = {};
|
|
@@ -8027,6 +8222,7 @@ class Models extends BaseModule {
|
|
|
8027
8222
|
body: JSON.stringify(body),
|
|
8028
8223
|
httpMethod: 'POST',
|
|
8029
8224
|
httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
|
|
8225
|
+
abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
|
|
8030
8226
|
})
|
|
8031
8227
|
.then((httpResponse) => {
|
|
8032
8228
|
return httpResponse.json();
|
|
@@ -8051,7 +8247,8 @@ class Models extends BaseModule {
|
|
|
8051
8247
|
queryParams: queryParams,
|
|
8052
8248
|
body: JSON.stringify(body),
|
|
8053
8249
|
httpMethod: 'POST',
|
|
8054
|
-
httpOptions: (
|
|
8250
|
+
httpOptions: (_c = params.config) === null || _c === void 0 ? void 0 : _c.httpOptions,
|
|
8251
|
+
abortSignal: (_d = params.config) === null || _d === void 0 ? void 0 : _d.abortSignal,
|
|
8055
8252
|
})
|
|
8056
8253
|
.then((httpResponse) => {
|
|
8057
8254
|
return httpResponse.json();
|
|
@@ -8084,7 +8281,7 @@ class Models extends BaseModule {
|
|
|
8084
8281
|
* ```
|
|
8085
8282
|
*/
|
|
8086
8283
|
async generateImagesInternal(params) {
|
|
8087
|
-
var _a, _b;
|
|
8284
|
+
var _a, _b, _c, _d;
|
|
8088
8285
|
let response;
|
|
8089
8286
|
let path = '';
|
|
8090
8287
|
let queryParams = {};
|
|
@@ -8102,6 +8299,7 @@ class Models extends BaseModule {
|
|
|
8102
8299
|
body: JSON.stringify(body),
|
|
8103
8300
|
httpMethod: 'POST',
|
|
8104
8301
|
httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
|
|
8302
|
+
abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
|
|
8105
8303
|
})
|
|
8106
8304
|
.then((httpResponse) => {
|
|
8107
8305
|
return httpResponse.json();
|
|
@@ -8126,7 +8324,8 @@ class Models extends BaseModule {
|
|
|
8126
8324
|
queryParams: queryParams,
|
|
8127
8325
|
body: JSON.stringify(body),
|
|
8128
8326
|
httpMethod: 'POST',
|
|
8129
|
-
httpOptions: (
|
|
8327
|
+
httpOptions: (_c = params.config) === null || _c === void 0 ? void 0 : _c.httpOptions,
|
|
8328
|
+
abortSignal: (_d = params.config) === null || _d === void 0 ? void 0 : _d.abortSignal,
|
|
8130
8329
|
})
|
|
8131
8330
|
.then((httpResponse) => {
|
|
8132
8331
|
return httpResponse.json();
|
|
@@ -8148,7 +8347,7 @@ class Models extends BaseModule {
|
|
|
8148
8347
|
* ```
|
|
8149
8348
|
*/
|
|
8150
8349
|
async get(params) {
|
|
8151
|
-
var _a, _b;
|
|
8350
|
+
var _a, _b, _c, _d;
|
|
8152
8351
|
let response;
|
|
8153
8352
|
let path = '';
|
|
8154
8353
|
let queryParams = {};
|
|
@@ -8166,6 +8365,7 @@ class Models extends BaseModule {
|
|
|
8166
8365
|
body: JSON.stringify(body),
|
|
8167
8366
|
httpMethod: 'GET',
|
|
8168
8367
|
httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
|
|
8368
|
+
abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
|
|
8169
8369
|
})
|
|
8170
8370
|
.then((httpResponse) => {
|
|
8171
8371
|
return httpResponse.json();
|
|
@@ -8188,7 +8388,8 @@ class Models extends BaseModule {
|
|
|
8188
8388
|
queryParams: queryParams,
|
|
8189
8389
|
body: JSON.stringify(body),
|
|
8190
8390
|
httpMethod: 'GET',
|
|
8191
|
-
httpOptions: (
|
|
8391
|
+
httpOptions: (_c = params.config) === null || _c === void 0 ? void 0 : _c.httpOptions,
|
|
8392
|
+
abortSignal: (_d = params.config) === null || _d === void 0 ? void 0 : _d.abortSignal,
|
|
8192
8393
|
})
|
|
8193
8394
|
.then((httpResponse) => {
|
|
8194
8395
|
return httpResponse.json();
|
|
@@ -8216,7 +8417,7 @@ class Models extends BaseModule {
|
|
|
8216
8417
|
* ```
|
|
8217
8418
|
*/
|
|
8218
8419
|
async countTokens(params) {
|
|
8219
|
-
var _a, _b;
|
|
8420
|
+
var _a, _b, _c, _d;
|
|
8220
8421
|
let response;
|
|
8221
8422
|
let path = '';
|
|
8222
8423
|
let queryParams = {};
|
|
@@ -8234,6 +8435,7 @@ class Models extends BaseModule {
|
|
|
8234
8435
|
body: JSON.stringify(body),
|
|
8235
8436
|
httpMethod: 'POST',
|
|
8236
8437
|
httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
|
|
8438
|
+
abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
|
|
8237
8439
|
})
|
|
8238
8440
|
.then((httpResponse) => {
|
|
8239
8441
|
return httpResponse.json();
|
|
@@ -8258,7 +8460,8 @@ class Models extends BaseModule {
|
|
|
8258
8460
|
queryParams: queryParams,
|
|
8259
8461
|
body: JSON.stringify(body),
|
|
8260
8462
|
httpMethod: 'POST',
|
|
8261
|
-
httpOptions: (
|
|
8463
|
+
httpOptions: (_c = params.config) === null || _c === void 0 ? void 0 : _c.httpOptions,
|
|
8464
|
+
abortSignal: (_d = params.config) === null || _d === void 0 ? void 0 : _d.abortSignal,
|
|
8262
8465
|
})
|
|
8263
8466
|
.then((httpResponse) => {
|
|
8264
8467
|
return httpResponse.json();
|
|
@@ -8290,7 +8493,7 @@ class Models extends BaseModule {
|
|
|
8290
8493
|
* ```
|
|
8291
8494
|
*/
|
|
8292
8495
|
async computeTokens(params) {
|
|
8293
|
-
var _a;
|
|
8496
|
+
var _a, _b;
|
|
8294
8497
|
let response;
|
|
8295
8498
|
let path = '';
|
|
8296
8499
|
let queryParams = {};
|
|
@@ -8308,6 +8511,7 @@ class Models extends BaseModule {
|
|
|
8308
8511
|
body: JSON.stringify(body),
|
|
8309
8512
|
httpMethod: 'POST',
|
|
8310
8513
|
httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
|
|
8514
|
+
abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
|
|
8311
8515
|
})
|
|
8312
8516
|
.then((httpResponse) => {
|
|
8313
8517
|
return httpResponse.json();
|
|
@@ -8347,7 +8551,7 @@ class Models extends BaseModule {
|
|
|
8347
8551
|
* ```
|
|
8348
8552
|
*/
|
|
8349
8553
|
async generateVideos(params) {
|
|
8350
|
-
var _a, _b;
|
|
8554
|
+
var _a, _b, _c, _d;
|
|
8351
8555
|
let response;
|
|
8352
8556
|
let path = '';
|
|
8353
8557
|
let queryParams = {};
|
|
@@ -8365,6 +8569,7 @@ class Models extends BaseModule {
|
|
|
8365
8569
|
body: JSON.stringify(body),
|
|
8366
8570
|
httpMethod: 'POST',
|
|
8367
8571
|
httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
|
|
8572
|
+
abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
|
|
8368
8573
|
})
|
|
8369
8574
|
.then((httpResponse) => {
|
|
8370
8575
|
return httpResponse.json();
|
|
@@ -8387,7 +8592,8 @@ class Models extends BaseModule {
|
|
|
8387
8592
|
queryParams: queryParams,
|
|
8388
8593
|
body: JSON.stringify(body),
|
|
8389
8594
|
httpMethod: 'POST',
|
|
8390
|
-
httpOptions: (
|
|
8595
|
+
httpOptions: (_c = params.config) === null || _c === void 0 ? void 0 : _c.httpOptions,
|
|
8596
|
+
abortSignal: (_d = params.config) === null || _d === void 0 ? void 0 : _d.abortSignal,
|
|
8391
8597
|
})
|
|
8392
8598
|
.then((httpResponse) => {
|
|
8393
8599
|
return httpResponse.json();
|
|
@@ -8654,7 +8860,7 @@ class Operations extends BaseModule {
|
|
|
8654
8860
|
}
|
|
8655
8861
|
}
|
|
8656
8862
|
async getVideosOperationInternal(params) {
|
|
8657
|
-
var _a, _b;
|
|
8863
|
+
var _a, _b, _c, _d;
|
|
8658
8864
|
let response;
|
|
8659
8865
|
let path = '';
|
|
8660
8866
|
let queryParams = {};
|
|
@@ -8672,6 +8878,7 @@ class Operations extends BaseModule {
|
|
|
8672
8878
|
body: JSON.stringify(body),
|
|
8673
8879
|
httpMethod: 'GET',
|
|
8674
8880
|
httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
|
|
8881
|
+
abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
|
|
8675
8882
|
})
|
|
8676
8883
|
.then((httpResponse) => {
|
|
8677
8884
|
return httpResponse.json();
|
|
@@ -8694,7 +8901,8 @@ class Operations extends BaseModule {
|
|
|
8694
8901
|
queryParams: queryParams,
|
|
8695
8902
|
body: JSON.stringify(body),
|
|
8696
8903
|
httpMethod: 'GET',
|
|
8697
|
-
httpOptions: (
|
|
8904
|
+
httpOptions: (_c = params.config) === null || _c === void 0 ? void 0 : _c.httpOptions,
|
|
8905
|
+
abortSignal: (_d = params.config) === null || _d === void 0 ? void 0 : _d.abortSignal,
|
|
8698
8906
|
})
|
|
8699
8907
|
.then((httpResponse) => {
|
|
8700
8908
|
return httpResponse.json();
|
|
@@ -8706,7 +8914,7 @@ class Operations extends BaseModule {
|
|
|
8706
8914
|
}
|
|
8707
8915
|
}
|
|
8708
8916
|
async fetchPredictVideosOperationInternal(params) {
|
|
8709
|
-
var _a;
|
|
8917
|
+
var _a, _b;
|
|
8710
8918
|
let response;
|
|
8711
8919
|
let path = '';
|
|
8712
8920
|
let queryParams = {};
|
|
@@ -8724,6 +8932,7 @@ class Operations extends BaseModule {
|
|
|
8724
8932
|
body: JSON.stringify(body),
|
|
8725
8933
|
httpMethod: 'POST',
|
|
8726
8934
|
httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
|
|
8935
|
+
abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
|
|
8727
8936
|
})
|
|
8728
8937
|
.then((httpResponse) => {
|
|
8729
8938
|
return httpResponse.json();
|
|
@@ -8748,7 +8957,7 @@ const CONTENT_TYPE_HEADER = 'Content-Type';
|
|
|
8748
8957
|
const SERVER_TIMEOUT_HEADER = 'X-Server-Timeout';
|
|
8749
8958
|
const USER_AGENT_HEADER = 'User-Agent';
|
|
8750
8959
|
const GOOGLE_API_CLIENT_HEADER = 'x-goog-api-client';
|
|
8751
|
-
const SDK_VERSION = '0.
|
|
8960
|
+
const SDK_VERSION = '0.10.0'; // x-release-please-version
|
|
8752
8961
|
const LIBRARY_LABEL = `google-genai-sdk/${SDK_VERSION}`;
|
|
8753
8962
|
const VERTEX_AI_API_DEFAULT_VERSION = 'v1beta1';
|
|
8754
8963
|
const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
|
|
@@ -8877,7 +9086,7 @@ class ApiClient {
|
|
|
8877
9086
|
getWebsocketBaseUrl() {
|
|
8878
9087
|
const baseUrl = this.getBaseUrl();
|
|
8879
9088
|
const urlParts = new URL(baseUrl);
|
|
8880
|
-
urlParts.protocol = 'wss';
|
|
9089
|
+
urlParts.protocol = urlParts.protocol == 'http:' ? 'ws' : 'wss';
|
|
8881
9090
|
return urlParts.toString();
|
|
8882
9091
|
}
|
|
8883
9092
|
setBaseUrl(url) {
|
|
@@ -8941,7 +9150,7 @@ class ApiClient {
|
|
|
8941
9150
|
else {
|
|
8942
9151
|
requestInit.body = request.body;
|
|
8943
9152
|
}
|
|
8944
|
-
requestInit = await this.includeExtraHttpOptionsToRequestInit(requestInit, patchedHttpOptions);
|
|
9153
|
+
requestInit = await this.includeExtraHttpOptionsToRequestInit(requestInit, patchedHttpOptions, request.abortSignal);
|
|
8945
9154
|
return this.unaryApiCall(url, requestInit, request.httpMethod);
|
|
8946
9155
|
}
|
|
8947
9156
|
patchHttpOptions(baseHttpOptions, requestHttpOptions) {
|
|
@@ -8975,14 +9184,21 @@ class ApiClient {
|
|
|
8975
9184
|
}
|
|
8976
9185
|
let requestInit = {};
|
|
8977
9186
|
requestInit.body = request.body;
|
|
8978
|
-
requestInit = await this.includeExtraHttpOptionsToRequestInit(requestInit, patchedHttpOptions);
|
|
9187
|
+
requestInit = await this.includeExtraHttpOptionsToRequestInit(requestInit, patchedHttpOptions, request.abortSignal);
|
|
8979
9188
|
return this.streamApiCall(url, requestInit, request.httpMethod);
|
|
8980
9189
|
}
|
|
8981
|
-
async includeExtraHttpOptionsToRequestInit(requestInit, httpOptions) {
|
|
8982
|
-
if (httpOptions && httpOptions.timeout
|
|
9190
|
+
async includeExtraHttpOptionsToRequestInit(requestInit, httpOptions, abortSignal) {
|
|
9191
|
+
if ((httpOptions && httpOptions.timeout) || abortSignal) {
|
|
8983
9192
|
const abortController = new AbortController();
|
|
8984
9193
|
const signal = abortController.signal;
|
|
8985
|
-
|
|
9194
|
+
if (httpOptions.timeout && (httpOptions === null || httpOptions === void 0 ? void 0 : httpOptions.timeout) > 0) {
|
|
9195
|
+
setTimeout(() => abortController.abort(), httpOptions.timeout);
|
|
9196
|
+
}
|
|
9197
|
+
if (abortSignal) {
|
|
9198
|
+
abortSignal.addEventListener('abort', () => {
|
|
9199
|
+
abortController.abort();
|
|
9200
|
+
});
|
|
9201
|
+
}
|
|
8986
9202
|
requestInit.signal = signal;
|
|
8987
9203
|
}
|
|
8988
9204
|
requestInit.headers = await this.getHeadersInternal(httpOptions);
|
|
@@ -9037,6 +9253,30 @@ class ApiClient {
|
|
|
9037
9253
|
break;
|
|
9038
9254
|
}
|
|
9039
9255
|
const chunkString = decoder.decode(value);
|
|
9256
|
+
// Parse and throw an error if the chunk contains an error.
|
|
9257
|
+
try {
|
|
9258
|
+
const chunkJson = JSON.parse(chunkString);
|
|
9259
|
+
if ('error' in chunkJson) {
|
|
9260
|
+
const errorJson = JSON.parse(JSON.stringify(chunkJson['error']));
|
|
9261
|
+
const status = errorJson['status'];
|
|
9262
|
+
const code = errorJson['code'];
|
|
9263
|
+
const errorMessage = `got status: ${status}. ${JSON.stringify(chunkJson)}`;
|
|
9264
|
+
if (code >= 400 && code < 500) {
|
|
9265
|
+
const clientError = new ClientError(errorMessage);
|
|
9266
|
+
throw clientError;
|
|
9267
|
+
}
|
|
9268
|
+
else if (code >= 500 && code < 600) {
|
|
9269
|
+
const serverError = new ServerError(errorMessage);
|
|
9270
|
+
throw serverError;
|
|
9271
|
+
}
|
|
9272
|
+
}
|
|
9273
|
+
}
|
|
9274
|
+
catch (e) {
|
|
9275
|
+
const error = e;
|
|
9276
|
+
if (error.name === 'ClientError' || error.name === 'ServerError') {
|
|
9277
|
+
throw e;
|
|
9278
|
+
}
|
|
9279
|
+
}
|
|
9040
9280
|
buffer += chunkString;
|
|
9041
9281
|
let match = buffer.match(responseLineRE);
|
|
9042
9282
|
while (match) {
|
|
@@ -9175,7 +9415,7 @@ async function throwErrorIfNotOK(response) {
|
|
|
9175
9415
|
else {
|
|
9176
9416
|
errorBody = {
|
|
9177
9417
|
error: {
|
|
9178
|
-
message:
|
|
9418
|
+
message: await response.text(),
|
|
9179
9419
|
code: response.status,
|
|
9180
9420
|
status: response.statusText,
|
|
9181
9421
|
},
|
|
@@ -9619,6 +9859,15 @@ class GoogleGenAI {
|
|
|
9619
9859
|
this.apiKey = undefined;
|
|
9620
9860
|
}
|
|
9621
9861
|
}
|
|
9862
|
+
const baseUrl = getBaseUrl(options, getEnv('GOOGLE_VERTEX_BASE_URL'), getEnv('GOOGLE_GEMINI_BASE_URL'));
|
|
9863
|
+
if (baseUrl) {
|
|
9864
|
+
if (options.httpOptions) {
|
|
9865
|
+
options.httpOptions.baseUrl = baseUrl;
|
|
9866
|
+
}
|
|
9867
|
+
else {
|
|
9868
|
+
options.httpOptions = { baseUrl: baseUrl };
|
|
9869
|
+
}
|
|
9870
|
+
}
|
|
9622
9871
|
this.apiVersion = options.apiVersion;
|
|
9623
9872
|
const auth = new NodeAuth({
|
|
9624
9873
|
apiKey: this.apiKey,
|
|
@@ -9694,4 +9943,5 @@ exports.createPartFromFunctionResponse = createPartFromFunctionResponse;
|
|
|
9694
9943
|
exports.createPartFromText = createPartFromText;
|
|
9695
9944
|
exports.createPartFromUri = createPartFromUri;
|
|
9696
9945
|
exports.createUserContent = createUserContent;
|
|
9946
|
+
exports.setDefaultBaseUrls = setDefaultBaseUrls;
|
|
9697
9947
|
//# sourceMappingURL=index.js.map
|