@google/genai 1.14.0 → 1.15.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
@@ -867,6 +867,15 @@ var EditMode;
867
867
  EditMode["EDIT_MODE_BGSWAP"] = "EDIT_MODE_BGSWAP";
868
868
  EditMode["EDIT_MODE_PRODUCT_IMAGE"] = "EDIT_MODE_PRODUCT_IMAGE";
869
869
  })(EditMode || (EditMode = {}));
870
+ /** Enum that represents the segmentation mode. */
871
+ var SegmentMode;
872
+ (function (SegmentMode) {
873
+ SegmentMode["FOREGROUND"] = "FOREGROUND";
874
+ SegmentMode["BACKGROUND"] = "BACKGROUND";
875
+ SegmentMode["PROMPT"] = "PROMPT";
876
+ SegmentMode["SEMANTIC"] = "SEMANTIC";
877
+ SegmentMode["INTERACTIVE"] = "INTERACTIVE";
878
+ })(SegmentMode || (SegmentMode = {}));
870
879
  /** Enum that controls the compression quality of the generated videos. */
871
880
  var VideoCompressionQuality;
872
881
  (function (VideoCompressionQuality) {
@@ -1513,6 +1522,9 @@ class UpscaleImageResponse {
1513
1522
  /** The output images response. */
1514
1523
  class RecontextImageResponse {
1515
1524
  }
1525
+ /** The output images response. */
1526
+ class SegmentImageResponse {
1527
+ }
1516
1528
  class ListModelsResponse {
1517
1529
  }
1518
1530
  class DeleteModelResponse {
@@ -4251,6 +4263,7 @@ class Batches extends BaseModule {
4251
4263
  * ```
4252
4264
  */
4253
4265
  this.create = async (params) => {
4266
+ var _a, _b;
4254
4267
  if (this.apiClient.isVertexAI()) {
4255
4268
  const timestamp = Date.now();
4256
4269
  const timestampStr = timestamp.toString();
@@ -4275,6 +4288,55 @@ class Batches extends BaseModule {
4275
4288
  }
4276
4289
  }
4277
4290
  }
4291
+ else {
4292
+ if (Array.isArray(params.src) ||
4293
+ (typeof params.src !== 'string' && params.src.inlinedRequests)) {
4294
+ // Move system instruction to httpOptions extraBody.
4295
+ let path = '';
4296
+ let queryParams = {};
4297
+ const body = createBatchJobParametersToMldev(this.apiClient, params);
4298
+ path = formatMap('{model}:batchGenerateContent', body['_url']);
4299
+ queryParams = body['_query'];
4300
+ // Move system instruction to 'request':
4301
+ // {'systemInstruction': system_instruction}
4302
+ const batch = body['batch'];
4303
+ const inputConfig = batch['inputConfig'];
4304
+ const requestsWrapper = inputConfig['requests'];
4305
+ const requests = requestsWrapper['requests'];
4306
+ const newRequests = [];
4307
+ for (const request of requests) {
4308
+ const requestDict = request;
4309
+ if (requestDict['systemInstruction']) {
4310
+ const systemInstructionValue = requestDict['systemInstruction'];
4311
+ delete requestDict['systemInstruction'];
4312
+ const requestContent = requestDict['request'];
4313
+ requestContent['systemInstruction'] = systemInstructionValue;
4314
+ requestDict['request'] = requestContent;
4315
+ }
4316
+ newRequests.push(requestDict);
4317
+ }
4318
+ requestsWrapper['requests'] = newRequests;
4319
+ delete body['config'];
4320
+ delete body['_url'];
4321
+ delete body['_query'];
4322
+ const response = this.apiClient
4323
+ .request({
4324
+ path: path,
4325
+ queryParams: queryParams,
4326
+ body: JSON.stringify(body),
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
+ });
4338
+ }
4339
+ }
4278
4340
  return await this.createInternal(params);
4279
4341
  };
4280
4342
  /**
@@ -6185,9 +6247,6 @@ function isValidContent(content) {
6185
6247
  if (part === undefined || Object.keys(part).length === 0) {
6186
6248
  return false;
6187
6249
  }
6188
- if (!part.thought && part.text !== undefined && part.text === '') {
6189
- return false;
6190
- }
6191
6250
  }
6192
6251
  return true;
6193
6252
  }
@@ -6510,7 +6569,7 @@ const CONTENT_TYPE_HEADER = 'Content-Type';
6510
6569
  const SERVER_TIMEOUT_HEADER = 'X-Server-Timeout';
6511
6570
  const USER_AGENT_HEADER = 'User-Agent';
6512
6571
  const GOOGLE_API_CLIENT_HEADER = 'x-goog-api-client';
6513
- const SDK_VERSION = '1.14.0'; // x-release-please-version
6572
+ const SDK_VERSION = '1.15.0'; // x-release-please-version
6514
6573
  const LIBRARY_LABEL = `google-genai-sdk/${SDK_VERSION}`;
6515
6574
  const VERTEX_AI_API_DEFAULT_VERSION = 'v1beta1';
6516
6575
  const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
@@ -11089,6 +11148,9 @@ function generateVideosConfigToMldev(fromObject, parentObject) {
11089
11148
  if (getValueByPath(fromObject, ['lastFrame']) !== undefined) {
11090
11149
  throw new Error('lastFrame parameter is not supported in Gemini API.');
11091
11150
  }
11151
+ if (getValueByPath(fromObject, ['referenceImages']) !== undefined) {
11152
+ throw new Error('referenceImages parameter is not supported in Gemini API.');
11153
+ }
11092
11154
  if (getValueByPath(fromObject, ['compressionQuality']) !== undefined) {
11093
11155
  throw new Error('compressionQuality parameter is not supported in Gemini API.');
11094
11156
  }
@@ -12399,6 +12461,78 @@ function recontextImageParametersToVertex(apiClient, fromObject) {
12399
12461
  }
12400
12462
  return toObject;
12401
12463
  }
12464
+ function scribbleImageToVertex(fromObject) {
12465
+ const toObject = {};
12466
+ const fromImage = getValueByPath(fromObject, ['image']);
12467
+ if (fromImage != null) {
12468
+ setValueByPath(toObject, ['image'], imageToVertex(fromImage));
12469
+ }
12470
+ return toObject;
12471
+ }
12472
+ function segmentImageSourceToVertex(fromObject, parentObject) {
12473
+ const toObject = {};
12474
+ const fromPrompt = getValueByPath(fromObject, ['prompt']);
12475
+ if (parentObject !== undefined && fromPrompt != null) {
12476
+ setValueByPath(parentObject, ['instances[0]', 'prompt'], fromPrompt);
12477
+ }
12478
+ const fromImage = getValueByPath(fromObject, ['image']);
12479
+ if (parentObject !== undefined && fromImage != null) {
12480
+ setValueByPath(parentObject, ['instances[0]', 'image'], imageToVertex(fromImage));
12481
+ }
12482
+ const fromScribbleImage = getValueByPath(fromObject, [
12483
+ 'scribbleImage',
12484
+ ]);
12485
+ if (parentObject !== undefined && fromScribbleImage != null) {
12486
+ setValueByPath(parentObject, ['instances[0]', 'scribble'], scribbleImageToVertex(fromScribbleImage));
12487
+ }
12488
+ return toObject;
12489
+ }
12490
+ function segmentImageConfigToVertex(fromObject, parentObject) {
12491
+ const toObject = {};
12492
+ const fromMode = getValueByPath(fromObject, ['mode']);
12493
+ if (parentObject !== undefined && fromMode != null) {
12494
+ setValueByPath(parentObject, ['parameters', 'mode'], fromMode);
12495
+ }
12496
+ const fromMaxPredictions = getValueByPath(fromObject, [
12497
+ 'maxPredictions',
12498
+ ]);
12499
+ if (parentObject !== undefined && fromMaxPredictions != null) {
12500
+ setValueByPath(parentObject, ['parameters', 'maxPredictions'], fromMaxPredictions);
12501
+ }
12502
+ const fromConfidenceThreshold = getValueByPath(fromObject, [
12503
+ 'confidenceThreshold',
12504
+ ]);
12505
+ if (parentObject !== undefined && fromConfidenceThreshold != null) {
12506
+ setValueByPath(parentObject, ['parameters', 'confidenceThreshold'], fromConfidenceThreshold);
12507
+ }
12508
+ const fromMaskDilation = getValueByPath(fromObject, ['maskDilation']);
12509
+ if (parentObject !== undefined && fromMaskDilation != null) {
12510
+ setValueByPath(parentObject, ['parameters', 'maskDilation'], fromMaskDilation);
12511
+ }
12512
+ const fromBinaryColorThreshold = getValueByPath(fromObject, [
12513
+ 'binaryColorThreshold',
12514
+ ]);
12515
+ if (parentObject !== undefined && fromBinaryColorThreshold != null) {
12516
+ setValueByPath(parentObject, ['parameters', 'binaryColorThreshold'], fromBinaryColorThreshold);
12517
+ }
12518
+ return toObject;
12519
+ }
12520
+ function segmentImageParametersToVertex(apiClient, fromObject) {
12521
+ const toObject = {};
12522
+ const fromModel = getValueByPath(fromObject, ['model']);
12523
+ if (fromModel != null) {
12524
+ setValueByPath(toObject, ['_url', 'model'], tModel(apiClient, fromModel));
12525
+ }
12526
+ const fromSource = getValueByPath(fromObject, ['source']);
12527
+ if (fromSource != null) {
12528
+ setValueByPath(toObject, ['config'], segmentImageSourceToVertex(fromSource, toObject));
12529
+ }
12530
+ const fromConfig = getValueByPath(fromObject, ['config']);
12531
+ if (fromConfig != null) {
12532
+ setValueByPath(toObject, ['config'], segmentImageConfigToVertex(fromConfig, toObject));
12533
+ }
12534
+ return toObject;
12535
+ }
12402
12536
  function getModelParametersToVertex(apiClient, fromObject) {
12403
12537
  const toObject = {};
12404
12538
  const fromModel = getValueByPath(fromObject, ['model']);
@@ -12567,6 +12701,20 @@ function videoToVertex(fromObject) {
12567
12701
  }
12568
12702
  return toObject;
12569
12703
  }
12704
+ function videoGenerationReferenceImageToVertex(fromObject) {
12705
+ const toObject = {};
12706
+ const fromImage = getValueByPath(fromObject, ['image']);
12707
+ if (fromImage != null) {
12708
+ setValueByPath(toObject, ['image'], imageToVertex(fromImage));
12709
+ }
12710
+ const fromReferenceType = getValueByPath(fromObject, [
12711
+ 'referenceType',
12712
+ ]);
12713
+ if (fromReferenceType != null) {
12714
+ setValueByPath(toObject, ['referenceType'], fromReferenceType);
12715
+ }
12716
+ return toObject;
12717
+ }
12570
12718
  function generateVideosConfigToVertex(fromObject, parentObject) {
12571
12719
  const toObject = {};
12572
12720
  const fromNumberOfVideos = getValueByPath(fromObject, [
@@ -12633,6 +12781,18 @@ function generateVideosConfigToVertex(fromObject, parentObject) {
12633
12781
  if (parentObject !== undefined && fromLastFrame != null) {
12634
12782
  setValueByPath(parentObject, ['instances[0]', 'lastFrame'], imageToVertex(fromLastFrame));
12635
12783
  }
12784
+ const fromReferenceImages = getValueByPath(fromObject, [
12785
+ 'referenceImages',
12786
+ ]);
12787
+ if (parentObject !== undefined && fromReferenceImages != null) {
12788
+ let transformedList = fromReferenceImages;
12789
+ if (Array.isArray(transformedList)) {
12790
+ transformedList = transformedList.map((item) => {
12791
+ return videoGenerationReferenceImageToVertex(item);
12792
+ });
12793
+ }
12794
+ setValueByPath(parentObject, ['instances[0]', 'referenceImages'], transformedList);
12795
+ }
12636
12796
  const fromCompressionQuality = getValueByPath(fromObject, [
12637
12797
  'compressionQuality',
12638
12798
  ]);
@@ -13682,6 +13842,50 @@ function recontextImageResponseFromVertex(fromObject) {
13682
13842
  }
13683
13843
  return toObject;
13684
13844
  }
13845
+ function entityLabelFromVertex(fromObject) {
13846
+ const toObject = {};
13847
+ const fromLabel = getValueByPath(fromObject, ['label']);
13848
+ if (fromLabel != null) {
13849
+ setValueByPath(toObject, ['label'], fromLabel);
13850
+ }
13851
+ const fromScore = getValueByPath(fromObject, ['score']);
13852
+ if (fromScore != null) {
13853
+ setValueByPath(toObject, ['score'], fromScore);
13854
+ }
13855
+ return toObject;
13856
+ }
13857
+ function generatedImageMaskFromVertex(fromObject) {
13858
+ const toObject = {};
13859
+ const fromMask = getValueByPath(fromObject, ['_self']);
13860
+ if (fromMask != null) {
13861
+ setValueByPath(toObject, ['mask'], imageFromVertex(fromMask));
13862
+ }
13863
+ const fromLabels = getValueByPath(fromObject, ['labels']);
13864
+ if (fromLabels != null) {
13865
+ let transformedList = fromLabels;
13866
+ if (Array.isArray(transformedList)) {
13867
+ transformedList = transformedList.map((item) => {
13868
+ return entityLabelFromVertex(item);
13869
+ });
13870
+ }
13871
+ setValueByPath(toObject, ['labels'], transformedList);
13872
+ }
13873
+ return toObject;
13874
+ }
13875
+ function segmentImageResponseFromVertex(fromObject) {
13876
+ const toObject = {};
13877
+ const fromGeneratedMasks = getValueByPath(fromObject, ['predictions']);
13878
+ if (fromGeneratedMasks != null) {
13879
+ let transformedList = fromGeneratedMasks;
13880
+ if (Array.isArray(transformedList)) {
13881
+ transformedList = transformedList.map((item) => {
13882
+ return generatedImageMaskFromVertex(item);
13883
+ });
13884
+ }
13885
+ setValueByPath(toObject, ['generatedMasks'], transformedList);
13886
+ }
13887
+ return toObject;
13888
+ }
13685
13889
  function endpointFromVertex(fromObject) {
13686
13890
  const toObject = {};
13687
13891
  const fromName = getValueByPath(fromObject, ['endpoint']);
@@ -15798,6 +16002,61 @@ class Models extends BaseModule {
15798
16002
  throw new Error('This method is only supported by the Vertex AI.');
15799
16003
  }
15800
16004
  }
16005
+ /**
16006
+ * Segments an image, creating a mask of a specified area.
16007
+ *
16008
+ * @param params - The parameters for segmenting an image.
16009
+ * @return The response from the API.
16010
+ *
16011
+ * @example
16012
+ * ```ts
16013
+ * const response = await ai.models.segmentImage({
16014
+ * model: 'image-segmentation-001',
16015
+ * source: {
16016
+ * image: image,
16017
+ * },
16018
+ * config: {
16019
+ * mode: 'foreground',
16020
+ * },
16021
+ * });
16022
+ * console.log(response?.generatedMasks?.[0]?.mask?.imageBytes);
16023
+ * ```
16024
+ */
16025
+ async segmentImage(params) {
16026
+ var _a, _b;
16027
+ let response;
16028
+ let path = '';
16029
+ let queryParams = {};
16030
+ if (this.apiClient.isVertexAI()) {
16031
+ const body = segmentImageParametersToVertex(this.apiClient, params);
16032
+ path = formatMap('{model}:predict', body['_url']);
16033
+ queryParams = body['_query'];
16034
+ delete body['config'];
16035
+ delete body['_url'];
16036
+ delete body['_query'];
16037
+ response = this.apiClient
16038
+ .request({
16039
+ path: path,
16040
+ queryParams: queryParams,
16041
+ body: JSON.stringify(body),
16042
+ httpMethod: 'POST',
16043
+ httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
16044
+ abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
16045
+ })
16046
+ .then((httpResponse) => {
16047
+ return httpResponse.json();
16048
+ });
16049
+ return response.then((apiResponse) => {
16050
+ const resp = segmentImageResponseFromVertex(apiResponse);
16051
+ const typedResp = new SegmentImageResponse();
16052
+ Object.assign(typedResp, resp);
16053
+ return typedResp;
16054
+ });
16055
+ }
16056
+ else {
16057
+ throw new Error('This method is only supported by the Vertex AI.');
16058
+ }
16059
+ }
15801
16060
  /**
15802
16061
  * Fetches information about a model by name.
15803
16062
  *
@@ -18394,5 +18653,5 @@ class GoogleGenAI {
18394
18653
  }
18395
18654
  }
18396
18655
 
18397
- export { ActivityHandling, AdapterSize, ApiError, ApiSpec, AuthType, Batches, Behavior, BlockedReason, Caches, Chat, Chats, ComputeTokensResponse, ControlReferenceImage, ControlReferenceType, CountTokensResponse, CreateFileResponse, DeleteCachedContentResponse, DeleteFileResponse, DeleteModelResponse, DynamicRetrievalConfigMode, EditImageResponse, EditMode, EmbedContentResponse, EndSensitivity, Environment, FeatureSelectionPreference, FileSource, FileState, Files, FinishReason, FunctionCallingConfigMode, FunctionResponse, FunctionResponseScheduling, GenerateContentResponse, GenerateContentResponsePromptFeedback, GenerateContentResponseUsageMetadata, GenerateImagesResponse, GenerateVideosOperation, GenerateVideosResponse, GoogleGenAI, HarmBlockMethod, HarmBlockThreshold, HarmCategory, HarmProbability, HarmSeverity, HttpResponse, ImagePromptLanguage, InlinedResponse, JobState, Language, ListBatchJobsResponse, ListCachedContentsResponse, ListFilesResponse, ListModelsResponse, ListTuningJobsResponse, Live, LiveClientToolResponse, LiveMusicPlaybackControl, LiveMusicServerMessage, LiveSendToolResponseParameters, LiveServerMessage, MaskReferenceImage, MaskReferenceMode, MediaModality, MediaResolution, Modality, Mode, Models, MusicGenerationMode, Operations, Outcome, PagedItem, Pager, PersonGeneration, RawReferenceImage, RecontextImageResponse, ReplayResponse, SafetyFilterLevel, Scale, Session, StartSensitivity, StyleReferenceImage, SubjectReferenceImage, SubjectReferenceType, Tokens, TrafficType, TuningMode, TurnCoverage, Type, UpscaleImageResponse, UrlRetrievalStatus, VideoCompressionQuality, createModelContent, createPartFromBase64, createPartFromCodeExecutionResult, createPartFromExecutableCode, createPartFromFunctionCall, createPartFromFunctionResponse, createPartFromText, createPartFromUri, createUserContent, mcpToTool, setDefaultBaseUrls };
18656
+ export { ActivityHandling, AdapterSize, ApiError, ApiSpec, AuthType, Batches, Behavior, BlockedReason, Caches, Chat, Chats, ComputeTokensResponse, ControlReferenceImage, ControlReferenceType, CountTokensResponse, CreateFileResponse, DeleteCachedContentResponse, DeleteFileResponse, DeleteModelResponse, DynamicRetrievalConfigMode, EditImageResponse, EditMode, EmbedContentResponse, EndSensitivity, Environment, FeatureSelectionPreference, FileSource, FileState, Files, FinishReason, FunctionCallingConfigMode, FunctionResponse, FunctionResponseScheduling, GenerateContentResponse, GenerateContentResponsePromptFeedback, GenerateContentResponseUsageMetadata, GenerateImagesResponse, GenerateVideosOperation, GenerateVideosResponse, GoogleGenAI, HarmBlockMethod, HarmBlockThreshold, HarmCategory, HarmProbability, HarmSeverity, HttpResponse, ImagePromptLanguage, InlinedResponse, JobState, Language, ListBatchJobsResponse, ListCachedContentsResponse, ListFilesResponse, ListModelsResponse, ListTuningJobsResponse, Live, LiveClientToolResponse, LiveMusicPlaybackControl, LiveMusicServerMessage, LiveSendToolResponseParameters, LiveServerMessage, MaskReferenceImage, MaskReferenceMode, MediaModality, MediaResolution, Modality, Mode, Models, MusicGenerationMode, Operations, Outcome, PagedItem, Pager, PersonGeneration, RawReferenceImage, RecontextImageResponse, ReplayResponse, SafetyFilterLevel, Scale, SegmentImageResponse, SegmentMode, Session, StartSensitivity, StyleReferenceImage, SubjectReferenceImage, SubjectReferenceType, Tokens, TrafficType, TuningMode, TurnCoverage, Type, UpscaleImageResponse, UrlRetrievalStatus, VideoCompressionQuality, createModelContent, createPartFromBase64, createPartFromCodeExecutionResult, createPartFromExecutableCode, createPartFromFunctionCall, createPartFromFunctionResponse, createPartFromText, createPartFromUri, createUserContent, mcpToTool, setDefaultBaseUrls };
18398
18657
  //# sourceMappingURL=index.mjs.map