@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/README.md CHANGED
@@ -339,6 +339,30 @@ if you are specifying those, you need to explicitly provide the full
339
339
  `Content[]` structure making it explicit which Parts are 'spoken' by the model,
340
340
  or the user. The SDK will throw an exception if you try this.
341
341
 
342
+ ## Error Handling
343
+
344
+ To handle errors raised by the API, the SDK provides this [ApiError](https://github.com/googleapis/js-genai/blob/main/src/errors.ts) class.
345
+
346
+ ```typescript
347
+ import {GoogleGenAI} from '@google/genai';
348
+ const GEMINI_API_KEY = process.env.GEMINI_API_KEY;
349
+
350
+ const ai = new GoogleGenAI({apiKey: GEMINI_API_KEY});
351
+
352
+ async function main() {
353
+ await ai.models.generateContent({
354
+ model: 'non-existent-model',
355
+ contents: 'Write a 100-word poem.',
356
+ }).catch((e) => {
357
+ console.error('error name: ', e.name);
358
+ console.error('error message: ', e.message);
359
+ console.error('error status: ', e.status);
360
+ });
361
+ }
362
+
363
+ main();
364
+ ```
365
+
342
366
  ## How is this different from the other Google AI SDKs
343
367
  This SDK (`@google/genai`) is Google Deepmind’s "vanilla" SDK for its generative
344
368
  AI offerings, and is where Google Deepmind adds new AI features.
package/dist/genai.d.ts CHANGED
@@ -1885,6 +1885,14 @@ export declare interface EnterpriseWebSearch {
1885
1885
  excludeDomains?: string[];
1886
1886
  }
1887
1887
 
1888
+ /** An entity representing the segmented area. */
1889
+ export declare interface EntityLabel {
1890
+ /** The label of the segmented entity. */
1891
+ label?: string;
1892
+ /** The confidence score of the detected label. */
1893
+ score?: number;
1894
+ }
1895
+
1888
1896
  /** The environment being operated. */
1889
1897
  export declare enum Environment {
1890
1898
  /**
@@ -2702,6 +2710,14 @@ export declare interface GeneratedImage {
2702
2710
  enhancedPrompt?: string;
2703
2711
  }
2704
2712
 
2713
+ /** A generated image mask. */
2714
+ export declare interface GeneratedImageMask {
2715
+ /** The generated image mask. */
2716
+ mask?: Image_2;
2717
+ /** The detected entities on the segmented area. */
2718
+ labels?: EntityLabel[];
2719
+ }
2720
+
2705
2721
  /** A generated video. */
2706
2722
  export declare interface GeneratedVideo {
2707
2723
  /** The output video */
@@ -2840,6 +2856,12 @@ export declare interface GenerateVideosConfig {
2840
2856
  generateAudio?: boolean;
2841
2857
  /** Image to use as the last frame of generated videos. Only supported for image to video use cases. */
2842
2858
  lastFrame?: Image_2;
2859
+ /** The images to use as the references to generate the videos.
2860
+ If this field is provided, the text prompt field must also be provided.
2861
+ The image, video, or last_frame field are not supported. Each image must
2862
+ be associated with a type. Veo 2 supports up to 3 asset images *or* 1
2863
+ style image. */
2864
+ referenceImages?: VideoGenerationReferenceImage[];
2843
2865
  /** Compression quality of the generated videos. */
2844
2866
  compressionQuality?: VideoCompressionQuality;
2845
2867
  }
@@ -5127,6 +5149,27 @@ export declare class Models extends BaseModule {
5127
5149
  * ```
5128
5150
  */
5129
5151
  recontextImage(params: types.RecontextImageParameters): Promise<types.RecontextImageResponse>;
5152
+ /**
5153
+ * Segments an image, creating a mask of a specified area.
5154
+ *
5155
+ * @param params - The parameters for segmenting an image.
5156
+ * @return The response from the API.
5157
+ *
5158
+ * @example
5159
+ * ```ts
5160
+ * const response = await ai.models.segmentImage({
5161
+ * model: 'image-segmentation-001',
5162
+ * source: {
5163
+ * image: image,
5164
+ * },
5165
+ * config: {
5166
+ * mode: 'foreground',
5167
+ * },
5168
+ * });
5169
+ * console.log(response?.generatedMasks?.[0]?.mask?.imageBytes);
5170
+ * ```
5171
+ */
5172
+ segmentImage(params: types.SegmentImageParameters): Promise<types.SegmentImageResponse>;
5130
5173
  /**
5131
5174
  * Fetches information about a model by name.
5132
5175
  *
@@ -5969,6 +6012,12 @@ export declare interface Schema {
5969
6012
 
5970
6013
  export declare type SchemaUnion = Schema | unknown;
5971
6014
 
6015
+ /** An image mask representing a brush scribble. */
6016
+ export declare interface ScribbleImage {
6017
+ /** The brush scribble to guide segmentation. Valid for the interactive mode. */
6018
+ image?: Image_2;
6019
+ }
6020
+
5972
6021
  /** Google search entry point. */
5973
6022
  export declare interface SearchEntryPoint {
5974
6023
  /** Optional. Web content snippet that can be embedded in a web page or an app webview. */
@@ -5990,6 +6039,75 @@ export declare interface Segment {
5990
6039
  text?: string;
5991
6040
  }
5992
6041
 
6042
+ /** Configuration for segmenting an image. */
6043
+ export declare interface SegmentImageConfig {
6044
+ /** Used to override HTTP request options. */
6045
+ httpOptions?: HttpOptions;
6046
+ /** Abort signal which can be used to cancel the request.
6047
+
6048
+ NOTE: AbortSignal is a client-only operation. Using it to cancel an
6049
+ operation will not cancel the request in the service. You will still
6050
+ be charged usage for any applicable operations.
6051
+ */
6052
+ abortSignal?: AbortSignal;
6053
+ /** The segmentation mode to use. */
6054
+ mode?: SegmentMode;
6055
+ /** The maximum number of predictions to return up to, by top
6056
+ confidence score. */
6057
+ maxPredictions?: number;
6058
+ /** The confidence score threshold for the detections as a decimal
6059
+ value. Only predictions with a confidence score higher than this
6060
+ threshold will be returned. */
6061
+ confidenceThreshold?: number;
6062
+ /** A decimal value representing how much dilation to apply to the
6063
+ masks. 0 for no dilation. 1.0 means the masked area covers the whole
6064
+ image. */
6065
+ maskDilation?: number;
6066
+ /** The binary color threshold to apply to the masks. The threshold
6067
+ can be set to a decimal value between 0 and 255 non-inclusive.
6068
+ Set to -1 for no binary color thresholding. */
6069
+ binaryColorThreshold?: number;
6070
+ }
6071
+
6072
+ /** The parameters for segmenting an image. */
6073
+ export declare interface SegmentImageParameters {
6074
+ /** ID of the model to use. For a list of models, see `Google models
6075
+ <https://cloud.google.com/vertex-ai/generative-ai/docs/learn/models>`_. */
6076
+ model: string;
6077
+ /** A set of source input(s) for image segmentation. */
6078
+ source: SegmentImageSource;
6079
+ /** Configuration for image segmentation. */
6080
+ config?: SegmentImageConfig;
6081
+ }
6082
+
6083
+ /** The output images response. */
6084
+ export declare class SegmentImageResponse {
6085
+ /** List of generated image masks.
6086
+ */
6087
+ generatedMasks?: GeneratedImageMask[];
6088
+ }
6089
+
6090
+ /** A set of source input(s) for image segmentation. */
6091
+ export declare interface SegmentImageSource {
6092
+ /** A text prompt for guiding the model during image segmentation.
6093
+ Required for prompt mode and semantic mode, disallowed for other modes. */
6094
+ prompt?: string;
6095
+ /** The image to be segmented. */
6096
+ image?: Image_2;
6097
+ /** The brush scribble to guide segmentation.
6098
+ Required for the interactive mode, disallowed for other modes. */
6099
+ scribbleImage?: ScribbleImage;
6100
+ }
6101
+
6102
+ /** Enum that represents the segmentation mode. */
6103
+ export declare enum SegmentMode {
6104
+ FOREGROUND = "FOREGROUND",
6105
+ BACKGROUND = "BACKGROUND",
6106
+ PROMPT = "PROMPT",
6107
+ SEMANTIC = "SEMANTIC",
6108
+ INTERACTIVE = "INTERACTIVE"
6109
+ }
6110
+
5993
6111
  /** Parameters for sending a message within a chat session.
5994
6112
 
5995
6113
  These parameters are used with the `chat.sendMessage()` method.
@@ -6877,6 +6995,7 @@ declare namespace types {
6877
6995
  ControlReferenceType,
6878
6996
  SubjectReferenceType,
6879
6997
  EditMode,
6998
+ SegmentMode,
6880
6999
  VideoCompressionQuality,
6881
7000
  FileState,
6882
7001
  FileSource,
@@ -7007,6 +7126,13 @@ declare namespace types {
7007
7126
  RecontextImageConfig,
7008
7127
  RecontextImageParameters,
7009
7128
  RecontextImageResponse,
7129
+ ScribbleImage,
7130
+ SegmentImageSource,
7131
+ SegmentImageConfig,
7132
+ SegmentImageParameters,
7133
+ EntityLabel,
7134
+ GeneratedImageMask,
7135
+ SegmentImageResponse,
7010
7136
  GetModelConfig,
7011
7137
  GetModelParameters,
7012
7138
  Endpoint,
@@ -7031,6 +7157,7 @@ declare namespace types {
7031
7157
  TokensInfo,
7032
7158
  ComputeTokensResponse,
7033
7159
  Video,
7160
+ VideoGenerationReferenceImage,
7034
7161
  GenerateVideosConfig,
7035
7162
  GenerateVideosParameters,
7036
7163
  GeneratedVideo,
@@ -7495,6 +7622,17 @@ export declare enum VideoCompressionQuality {
7495
7622
  LOSSLESS = "LOSSLESS"
7496
7623
  }
7497
7624
 
7625
+ /** A reference image for video generation. */
7626
+ export declare interface VideoGenerationReferenceImage {
7627
+ /** The reference image.
7628
+ */
7629
+ image?: Image_2;
7630
+ /** The type of the reference image, which defines how the reference
7631
+ image will be used to generate the video. Supported values are 'asset'
7632
+ or 'style'. */
7633
+ referenceType?: string;
7634
+ }
7635
+
7498
7636
  /** Describes how the video in the Part should be used by the model. */
7499
7637
  export declare interface VideoMetadata {
7500
7638
  /** The frame rate of the video sent to the model. If not specified, the
package/dist/index.cjs CHANGED
@@ -869,6 +869,15 @@ exports.EditMode = void 0;
869
869
  EditMode["EDIT_MODE_BGSWAP"] = "EDIT_MODE_BGSWAP";
870
870
  EditMode["EDIT_MODE_PRODUCT_IMAGE"] = "EDIT_MODE_PRODUCT_IMAGE";
871
871
  })(exports.EditMode || (exports.EditMode = {}));
872
+ /** Enum that represents the segmentation mode. */
873
+ exports.SegmentMode = void 0;
874
+ (function (SegmentMode) {
875
+ SegmentMode["FOREGROUND"] = "FOREGROUND";
876
+ SegmentMode["BACKGROUND"] = "BACKGROUND";
877
+ SegmentMode["PROMPT"] = "PROMPT";
878
+ SegmentMode["SEMANTIC"] = "SEMANTIC";
879
+ SegmentMode["INTERACTIVE"] = "INTERACTIVE";
880
+ })(exports.SegmentMode || (exports.SegmentMode = {}));
872
881
  /** Enum that controls the compression quality of the generated videos. */
873
882
  exports.VideoCompressionQuality = void 0;
874
883
  (function (VideoCompressionQuality) {
@@ -1515,6 +1524,9 @@ class UpscaleImageResponse {
1515
1524
  /** The output images response. */
1516
1525
  class RecontextImageResponse {
1517
1526
  }
1527
+ /** The output images response. */
1528
+ class SegmentImageResponse {
1529
+ }
1518
1530
  class ListModelsResponse {
1519
1531
  }
1520
1532
  class DeleteModelResponse {
@@ -4253,6 +4265,7 @@ class Batches extends BaseModule {
4253
4265
  * ```
4254
4266
  */
4255
4267
  this.create = async (params) => {
4268
+ var _a, _b;
4256
4269
  if (this.apiClient.isVertexAI()) {
4257
4270
  const timestamp = Date.now();
4258
4271
  const timestampStr = timestamp.toString();
@@ -4277,6 +4290,55 @@ class Batches extends BaseModule {
4277
4290
  }
4278
4291
  }
4279
4292
  }
4293
+ else {
4294
+ if (Array.isArray(params.src) ||
4295
+ (typeof params.src !== 'string' && params.src.inlinedRequests)) {
4296
+ // Move system instruction to httpOptions extraBody.
4297
+ let path = '';
4298
+ let queryParams = {};
4299
+ const body = createBatchJobParametersToMldev(this.apiClient, params);
4300
+ path = formatMap('{model}:batchGenerateContent', body['_url']);
4301
+ queryParams = body['_query'];
4302
+ // Move system instruction to 'request':
4303
+ // {'systemInstruction': system_instruction}
4304
+ const batch = body['batch'];
4305
+ const inputConfig = batch['inputConfig'];
4306
+ const requestsWrapper = inputConfig['requests'];
4307
+ const requests = requestsWrapper['requests'];
4308
+ const newRequests = [];
4309
+ for (const request of requests) {
4310
+ const requestDict = request;
4311
+ if (requestDict['systemInstruction']) {
4312
+ const systemInstructionValue = requestDict['systemInstruction'];
4313
+ delete requestDict['systemInstruction'];
4314
+ const requestContent = requestDict['request'];
4315
+ requestContent['systemInstruction'] = systemInstructionValue;
4316
+ requestDict['request'] = requestContent;
4317
+ }
4318
+ newRequests.push(requestDict);
4319
+ }
4320
+ requestsWrapper['requests'] = newRequests;
4321
+ delete body['config'];
4322
+ delete body['_url'];
4323
+ delete body['_query'];
4324
+ const response = this.apiClient
4325
+ .request({
4326
+ path: path,
4327
+ queryParams: queryParams,
4328
+ body: JSON.stringify(body),
4329
+ httpMethod: 'POST',
4330
+ httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
4331
+ abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
4332
+ })
4333
+ .then((httpResponse) => {
4334
+ return httpResponse.json();
4335
+ });
4336
+ return response.then((apiResponse) => {
4337
+ const resp = batchJobFromMldev(apiResponse);
4338
+ return resp;
4339
+ });
4340
+ }
4341
+ }
4280
4342
  return await this.createInternal(params);
4281
4343
  };
4282
4344
  /**
@@ -6187,9 +6249,6 @@ function isValidContent(content) {
6187
6249
  if (part === undefined || Object.keys(part).length === 0) {
6188
6250
  return false;
6189
6251
  }
6190
- if (!part.thought && part.text !== undefined && part.text === '') {
6191
- return false;
6192
- }
6193
6252
  }
6194
6253
  return true;
6195
6254
  }
@@ -6512,7 +6571,7 @@ const CONTENT_TYPE_HEADER = 'Content-Type';
6512
6571
  const SERVER_TIMEOUT_HEADER = 'X-Server-Timeout';
6513
6572
  const USER_AGENT_HEADER = 'User-Agent';
6514
6573
  const GOOGLE_API_CLIENT_HEADER = 'x-goog-api-client';
6515
- const SDK_VERSION = '1.14.0'; // x-release-please-version
6574
+ const SDK_VERSION = '1.15.0'; // x-release-please-version
6516
6575
  const LIBRARY_LABEL = `google-genai-sdk/${SDK_VERSION}`;
6517
6576
  const VERTEX_AI_API_DEFAULT_VERSION = 'v1beta1';
6518
6577
  const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
@@ -11091,6 +11150,9 @@ function generateVideosConfigToMldev(fromObject, parentObject) {
11091
11150
  if (getValueByPath(fromObject, ['lastFrame']) !== undefined) {
11092
11151
  throw new Error('lastFrame parameter is not supported in Gemini API.');
11093
11152
  }
11153
+ if (getValueByPath(fromObject, ['referenceImages']) !== undefined) {
11154
+ throw new Error('referenceImages parameter is not supported in Gemini API.');
11155
+ }
11094
11156
  if (getValueByPath(fromObject, ['compressionQuality']) !== undefined) {
11095
11157
  throw new Error('compressionQuality parameter is not supported in Gemini API.');
11096
11158
  }
@@ -12401,6 +12463,78 @@ function recontextImageParametersToVertex(apiClient, fromObject) {
12401
12463
  }
12402
12464
  return toObject;
12403
12465
  }
12466
+ function scribbleImageToVertex(fromObject) {
12467
+ const toObject = {};
12468
+ const fromImage = getValueByPath(fromObject, ['image']);
12469
+ if (fromImage != null) {
12470
+ setValueByPath(toObject, ['image'], imageToVertex(fromImage));
12471
+ }
12472
+ return toObject;
12473
+ }
12474
+ function segmentImageSourceToVertex(fromObject, parentObject) {
12475
+ const toObject = {};
12476
+ const fromPrompt = getValueByPath(fromObject, ['prompt']);
12477
+ if (parentObject !== undefined && fromPrompt != null) {
12478
+ setValueByPath(parentObject, ['instances[0]', 'prompt'], fromPrompt);
12479
+ }
12480
+ const fromImage = getValueByPath(fromObject, ['image']);
12481
+ if (parentObject !== undefined && fromImage != null) {
12482
+ setValueByPath(parentObject, ['instances[0]', 'image'], imageToVertex(fromImage));
12483
+ }
12484
+ const fromScribbleImage = getValueByPath(fromObject, [
12485
+ 'scribbleImage',
12486
+ ]);
12487
+ if (parentObject !== undefined && fromScribbleImage != null) {
12488
+ setValueByPath(parentObject, ['instances[0]', 'scribble'], scribbleImageToVertex(fromScribbleImage));
12489
+ }
12490
+ return toObject;
12491
+ }
12492
+ function segmentImageConfigToVertex(fromObject, parentObject) {
12493
+ const toObject = {};
12494
+ const fromMode = getValueByPath(fromObject, ['mode']);
12495
+ if (parentObject !== undefined && fromMode != null) {
12496
+ setValueByPath(parentObject, ['parameters', 'mode'], fromMode);
12497
+ }
12498
+ const fromMaxPredictions = getValueByPath(fromObject, [
12499
+ 'maxPredictions',
12500
+ ]);
12501
+ if (parentObject !== undefined && fromMaxPredictions != null) {
12502
+ setValueByPath(parentObject, ['parameters', 'maxPredictions'], fromMaxPredictions);
12503
+ }
12504
+ const fromConfidenceThreshold = getValueByPath(fromObject, [
12505
+ 'confidenceThreshold',
12506
+ ]);
12507
+ if (parentObject !== undefined && fromConfidenceThreshold != null) {
12508
+ setValueByPath(parentObject, ['parameters', 'confidenceThreshold'], fromConfidenceThreshold);
12509
+ }
12510
+ const fromMaskDilation = getValueByPath(fromObject, ['maskDilation']);
12511
+ if (parentObject !== undefined && fromMaskDilation != null) {
12512
+ setValueByPath(parentObject, ['parameters', 'maskDilation'], fromMaskDilation);
12513
+ }
12514
+ const fromBinaryColorThreshold = getValueByPath(fromObject, [
12515
+ 'binaryColorThreshold',
12516
+ ]);
12517
+ if (parentObject !== undefined && fromBinaryColorThreshold != null) {
12518
+ setValueByPath(parentObject, ['parameters', 'binaryColorThreshold'], fromBinaryColorThreshold);
12519
+ }
12520
+ return toObject;
12521
+ }
12522
+ function segmentImageParametersToVertex(apiClient, fromObject) {
12523
+ const toObject = {};
12524
+ const fromModel = getValueByPath(fromObject, ['model']);
12525
+ if (fromModel != null) {
12526
+ setValueByPath(toObject, ['_url', 'model'], tModel(apiClient, fromModel));
12527
+ }
12528
+ const fromSource = getValueByPath(fromObject, ['source']);
12529
+ if (fromSource != null) {
12530
+ setValueByPath(toObject, ['config'], segmentImageSourceToVertex(fromSource, toObject));
12531
+ }
12532
+ const fromConfig = getValueByPath(fromObject, ['config']);
12533
+ if (fromConfig != null) {
12534
+ setValueByPath(toObject, ['config'], segmentImageConfigToVertex(fromConfig, toObject));
12535
+ }
12536
+ return toObject;
12537
+ }
12404
12538
  function getModelParametersToVertex(apiClient, fromObject) {
12405
12539
  const toObject = {};
12406
12540
  const fromModel = getValueByPath(fromObject, ['model']);
@@ -12569,6 +12703,20 @@ function videoToVertex(fromObject) {
12569
12703
  }
12570
12704
  return toObject;
12571
12705
  }
12706
+ function videoGenerationReferenceImageToVertex(fromObject) {
12707
+ const toObject = {};
12708
+ const fromImage = getValueByPath(fromObject, ['image']);
12709
+ if (fromImage != null) {
12710
+ setValueByPath(toObject, ['image'], imageToVertex(fromImage));
12711
+ }
12712
+ const fromReferenceType = getValueByPath(fromObject, [
12713
+ 'referenceType',
12714
+ ]);
12715
+ if (fromReferenceType != null) {
12716
+ setValueByPath(toObject, ['referenceType'], fromReferenceType);
12717
+ }
12718
+ return toObject;
12719
+ }
12572
12720
  function generateVideosConfigToVertex(fromObject, parentObject) {
12573
12721
  const toObject = {};
12574
12722
  const fromNumberOfVideos = getValueByPath(fromObject, [
@@ -12635,6 +12783,18 @@ function generateVideosConfigToVertex(fromObject, parentObject) {
12635
12783
  if (parentObject !== undefined && fromLastFrame != null) {
12636
12784
  setValueByPath(parentObject, ['instances[0]', 'lastFrame'], imageToVertex(fromLastFrame));
12637
12785
  }
12786
+ const fromReferenceImages = getValueByPath(fromObject, [
12787
+ 'referenceImages',
12788
+ ]);
12789
+ if (parentObject !== undefined && fromReferenceImages != null) {
12790
+ let transformedList = fromReferenceImages;
12791
+ if (Array.isArray(transformedList)) {
12792
+ transformedList = transformedList.map((item) => {
12793
+ return videoGenerationReferenceImageToVertex(item);
12794
+ });
12795
+ }
12796
+ setValueByPath(parentObject, ['instances[0]', 'referenceImages'], transformedList);
12797
+ }
12638
12798
  const fromCompressionQuality = getValueByPath(fromObject, [
12639
12799
  'compressionQuality',
12640
12800
  ]);
@@ -13684,6 +13844,50 @@ function recontextImageResponseFromVertex(fromObject) {
13684
13844
  }
13685
13845
  return toObject;
13686
13846
  }
13847
+ function entityLabelFromVertex(fromObject) {
13848
+ const toObject = {};
13849
+ const fromLabel = getValueByPath(fromObject, ['label']);
13850
+ if (fromLabel != null) {
13851
+ setValueByPath(toObject, ['label'], fromLabel);
13852
+ }
13853
+ const fromScore = getValueByPath(fromObject, ['score']);
13854
+ if (fromScore != null) {
13855
+ setValueByPath(toObject, ['score'], fromScore);
13856
+ }
13857
+ return toObject;
13858
+ }
13859
+ function generatedImageMaskFromVertex(fromObject) {
13860
+ const toObject = {};
13861
+ const fromMask = getValueByPath(fromObject, ['_self']);
13862
+ if (fromMask != null) {
13863
+ setValueByPath(toObject, ['mask'], imageFromVertex(fromMask));
13864
+ }
13865
+ const fromLabels = getValueByPath(fromObject, ['labels']);
13866
+ if (fromLabels != null) {
13867
+ let transformedList = fromLabels;
13868
+ if (Array.isArray(transformedList)) {
13869
+ transformedList = transformedList.map((item) => {
13870
+ return entityLabelFromVertex(item);
13871
+ });
13872
+ }
13873
+ setValueByPath(toObject, ['labels'], transformedList);
13874
+ }
13875
+ return toObject;
13876
+ }
13877
+ function segmentImageResponseFromVertex(fromObject) {
13878
+ const toObject = {};
13879
+ const fromGeneratedMasks = getValueByPath(fromObject, ['predictions']);
13880
+ if (fromGeneratedMasks != null) {
13881
+ let transformedList = fromGeneratedMasks;
13882
+ if (Array.isArray(transformedList)) {
13883
+ transformedList = transformedList.map((item) => {
13884
+ return generatedImageMaskFromVertex(item);
13885
+ });
13886
+ }
13887
+ setValueByPath(toObject, ['generatedMasks'], transformedList);
13888
+ }
13889
+ return toObject;
13890
+ }
13687
13891
  function endpointFromVertex(fromObject) {
13688
13892
  const toObject = {};
13689
13893
  const fromName = getValueByPath(fromObject, ['endpoint']);
@@ -15800,6 +16004,61 @@ class Models extends BaseModule {
15800
16004
  throw new Error('This method is only supported by the Vertex AI.');
15801
16005
  }
15802
16006
  }
16007
+ /**
16008
+ * Segments an image, creating a mask of a specified area.
16009
+ *
16010
+ * @param params - The parameters for segmenting an image.
16011
+ * @return The response from the API.
16012
+ *
16013
+ * @example
16014
+ * ```ts
16015
+ * const response = await ai.models.segmentImage({
16016
+ * model: 'image-segmentation-001',
16017
+ * source: {
16018
+ * image: image,
16019
+ * },
16020
+ * config: {
16021
+ * mode: 'foreground',
16022
+ * },
16023
+ * });
16024
+ * console.log(response?.generatedMasks?.[0]?.mask?.imageBytes);
16025
+ * ```
16026
+ */
16027
+ async segmentImage(params) {
16028
+ var _a, _b;
16029
+ let response;
16030
+ let path = '';
16031
+ let queryParams = {};
16032
+ if (this.apiClient.isVertexAI()) {
16033
+ const body = segmentImageParametersToVertex(this.apiClient, params);
16034
+ path = formatMap('{model}:predict', body['_url']);
16035
+ queryParams = body['_query'];
16036
+ delete body['config'];
16037
+ delete body['_url'];
16038
+ delete body['_query'];
16039
+ response = this.apiClient
16040
+ .request({
16041
+ path: path,
16042
+ queryParams: queryParams,
16043
+ body: JSON.stringify(body),
16044
+ httpMethod: 'POST',
16045
+ httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
16046
+ abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
16047
+ })
16048
+ .then((httpResponse) => {
16049
+ return httpResponse.json();
16050
+ });
16051
+ return response.then((apiResponse) => {
16052
+ const resp = segmentImageResponseFromVertex(apiResponse);
16053
+ const typedResp = new SegmentImageResponse();
16054
+ Object.assign(typedResp, resp);
16055
+ return typedResp;
16056
+ });
16057
+ }
16058
+ else {
16059
+ throw new Error('This method is only supported by the Vertex AI.');
16060
+ }
16061
+ }
15803
16062
  /**
15804
16063
  * Fetches information about a model by name.
15805
16064
  *
@@ -18438,6 +18697,7 @@ exports.Pager = Pager;
18438
18697
  exports.RawReferenceImage = RawReferenceImage;
18439
18698
  exports.RecontextImageResponse = RecontextImageResponse;
18440
18699
  exports.ReplayResponse = ReplayResponse;
18700
+ exports.SegmentImageResponse = SegmentImageResponse;
18441
18701
  exports.Session = Session;
18442
18702
  exports.StyleReferenceImage = StyleReferenceImage;
18443
18703
  exports.SubjectReferenceImage = SubjectReferenceImage;