@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.
@@ -1,3 +1,63 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ let _defaultBaseGeminiUrl = undefined;
7
+ let _defaultBaseVertexUrl = undefined;
8
+ /**
9
+ * Overrides the base URLs for the Gemini API and Vertex AI API.
10
+ *
11
+ * @remarks This function should be called before initializing the SDK. If the
12
+ * base URLs are set after initializing the SDK, the base URLs will not be
13
+ * updated. Base URLs provided in the HttpOptions will also take precedence over
14
+ * URLs set here.
15
+ *
16
+ * @example
17
+ * ```ts
18
+ * import {GoogleGenAI, setDefaultBaseUrls} from '@google/genai';
19
+ * // Override the base URL for the Gemini API.
20
+ * setDefaultBaseUrls({geminiUrl:'https://gemini.google.com'});
21
+ *
22
+ * // Override the base URL for the Vertex AI API.
23
+ * setDefaultBaseUrls({vertexUrl: 'https://vertexai.googleapis.com'});
24
+ *
25
+ * const ai = new GoogleGenAI({apiKey: 'GEMINI_API_KEY'});
26
+ * ```
27
+ */
28
+ function setDefaultBaseUrls(baseUrlParams) {
29
+ _defaultBaseGeminiUrl = baseUrlParams.geminiUrl;
30
+ _defaultBaseVertexUrl = baseUrlParams.vertexUrl;
31
+ }
32
+ /**
33
+ * Returns the default base URLs for the Gemini API and Vertex AI API.
34
+ */
35
+ function getDefaultBaseUrls() {
36
+ return {
37
+ geminiUrl: _defaultBaseGeminiUrl,
38
+ vertexUrl: _defaultBaseVertexUrl,
39
+ };
40
+ }
41
+ /**
42
+ * Returns the default base URL based on the following priority:
43
+ * 1. Base URLs set via HttpOptions.
44
+ * 2. Base URLs set via the latest call to setDefaultBaseUrls.
45
+ * 3. Base URLs set via environment variables.
46
+ */
47
+ function getBaseUrl(options, vertexBaseUrlFromEnv, geminiBaseUrlFromEnv) {
48
+ var _a, _b, _c;
49
+ if (!((_a = options.httpOptions) === null || _a === void 0 ? void 0 : _a.baseUrl)) {
50
+ const defaultBaseUrls = getDefaultBaseUrls();
51
+ if (options.vertexai) {
52
+ return (_b = defaultBaseUrls.vertexUrl) !== null && _b !== void 0 ? _b : vertexBaseUrlFromEnv;
53
+ }
54
+ else {
55
+ return (_c = defaultBaseUrls.geminiUrl) !== null && _c !== void 0 ? _c : geminiBaseUrlFromEnv;
56
+ }
57
+ }
58
+ return options.httpOptions.baseUrl;
59
+ }
60
+
1
61
  /**
2
62
  * @license
3
63
  * Copyright 2025 Google LLC
@@ -173,6 +233,36 @@ function tCachesModel(apiClient, model) {
173
233
  return transformedModel;
174
234
  }
175
235
  }
236
+ function tBlobs(apiClient, blobs) {
237
+ if (Array.isArray(blobs)) {
238
+ return blobs.map((blob) => tBlob(apiClient, blob));
239
+ }
240
+ else {
241
+ return [tBlob(apiClient, blobs)];
242
+ }
243
+ }
244
+ function tBlob(apiClient, blob) {
245
+ if (typeof blob === 'object' && blob !== null) {
246
+ return blob;
247
+ }
248
+ throw new Error(`Could not parse input as Blob. Unsupported blob type: ${typeof blob}`);
249
+ }
250
+ function tImageBlob(apiClient, blob) {
251
+ const transformedBlob = tBlob(apiClient, blob);
252
+ if (transformedBlob.mimeType &&
253
+ transformedBlob.mimeType.startsWith('image/')) {
254
+ return transformedBlob;
255
+ }
256
+ throw new Error(`Unsupported mime type: ${transformedBlob.mimeType}`);
257
+ }
258
+ function tAudioBlob(apiClient, blob) {
259
+ const transformedBlob = tBlob(apiClient, blob);
260
+ if (transformedBlob.mimeType &&
261
+ transformedBlob.mimeType.startsWith('audio/')) {
262
+ return transformedBlob;
263
+ }
264
+ throw new Error(`Unsupported mime type: ${transformedBlob.mimeType}`);
265
+ }
176
266
  function tPart(apiClient, origin) {
177
267
  if (origin === null || origin === undefined) {
178
268
  throw new Error('PartUnion is required');
@@ -296,38 +386,11 @@ function tContents(apiClient, origin) {
296
386
  }
297
387
  return result;
298
388
  }
299
- function processSchema(apiClient, schema) {
300
- if (!apiClient.isVertexAI()) {
301
- if ('default' in schema) {
302
- throw new Error('Default value is not supported in the response schema for the Gemini API.');
303
- }
304
- }
305
- if ('anyOf' in schema) {
306
- if (schema['anyOf'] !== undefined) {
307
- for (const subSchema of schema['anyOf']) {
308
- processSchema(apiClient, subSchema);
309
- }
310
- }
311
- }
312
- if ('items' in schema) {
313
- if (schema['items'] !== undefined) {
314
- processSchema(apiClient, schema['items']);
315
- }
316
- }
317
- if ('properties' in schema) {
318
- if (schema['properties'] !== undefined) {
319
- for (const subSchema of Object.values(schema['properties'])) {
320
- processSchema(apiClient, subSchema);
321
- }
322
- }
323
- }
324
- }
325
389
  function tSchema(apiClient, schema) {
326
- processSchema(apiClient, schema);
327
390
  return schema;
328
391
  }
329
392
  function tSpeechConfig(apiClient, speechConfig) {
330
- if (typeof speechConfig === 'object' && 'voiceConfig' in speechConfig) {
393
+ if (typeof speechConfig === 'object') {
331
394
  return speechConfig;
332
395
  }
333
396
  else if (typeof speechConfig === 'string') {
@@ -1534,6 +1597,7 @@ var FinishReason;
1534
1597
  FinishReason["MAX_TOKENS"] = "MAX_TOKENS";
1535
1598
  FinishReason["SAFETY"] = "SAFETY";
1536
1599
  FinishReason["RECITATION"] = "RECITATION";
1600
+ FinishReason["LANGUAGE"] = "LANGUAGE";
1537
1601
  FinishReason["OTHER"] = "OTHER";
1538
1602
  FinishReason["BLOCKLIST"] = "BLOCKLIST";
1539
1603
  FinishReason["PROHIBITED_CONTENT"] = "PROHIBITED_CONTENT";
@@ -1916,6 +1980,42 @@ class GenerateContentResponse {
1916
1980
  // part.text === '' is different from part.text is null
1917
1981
  return anyTextPartText ? text : undefined;
1918
1982
  }
1983
+ /**
1984
+ * Returns the concatenation of all inline data parts from the first candidate
1985
+ * in the response.
1986
+ *
1987
+ * @remarks
1988
+ * If there are multiple candidates in the response, the inline data from the
1989
+ * first one will be returned. If there are non-inline data parts in the
1990
+ * response, the concatenation of all inline data parts will be returned, and
1991
+ * a warning will be logged.
1992
+ */
1993
+ get data() {
1994
+ var _a, _b, _c, _d, _e, _f, _g, _h;
1995
+ 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) {
1996
+ return undefined;
1997
+ }
1998
+ if (this.candidates && this.candidates.length > 1) {
1999
+ console.warn('there are multiple candidates in the response, returning data from the first one.');
2000
+ }
2001
+ let data = '';
2002
+ const nonDataParts = [];
2003
+ 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 : []) {
2004
+ for (const [fieldName, fieldValue] of Object.entries(part)) {
2005
+ if (fieldName !== 'inlineData' &&
2006
+ (fieldValue !== null || fieldValue !== undefined)) {
2007
+ nonDataParts.push(fieldName);
2008
+ }
2009
+ }
2010
+ if (part.inlineData && typeof part.inlineData.data === 'string') {
2011
+ data += atob(part.inlineData.data);
2012
+ }
2013
+ }
2014
+ if (nonDataParts.length > 0) {
2015
+ 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.`);
2016
+ }
2017
+ return data.length > 0 ? btoa(data) : undefined;
2018
+ }
1919
2019
  /**
1920
2020
  * Returns the function calls from the first candidate in the response.
1921
2021
  *
@@ -2171,7 +2271,7 @@ class Caches extends BaseModule {
2171
2271
  * ```
2172
2272
  */
2173
2273
  async create(params) {
2174
- var _a, _b;
2274
+ var _a, _b, _c, _d;
2175
2275
  let response;
2176
2276
  let path = '';
2177
2277
  let queryParams = {};
@@ -2189,6 +2289,7 @@ class Caches extends BaseModule {
2189
2289
  body: JSON.stringify(body),
2190
2290
  httpMethod: 'POST',
2191
2291
  httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
2292
+ abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
2192
2293
  })
2193
2294
  .then((httpResponse) => {
2194
2295
  return httpResponse.json();
@@ -2211,7 +2312,8 @@ class Caches extends BaseModule {
2211
2312
  queryParams: queryParams,
2212
2313
  body: JSON.stringify(body),
2213
2314
  httpMethod: 'POST',
2214
- httpOptions: (_b = params.config) === null || _b === void 0 ? void 0 : _b.httpOptions,
2315
+ httpOptions: (_c = params.config) === null || _c === void 0 ? void 0 : _c.httpOptions,
2316
+ abortSignal: (_d = params.config) === null || _d === void 0 ? void 0 : _d.abortSignal,
2215
2317
  })
2216
2318
  .then((httpResponse) => {
2217
2319
  return httpResponse.json();
@@ -2234,7 +2336,7 @@ class Caches extends BaseModule {
2234
2336
  * ```
2235
2337
  */
2236
2338
  async get(params) {
2237
- var _a, _b;
2339
+ var _a, _b, _c, _d;
2238
2340
  let response;
2239
2341
  let path = '';
2240
2342
  let queryParams = {};
@@ -2252,6 +2354,7 @@ class Caches extends BaseModule {
2252
2354
  body: JSON.stringify(body),
2253
2355
  httpMethod: 'GET',
2254
2356
  httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
2357
+ abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
2255
2358
  })
2256
2359
  .then((httpResponse) => {
2257
2360
  return httpResponse.json();
@@ -2274,7 +2377,8 @@ class Caches extends BaseModule {
2274
2377
  queryParams: queryParams,
2275
2378
  body: JSON.stringify(body),
2276
2379
  httpMethod: 'GET',
2277
- httpOptions: (_b = params.config) === null || _b === void 0 ? void 0 : _b.httpOptions,
2380
+ httpOptions: (_c = params.config) === null || _c === void 0 ? void 0 : _c.httpOptions,
2381
+ abortSignal: (_d = params.config) === null || _d === void 0 ? void 0 : _d.abortSignal,
2278
2382
  })
2279
2383
  .then((httpResponse) => {
2280
2384
  return httpResponse.json();
@@ -2297,7 +2401,7 @@ class Caches extends BaseModule {
2297
2401
  * ```
2298
2402
  */
2299
2403
  async delete(params) {
2300
- var _a, _b;
2404
+ var _a, _b, _c, _d;
2301
2405
  let response;
2302
2406
  let path = '';
2303
2407
  let queryParams = {};
@@ -2315,6 +2419,7 @@ class Caches extends BaseModule {
2315
2419
  body: JSON.stringify(body),
2316
2420
  httpMethod: 'DELETE',
2317
2421
  httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
2422
+ abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
2318
2423
  })
2319
2424
  .then((httpResponse) => {
2320
2425
  return httpResponse.json();
@@ -2339,7 +2444,8 @@ class Caches extends BaseModule {
2339
2444
  queryParams: queryParams,
2340
2445
  body: JSON.stringify(body),
2341
2446
  httpMethod: 'DELETE',
2342
- httpOptions: (_b = params.config) === null || _b === void 0 ? void 0 : _b.httpOptions,
2447
+ httpOptions: (_c = params.config) === null || _c === void 0 ? void 0 : _c.httpOptions,
2448
+ abortSignal: (_d = params.config) === null || _d === void 0 ? void 0 : _d.abortSignal,
2343
2449
  })
2344
2450
  .then((httpResponse) => {
2345
2451
  return httpResponse.json();
@@ -2367,7 +2473,7 @@ class Caches extends BaseModule {
2367
2473
  * ```
2368
2474
  */
2369
2475
  async update(params) {
2370
- var _a, _b;
2476
+ var _a, _b, _c, _d;
2371
2477
  let response;
2372
2478
  let path = '';
2373
2479
  let queryParams = {};
@@ -2385,6 +2491,7 @@ class Caches extends BaseModule {
2385
2491
  body: JSON.stringify(body),
2386
2492
  httpMethod: 'PATCH',
2387
2493
  httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
2494
+ abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
2388
2495
  })
2389
2496
  .then((httpResponse) => {
2390
2497
  return httpResponse.json();
@@ -2407,7 +2514,8 @@ class Caches extends BaseModule {
2407
2514
  queryParams: queryParams,
2408
2515
  body: JSON.stringify(body),
2409
2516
  httpMethod: 'PATCH',
2410
- httpOptions: (_b = params.config) === null || _b === void 0 ? void 0 : _b.httpOptions,
2517
+ httpOptions: (_c = params.config) === null || _c === void 0 ? void 0 : _c.httpOptions,
2518
+ abortSignal: (_d = params.config) === null || _d === void 0 ? void 0 : _d.abortSignal,
2411
2519
  })
2412
2520
  .then((httpResponse) => {
2413
2521
  return httpResponse.json();
@@ -2419,7 +2527,7 @@ class Caches extends BaseModule {
2419
2527
  }
2420
2528
  }
2421
2529
  async listInternal(params) {
2422
- var _a, _b;
2530
+ var _a, _b, _c, _d;
2423
2531
  let response;
2424
2532
  let path = '';
2425
2533
  let queryParams = {};
@@ -2437,6 +2545,7 @@ class Caches extends BaseModule {
2437
2545
  body: JSON.stringify(body),
2438
2546
  httpMethod: 'GET',
2439
2547
  httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
2548
+ abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
2440
2549
  })
2441
2550
  .then((httpResponse) => {
2442
2551
  return httpResponse.json();
@@ -2461,7 +2570,8 @@ class Caches extends BaseModule {
2461
2570
  queryParams: queryParams,
2462
2571
  body: JSON.stringify(body),
2463
2572
  httpMethod: 'GET',
2464
- httpOptions: (_b = params.config) === null || _b === void 0 ? void 0 : _b.httpOptions,
2573
+ httpOptions: (_c = params.config) === null || _c === void 0 ? void 0 : _c.httpOptions,
2574
+ abortSignal: (_d = params.config) === null || _d === void 0 ? void 0 : _d.abortSignal,
2465
2575
  })
2466
2576
  .then((httpResponse) => {
2467
2577
  return httpResponse.json();
@@ -3170,7 +3280,7 @@ class Files extends BaseModule {
3170
3280
  });
3171
3281
  }
3172
3282
  async listInternal(params) {
3173
- var _a;
3283
+ var _a, _b;
3174
3284
  let response;
3175
3285
  let path = '';
3176
3286
  let queryParams = {};
@@ -3191,6 +3301,7 @@ class Files extends BaseModule {
3191
3301
  body: JSON.stringify(body),
3192
3302
  httpMethod: 'GET',
3193
3303
  httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
3304
+ abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
3194
3305
  })
3195
3306
  .then((httpResponse) => {
3196
3307
  return httpResponse.json();
@@ -3204,7 +3315,7 @@ class Files extends BaseModule {
3204
3315
  }
3205
3316
  }
3206
3317
  async createInternal(params) {
3207
- var _a;
3318
+ var _a, _b;
3208
3319
  let response;
3209
3320
  let path = '';
3210
3321
  let queryParams = {};
@@ -3225,6 +3336,7 @@ class Files extends BaseModule {
3225
3336
  body: JSON.stringify(body),
3226
3337
  httpMethod: 'POST',
3227
3338
  httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
3339
+ abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
3228
3340
  })
3229
3341
  .then((httpResponse) => {
3230
3342
  return httpResponse.json();
@@ -3253,7 +3365,7 @@ class Files extends BaseModule {
3253
3365
  * ```
3254
3366
  */
3255
3367
  async get(params) {
3256
- var _a;
3368
+ var _a, _b;
3257
3369
  let response;
3258
3370
  let path = '';
3259
3371
  let queryParams = {};
@@ -3274,6 +3386,7 @@ class Files extends BaseModule {
3274
3386
  body: JSON.stringify(body),
3275
3387
  httpMethod: 'GET',
3276
3388
  httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
3389
+ abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
3277
3390
  })
3278
3391
  .then((httpResponse) => {
3279
3392
  return httpResponse.json();
@@ -3298,7 +3411,7 @@ class Files extends BaseModule {
3298
3411
  * ```
3299
3412
  */
3300
3413
  async delete(params) {
3301
- var _a;
3414
+ var _a, _b;
3302
3415
  let response;
3303
3416
  let path = '';
3304
3417
  let queryParams = {};
@@ -3319,6 +3432,7 @@ class Files extends BaseModule {
3319
3432
  body: JSON.stringify(body),
3320
3433
  httpMethod: 'DELETE',
3321
3434
  httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
3435
+ abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
3322
3436
  })
3323
3437
  .then((httpResponse) => {
3324
3438
  return httpResponse.json();
@@ -4129,6 +4243,91 @@ function liveConnectParametersToVertex(apiClient, fromObject) {
4129
4243
  }
4130
4244
  return toObject;
4131
4245
  }
4246
+ function activityStartToMldev() {
4247
+ const toObject = {};
4248
+ return toObject;
4249
+ }
4250
+ function activityStartToVertex() {
4251
+ const toObject = {};
4252
+ return toObject;
4253
+ }
4254
+ function activityEndToMldev() {
4255
+ const toObject = {};
4256
+ return toObject;
4257
+ }
4258
+ function activityEndToVertex() {
4259
+ const toObject = {};
4260
+ return toObject;
4261
+ }
4262
+ function liveSendRealtimeInputParametersToMldev(apiClient, fromObject) {
4263
+ const toObject = {};
4264
+ const fromMedia = getValueByPath(fromObject, ['media']);
4265
+ if (fromMedia != null) {
4266
+ setValueByPath(toObject, ['mediaChunks'], tBlobs(apiClient, fromMedia));
4267
+ }
4268
+ const fromAudio = getValueByPath(fromObject, ['audio']);
4269
+ if (fromAudio != null) {
4270
+ setValueByPath(toObject, ['audio'], tAudioBlob(apiClient, fromAudio));
4271
+ }
4272
+ const fromAudioStreamEnd = getValueByPath(fromObject, [
4273
+ 'audioStreamEnd',
4274
+ ]);
4275
+ if (fromAudioStreamEnd != null) {
4276
+ setValueByPath(toObject, ['audioStreamEnd'], fromAudioStreamEnd);
4277
+ }
4278
+ const fromVideo = getValueByPath(fromObject, ['video']);
4279
+ if (fromVideo != null) {
4280
+ setValueByPath(toObject, ['video'], tImageBlob(apiClient, fromVideo));
4281
+ }
4282
+ const fromText = getValueByPath(fromObject, ['text']);
4283
+ if (fromText != null) {
4284
+ setValueByPath(toObject, ['text'], fromText);
4285
+ }
4286
+ const fromActivityStart = getValueByPath(fromObject, [
4287
+ 'activityStart',
4288
+ ]);
4289
+ if (fromActivityStart != null) {
4290
+ setValueByPath(toObject, ['activityStart'], activityStartToMldev());
4291
+ }
4292
+ const fromActivityEnd = getValueByPath(fromObject, ['activityEnd']);
4293
+ if (fromActivityEnd != null) {
4294
+ setValueByPath(toObject, ['activityEnd'], activityEndToMldev());
4295
+ }
4296
+ return toObject;
4297
+ }
4298
+ function liveSendRealtimeInputParametersToVertex(apiClient, fromObject) {
4299
+ const toObject = {};
4300
+ const fromMedia = getValueByPath(fromObject, ['media']);
4301
+ if (fromMedia != null) {
4302
+ setValueByPath(toObject, ['mediaChunks'], tBlobs(apiClient, fromMedia));
4303
+ }
4304
+ if (getValueByPath(fromObject, ['audio']) !== undefined) {
4305
+ throw new Error('audio parameter is not supported in Vertex AI.');
4306
+ }
4307
+ const fromAudioStreamEnd = getValueByPath(fromObject, [
4308
+ 'audioStreamEnd',
4309
+ ]);
4310
+ if (fromAudioStreamEnd != null) {
4311
+ setValueByPath(toObject, ['audioStreamEnd'], fromAudioStreamEnd);
4312
+ }
4313
+ if (getValueByPath(fromObject, ['video']) !== undefined) {
4314
+ throw new Error('video parameter is not supported in Vertex AI.');
4315
+ }
4316
+ if (getValueByPath(fromObject, ['text']) !== undefined) {
4317
+ throw new Error('text parameter is not supported in Vertex AI.');
4318
+ }
4319
+ const fromActivityStart = getValueByPath(fromObject, [
4320
+ 'activityStart',
4321
+ ]);
4322
+ if (fromActivityStart != null) {
4323
+ setValueByPath(toObject, ['activityStart'], activityStartToVertex());
4324
+ }
4325
+ const fromActivityEnd = getValueByPath(fromObject, ['activityEnd']);
4326
+ if (fromActivityEnd != null) {
4327
+ setValueByPath(toObject, ['activityEnd'], activityEndToVertex());
4328
+ }
4329
+ return toObject;
4330
+ }
4132
4331
  function liveServerSetupCompleteFromMldev() {
4133
4332
  const toObject = {};
4134
4333
  return toObject;
@@ -7476,21 +7675,6 @@ class Session {
7476
7675
  clientContent: { turnComplete: params.turnComplete },
7477
7676
  };
7478
7677
  }
7479
- tLiveClientRealtimeInput(apiClient, params) {
7480
- let clientMessage = {};
7481
- if (!('media' in params) || !params.media) {
7482
- throw new Error(`Failed to convert realtime input "media", type: '${typeof params.media}'`);
7483
- }
7484
- // LiveClientRealtimeInput
7485
- clientMessage = {
7486
- realtimeInput: {
7487
- mediaChunks: [params.media],
7488
- activityStart: params.activityStart,
7489
- activityEnd: params.activityEnd,
7490
- },
7491
- };
7492
- return clientMessage;
7493
- }
7494
7678
  tLiveClienttToolResponse(apiClient, params) {
7495
7679
  let functionResponses = [];
7496
7680
  if (params.functionResponses == null) {
@@ -7598,10 +7782,17 @@ class Session {
7598
7782
  of audio and image mimetypes are allowed.
7599
7783
  */
7600
7784
  sendRealtimeInput(params) {
7601
- if (params.media == null) {
7602
- throw new Error('Media is required.');
7785
+ let clientMessage = {};
7786
+ if (this.apiClient.isVertexAI()) {
7787
+ clientMessage = {
7788
+ 'realtimeInput': liveSendRealtimeInputParametersToVertex(this.apiClient, params),
7789
+ };
7790
+ }
7791
+ else {
7792
+ clientMessage = {
7793
+ 'realtimeInput': liveSendRealtimeInputParametersToMldev(this.apiClient, params),
7794
+ };
7603
7795
  }
7604
- const clientMessage = this.tLiveClientRealtimeInput(this.apiClient, params);
7605
7796
  this.conn.send(JSON.stringify(clientMessage));
7606
7797
  }
7607
7798
  /**
@@ -7822,7 +8013,7 @@ class Models extends BaseModule {
7822
8013
  };
7823
8014
  }
7824
8015
  async generateContentInternal(params) {
7825
- var _a, _b;
8016
+ var _a, _b, _c, _d;
7826
8017
  let response;
7827
8018
  let path = '';
7828
8019
  let queryParams = {};
@@ -7840,6 +8031,7 @@ class Models extends BaseModule {
7840
8031
  body: JSON.stringify(body),
7841
8032
  httpMethod: 'POST',
7842
8033
  httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
8034
+ abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
7843
8035
  })
7844
8036
  .then((httpResponse) => {
7845
8037
  return httpResponse.json();
@@ -7864,7 +8056,8 @@ class Models extends BaseModule {
7864
8056
  queryParams: queryParams,
7865
8057
  body: JSON.stringify(body),
7866
8058
  httpMethod: 'POST',
7867
- httpOptions: (_b = params.config) === null || _b === void 0 ? void 0 : _b.httpOptions,
8059
+ httpOptions: (_c = params.config) === null || _c === void 0 ? void 0 : _c.httpOptions,
8060
+ abortSignal: (_d = params.config) === null || _d === void 0 ? void 0 : _d.abortSignal,
7868
8061
  })
7869
8062
  .then((httpResponse) => {
7870
8063
  return httpResponse.json();
@@ -7878,7 +8071,7 @@ class Models extends BaseModule {
7878
8071
  }
7879
8072
  }
7880
8073
  async generateContentStreamInternal(params) {
7881
- var _a, _b;
8074
+ var _a, _b, _c, _d;
7882
8075
  let response;
7883
8076
  let path = '';
7884
8077
  let queryParams = {};
@@ -7896,6 +8089,7 @@ class Models extends BaseModule {
7896
8089
  body: JSON.stringify(body),
7897
8090
  httpMethod: 'POST',
7898
8091
  httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
8092
+ abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
7899
8093
  });
7900
8094
  return response.then(function (apiResponse) {
7901
8095
  return __asyncGenerator(this, arguments, function* () {
@@ -7934,7 +8128,8 @@ class Models extends BaseModule {
7934
8128
  queryParams: queryParams,
7935
8129
  body: JSON.stringify(body),
7936
8130
  httpMethod: 'POST',
7937
- httpOptions: (_b = params.config) === null || _b === void 0 ? void 0 : _b.httpOptions,
8131
+ httpOptions: (_c = params.config) === null || _c === void 0 ? void 0 : _c.httpOptions,
8132
+ abortSignal: (_d = params.config) === null || _d === void 0 ? void 0 : _d.abortSignal,
7938
8133
  });
7939
8134
  return response.then(function (apiResponse) {
7940
8135
  return __asyncGenerator(this, arguments, function* () {
@@ -7983,7 +8178,7 @@ class Models extends BaseModule {
7983
8178
  * ```
7984
8179
  */
7985
8180
  async embedContent(params) {
7986
- var _a, _b;
8181
+ var _a, _b, _c, _d;
7987
8182
  let response;
7988
8183
  let path = '';
7989
8184
  let queryParams = {};
@@ -8001,6 +8196,7 @@ class Models extends BaseModule {
8001
8196
  body: JSON.stringify(body),
8002
8197
  httpMethod: 'POST',
8003
8198
  httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
8199
+ abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
8004
8200
  })
8005
8201
  .then((httpResponse) => {
8006
8202
  return httpResponse.json();
@@ -8025,7 +8221,8 @@ class Models extends BaseModule {
8025
8221
  queryParams: queryParams,
8026
8222
  body: JSON.stringify(body),
8027
8223
  httpMethod: 'POST',
8028
- httpOptions: (_b = params.config) === null || _b === void 0 ? void 0 : _b.httpOptions,
8224
+ httpOptions: (_c = params.config) === null || _c === void 0 ? void 0 : _c.httpOptions,
8225
+ abortSignal: (_d = params.config) === null || _d === void 0 ? void 0 : _d.abortSignal,
8029
8226
  })
8030
8227
  .then((httpResponse) => {
8031
8228
  return httpResponse.json();
@@ -8058,7 +8255,7 @@ class Models extends BaseModule {
8058
8255
  * ```
8059
8256
  */
8060
8257
  async generateImagesInternal(params) {
8061
- var _a, _b;
8258
+ var _a, _b, _c, _d;
8062
8259
  let response;
8063
8260
  let path = '';
8064
8261
  let queryParams = {};
@@ -8076,6 +8273,7 @@ class Models extends BaseModule {
8076
8273
  body: JSON.stringify(body),
8077
8274
  httpMethod: 'POST',
8078
8275
  httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
8276
+ abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
8079
8277
  })
8080
8278
  .then((httpResponse) => {
8081
8279
  return httpResponse.json();
@@ -8100,7 +8298,8 @@ class Models extends BaseModule {
8100
8298
  queryParams: queryParams,
8101
8299
  body: JSON.stringify(body),
8102
8300
  httpMethod: 'POST',
8103
- httpOptions: (_b = params.config) === null || _b === void 0 ? void 0 : _b.httpOptions,
8301
+ httpOptions: (_c = params.config) === null || _c === void 0 ? void 0 : _c.httpOptions,
8302
+ abortSignal: (_d = params.config) === null || _d === void 0 ? void 0 : _d.abortSignal,
8104
8303
  })
8105
8304
  .then((httpResponse) => {
8106
8305
  return httpResponse.json();
@@ -8122,7 +8321,7 @@ class Models extends BaseModule {
8122
8321
  * ```
8123
8322
  */
8124
8323
  async get(params) {
8125
- var _a, _b;
8324
+ var _a, _b, _c, _d;
8126
8325
  let response;
8127
8326
  let path = '';
8128
8327
  let queryParams = {};
@@ -8140,6 +8339,7 @@ class Models extends BaseModule {
8140
8339
  body: JSON.stringify(body),
8141
8340
  httpMethod: 'GET',
8142
8341
  httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
8342
+ abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
8143
8343
  })
8144
8344
  .then((httpResponse) => {
8145
8345
  return httpResponse.json();
@@ -8162,7 +8362,8 @@ class Models extends BaseModule {
8162
8362
  queryParams: queryParams,
8163
8363
  body: JSON.stringify(body),
8164
8364
  httpMethod: 'GET',
8165
- httpOptions: (_b = params.config) === null || _b === void 0 ? void 0 : _b.httpOptions,
8365
+ httpOptions: (_c = params.config) === null || _c === void 0 ? void 0 : _c.httpOptions,
8366
+ abortSignal: (_d = params.config) === null || _d === void 0 ? void 0 : _d.abortSignal,
8166
8367
  })
8167
8368
  .then((httpResponse) => {
8168
8369
  return httpResponse.json();
@@ -8190,7 +8391,7 @@ class Models extends BaseModule {
8190
8391
  * ```
8191
8392
  */
8192
8393
  async countTokens(params) {
8193
- var _a, _b;
8394
+ var _a, _b, _c, _d;
8194
8395
  let response;
8195
8396
  let path = '';
8196
8397
  let queryParams = {};
@@ -8208,6 +8409,7 @@ class Models extends BaseModule {
8208
8409
  body: JSON.stringify(body),
8209
8410
  httpMethod: 'POST',
8210
8411
  httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
8412
+ abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
8211
8413
  })
8212
8414
  .then((httpResponse) => {
8213
8415
  return httpResponse.json();
@@ -8232,7 +8434,8 @@ class Models extends BaseModule {
8232
8434
  queryParams: queryParams,
8233
8435
  body: JSON.stringify(body),
8234
8436
  httpMethod: 'POST',
8235
- httpOptions: (_b = params.config) === null || _b === void 0 ? void 0 : _b.httpOptions,
8437
+ httpOptions: (_c = params.config) === null || _c === void 0 ? void 0 : _c.httpOptions,
8438
+ abortSignal: (_d = params.config) === null || _d === void 0 ? void 0 : _d.abortSignal,
8236
8439
  })
8237
8440
  .then((httpResponse) => {
8238
8441
  return httpResponse.json();
@@ -8264,7 +8467,7 @@ class Models extends BaseModule {
8264
8467
  * ```
8265
8468
  */
8266
8469
  async computeTokens(params) {
8267
- var _a;
8470
+ var _a, _b;
8268
8471
  let response;
8269
8472
  let path = '';
8270
8473
  let queryParams = {};
@@ -8282,6 +8485,7 @@ class Models extends BaseModule {
8282
8485
  body: JSON.stringify(body),
8283
8486
  httpMethod: 'POST',
8284
8487
  httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
8488
+ abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
8285
8489
  })
8286
8490
  .then((httpResponse) => {
8287
8491
  return httpResponse.json();
@@ -8321,7 +8525,7 @@ class Models extends BaseModule {
8321
8525
  * ```
8322
8526
  */
8323
8527
  async generateVideos(params) {
8324
- var _a, _b;
8528
+ var _a, _b, _c, _d;
8325
8529
  let response;
8326
8530
  let path = '';
8327
8531
  let queryParams = {};
@@ -8339,6 +8543,7 @@ class Models extends BaseModule {
8339
8543
  body: JSON.stringify(body),
8340
8544
  httpMethod: 'POST',
8341
8545
  httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
8546
+ abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
8342
8547
  })
8343
8548
  .then((httpResponse) => {
8344
8549
  return httpResponse.json();
@@ -8361,7 +8566,8 @@ class Models extends BaseModule {
8361
8566
  queryParams: queryParams,
8362
8567
  body: JSON.stringify(body),
8363
8568
  httpMethod: 'POST',
8364
- httpOptions: (_b = params.config) === null || _b === void 0 ? void 0 : _b.httpOptions,
8569
+ httpOptions: (_c = params.config) === null || _c === void 0 ? void 0 : _c.httpOptions,
8570
+ abortSignal: (_d = params.config) === null || _d === void 0 ? void 0 : _d.abortSignal,
8365
8571
  })
8366
8572
  .then((httpResponse) => {
8367
8573
  return httpResponse.json();
@@ -8628,7 +8834,7 @@ class Operations extends BaseModule {
8628
8834
  }
8629
8835
  }
8630
8836
  async getVideosOperationInternal(params) {
8631
- var _a, _b;
8837
+ var _a, _b, _c, _d;
8632
8838
  let response;
8633
8839
  let path = '';
8634
8840
  let queryParams = {};
@@ -8646,6 +8852,7 @@ class Operations extends BaseModule {
8646
8852
  body: JSON.stringify(body),
8647
8853
  httpMethod: 'GET',
8648
8854
  httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
8855
+ abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
8649
8856
  })
8650
8857
  .then((httpResponse) => {
8651
8858
  return httpResponse.json();
@@ -8668,7 +8875,8 @@ class Operations extends BaseModule {
8668
8875
  queryParams: queryParams,
8669
8876
  body: JSON.stringify(body),
8670
8877
  httpMethod: 'GET',
8671
- httpOptions: (_b = params.config) === null || _b === void 0 ? void 0 : _b.httpOptions,
8878
+ httpOptions: (_c = params.config) === null || _c === void 0 ? void 0 : _c.httpOptions,
8879
+ abortSignal: (_d = params.config) === null || _d === void 0 ? void 0 : _d.abortSignal,
8672
8880
  })
8673
8881
  .then((httpResponse) => {
8674
8882
  return httpResponse.json();
@@ -8680,7 +8888,7 @@ class Operations extends BaseModule {
8680
8888
  }
8681
8889
  }
8682
8890
  async fetchPredictVideosOperationInternal(params) {
8683
- var _a;
8891
+ var _a, _b;
8684
8892
  let response;
8685
8893
  let path = '';
8686
8894
  let queryParams = {};
@@ -8698,6 +8906,7 @@ class Operations extends BaseModule {
8698
8906
  body: JSON.stringify(body),
8699
8907
  httpMethod: 'POST',
8700
8908
  httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
8909
+ abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
8701
8910
  })
8702
8911
  .then((httpResponse) => {
8703
8912
  return httpResponse.json();
@@ -8722,7 +8931,7 @@ const CONTENT_TYPE_HEADER = 'Content-Type';
8722
8931
  const SERVER_TIMEOUT_HEADER = 'X-Server-Timeout';
8723
8932
  const USER_AGENT_HEADER = 'User-Agent';
8724
8933
  const GOOGLE_API_CLIENT_HEADER = 'x-goog-api-client';
8725
- const SDK_VERSION = '0.9.0'; // x-release-please-version
8934
+ const SDK_VERSION = '0.10.0'; // x-release-please-version
8726
8935
  const LIBRARY_LABEL = `google-genai-sdk/${SDK_VERSION}`;
8727
8936
  const VERTEX_AI_API_DEFAULT_VERSION = 'v1beta1';
8728
8937
  const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
@@ -8851,7 +9060,7 @@ class ApiClient {
8851
9060
  getWebsocketBaseUrl() {
8852
9061
  const baseUrl = this.getBaseUrl();
8853
9062
  const urlParts = new URL(baseUrl);
8854
- urlParts.protocol = 'wss';
9063
+ urlParts.protocol = urlParts.protocol == 'http:' ? 'ws' : 'wss';
8855
9064
  return urlParts.toString();
8856
9065
  }
8857
9066
  setBaseUrl(url) {
@@ -8915,7 +9124,7 @@ class ApiClient {
8915
9124
  else {
8916
9125
  requestInit.body = request.body;
8917
9126
  }
8918
- requestInit = await this.includeExtraHttpOptionsToRequestInit(requestInit, patchedHttpOptions);
9127
+ requestInit = await this.includeExtraHttpOptionsToRequestInit(requestInit, patchedHttpOptions, request.abortSignal);
8919
9128
  return this.unaryApiCall(url, requestInit, request.httpMethod);
8920
9129
  }
8921
9130
  patchHttpOptions(baseHttpOptions, requestHttpOptions) {
@@ -8949,14 +9158,21 @@ class ApiClient {
8949
9158
  }
8950
9159
  let requestInit = {};
8951
9160
  requestInit.body = request.body;
8952
- requestInit = await this.includeExtraHttpOptionsToRequestInit(requestInit, patchedHttpOptions);
9161
+ requestInit = await this.includeExtraHttpOptionsToRequestInit(requestInit, patchedHttpOptions, request.abortSignal);
8953
9162
  return this.streamApiCall(url, requestInit, request.httpMethod);
8954
9163
  }
8955
- async includeExtraHttpOptionsToRequestInit(requestInit, httpOptions) {
8956
- if (httpOptions && httpOptions.timeout && httpOptions.timeout > 0) {
9164
+ async includeExtraHttpOptionsToRequestInit(requestInit, httpOptions, abortSignal) {
9165
+ if ((httpOptions && httpOptions.timeout) || abortSignal) {
8957
9166
  const abortController = new AbortController();
8958
9167
  const signal = abortController.signal;
8959
- setTimeout(() => abortController.abort(), httpOptions.timeout);
9168
+ if (httpOptions.timeout && (httpOptions === null || httpOptions === void 0 ? void 0 : httpOptions.timeout) > 0) {
9169
+ setTimeout(() => abortController.abort(), httpOptions.timeout);
9170
+ }
9171
+ if (abortSignal) {
9172
+ abortSignal.addEventListener('abort', () => {
9173
+ abortController.abort();
9174
+ });
9175
+ }
8960
9176
  requestInit.signal = signal;
8961
9177
  }
8962
9178
  requestInit.headers = await this.getHeadersInternal(httpOptions);
@@ -9011,6 +9227,30 @@ class ApiClient {
9011
9227
  break;
9012
9228
  }
9013
9229
  const chunkString = decoder.decode(value);
9230
+ // Parse and throw an error if the chunk contains an error.
9231
+ try {
9232
+ const chunkJson = JSON.parse(chunkString);
9233
+ if ('error' in chunkJson) {
9234
+ const errorJson = JSON.parse(JSON.stringify(chunkJson['error']));
9235
+ const status = errorJson['status'];
9236
+ const code = errorJson['code'];
9237
+ const errorMessage = `got status: ${status}. ${JSON.stringify(chunkJson)}`;
9238
+ if (code >= 400 && code < 500) {
9239
+ const clientError = new ClientError(errorMessage);
9240
+ throw clientError;
9241
+ }
9242
+ else if (code >= 500 && code < 600) {
9243
+ const serverError = new ServerError(errorMessage);
9244
+ throw serverError;
9245
+ }
9246
+ }
9247
+ }
9248
+ catch (e) {
9249
+ const error = e;
9250
+ if (error.name === 'ClientError' || error.name === 'ServerError') {
9251
+ throw e;
9252
+ }
9253
+ }
9014
9254
  buffer += chunkString;
9015
9255
  let match = buffer.match(responseLineRE);
9016
9256
  while (match) {
@@ -9149,7 +9389,7 @@ async function throwErrorIfNotOK(response) {
9149
9389
  else {
9150
9390
  errorBody = {
9151
9391
  error: {
9152
- message: 'exception parsing response',
9392
+ message: await response.text(),
9153
9393
  code: response.status,
9154
9394
  status: response.statusText,
9155
9395
  },
@@ -9349,6 +9589,17 @@ class GoogleGenAI {
9349
9589
  }
9350
9590
  this.vertexai = (_a = options.vertexai) !== null && _a !== void 0 ? _a : false;
9351
9591
  this.apiKey = options.apiKey;
9592
+ const baseUrl = getBaseUrl(options,
9593
+ /*vertexBaseUrlFromEnv*/ undefined,
9594
+ /*geminiBaseUrlFromEnv*/ undefined);
9595
+ if (baseUrl) {
9596
+ if (options.httpOptions) {
9597
+ options.httpOptions.baseUrl = baseUrl;
9598
+ }
9599
+ else {
9600
+ options.httpOptions = { baseUrl: baseUrl };
9601
+ }
9602
+ }
9352
9603
  this.apiVersion = options.apiVersion;
9353
9604
  const auth = new WebAuth(this.apiKey);
9354
9605
  this.apiClient = new ApiClient({
@@ -9369,5 +9620,5 @@ class GoogleGenAI {
9369
9620
  }
9370
9621
  }
9371
9622
 
9372
- export { ActivityHandling, BlockedReason, Caches, Chat, Chats, ComputeTokensResponse, ControlReferenceType, CountTokensResponse, CreateFileResponse, DeleteCachedContentResponse, DeleteFileResponse, DynamicRetrievalConfigMode, EmbedContentResponse, EndSensitivity, FeatureSelectionPreference, FileSource, FileState, Files, FinishReason, FunctionCallingConfigMode, FunctionResponse, GenerateContentResponse, GenerateContentResponsePromptFeedback, GenerateContentResponseUsageMetadata, GenerateImagesResponse, GenerateVideosResponse, GoogleGenAI, HarmBlockMethod, HarmBlockThreshold, HarmCategory, HarmProbability, HarmSeverity, HttpResponse, ImagePromptLanguage, Language, ListCachedContentsResponse, ListFilesResponse, Live, LiveClientToolResponse, LiveSendToolResponseParameters, MaskReferenceMode, MediaModality, MediaResolution, Modality, Mode, Models, Operations, Outcome, PagedItem, Pager, PersonGeneration, ReplayResponse, SafetyFilterLevel, Session, StartSensitivity, SubjectReferenceType, TrafficType, TurnCoverage, Type, createModelContent, createPartFromBase64, createPartFromCodeExecutionResult, createPartFromExecutableCode, createPartFromFunctionCall, createPartFromFunctionResponse, createPartFromText, createPartFromUri, createUserContent };
9623
+ export { ActivityHandling, BlockedReason, Caches, Chat, Chats, ComputeTokensResponse, ControlReferenceType, CountTokensResponse, CreateFileResponse, DeleteCachedContentResponse, DeleteFileResponse, DynamicRetrievalConfigMode, EmbedContentResponse, EndSensitivity, FeatureSelectionPreference, FileSource, FileState, Files, FinishReason, FunctionCallingConfigMode, FunctionResponse, GenerateContentResponse, GenerateContentResponsePromptFeedback, GenerateContentResponseUsageMetadata, GenerateImagesResponse, GenerateVideosResponse, GoogleGenAI, HarmBlockMethod, HarmBlockThreshold, HarmCategory, HarmProbability, HarmSeverity, HttpResponse, ImagePromptLanguage, Language, ListCachedContentsResponse, ListFilesResponse, Live, LiveClientToolResponse, LiveSendToolResponseParameters, MaskReferenceMode, MediaModality, MediaResolution, Modality, Mode, Models, Operations, Outcome, PagedItem, Pager, PersonGeneration, ReplayResponse, SafetyFilterLevel, Session, StartSensitivity, SubjectReferenceType, TrafficType, TurnCoverage, Type, createModelContent, createPartFromBase64, createPartFromCodeExecutionResult, createPartFromExecutableCode, createPartFromFunctionCall, createPartFromFunctionResponse, createPartFromText, createPartFromUri, createUserContent, setDefaultBaseUrls };
9373
9624
  //# sourceMappingURL=index.mjs.map