@google/genai 1.23.0 → 1.25.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.
@@ -221,6 +221,98 @@ function getValueByPath(data, keys, defaultValue = undefined) {
221
221
  throw error;
222
222
  }
223
223
  }
224
+ /**
225
+ * Moves values from source paths to destination paths.
226
+ *
227
+ * Examples:
228
+ * moveValueByPath(
229
+ * {'requests': [{'content': v1}, {'content': v2}]},
230
+ * {'requests[].*': 'requests[].request.*'}
231
+ * )
232
+ * -> {'requests': [{'request': {'content': v1}}, {'request': {'content': v2}}]}
233
+ */
234
+ function moveValueByPath(data, paths) {
235
+ for (const [sourcePath, destPath] of Object.entries(paths)) {
236
+ const sourceKeys = sourcePath.split('.');
237
+ const destKeys = destPath.split('.');
238
+ // Determine keys to exclude from wildcard to avoid cyclic references
239
+ const excludeKeys = new Set();
240
+ let wildcardIdx = -1;
241
+ for (let i = 0; i < sourceKeys.length; i++) {
242
+ if (sourceKeys[i] === '*') {
243
+ wildcardIdx = i;
244
+ break;
245
+ }
246
+ }
247
+ if (wildcardIdx !== -1 && destKeys.length > wildcardIdx) {
248
+ // Extract the intermediate key between source and dest paths
249
+ // Example: source=['requests[]', '*'], dest=['requests[]', 'request', '*']
250
+ // We want to exclude 'request'
251
+ for (let i = wildcardIdx; i < destKeys.length; i++) {
252
+ const key = destKeys[i];
253
+ if (key !== '*' && !key.endsWith('[]') && !key.endsWith('[0]')) {
254
+ excludeKeys.add(key);
255
+ }
256
+ }
257
+ }
258
+ _moveValueRecursive(data, sourceKeys, destKeys, 0, excludeKeys);
259
+ }
260
+ }
261
+ /**
262
+ * Recursively moves values from source path to destination path.
263
+ */
264
+ function _moveValueRecursive(data, sourceKeys, destKeys, keyIdx, excludeKeys) {
265
+ if (keyIdx >= sourceKeys.length) {
266
+ return;
267
+ }
268
+ if (typeof data !== 'object' || data === null) {
269
+ return;
270
+ }
271
+ const key = sourceKeys[keyIdx];
272
+ if (key.endsWith('[]')) {
273
+ const keyName = key.slice(0, -2);
274
+ const dataRecord = data;
275
+ if (keyName in dataRecord && Array.isArray(dataRecord[keyName])) {
276
+ for (const item of dataRecord[keyName]) {
277
+ _moveValueRecursive(item, sourceKeys, destKeys, keyIdx + 1, excludeKeys);
278
+ }
279
+ }
280
+ }
281
+ else if (key === '*') {
282
+ // wildcard - move all fields
283
+ if (typeof data === 'object' && data !== null && !Array.isArray(data)) {
284
+ const dataRecord = data;
285
+ const keysToMove = Object.keys(dataRecord).filter((k) => !k.startsWith('_') && !excludeKeys.has(k));
286
+ const valuesToMove = {};
287
+ for (const k of keysToMove) {
288
+ valuesToMove[k] = dataRecord[k];
289
+ }
290
+ // Set values at destination
291
+ for (const [k, v] of Object.entries(valuesToMove)) {
292
+ const newDestKeys = [];
293
+ for (const dk of destKeys.slice(keyIdx)) {
294
+ if (dk === '*') {
295
+ newDestKeys.push(k);
296
+ }
297
+ else {
298
+ newDestKeys.push(dk);
299
+ }
300
+ }
301
+ setValueByPath(dataRecord, newDestKeys, v);
302
+ }
303
+ for (const k of keysToMove) {
304
+ delete dataRecord[k];
305
+ }
306
+ }
307
+ }
308
+ else {
309
+ // Navigate to next level
310
+ const dataRecord = data;
311
+ if (key in dataRecord) {
312
+ _moveValueRecursive(dataRecord[key], sourceKeys, destKeys, keyIdx + 1, excludeKeys);
313
+ }
314
+ }
315
+ }
224
316
 
225
317
  /**
226
318
  * @license
@@ -362,7 +454,7 @@ function generateVideosResponseFromVertex$1(fromObject) {
362
454
  }
363
455
  function generatedVideoFromMldev$1(fromObject) {
364
456
  const toObject = {};
365
- const fromVideo = getValueByPath(fromObject, ['_self']);
457
+ const fromVideo = getValueByPath(fromObject, ['video']);
366
458
  if (fromVideo != null) {
367
459
  setValueByPath(toObject, ['video'], videoFromMldev$1(fromVideo));
368
460
  }
@@ -398,14 +490,11 @@ function getOperationParametersToVertex(fromObject) {
398
490
  }
399
491
  function videoFromMldev$1(fromObject) {
400
492
  const toObject = {};
401
- const fromUri = getValueByPath(fromObject, ['video', 'uri']);
493
+ const fromUri = getValueByPath(fromObject, ['uri']);
402
494
  if (fromUri != null) {
403
495
  setValueByPath(toObject, ['uri'], fromUri);
404
496
  }
405
- const fromVideoBytes = getValueByPath(fromObject, [
406
- 'video',
407
- 'encodedVideo',
408
- ]);
497
+ const fromVideoBytes = getValueByPath(fromObject, ['encodedVideo']);
409
498
  if (fromVideoBytes != null) {
410
499
  setValueByPath(toObject, ['videoBytes'], tBytes$1(fromVideoBytes));
411
500
  }
@@ -3538,6 +3627,7 @@ function embedContentBatchToMldev(apiClient, fromObject) {
3538
3627
  const fromConfig = getValueByPath(fromObject, ['config']);
3539
3628
  if (fromConfig != null) {
3540
3629
  setValueByPath(toObject, ['_self'], embedContentConfigToMldev$1(fromConfig, toObject));
3630
+ moveValueByPath(toObject, { 'requests[].*': 'requests[].request.*' });
3541
3631
  }
3542
3632
  return toObject;
3543
3633
  }
@@ -3804,6 +3894,17 @@ function getBatchJobParametersToVertex(apiClient, fromObject) {
3804
3894
  }
3805
3895
  return toObject;
3806
3896
  }
3897
+ function googleMapsToMldev$4(fromObject) {
3898
+ const toObject = {};
3899
+ if (getValueByPath(fromObject, ['authConfig']) !== undefined) {
3900
+ throw new Error('authConfig parameter is not supported in Gemini API.');
3901
+ }
3902
+ const fromEnableWidget = getValueByPath(fromObject, ['enableWidget']);
3903
+ if (fromEnableWidget != null) {
3904
+ setValueByPath(toObject, ['enableWidget'], fromEnableWidget);
3905
+ }
3906
+ return toObject;
3907
+ }
3807
3908
  function googleSearchToMldev$4(fromObject) {
3808
3909
  const toObject = {};
3809
3910
  const fromTimeRangeFilter = getValueByPath(fromObject, [
@@ -3833,6 +3934,10 @@ function inlinedRequestToMldev(apiClient, fromObject) {
3833
3934
  }
3834
3935
  setValueByPath(toObject, ['request', 'contents'], transformedList);
3835
3936
  }
3937
+ const fromMetadata = getValueByPath(fromObject, ['metadata']);
3938
+ if (fromMetadata != null) {
3939
+ setValueByPath(toObject, ['metadata'], fromMetadata);
3940
+ }
3836
3941
  const fromConfig = getValueByPath(fromObject, ['config']);
3837
3942
  if (fromConfig != null) {
3838
3943
  setValueByPath(toObject, ['request', 'generationConfig'], generateContentConfigToMldev$1(apiClient, fromConfig, getValueByPath(toObject, ['request'], {})));
@@ -4051,8 +4156,9 @@ function toolToMldev$4(fromObject) {
4051
4156
  if (getValueByPath(fromObject, ['enterpriseWebSearch']) !== undefined) {
4052
4157
  throw new Error('enterpriseWebSearch parameter is not supported in Gemini API.');
4053
4158
  }
4054
- if (getValueByPath(fromObject, ['googleMaps']) !== undefined) {
4055
- throw new Error('googleMaps parameter is not supported in Gemini API.');
4159
+ const fromGoogleMaps = getValueByPath(fromObject, ['googleMaps']);
4160
+ if (fromGoogleMaps != null) {
4161
+ setValueByPath(toObject, ['googleMaps'], googleMapsToMldev$4(fromGoogleMaps));
4056
4162
  }
4057
4163
  const fromUrlContext = getValueByPath(fromObject, ['urlContext']);
4058
4164
  if (fromUrlContext != null) {
@@ -4303,38 +4409,11 @@ class Batches extends BaseModule {
4303
4409
  * ```
4304
4410
  */
4305
4411
  this.createEmbeddings = async (params) => {
4306
- var _a, _b;
4307
4412
  console.warn('batches.createEmbeddings() is experimental and may change without notice.');
4308
4413
  if (this.apiClient.isVertexAI()) {
4309
4414
  throw new Error('Vertex AI does not support batches.createEmbeddings.');
4310
4415
  }
4311
- // MLDEV
4312
- const src = params.src;
4313
- const is_inlined = src.inlinedRequests !== undefined;
4314
- if (!is_inlined) {
4315
- return this.createEmbeddingsInternal(params); // Fixed typo here
4316
- }
4317
- // Inlined embed content requests handling
4318
- const result = this.createInlinedEmbedContentRequest(params);
4319
- const path = result.path;
4320
- const requestBody = result.body;
4321
- const queryParams = createEmbeddingsBatchJobParametersToMldev(this.apiClient, params)['_query'] || {};
4322
- const response = this.apiClient
4323
- .request({
4324
- path: path,
4325
- queryParams: queryParams,
4326
- body: JSON.stringify(requestBody),
4327
- httpMethod: 'POST',
4328
- httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
4329
- abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
4330
- })
4331
- .then((httpResponse) => {
4332
- return httpResponse.json();
4333
- });
4334
- return response.then((apiResponse) => {
4335
- const resp = batchJobFromMldev(apiResponse);
4336
- return resp;
4337
- });
4416
+ return this.createEmbeddingsInternal(params);
4338
4417
  };
4339
4418
  /**
4340
4419
  * Lists batch job configurations.
@@ -4382,35 +4461,6 @@ class Batches extends BaseModule {
4382
4461
  delete body['_query'];
4383
4462
  return { path, body };
4384
4463
  }
4385
- // Helper function to handle inlined embedding requests
4386
- createInlinedEmbedContentRequest(params) {
4387
- const body = createEmbeddingsBatchJobParametersToMldev(this.apiClient, // Use instance apiClient
4388
- params);
4389
- const urlParams = body['_url'];
4390
- const path = formatMap('{model}:asyncBatchEmbedContent', urlParams);
4391
- const batch = body['batch'];
4392
- const inputConfig = batch['inputConfig'];
4393
- const requestsWrapper = inputConfig['requests'];
4394
- const requests = requestsWrapper['requests'];
4395
- const newRequests = [];
4396
- delete requestsWrapper['config']; // Remove top-level config
4397
- for (const request of requests) {
4398
- const requestDict = Object.assign({}, request); // Clone
4399
- const innerRequest = requestDict['request'];
4400
- for (const key in requestDict) {
4401
- if (key !== 'request') {
4402
- innerRequest[key] = requestDict[key];
4403
- delete requestDict[key];
4404
- }
4405
- }
4406
- newRequests.push(requestDict);
4407
- }
4408
- requestsWrapper['requests'] = newRequests;
4409
- delete body['config'];
4410
- delete body['_url'];
4411
- delete body['_query'];
4412
- return { path, body };
4413
- }
4414
4464
  // Helper function to get the first GCS URI
4415
4465
  getGcsUri(src) {
4416
4466
  if (typeof src === 'string') {
@@ -5075,6 +5125,17 @@ function getCachedContentParametersToVertex(apiClient, fromObject) {
5075
5125
  }
5076
5126
  return toObject;
5077
5127
  }
5128
+ function googleMapsToMldev$3(fromObject) {
5129
+ const toObject = {};
5130
+ if (getValueByPath(fromObject, ['authConfig']) !== undefined) {
5131
+ throw new Error('authConfig parameter is not supported in Gemini API.');
5132
+ }
5133
+ const fromEnableWidget = getValueByPath(fromObject, ['enableWidget']);
5134
+ if (fromEnableWidget != null) {
5135
+ setValueByPath(toObject, ['enableWidget'], fromEnableWidget);
5136
+ }
5137
+ return toObject;
5138
+ }
5078
5139
  function googleSearchToMldev$3(fromObject) {
5079
5140
  const toObject = {};
5080
5141
  const fromTimeRangeFilter = getValueByPath(fromObject, [
@@ -5268,8 +5329,9 @@ function toolToMldev$3(fromObject) {
5268
5329
  if (getValueByPath(fromObject, ['enterpriseWebSearch']) !== undefined) {
5269
5330
  throw new Error('enterpriseWebSearch parameter is not supported in Gemini API.');
5270
5331
  }
5271
- if (getValueByPath(fromObject, ['googleMaps']) !== undefined) {
5272
- throw new Error('googleMaps parameter is not supported in Gemini API.');
5332
+ const fromGoogleMaps = getValueByPath(fromObject, ['googleMaps']);
5333
+ if (fromGoogleMaps != null) {
5334
+ setValueByPath(toObject, ['googleMaps'], googleMapsToMldev$3(fromGoogleMaps));
5273
5335
  }
5274
5336
  const fromUrlContext = getValueByPath(fromObject, ['urlContext']);
5275
5337
  if (fromUrlContext != null) {
@@ -6752,6 +6814,17 @@ function generationConfigToVertex$1(fromObject) {
6752
6814
  }
6753
6815
  return toObject;
6754
6816
  }
6817
+ function googleMapsToMldev$2(fromObject) {
6818
+ const toObject = {};
6819
+ if (getValueByPath(fromObject, ['authConfig']) !== undefined) {
6820
+ throw new Error('authConfig parameter is not supported in Gemini API.');
6821
+ }
6822
+ const fromEnableWidget = getValueByPath(fromObject, ['enableWidget']);
6823
+ if (fromEnableWidget != null) {
6824
+ setValueByPath(toObject, ['enableWidget'], fromEnableWidget);
6825
+ }
6826
+ return toObject;
6827
+ }
6755
6828
  function googleSearchToMldev$2(fromObject) {
6756
6829
  const toObject = {};
6757
6830
  const fromTimeRangeFilter = getValueByPath(fromObject, [
@@ -7271,8 +7344,9 @@ function toolToMldev$2(fromObject) {
7271
7344
  if (getValueByPath(fromObject, ['enterpriseWebSearch']) !== undefined) {
7272
7345
  throw new Error('enterpriseWebSearch parameter is not supported in Gemini API.');
7273
7346
  }
7274
- if (getValueByPath(fromObject, ['googleMaps']) !== undefined) {
7275
- throw new Error('googleMaps parameter is not supported in Gemini API.');
7347
+ const fromGoogleMaps = getValueByPath(fromObject, ['googleMaps']);
7348
+ if (fromGoogleMaps != null) {
7349
+ setValueByPath(toObject, ['googleMaps'], googleMapsToMldev$2(fromGoogleMaps));
7276
7350
  }
7277
7351
  const fromUrlContext = getValueByPath(fromObject, ['urlContext']);
7278
7352
  if (fromUrlContext != null) {
@@ -9261,7 +9335,7 @@ function generatedImageMaskFromVertex(fromObject) {
9261
9335
  }
9262
9336
  function generatedVideoFromMldev(fromObject) {
9263
9337
  const toObject = {};
9264
- const fromVideo = getValueByPath(fromObject, ['_self']);
9338
+ const fromVideo = getValueByPath(fromObject, ['video']);
9265
9339
  if (fromVideo != null) {
9266
9340
  setValueByPath(toObject, ['video'], videoFromMldev(fromVideo));
9267
9341
  }
@@ -9415,6 +9489,17 @@ function getModelParametersToVertex(apiClient, fromObject) {
9415
9489
  }
9416
9490
  return toObject;
9417
9491
  }
9492
+ function googleMapsToMldev$1(fromObject) {
9493
+ const toObject = {};
9494
+ if (getValueByPath(fromObject, ['authConfig']) !== undefined) {
9495
+ throw new Error('authConfig parameter is not supported in Gemini API.');
9496
+ }
9497
+ const fromEnableWidget = getValueByPath(fromObject, ['enableWidget']);
9498
+ if (fromEnableWidget != null) {
9499
+ setValueByPath(toObject, ['enableWidget'], fromEnableWidget);
9500
+ }
9501
+ return toObject;
9502
+ }
9418
9503
  function googleSearchToMldev$1(fromObject) {
9419
9504
  const toObject = {};
9420
9505
  const fromTimeRangeFilter = getValueByPath(fromObject, [
@@ -10129,8 +10214,9 @@ function toolToMldev$1(fromObject) {
10129
10214
  if (getValueByPath(fromObject, ['enterpriseWebSearch']) !== undefined) {
10130
10215
  throw new Error('enterpriseWebSearch parameter is not supported in Gemini API.');
10131
10216
  }
10132
- if (getValueByPath(fromObject, ['googleMaps']) !== undefined) {
10133
- throw new Error('googleMaps parameter is not supported in Gemini API.');
10217
+ const fromGoogleMaps = getValueByPath(fromObject, ['googleMaps']);
10218
+ if (fromGoogleMaps != null) {
10219
+ setValueByPath(toObject, ['googleMaps'], googleMapsToMldev$1(fromGoogleMaps));
10134
10220
  }
10135
10221
  const fromUrlContext = getValueByPath(fromObject, ['urlContext']);
10136
10222
  if (fromUrlContext != null) {
@@ -10395,14 +10481,11 @@ function upscaleImageResponseFromVertex(fromObject) {
10395
10481
  }
10396
10482
  function videoFromMldev(fromObject) {
10397
10483
  const toObject = {};
10398
- const fromUri = getValueByPath(fromObject, ['video', 'uri']);
10484
+ const fromUri = getValueByPath(fromObject, ['uri']);
10399
10485
  if (fromUri != null) {
10400
10486
  setValueByPath(toObject, ['uri'], fromUri);
10401
10487
  }
10402
- const fromVideoBytes = getValueByPath(fromObject, [
10403
- 'video',
10404
- 'encodedVideo',
10405
- ]);
10488
+ const fromVideoBytes = getValueByPath(fromObject, ['encodedVideo']);
10406
10489
  if (fromVideoBytes != null) {
10407
10490
  setValueByPath(toObject, ['videoBytes'], tBytes(fromVideoBytes));
10408
10491
  }
@@ -10474,11 +10557,11 @@ function videoToMldev(fromObject) {
10474
10557
  const toObject = {};
10475
10558
  const fromUri = getValueByPath(fromObject, ['uri']);
10476
10559
  if (fromUri != null) {
10477
- setValueByPath(toObject, ['video', 'uri'], fromUri);
10560
+ setValueByPath(toObject, ['uri'], fromUri);
10478
10561
  }
10479
10562
  const fromVideoBytes = getValueByPath(fromObject, ['videoBytes']);
10480
10563
  if (fromVideoBytes != null) {
10481
- setValueByPath(toObject, ['video', 'encodedVideo'], tBytes(fromVideoBytes));
10564
+ setValueByPath(toObject, ['encodedVideo'], tBytes(fromVideoBytes));
10482
10565
  }
10483
10566
  const fromMimeType = getValueByPath(fromObject, ['mimeType']);
10484
10567
  if (fromMimeType != null) {
@@ -10512,7 +10595,7 @@ const CONTENT_TYPE_HEADER = 'Content-Type';
10512
10595
  const SERVER_TIMEOUT_HEADER = 'X-Server-Timeout';
10513
10596
  const USER_AGENT_HEADER = 'User-Agent';
10514
10597
  const GOOGLE_API_CLIENT_HEADER = 'x-goog-api-client';
10515
- const SDK_VERSION = '1.23.0'; // x-release-please-version
10598
+ const SDK_VERSION = '1.25.0'; // x-release-please-version
10516
10599
  const LIBRARY_LABEL = `google-genai-sdk/${SDK_VERSION}`;
10517
10600
  const VERTEX_AI_API_DEFAULT_VERSION = 'v1beta1';
10518
10601
  const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
@@ -12290,9 +12373,26 @@ class Models extends BaseModule {
12290
12373
  * ```
12291
12374
  */
12292
12375
  this.generateVideos = async (params) => {
12376
+ var _a, _b, _c, _d, _e, _f;
12293
12377
  if ((params.prompt || params.image || params.video) && params.source) {
12294
12378
  throw new Error('Source and prompt/image/video are mutually exclusive. Please only use source.');
12295
12379
  }
12380
+ // Gemini API does not support video bytes.
12381
+ if (!this.apiClient.isVertexAI()) {
12382
+ if (((_a = params.video) === null || _a === void 0 ? void 0 : _a.uri) && ((_b = params.video) === null || _b === void 0 ? void 0 : _b.videoBytes)) {
12383
+ params.video = {
12384
+ uri: params.video.uri,
12385
+ mimeType: params.video.mimeType,
12386
+ };
12387
+ }
12388
+ else if (((_d = (_c = params.source) === null || _c === void 0 ? void 0 : _c.video) === null || _d === void 0 ? void 0 : _d.uri) &&
12389
+ ((_f = (_e = params.source) === null || _e === void 0 ? void 0 : _e.video) === null || _f === void 0 ? void 0 : _f.videoBytes)) {
12390
+ params.source.video = {
12391
+ uri: params.source.video.uri,
12392
+ mimeType: params.source.video.mimeType,
12393
+ };
12394
+ }
12395
+ }
12296
12396
  return await this.generateVideosInternal(params);
12297
12397
  };
12298
12398
  }
@@ -13718,6 +13818,17 @@ function fileDataToMldev(fromObject) {
13718
13818
  }
13719
13819
  return toObject;
13720
13820
  }
13821
+ function googleMapsToMldev(fromObject) {
13822
+ const toObject = {};
13823
+ if (getValueByPath(fromObject, ['authConfig']) !== undefined) {
13824
+ throw new Error('authConfig parameter is not supported in Gemini API.');
13825
+ }
13826
+ const fromEnableWidget = getValueByPath(fromObject, ['enableWidget']);
13827
+ if (fromEnableWidget != null) {
13828
+ setValueByPath(toObject, ['enableWidget'], fromEnableWidget);
13829
+ }
13830
+ return toObject;
13831
+ }
13721
13832
  function googleSearchToMldev(fromObject) {
13722
13833
  const toObject = {};
13723
13834
  const fromTimeRangeFilter = getValueByPath(fromObject, [
@@ -13948,8 +14059,9 @@ function toolToMldev(fromObject) {
13948
14059
  if (getValueByPath(fromObject, ['enterpriseWebSearch']) !== undefined) {
13949
14060
  throw new Error('enterpriseWebSearch parameter is not supported in Gemini API.');
13950
14061
  }
13951
- if (getValueByPath(fromObject, ['googleMaps']) !== undefined) {
13952
- throw new Error('googleMaps parameter is not supported in Gemini API.');
14062
+ const fromGoogleMaps = getValueByPath(fromObject, ['googleMaps']);
14063
+ if (fromGoogleMaps != null) {
14064
+ setValueByPath(toObject, ['googleMaps'], googleMapsToMldev(fromGoogleMaps));
13953
14065
  }
13954
14066
  const fromUrlContext = getValueByPath(fromObject, ['urlContext']);
13955
14067
  if (fromUrlContext != null) {