@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/dist/index.mjs CHANGED
@@ -1,3 +1,33 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ /**
7
+ * Overrides the base URLs for the Gemini API and Vertex AI API.
8
+ *
9
+ * @remarks This function should be called before initializing the SDK. If the
10
+ * base URLs are set after initializing the SDK, the base URLs will not be
11
+ * updated. Base URLs provided in the HttpOptions will also take precedence over
12
+ * URLs set here.
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * import {GoogleGenAI, setDefaultBaseUrls} from '@google/genai';
17
+ * // Override the base URL for the Gemini API.
18
+ * setDefaultBaseUrls({geminiUrl:'https://gemini.google.com'});
19
+ *
20
+ * // Override the base URL for the Vertex AI API.
21
+ * setDefaultBaseUrls({vertexUrl: 'https://vertexai.googleapis.com'});
22
+ *
23
+ * const ai = new GoogleGenAI({apiKey: 'GEMINI_API_KEY'});
24
+ * ```
25
+ */
26
+ function setDefaultBaseUrls(baseUrlParams) {
27
+ baseUrlParams.geminiUrl;
28
+ baseUrlParams.vertexUrl;
29
+ }
30
+
1
31
  /**
2
32
  * @license
3
33
  * Copyright 2025 Google LLC
@@ -173,6 +203,36 @@ function tCachesModel(apiClient, model) {
173
203
  return transformedModel;
174
204
  }
175
205
  }
206
+ function tBlobs(apiClient, blobs) {
207
+ if (Array.isArray(blobs)) {
208
+ return blobs.map((blob) => tBlob(apiClient, blob));
209
+ }
210
+ else {
211
+ return [tBlob(apiClient, blobs)];
212
+ }
213
+ }
214
+ function tBlob(apiClient, blob) {
215
+ if (typeof blob === 'object' && blob !== null) {
216
+ return blob;
217
+ }
218
+ throw new Error(`Could not parse input as Blob. Unsupported blob type: ${typeof blob}`);
219
+ }
220
+ function tImageBlob(apiClient, blob) {
221
+ const transformedBlob = tBlob(apiClient, blob);
222
+ if (transformedBlob.mimeType &&
223
+ transformedBlob.mimeType.startsWith('image/')) {
224
+ return transformedBlob;
225
+ }
226
+ throw new Error(`Unsupported mime type: ${transformedBlob.mimeType}`);
227
+ }
228
+ function tAudioBlob(apiClient, blob) {
229
+ const transformedBlob = tBlob(apiClient, blob);
230
+ if (transformedBlob.mimeType &&
231
+ transformedBlob.mimeType.startsWith('audio/')) {
232
+ return transformedBlob;
233
+ }
234
+ throw new Error(`Unsupported mime type: ${transformedBlob.mimeType}`);
235
+ }
176
236
  function tPart(apiClient, origin) {
177
237
  if (origin === null || origin === undefined) {
178
238
  throw new Error('PartUnion is required');
@@ -296,38 +356,11 @@ function tContents(apiClient, origin) {
296
356
  }
297
357
  return result;
298
358
  }
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
359
  function tSchema(apiClient, schema) {
326
- processSchema(apiClient, schema);
327
360
  return schema;
328
361
  }
329
362
  function tSpeechConfig(apiClient, speechConfig) {
330
- if (typeof speechConfig === 'object' && 'voiceConfig' in speechConfig) {
363
+ if (typeof speechConfig === 'object') {
331
364
  return speechConfig;
332
365
  }
333
366
  else if (typeof speechConfig === 'string') {
@@ -1534,6 +1567,7 @@ var FinishReason;
1534
1567
  FinishReason["MAX_TOKENS"] = "MAX_TOKENS";
1535
1568
  FinishReason["SAFETY"] = "SAFETY";
1536
1569
  FinishReason["RECITATION"] = "RECITATION";
1570
+ FinishReason["LANGUAGE"] = "LANGUAGE";
1537
1571
  FinishReason["OTHER"] = "OTHER";
1538
1572
  FinishReason["BLOCKLIST"] = "BLOCKLIST";
1539
1573
  FinishReason["PROHIBITED_CONTENT"] = "PROHIBITED_CONTENT";
@@ -1916,6 +1950,42 @@ class GenerateContentResponse {
1916
1950
  // part.text === '' is different from part.text is null
1917
1951
  return anyTextPartText ? text : undefined;
1918
1952
  }
1953
+ /**
1954
+ * Returns the concatenation of all inline data parts from the first candidate
1955
+ * in the response.
1956
+ *
1957
+ * @remarks
1958
+ * If there are multiple candidates in the response, the inline data from the
1959
+ * first one will be returned. If there are non-inline data parts in the
1960
+ * response, the concatenation of all inline data parts will be returned, and
1961
+ * a warning will be logged.
1962
+ */
1963
+ get data() {
1964
+ var _a, _b, _c, _d, _e, _f, _g, _h;
1965
+ 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) {
1966
+ return undefined;
1967
+ }
1968
+ if (this.candidates && this.candidates.length > 1) {
1969
+ console.warn('there are multiple candidates in the response, returning data from the first one.');
1970
+ }
1971
+ let data = '';
1972
+ const nonDataParts = [];
1973
+ 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 : []) {
1974
+ for (const [fieldName, fieldValue] of Object.entries(part)) {
1975
+ if (fieldName !== 'inlineData' &&
1976
+ (fieldValue !== null || fieldValue !== undefined)) {
1977
+ nonDataParts.push(fieldName);
1978
+ }
1979
+ }
1980
+ if (part.inlineData && typeof part.inlineData.data === 'string') {
1981
+ data += atob(part.inlineData.data);
1982
+ }
1983
+ }
1984
+ if (nonDataParts.length > 0) {
1985
+ 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.`);
1986
+ }
1987
+ return data.length > 0 ? btoa(data) : undefined;
1988
+ }
1919
1989
  /**
1920
1990
  * Returns the function calls from the first candidate in the response.
1921
1991
  *
@@ -2171,7 +2241,7 @@ class Caches extends BaseModule {
2171
2241
  * ```
2172
2242
  */
2173
2243
  async create(params) {
2174
- var _a, _b;
2244
+ var _a, _b, _c, _d;
2175
2245
  let response;
2176
2246
  let path = '';
2177
2247
  let queryParams = {};
@@ -2189,6 +2259,7 @@ class Caches extends BaseModule {
2189
2259
  body: JSON.stringify(body),
2190
2260
  httpMethod: 'POST',
2191
2261
  httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
2262
+ abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
2192
2263
  })
2193
2264
  .then((httpResponse) => {
2194
2265
  return httpResponse.json();
@@ -2211,7 +2282,8 @@ class Caches extends BaseModule {
2211
2282
  queryParams: queryParams,
2212
2283
  body: JSON.stringify(body),
2213
2284
  httpMethod: 'POST',
2214
- httpOptions: (_b = params.config) === null || _b === void 0 ? void 0 : _b.httpOptions,
2285
+ httpOptions: (_c = params.config) === null || _c === void 0 ? void 0 : _c.httpOptions,
2286
+ abortSignal: (_d = params.config) === null || _d === void 0 ? void 0 : _d.abortSignal,
2215
2287
  })
2216
2288
  .then((httpResponse) => {
2217
2289
  return httpResponse.json();
@@ -2234,7 +2306,7 @@ class Caches extends BaseModule {
2234
2306
  * ```
2235
2307
  */
2236
2308
  async get(params) {
2237
- var _a, _b;
2309
+ var _a, _b, _c, _d;
2238
2310
  let response;
2239
2311
  let path = '';
2240
2312
  let queryParams = {};
@@ -2252,6 +2324,7 @@ class Caches extends BaseModule {
2252
2324
  body: JSON.stringify(body),
2253
2325
  httpMethod: 'GET',
2254
2326
  httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
2327
+ abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
2255
2328
  })
2256
2329
  .then((httpResponse) => {
2257
2330
  return httpResponse.json();
@@ -2274,7 +2347,8 @@ class Caches extends BaseModule {
2274
2347
  queryParams: queryParams,
2275
2348
  body: JSON.stringify(body),
2276
2349
  httpMethod: 'GET',
2277
- httpOptions: (_b = params.config) === null || _b === void 0 ? void 0 : _b.httpOptions,
2350
+ httpOptions: (_c = params.config) === null || _c === void 0 ? void 0 : _c.httpOptions,
2351
+ abortSignal: (_d = params.config) === null || _d === void 0 ? void 0 : _d.abortSignal,
2278
2352
  })
2279
2353
  .then((httpResponse) => {
2280
2354
  return httpResponse.json();
@@ -2297,7 +2371,7 @@ class Caches extends BaseModule {
2297
2371
  * ```
2298
2372
  */
2299
2373
  async delete(params) {
2300
- var _a, _b;
2374
+ var _a, _b, _c, _d;
2301
2375
  let response;
2302
2376
  let path = '';
2303
2377
  let queryParams = {};
@@ -2315,6 +2389,7 @@ class Caches extends BaseModule {
2315
2389
  body: JSON.stringify(body),
2316
2390
  httpMethod: 'DELETE',
2317
2391
  httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
2392
+ abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
2318
2393
  })
2319
2394
  .then((httpResponse) => {
2320
2395
  return httpResponse.json();
@@ -2339,7 +2414,8 @@ class Caches extends BaseModule {
2339
2414
  queryParams: queryParams,
2340
2415
  body: JSON.stringify(body),
2341
2416
  httpMethod: 'DELETE',
2342
- httpOptions: (_b = params.config) === null || _b === void 0 ? void 0 : _b.httpOptions,
2417
+ httpOptions: (_c = params.config) === null || _c === void 0 ? void 0 : _c.httpOptions,
2418
+ abortSignal: (_d = params.config) === null || _d === void 0 ? void 0 : _d.abortSignal,
2343
2419
  })
2344
2420
  .then((httpResponse) => {
2345
2421
  return httpResponse.json();
@@ -2367,7 +2443,7 @@ class Caches extends BaseModule {
2367
2443
  * ```
2368
2444
  */
2369
2445
  async update(params) {
2370
- var _a, _b;
2446
+ var _a, _b, _c, _d;
2371
2447
  let response;
2372
2448
  let path = '';
2373
2449
  let queryParams = {};
@@ -2385,6 +2461,7 @@ class Caches extends BaseModule {
2385
2461
  body: JSON.stringify(body),
2386
2462
  httpMethod: 'PATCH',
2387
2463
  httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
2464
+ abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
2388
2465
  })
2389
2466
  .then((httpResponse) => {
2390
2467
  return httpResponse.json();
@@ -2407,7 +2484,8 @@ class Caches extends BaseModule {
2407
2484
  queryParams: queryParams,
2408
2485
  body: JSON.stringify(body),
2409
2486
  httpMethod: 'PATCH',
2410
- httpOptions: (_b = params.config) === null || _b === void 0 ? void 0 : _b.httpOptions,
2487
+ httpOptions: (_c = params.config) === null || _c === void 0 ? void 0 : _c.httpOptions,
2488
+ abortSignal: (_d = params.config) === null || _d === void 0 ? void 0 : _d.abortSignal,
2411
2489
  })
2412
2490
  .then((httpResponse) => {
2413
2491
  return httpResponse.json();
@@ -2419,7 +2497,7 @@ class Caches extends BaseModule {
2419
2497
  }
2420
2498
  }
2421
2499
  async listInternal(params) {
2422
- var _a, _b;
2500
+ var _a, _b, _c, _d;
2423
2501
  let response;
2424
2502
  let path = '';
2425
2503
  let queryParams = {};
@@ -2437,6 +2515,7 @@ class Caches extends BaseModule {
2437
2515
  body: JSON.stringify(body),
2438
2516
  httpMethod: 'GET',
2439
2517
  httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
2518
+ abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
2440
2519
  })
2441
2520
  .then((httpResponse) => {
2442
2521
  return httpResponse.json();
@@ -2461,7 +2540,8 @@ class Caches extends BaseModule {
2461
2540
  queryParams: queryParams,
2462
2541
  body: JSON.stringify(body),
2463
2542
  httpMethod: 'GET',
2464
- httpOptions: (_b = params.config) === null || _b === void 0 ? void 0 : _b.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,
2465
2545
  })
2466
2546
  .then((httpResponse) => {
2467
2547
  return httpResponse.json();
@@ -2843,7 +2923,7 @@ const CONTENT_TYPE_HEADER = 'Content-Type';
2843
2923
  const SERVER_TIMEOUT_HEADER = 'X-Server-Timeout';
2844
2924
  const USER_AGENT_HEADER = 'User-Agent';
2845
2925
  const GOOGLE_API_CLIENT_HEADER = 'x-goog-api-client';
2846
- const SDK_VERSION = '0.9.0'; // x-release-please-version
2926
+ const SDK_VERSION = '0.10.0'; // x-release-please-version
2847
2927
  const LIBRARY_LABEL = `google-genai-sdk/${SDK_VERSION}`;
2848
2928
  const VERTEX_AI_API_DEFAULT_VERSION = 'v1beta1';
2849
2929
  const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
@@ -2972,7 +3052,7 @@ class ApiClient {
2972
3052
  getWebsocketBaseUrl() {
2973
3053
  const baseUrl = this.getBaseUrl();
2974
3054
  const urlParts = new URL(baseUrl);
2975
- urlParts.protocol = 'wss';
3055
+ urlParts.protocol = urlParts.protocol == 'http:' ? 'ws' : 'wss';
2976
3056
  return urlParts.toString();
2977
3057
  }
2978
3058
  setBaseUrl(url) {
@@ -3036,7 +3116,7 @@ class ApiClient {
3036
3116
  else {
3037
3117
  requestInit.body = request.body;
3038
3118
  }
3039
- requestInit = await this.includeExtraHttpOptionsToRequestInit(requestInit, patchedHttpOptions);
3119
+ requestInit = await this.includeExtraHttpOptionsToRequestInit(requestInit, patchedHttpOptions, request.abortSignal);
3040
3120
  return this.unaryApiCall(url, requestInit, request.httpMethod);
3041
3121
  }
3042
3122
  patchHttpOptions(baseHttpOptions, requestHttpOptions) {
@@ -3070,14 +3150,21 @@ class ApiClient {
3070
3150
  }
3071
3151
  let requestInit = {};
3072
3152
  requestInit.body = request.body;
3073
- requestInit = await this.includeExtraHttpOptionsToRequestInit(requestInit, patchedHttpOptions);
3153
+ requestInit = await this.includeExtraHttpOptionsToRequestInit(requestInit, patchedHttpOptions, request.abortSignal);
3074
3154
  return this.streamApiCall(url, requestInit, request.httpMethod);
3075
3155
  }
3076
- async includeExtraHttpOptionsToRequestInit(requestInit, httpOptions) {
3077
- if (httpOptions && httpOptions.timeout && httpOptions.timeout > 0) {
3156
+ async includeExtraHttpOptionsToRequestInit(requestInit, httpOptions, abortSignal) {
3157
+ if ((httpOptions && httpOptions.timeout) || abortSignal) {
3078
3158
  const abortController = new AbortController();
3079
3159
  const signal = abortController.signal;
3080
- setTimeout(() => abortController.abort(), httpOptions.timeout);
3160
+ if (httpOptions.timeout && (httpOptions === null || httpOptions === void 0 ? void 0 : httpOptions.timeout) > 0) {
3161
+ setTimeout(() => abortController.abort(), httpOptions.timeout);
3162
+ }
3163
+ if (abortSignal) {
3164
+ abortSignal.addEventListener('abort', () => {
3165
+ abortController.abort();
3166
+ });
3167
+ }
3081
3168
  requestInit.signal = signal;
3082
3169
  }
3083
3170
  requestInit.headers = await this.getHeadersInternal(httpOptions);
@@ -3132,6 +3219,30 @@ class ApiClient {
3132
3219
  break;
3133
3220
  }
3134
3221
  const chunkString = decoder.decode(value);
3222
+ // Parse and throw an error if the chunk contains an error.
3223
+ try {
3224
+ const chunkJson = JSON.parse(chunkString);
3225
+ if ('error' in chunkJson) {
3226
+ const errorJson = JSON.parse(JSON.stringify(chunkJson['error']));
3227
+ const status = errorJson['status'];
3228
+ const code = errorJson['code'];
3229
+ const errorMessage = `got status: ${status}. ${JSON.stringify(chunkJson)}`;
3230
+ if (code >= 400 && code < 500) {
3231
+ const clientError = new ClientError(errorMessage);
3232
+ throw clientError;
3233
+ }
3234
+ else if (code >= 500 && code < 600) {
3235
+ const serverError = new ServerError(errorMessage);
3236
+ throw serverError;
3237
+ }
3238
+ }
3239
+ }
3240
+ catch (e) {
3241
+ const error = e;
3242
+ if (error.name === 'ClientError' || error.name === 'ServerError') {
3243
+ throw e;
3244
+ }
3245
+ }
3135
3246
  buffer += chunkString;
3136
3247
  let match = buffer.match(responseLineRE);
3137
3248
  while (match) {
@@ -3270,7 +3381,7 @@ async function throwErrorIfNotOK(response) {
3270
3381
  else {
3271
3382
  errorBody = {
3272
3383
  error: {
3273
- message: 'exception parsing response',
3384
+ message: await response.text(),
3274
3385
  code: response.status,
3275
3386
  status: response.statusText,
3276
3387
  },
@@ -3722,7 +3833,7 @@ class Files extends BaseModule {
3722
3833
  });
3723
3834
  }
3724
3835
  async listInternal(params) {
3725
- var _a;
3836
+ var _a, _b;
3726
3837
  let response;
3727
3838
  let path = '';
3728
3839
  let queryParams = {};
@@ -3743,6 +3854,7 @@ class Files extends BaseModule {
3743
3854
  body: JSON.stringify(body),
3744
3855
  httpMethod: 'GET',
3745
3856
  httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
3857
+ abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
3746
3858
  })
3747
3859
  .then((httpResponse) => {
3748
3860
  return httpResponse.json();
@@ -3756,7 +3868,7 @@ class Files extends BaseModule {
3756
3868
  }
3757
3869
  }
3758
3870
  async createInternal(params) {
3759
- var _a;
3871
+ var _a, _b;
3760
3872
  let response;
3761
3873
  let path = '';
3762
3874
  let queryParams = {};
@@ -3777,6 +3889,7 @@ class Files extends BaseModule {
3777
3889
  body: JSON.stringify(body),
3778
3890
  httpMethod: 'POST',
3779
3891
  httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
3892
+ abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
3780
3893
  })
3781
3894
  .then((httpResponse) => {
3782
3895
  return httpResponse.json();
@@ -3805,7 +3918,7 @@ class Files extends BaseModule {
3805
3918
  * ```
3806
3919
  */
3807
3920
  async get(params) {
3808
- var _a;
3921
+ var _a, _b;
3809
3922
  let response;
3810
3923
  let path = '';
3811
3924
  let queryParams = {};
@@ -3826,6 +3939,7 @@ class Files extends BaseModule {
3826
3939
  body: JSON.stringify(body),
3827
3940
  httpMethod: 'GET',
3828
3941
  httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
3942
+ abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
3829
3943
  })
3830
3944
  .then((httpResponse) => {
3831
3945
  return httpResponse.json();
@@ -3850,7 +3964,7 @@ class Files extends BaseModule {
3850
3964
  * ```
3851
3965
  */
3852
3966
  async delete(params) {
3853
- var _a;
3967
+ var _a, _b;
3854
3968
  let response;
3855
3969
  let path = '';
3856
3970
  let queryParams = {};
@@ -3871,6 +3985,7 @@ class Files extends BaseModule {
3871
3985
  body: JSON.stringify(body),
3872
3986
  httpMethod: 'DELETE',
3873
3987
  httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
3988
+ abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
3874
3989
  })
3875
3990
  .then((httpResponse) => {
3876
3991
  return httpResponse.json();
@@ -4681,6 +4796,91 @@ function liveConnectParametersToVertex(apiClient, fromObject) {
4681
4796
  }
4682
4797
  return toObject;
4683
4798
  }
4799
+ function activityStartToMldev() {
4800
+ const toObject = {};
4801
+ return toObject;
4802
+ }
4803
+ function activityStartToVertex() {
4804
+ const toObject = {};
4805
+ return toObject;
4806
+ }
4807
+ function activityEndToMldev() {
4808
+ const toObject = {};
4809
+ return toObject;
4810
+ }
4811
+ function activityEndToVertex() {
4812
+ const toObject = {};
4813
+ return toObject;
4814
+ }
4815
+ function liveSendRealtimeInputParametersToMldev(apiClient, fromObject) {
4816
+ const toObject = {};
4817
+ const fromMedia = getValueByPath(fromObject, ['media']);
4818
+ if (fromMedia != null) {
4819
+ setValueByPath(toObject, ['mediaChunks'], tBlobs(apiClient, fromMedia));
4820
+ }
4821
+ const fromAudio = getValueByPath(fromObject, ['audio']);
4822
+ if (fromAudio != null) {
4823
+ setValueByPath(toObject, ['audio'], tAudioBlob(apiClient, fromAudio));
4824
+ }
4825
+ const fromAudioStreamEnd = getValueByPath(fromObject, [
4826
+ 'audioStreamEnd',
4827
+ ]);
4828
+ if (fromAudioStreamEnd != null) {
4829
+ setValueByPath(toObject, ['audioStreamEnd'], fromAudioStreamEnd);
4830
+ }
4831
+ const fromVideo = getValueByPath(fromObject, ['video']);
4832
+ if (fromVideo != null) {
4833
+ setValueByPath(toObject, ['video'], tImageBlob(apiClient, fromVideo));
4834
+ }
4835
+ const fromText = getValueByPath(fromObject, ['text']);
4836
+ if (fromText != null) {
4837
+ setValueByPath(toObject, ['text'], fromText);
4838
+ }
4839
+ const fromActivityStart = getValueByPath(fromObject, [
4840
+ 'activityStart',
4841
+ ]);
4842
+ if (fromActivityStart != null) {
4843
+ setValueByPath(toObject, ['activityStart'], activityStartToMldev());
4844
+ }
4845
+ const fromActivityEnd = getValueByPath(fromObject, ['activityEnd']);
4846
+ if (fromActivityEnd != null) {
4847
+ setValueByPath(toObject, ['activityEnd'], activityEndToMldev());
4848
+ }
4849
+ return toObject;
4850
+ }
4851
+ function liveSendRealtimeInputParametersToVertex(apiClient, fromObject) {
4852
+ const toObject = {};
4853
+ const fromMedia = getValueByPath(fromObject, ['media']);
4854
+ if (fromMedia != null) {
4855
+ setValueByPath(toObject, ['mediaChunks'], tBlobs(apiClient, fromMedia));
4856
+ }
4857
+ if (getValueByPath(fromObject, ['audio']) !== undefined) {
4858
+ throw new Error('audio parameter is not supported in Vertex AI.');
4859
+ }
4860
+ const fromAudioStreamEnd = getValueByPath(fromObject, [
4861
+ 'audioStreamEnd',
4862
+ ]);
4863
+ if (fromAudioStreamEnd != null) {
4864
+ setValueByPath(toObject, ['audioStreamEnd'], fromAudioStreamEnd);
4865
+ }
4866
+ if (getValueByPath(fromObject, ['video']) !== undefined) {
4867
+ throw new Error('video parameter is not supported in Vertex AI.');
4868
+ }
4869
+ if (getValueByPath(fromObject, ['text']) !== undefined) {
4870
+ throw new Error('text parameter is not supported in Vertex AI.');
4871
+ }
4872
+ const fromActivityStart = getValueByPath(fromObject, [
4873
+ 'activityStart',
4874
+ ]);
4875
+ if (fromActivityStart != null) {
4876
+ setValueByPath(toObject, ['activityStart'], activityStartToVertex());
4877
+ }
4878
+ const fromActivityEnd = getValueByPath(fromObject, ['activityEnd']);
4879
+ if (fromActivityEnd != null) {
4880
+ setValueByPath(toObject, ['activityEnd'], activityEndToVertex());
4881
+ }
4882
+ return toObject;
4883
+ }
4684
4884
  function liveServerSetupCompleteFromMldev() {
4685
4885
  const toObject = {};
4686
4886
  return toObject;
@@ -8028,21 +8228,6 @@ class Session {
8028
8228
  clientContent: { turnComplete: params.turnComplete },
8029
8229
  };
8030
8230
  }
8031
- tLiveClientRealtimeInput(apiClient, params) {
8032
- let clientMessage = {};
8033
- if (!('media' in params) || !params.media) {
8034
- throw new Error(`Failed to convert realtime input "media", type: '${typeof params.media}'`);
8035
- }
8036
- // LiveClientRealtimeInput
8037
- clientMessage = {
8038
- realtimeInput: {
8039
- mediaChunks: [params.media],
8040
- activityStart: params.activityStart,
8041
- activityEnd: params.activityEnd,
8042
- },
8043
- };
8044
- return clientMessage;
8045
- }
8046
8231
  tLiveClienttToolResponse(apiClient, params) {
8047
8232
  let functionResponses = [];
8048
8233
  if (params.functionResponses == null) {
@@ -8150,10 +8335,17 @@ class Session {
8150
8335
  of audio and image mimetypes are allowed.
8151
8336
  */
8152
8337
  sendRealtimeInput(params) {
8153
- if (params.media == null) {
8154
- throw new Error('Media is required.');
8338
+ let clientMessage = {};
8339
+ if (this.apiClient.isVertexAI()) {
8340
+ clientMessage = {
8341
+ 'realtimeInput': liveSendRealtimeInputParametersToVertex(this.apiClient, params),
8342
+ };
8343
+ }
8344
+ else {
8345
+ clientMessage = {
8346
+ 'realtimeInput': liveSendRealtimeInputParametersToMldev(this.apiClient, params),
8347
+ };
8155
8348
  }
8156
- const clientMessage = this.tLiveClientRealtimeInput(this.apiClient, params);
8157
8349
  this.conn.send(JSON.stringify(clientMessage));
8158
8350
  }
8159
8351
  /**
@@ -8374,7 +8566,7 @@ class Models extends BaseModule {
8374
8566
  };
8375
8567
  }
8376
8568
  async generateContentInternal(params) {
8377
- var _a, _b;
8569
+ var _a, _b, _c, _d;
8378
8570
  let response;
8379
8571
  let path = '';
8380
8572
  let queryParams = {};
@@ -8392,6 +8584,7 @@ class Models extends BaseModule {
8392
8584
  body: JSON.stringify(body),
8393
8585
  httpMethod: 'POST',
8394
8586
  httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
8587
+ abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
8395
8588
  })
8396
8589
  .then((httpResponse) => {
8397
8590
  return httpResponse.json();
@@ -8416,7 +8609,8 @@ class Models extends BaseModule {
8416
8609
  queryParams: queryParams,
8417
8610
  body: JSON.stringify(body),
8418
8611
  httpMethod: 'POST',
8419
- httpOptions: (_b = params.config) === null || _b === void 0 ? void 0 : _b.httpOptions,
8612
+ httpOptions: (_c = params.config) === null || _c === void 0 ? void 0 : _c.httpOptions,
8613
+ abortSignal: (_d = params.config) === null || _d === void 0 ? void 0 : _d.abortSignal,
8420
8614
  })
8421
8615
  .then((httpResponse) => {
8422
8616
  return httpResponse.json();
@@ -8430,7 +8624,7 @@ class Models extends BaseModule {
8430
8624
  }
8431
8625
  }
8432
8626
  async generateContentStreamInternal(params) {
8433
- var _a, _b;
8627
+ var _a, _b, _c, _d;
8434
8628
  let response;
8435
8629
  let path = '';
8436
8630
  let queryParams = {};
@@ -8448,6 +8642,7 @@ class Models extends BaseModule {
8448
8642
  body: JSON.stringify(body),
8449
8643
  httpMethod: 'POST',
8450
8644
  httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
8645
+ abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
8451
8646
  });
8452
8647
  return response.then(function (apiResponse) {
8453
8648
  return __asyncGenerator(this, arguments, function* () {
@@ -8486,7 +8681,8 @@ class Models extends BaseModule {
8486
8681
  queryParams: queryParams,
8487
8682
  body: JSON.stringify(body),
8488
8683
  httpMethod: 'POST',
8489
- httpOptions: (_b = params.config) === null || _b === void 0 ? void 0 : _b.httpOptions,
8684
+ httpOptions: (_c = params.config) === null || _c === void 0 ? void 0 : _c.httpOptions,
8685
+ abortSignal: (_d = params.config) === null || _d === void 0 ? void 0 : _d.abortSignal,
8490
8686
  });
8491
8687
  return response.then(function (apiResponse) {
8492
8688
  return __asyncGenerator(this, arguments, function* () {
@@ -8535,7 +8731,7 @@ class Models extends BaseModule {
8535
8731
  * ```
8536
8732
  */
8537
8733
  async embedContent(params) {
8538
- var _a, _b;
8734
+ var _a, _b, _c, _d;
8539
8735
  let response;
8540
8736
  let path = '';
8541
8737
  let queryParams = {};
@@ -8553,6 +8749,7 @@ class Models extends BaseModule {
8553
8749
  body: JSON.stringify(body),
8554
8750
  httpMethod: 'POST',
8555
8751
  httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
8752
+ abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
8556
8753
  })
8557
8754
  .then((httpResponse) => {
8558
8755
  return httpResponse.json();
@@ -8577,7 +8774,8 @@ class Models extends BaseModule {
8577
8774
  queryParams: queryParams,
8578
8775
  body: JSON.stringify(body),
8579
8776
  httpMethod: 'POST',
8580
- httpOptions: (_b = params.config) === null || _b === void 0 ? void 0 : _b.httpOptions,
8777
+ httpOptions: (_c = params.config) === null || _c === void 0 ? void 0 : _c.httpOptions,
8778
+ abortSignal: (_d = params.config) === null || _d === void 0 ? void 0 : _d.abortSignal,
8581
8779
  })
8582
8780
  .then((httpResponse) => {
8583
8781
  return httpResponse.json();
@@ -8610,7 +8808,7 @@ class Models extends BaseModule {
8610
8808
  * ```
8611
8809
  */
8612
8810
  async generateImagesInternal(params) {
8613
- var _a, _b;
8811
+ var _a, _b, _c, _d;
8614
8812
  let response;
8615
8813
  let path = '';
8616
8814
  let queryParams = {};
@@ -8628,6 +8826,7 @@ class Models extends BaseModule {
8628
8826
  body: JSON.stringify(body),
8629
8827
  httpMethod: 'POST',
8630
8828
  httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
8829
+ abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
8631
8830
  })
8632
8831
  .then((httpResponse) => {
8633
8832
  return httpResponse.json();
@@ -8652,7 +8851,8 @@ class Models extends BaseModule {
8652
8851
  queryParams: queryParams,
8653
8852
  body: JSON.stringify(body),
8654
8853
  httpMethod: 'POST',
8655
- httpOptions: (_b = params.config) === null || _b === void 0 ? void 0 : _b.httpOptions,
8854
+ httpOptions: (_c = params.config) === null || _c === void 0 ? void 0 : _c.httpOptions,
8855
+ abortSignal: (_d = params.config) === null || _d === void 0 ? void 0 : _d.abortSignal,
8656
8856
  })
8657
8857
  .then((httpResponse) => {
8658
8858
  return httpResponse.json();
@@ -8674,7 +8874,7 @@ class Models extends BaseModule {
8674
8874
  * ```
8675
8875
  */
8676
8876
  async get(params) {
8677
- var _a, _b;
8877
+ var _a, _b, _c, _d;
8678
8878
  let response;
8679
8879
  let path = '';
8680
8880
  let queryParams = {};
@@ -8692,6 +8892,7 @@ class Models extends BaseModule {
8692
8892
  body: JSON.stringify(body),
8693
8893
  httpMethod: 'GET',
8694
8894
  httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
8895
+ abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
8695
8896
  })
8696
8897
  .then((httpResponse) => {
8697
8898
  return httpResponse.json();
@@ -8714,7 +8915,8 @@ class Models extends BaseModule {
8714
8915
  queryParams: queryParams,
8715
8916
  body: JSON.stringify(body),
8716
8917
  httpMethod: 'GET',
8717
- httpOptions: (_b = params.config) === null || _b === void 0 ? void 0 : _b.httpOptions,
8918
+ httpOptions: (_c = params.config) === null || _c === void 0 ? void 0 : _c.httpOptions,
8919
+ abortSignal: (_d = params.config) === null || _d === void 0 ? void 0 : _d.abortSignal,
8718
8920
  })
8719
8921
  .then((httpResponse) => {
8720
8922
  return httpResponse.json();
@@ -8742,7 +8944,7 @@ class Models extends BaseModule {
8742
8944
  * ```
8743
8945
  */
8744
8946
  async countTokens(params) {
8745
- var _a, _b;
8947
+ var _a, _b, _c, _d;
8746
8948
  let response;
8747
8949
  let path = '';
8748
8950
  let queryParams = {};
@@ -8760,6 +8962,7 @@ class Models extends BaseModule {
8760
8962
  body: JSON.stringify(body),
8761
8963
  httpMethod: 'POST',
8762
8964
  httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
8965
+ abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
8763
8966
  })
8764
8967
  .then((httpResponse) => {
8765
8968
  return httpResponse.json();
@@ -8784,7 +8987,8 @@ class Models extends BaseModule {
8784
8987
  queryParams: queryParams,
8785
8988
  body: JSON.stringify(body),
8786
8989
  httpMethod: 'POST',
8787
- httpOptions: (_b = params.config) === null || _b === void 0 ? void 0 : _b.httpOptions,
8990
+ httpOptions: (_c = params.config) === null || _c === void 0 ? void 0 : _c.httpOptions,
8991
+ abortSignal: (_d = params.config) === null || _d === void 0 ? void 0 : _d.abortSignal,
8788
8992
  })
8789
8993
  .then((httpResponse) => {
8790
8994
  return httpResponse.json();
@@ -8816,7 +9020,7 @@ class Models extends BaseModule {
8816
9020
  * ```
8817
9021
  */
8818
9022
  async computeTokens(params) {
8819
- var _a;
9023
+ var _a, _b;
8820
9024
  let response;
8821
9025
  let path = '';
8822
9026
  let queryParams = {};
@@ -8834,6 +9038,7 @@ class Models extends BaseModule {
8834
9038
  body: JSON.stringify(body),
8835
9039
  httpMethod: 'POST',
8836
9040
  httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
9041
+ abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
8837
9042
  })
8838
9043
  .then((httpResponse) => {
8839
9044
  return httpResponse.json();
@@ -8873,7 +9078,7 @@ class Models extends BaseModule {
8873
9078
  * ```
8874
9079
  */
8875
9080
  async generateVideos(params) {
8876
- var _a, _b;
9081
+ var _a, _b, _c, _d;
8877
9082
  let response;
8878
9083
  let path = '';
8879
9084
  let queryParams = {};
@@ -8891,6 +9096,7 @@ class Models extends BaseModule {
8891
9096
  body: JSON.stringify(body),
8892
9097
  httpMethod: 'POST',
8893
9098
  httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
9099
+ abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
8894
9100
  })
8895
9101
  .then((httpResponse) => {
8896
9102
  return httpResponse.json();
@@ -8913,7 +9119,8 @@ class Models extends BaseModule {
8913
9119
  queryParams: queryParams,
8914
9120
  body: JSON.stringify(body),
8915
9121
  httpMethod: 'POST',
8916
- httpOptions: (_b = params.config) === null || _b === void 0 ? void 0 : _b.httpOptions,
9122
+ httpOptions: (_c = params.config) === null || _c === void 0 ? void 0 : _c.httpOptions,
9123
+ abortSignal: (_d = params.config) === null || _d === void 0 ? void 0 : _d.abortSignal,
8917
9124
  })
8918
9125
  .then((httpResponse) => {
8919
9126
  return httpResponse.json();
@@ -9180,7 +9387,7 @@ class Operations extends BaseModule {
9180
9387
  }
9181
9388
  }
9182
9389
  async getVideosOperationInternal(params) {
9183
- var _a, _b;
9390
+ var _a, _b, _c, _d;
9184
9391
  let response;
9185
9392
  let path = '';
9186
9393
  let queryParams = {};
@@ -9198,6 +9405,7 @@ class Operations extends BaseModule {
9198
9405
  body: JSON.stringify(body),
9199
9406
  httpMethod: 'GET',
9200
9407
  httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
9408
+ abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
9201
9409
  })
9202
9410
  .then((httpResponse) => {
9203
9411
  return httpResponse.json();
@@ -9220,7 +9428,8 @@ class Operations extends BaseModule {
9220
9428
  queryParams: queryParams,
9221
9429
  body: JSON.stringify(body),
9222
9430
  httpMethod: 'GET',
9223
- httpOptions: (_b = params.config) === null || _b === void 0 ? void 0 : _b.httpOptions,
9431
+ httpOptions: (_c = params.config) === null || _c === void 0 ? void 0 : _c.httpOptions,
9432
+ abortSignal: (_d = params.config) === null || _d === void 0 ? void 0 : _d.abortSignal,
9224
9433
  })
9225
9434
  .then((httpResponse) => {
9226
9435
  return httpResponse.json();
@@ -9232,7 +9441,7 @@ class Operations extends BaseModule {
9232
9441
  }
9233
9442
  }
9234
9443
  async fetchPredictVideosOperationInternal(params) {
9235
- var _a;
9444
+ var _a, _b;
9236
9445
  let response;
9237
9446
  let path = '';
9238
9447
  let queryParams = {};
@@ -9250,6 +9459,7 @@ class Operations extends BaseModule {
9250
9459
  body: JSON.stringify(body),
9251
9460
  httpMethod: 'POST',
9252
9461
  httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
9462
+ abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
9253
9463
  })
9254
9464
  .then((httpResponse) => {
9255
9465
  return httpResponse.json();
@@ -9349,5 +9559,5 @@ class GoogleGenAI {
9349
9559
  }
9350
9560
  }
9351
9561
 
9352
- 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 };
9562
+ 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 };
9353
9563
  //# sourceMappingURL=index.mjs.map