@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.
@@ -903,6 +903,15 @@ var EditMode;
903
903
  EditMode["EDIT_MODE_BGSWAP"] = "EDIT_MODE_BGSWAP";
904
904
  EditMode["EDIT_MODE_PRODUCT_IMAGE"] = "EDIT_MODE_PRODUCT_IMAGE";
905
905
  })(EditMode || (EditMode = {}));
906
+ /** Enum that represents the segmentation mode. */
907
+ var SegmentMode;
908
+ (function (SegmentMode) {
909
+ SegmentMode["FOREGROUND"] = "FOREGROUND";
910
+ SegmentMode["BACKGROUND"] = "BACKGROUND";
911
+ SegmentMode["PROMPT"] = "PROMPT";
912
+ SegmentMode["SEMANTIC"] = "SEMANTIC";
913
+ SegmentMode["INTERACTIVE"] = "INTERACTIVE";
914
+ })(SegmentMode || (SegmentMode = {}));
906
915
  /** Enum that controls the compression quality of the generated videos. */
907
916
  var VideoCompressionQuality;
908
917
  (function (VideoCompressionQuality) {
@@ -1549,6 +1558,9 @@ class UpscaleImageResponse {
1549
1558
  /** The output images response. */
1550
1559
  class RecontextImageResponse {
1551
1560
  }
1561
+ /** The output images response. */
1562
+ class SegmentImageResponse {
1563
+ }
1552
1564
  class ListModelsResponse {
1553
1565
  }
1554
1566
  class DeleteModelResponse {
@@ -4287,6 +4299,7 @@ class Batches extends BaseModule {
4287
4299
  * ```
4288
4300
  */
4289
4301
  this.create = async (params) => {
4302
+ var _a, _b;
4290
4303
  if (this.apiClient.isVertexAI()) {
4291
4304
  const timestamp = Date.now();
4292
4305
  const timestampStr = timestamp.toString();
@@ -4311,6 +4324,55 @@ class Batches extends BaseModule {
4311
4324
  }
4312
4325
  }
4313
4326
  }
4327
+ else {
4328
+ if (Array.isArray(params.src) ||
4329
+ (typeof params.src !== 'string' && params.src.inlinedRequests)) {
4330
+ // Move system instruction to httpOptions extraBody.
4331
+ let path = '';
4332
+ let queryParams = {};
4333
+ const body = createBatchJobParametersToMldev(this.apiClient, params);
4334
+ path = formatMap('{model}:batchGenerateContent', body['_url']);
4335
+ queryParams = body['_query'];
4336
+ // Move system instruction to 'request':
4337
+ // {'systemInstruction': system_instruction}
4338
+ const batch = body['batch'];
4339
+ const inputConfig = batch['inputConfig'];
4340
+ const requestsWrapper = inputConfig['requests'];
4341
+ const requests = requestsWrapper['requests'];
4342
+ const newRequests = [];
4343
+ for (const request of requests) {
4344
+ const requestDict = request;
4345
+ if (requestDict['systemInstruction']) {
4346
+ const systemInstructionValue = requestDict['systemInstruction'];
4347
+ delete requestDict['systemInstruction'];
4348
+ const requestContent = requestDict['request'];
4349
+ requestContent['systemInstruction'] = systemInstructionValue;
4350
+ requestDict['request'] = requestContent;
4351
+ }
4352
+ newRequests.push(requestDict);
4353
+ }
4354
+ requestsWrapper['requests'] = newRequests;
4355
+ delete body['config'];
4356
+ delete body['_url'];
4357
+ delete body['_query'];
4358
+ const response = this.apiClient
4359
+ .request({
4360
+ path: path,
4361
+ queryParams: queryParams,
4362
+ body: JSON.stringify(body),
4363
+ httpMethod: 'POST',
4364
+ httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
4365
+ abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
4366
+ })
4367
+ .then((httpResponse) => {
4368
+ return httpResponse.json();
4369
+ });
4370
+ return response.then((apiResponse) => {
4371
+ const resp = batchJobFromMldev(apiResponse);
4372
+ return resp;
4373
+ });
4374
+ }
4375
+ }
4314
4376
  return await this.createInternal(params);
4315
4377
  };
4316
4378
  /**
@@ -6221,9 +6283,6 @@ function isValidContent(content) {
6221
6283
  if (part === undefined || Object.keys(part).length === 0) {
6222
6284
  return false;
6223
6285
  }
6224
- if (!part.thought && part.text !== undefined && part.text === '') {
6225
- return false;
6226
- }
6227
6286
  }
6228
6287
  return true;
6229
6288
  }
@@ -10428,6 +10487,9 @@ function generateVideosConfigToMldev(fromObject, parentObject) {
10428
10487
  if (getValueByPath(fromObject, ['lastFrame']) !== undefined) {
10429
10488
  throw new Error('lastFrame parameter is not supported in Gemini API.');
10430
10489
  }
10490
+ if (getValueByPath(fromObject, ['referenceImages']) !== undefined) {
10491
+ throw new Error('referenceImages parameter is not supported in Gemini API.');
10492
+ }
10431
10493
  if (getValueByPath(fromObject, ['compressionQuality']) !== undefined) {
10432
10494
  throw new Error('compressionQuality parameter is not supported in Gemini API.');
10433
10495
  }
@@ -11738,6 +11800,78 @@ function recontextImageParametersToVertex(apiClient, fromObject) {
11738
11800
  }
11739
11801
  return toObject;
11740
11802
  }
11803
+ function scribbleImageToVertex(fromObject) {
11804
+ const toObject = {};
11805
+ const fromImage = getValueByPath(fromObject, ['image']);
11806
+ if (fromImage != null) {
11807
+ setValueByPath(toObject, ['image'], imageToVertex(fromImage));
11808
+ }
11809
+ return toObject;
11810
+ }
11811
+ function segmentImageSourceToVertex(fromObject, parentObject) {
11812
+ const toObject = {};
11813
+ const fromPrompt = getValueByPath(fromObject, ['prompt']);
11814
+ if (parentObject !== undefined && fromPrompt != null) {
11815
+ setValueByPath(parentObject, ['instances[0]', 'prompt'], fromPrompt);
11816
+ }
11817
+ const fromImage = getValueByPath(fromObject, ['image']);
11818
+ if (parentObject !== undefined && fromImage != null) {
11819
+ setValueByPath(parentObject, ['instances[0]', 'image'], imageToVertex(fromImage));
11820
+ }
11821
+ const fromScribbleImage = getValueByPath(fromObject, [
11822
+ 'scribbleImage',
11823
+ ]);
11824
+ if (parentObject !== undefined && fromScribbleImage != null) {
11825
+ setValueByPath(parentObject, ['instances[0]', 'scribble'], scribbleImageToVertex(fromScribbleImage));
11826
+ }
11827
+ return toObject;
11828
+ }
11829
+ function segmentImageConfigToVertex(fromObject, parentObject) {
11830
+ const toObject = {};
11831
+ const fromMode = getValueByPath(fromObject, ['mode']);
11832
+ if (parentObject !== undefined && fromMode != null) {
11833
+ setValueByPath(parentObject, ['parameters', 'mode'], fromMode);
11834
+ }
11835
+ const fromMaxPredictions = getValueByPath(fromObject, [
11836
+ 'maxPredictions',
11837
+ ]);
11838
+ if (parentObject !== undefined && fromMaxPredictions != null) {
11839
+ setValueByPath(parentObject, ['parameters', 'maxPredictions'], fromMaxPredictions);
11840
+ }
11841
+ const fromConfidenceThreshold = getValueByPath(fromObject, [
11842
+ 'confidenceThreshold',
11843
+ ]);
11844
+ if (parentObject !== undefined && fromConfidenceThreshold != null) {
11845
+ setValueByPath(parentObject, ['parameters', 'confidenceThreshold'], fromConfidenceThreshold);
11846
+ }
11847
+ const fromMaskDilation = getValueByPath(fromObject, ['maskDilation']);
11848
+ if (parentObject !== undefined && fromMaskDilation != null) {
11849
+ setValueByPath(parentObject, ['parameters', 'maskDilation'], fromMaskDilation);
11850
+ }
11851
+ const fromBinaryColorThreshold = getValueByPath(fromObject, [
11852
+ 'binaryColorThreshold',
11853
+ ]);
11854
+ if (parentObject !== undefined && fromBinaryColorThreshold != null) {
11855
+ setValueByPath(parentObject, ['parameters', 'binaryColorThreshold'], fromBinaryColorThreshold);
11856
+ }
11857
+ return toObject;
11858
+ }
11859
+ function segmentImageParametersToVertex(apiClient, fromObject) {
11860
+ const toObject = {};
11861
+ const fromModel = getValueByPath(fromObject, ['model']);
11862
+ if (fromModel != null) {
11863
+ setValueByPath(toObject, ['_url', 'model'], tModel(apiClient, fromModel));
11864
+ }
11865
+ const fromSource = getValueByPath(fromObject, ['source']);
11866
+ if (fromSource != null) {
11867
+ setValueByPath(toObject, ['config'], segmentImageSourceToVertex(fromSource, toObject));
11868
+ }
11869
+ const fromConfig = getValueByPath(fromObject, ['config']);
11870
+ if (fromConfig != null) {
11871
+ setValueByPath(toObject, ['config'], segmentImageConfigToVertex(fromConfig, toObject));
11872
+ }
11873
+ return toObject;
11874
+ }
11741
11875
  function getModelParametersToVertex(apiClient, fromObject) {
11742
11876
  const toObject = {};
11743
11877
  const fromModel = getValueByPath(fromObject, ['model']);
@@ -11906,6 +12040,20 @@ function videoToVertex(fromObject) {
11906
12040
  }
11907
12041
  return toObject;
11908
12042
  }
12043
+ function videoGenerationReferenceImageToVertex(fromObject) {
12044
+ const toObject = {};
12045
+ const fromImage = getValueByPath(fromObject, ['image']);
12046
+ if (fromImage != null) {
12047
+ setValueByPath(toObject, ['image'], imageToVertex(fromImage));
12048
+ }
12049
+ const fromReferenceType = getValueByPath(fromObject, [
12050
+ 'referenceType',
12051
+ ]);
12052
+ if (fromReferenceType != null) {
12053
+ setValueByPath(toObject, ['referenceType'], fromReferenceType);
12054
+ }
12055
+ return toObject;
12056
+ }
11909
12057
  function generateVideosConfigToVertex(fromObject, parentObject) {
11910
12058
  const toObject = {};
11911
12059
  const fromNumberOfVideos = getValueByPath(fromObject, [
@@ -11972,6 +12120,18 @@ function generateVideosConfigToVertex(fromObject, parentObject) {
11972
12120
  if (parentObject !== undefined && fromLastFrame != null) {
11973
12121
  setValueByPath(parentObject, ['instances[0]', 'lastFrame'], imageToVertex(fromLastFrame));
11974
12122
  }
12123
+ const fromReferenceImages = getValueByPath(fromObject, [
12124
+ 'referenceImages',
12125
+ ]);
12126
+ if (parentObject !== undefined && fromReferenceImages != null) {
12127
+ let transformedList = fromReferenceImages;
12128
+ if (Array.isArray(transformedList)) {
12129
+ transformedList = transformedList.map((item) => {
12130
+ return videoGenerationReferenceImageToVertex(item);
12131
+ });
12132
+ }
12133
+ setValueByPath(parentObject, ['instances[0]', 'referenceImages'], transformedList);
12134
+ }
11975
12135
  const fromCompressionQuality = getValueByPath(fromObject, [
11976
12136
  'compressionQuality',
11977
12137
  ]);
@@ -13021,6 +13181,50 @@ function recontextImageResponseFromVertex(fromObject) {
13021
13181
  }
13022
13182
  return toObject;
13023
13183
  }
13184
+ function entityLabelFromVertex(fromObject) {
13185
+ const toObject = {};
13186
+ const fromLabel = getValueByPath(fromObject, ['label']);
13187
+ if (fromLabel != null) {
13188
+ setValueByPath(toObject, ['label'], fromLabel);
13189
+ }
13190
+ const fromScore = getValueByPath(fromObject, ['score']);
13191
+ if (fromScore != null) {
13192
+ setValueByPath(toObject, ['score'], fromScore);
13193
+ }
13194
+ return toObject;
13195
+ }
13196
+ function generatedImageMaskFromVertex(fromObject) {
13197
+ const toObject = {};
13198
+ const fromMask = getValueByPath(fromObject, ['_self']);
13199
+ if (fromMask != null) {
13200
+ setValueByPath(toObject, ['mask'], imageFromVertex(fromMask));
13201
+ }
13202
+ const fromLabels = getValueByPath(fromObject, ['labels']);
13203
+ if (fromLabels != null) {
13204
+ let transformedList = fromLabels;
13205
+ if (Array.isArray(transformedList)) {
13206
+ transformedList = transformedList.map((item) => {
13207
+ return entityLabelFromVertex(item);
13208
+ });
13209
+ }
13210
+ setValueByPath(toObject, ['labels'], transformedList);
13211
+ }
13212
+ return toObject;
13213
+ }
13214
+ function segmentImageResponseFromVertex(fromObject) {
13215
+ const toObject = {};
13216
+ const fromGeneratedMasks = getValueByPath(fromObject, ['predictions']);
13217
+ if (fromGeneratedMasks != null) {
13218
+ let transformedList = fromGeneratedMasks;
13219
+ if (Array.isArray(transformedList)) {
13220
+ transformedList = transformedList.map((item) => {
13221
+ return generatedImageMaskFromVertex(item);
13222
+ });
13223
+ }
13224
+ setValueByPath(toObject, ['generatedMasks'], transformedList);
13225
+ }
13226
+ return toObject;
13227
+ }
13024
13228
  function endpointFromVertex(fromObject) {
13025
13229
  const toObject = {};
13026
13230
  const fromName = getValueByPath(fromObject, ['endpoint']);
@@ -13268,7 +13472,7 @@ const CONTENT_TYPE_HEADER = 'Content-Type';
13268
13472
  const SERVER_TIMEOUT_HEADER = 'X-Server-Timeout';
13269
13473
  const USER_AGENT_HEADER = 'User-Agent';
13270
13474
  const GOOGLE_API_CLIENT_HEADER = 'x-goog-api-client';
13271
- const SDK_VERSION = '1.14.0'; // x-release-please-version
13475
+ const SDK_VERSION = '1.15.0'; // x-release-please-version
13272
13476
  const LIBRARY_LABEL = `google-genai-sdk/${SDK_VERSION}`;
13273
13477
  const VERTEX_AI_API_DEFAULT_VERSION = 'v1beta1';
13274
13478
  const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
@@ -15711,6 +15915,61 @@ class Models extends BaseModule {
15711
15915
  throw new Error('This method is only supported by the Vertex AI.');
15712
15916
  }
15713
15917
  }
15918
+ /**
15919
+ * Segments an image, creating a mask of a specified area.
15920
+ *
15921
+ * @param params - The parameters for segmenting an image.
15922
+ * @return The response from the API.
15923
+ *
15924
+ * @example
15925
+ * ```ts
15926
+ * const response = await ai.models.segmentImage({
15927
+ * model: 'image-segmentation-001',
15928
+ * source: {
15929
+ * image: image,
15930
+ * },
15931
+ * config: {
15932
+ * mode: 'foreground',
15933
+ * },
15934
+ * });
15935
+ * console.log(response?.generatedMasks?.[0]?.mask?.imageBytes);
15936
+ * ```
15937
+ */
15938
+ async segmentImage(params) {
15939
+ var _a, _b;
15940
+ let response;
15941
+ let path = '';
15942
+ let queryParams = {};
15943
+ if (this.apiClient.isVertexAI()) {
15944
+ const body = segmentImageParametersToVertex(this.apiClient, params);
15945
+ path = formatMap('{model}:predict', body['_url']);
15946
+ queryParams = body['_query'];
15947
+ delete body['config'];
15948
+ delete body['_url'];
15949
+ delete body['_query'];
15950
+ response = this.apiClient
15951
+ .request({
15952
+ path: path,
15953
+ queryParams: queryParams,
15954
+ body: JSON.stringify(body),
15955
+ httpMethod: 'POST',
15956
+ httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
15957
+ abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
15958
+ })
15959
+ .then((httpResponse) => {
15960
+ return httpResponse.json();
15961
+ });
15962
+ return response.then((apiResponse) => {
15963
+ const resp = segmentImageResponseFromVertex(apiResponse);
15964
+ const typedResp = new SegmentImageResponse();
15965
+ Object.assign(typedResp, resp);
15966
+ return typedResp;
15967
+ });
15968
+ }
15969
+ else {
15970
+ throw new Error('This method is only supported by the Vertex AI.');
15971
+ }
15972
+ }
15714
15973
  /**
15715
15974
  * Fetches information about a model by name.
15716
15975
  *
@@ -18792,5 +19051,5 @@ function getApiKeyFromEnv() {
18792
19051
  return envGoogleApiKey || envGeminiApiKey;
18793
19052
  }
18794
19053
 
18795
- 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 };
19054
+ 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 };
18796
19055
  //# sourceMappingURL=index.mjs.map