@google/genai 1.31.0 → 1.32.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.
@@ -3017,6 +3017,10 @@ export declare interface GenerateContentConfig {
3017
3017
  /** The image generation configuration.
3018
3018
  */
3019
3019
  imageConfig?: ImageConfig;
3020
+ /** Enables enhanced civic answers. It may not be available for all
3021
+ models. This field is not supported in Vertex AI.
3022
+ */
3023
+ enableEnhancedCivicAnswers?: boolean;
3020
3024
  }
3021
3025
 
3022
3026
  /** Config for models.generate_content parameters. */
@@ -6711,6 +6715,17 @@ export declare class ReplayResponse {
6711
6715
  sdkResponseSegments?: Record<string, unknown>[];
6712
6716
  }
6713
6717
 
6718
+ /** ReplicatedVoiceConfig is used to configure replicated voice. */
6719
+ export declare interface ReplicatedVoiceConfig {
6720
+ /** The mime type of the replicated voice.
6721
+ */
6722
+ mimeType?: string;
6723
+ /** The sample audio of the replicated voice.
6724
+
6725
+ * @remarks Encoded as base64 string. */
6726
+ voiceSampleAudio?: string;
6727
+ }
6728
+
6714
6729
  /** Defines a retrieval tool that model can call to access external knowledge. This data type is not supported in Gemini API. */
6715
6730
  export declare interface Retrieval {
6716
6731
  /** Optional. Deprecated. This option is no longer supported. */
@@ -7201,12 +7216,11 @@ export declare interface SpeakerVoiceConfig {
7201
7216
  voiceConfig?: VoiceConfig;
7202
7217
  }
7203
7218
 
7204
- /** The speech generation config. */
7205
7219
  export declare interface SpeechConfig {
7220
+ /** Configuration for the voice of the response. */
7221
+ voiceConfig?: VoiceConfig;
7206
7222
  /** Optional. Language code (ISO 639. e.g. en-US) for the speech synthesization. */
7207
7223
  languageCode?: string;
7208
- /** The configuration for the speaker to use. */
7209
- voiceConfig?: VoiceConfig;
7210
7224
  /** Optional. The configuration for the multi-speaker setup. It is mutually exclusive with the voice_config field. This field is not supported in Vertex AI. */
7211
7225
  multiSpeakerVoiceConfig?: MultiSpeakerVoiceConfig;
7212
7226
  }
@@ -8056,6 +8070,12 @@ declare namespace types {
8056
8070
  LatLng,
8057
8071
  RetrievalConfig,
8058
8072
  ToolConfig,
8073
+ ReplicatedVoiceConfig,
8074
+ PrebuiltVoiceConfig,
8075
+ VoiceConfig,
8076
+ SpeakerVoiceConfig,
8077
+ MultiSpeakerVoiceConfig,
8078
+ SpeechConfig,
8059
8079
  AutomaticFunctionCallingConfig,
8060
8080
  ThinkingConfig,
8061
8081
  ImageConfig,
@@ -8143,11 +8163,6 @@ declare namespace types {
8143
8163
  DeleteModelConfig,
8144
8164
  DeleteModelParameters,
8145
8165
  DeleteModelResponse,
8146
- PrebuiltVoiceConfig,
8147
- VoiceConfig,
8148
- SpeakerVoiceConfig,
8149
- MultiSpeakerVoiceConfig,
8150
- SpeechConfig,
8151
8166
  GenerationConfig,
8152
8167
  CountTokensConfig,
8153
8168
  CountTokensParameters,
@@ -8856,8 +8871,9 @@ export declare interface VideoMetadata {
8856
8871
  startOffset?: string;
8857
8872
  }
8858
8873
 
8859
- /** The configuration for the voice to use. */
8860
8874
  export declare interface VoiceConfig {
8875
+ /** If true, the model will use a replicated voice for the response. */
8876
+ replicatedVoiceConfig?: ReplicatedVoiceConfig;
8861
8877
  /** The configuration for the prebuilt voice to use. */
8862
8878
  prebuiltVoiceConfig?: PrebuiltVoiceConfig;
8863
8879
  }
@@ -4113,6 +4113,12 @@ function generateContentConfigToMldev$1(apiClient, fromObject, parentObject) {
4113
4113
  if (fromImageConfig != null) {
4114
4114
  setValueByPath(toObject, ['imageConfig'], imageConfigToMldev$1(fromImageConfig));
4115
4115
  }
4116
+ const fromEnableEnhancedCivicAnswers = getValueByPath(fromObject, [
4117
+ 'enableEnhancedCivicAnswers',
4118
+ ]);
4119
+ if (fromEnableEnhancedCivicAnswers != null) {
4120
+ setValueByPath(toObject, ['enableEnhancedCivicAnswers'], fromEnableEnhancedCivicAnswers);
4121
+ }
4116
4122
  return toObject;
4117
4123
  }
4118
4124
  function generateContentResponseFromMldev$1(fromObject) {
@@ -6557,17 +6563,17 @@ class Chat {
6557
6563
  return structuredClone(history);
6558
6564
  }
6559
6565
  processStreamResponse(streamResponse, inputContent) {
6560
- var _a, _b;
6561
6566
  return __asyncGenerator(this, arguments, function* processStreamResponse_1() {
6562
- var _c, e_1, _d, _e;
6567
+ var _a, e_1, _b, _c;
6568
+ var _d, _e;
6563
6569
  const outputContent = [];
6564
6570
  try {
6565
- for (var _f = true, streamResponse_1 = __asyncValues(streamResponse), streamResponse_1_1; streamResponse_1_1 = yield __await(streamResponse_1.next()), _c = streamResponse_1_1.done, !_c; _f = true) {
6566
- _e = streamResponse_1_1.value;
6571
+ for (var _f = true, streamResponse_1 = __asyncValues(streamResponse), streamResponse_1_1; streamResponse_1_1 = yield __await(streamResponse_1.next()), _a = streamResponse_1_1.done, !_a; _f = true) {
6572
+ _c = streamResponse_1_1.value;
6567
6573
  _f = false;
6568
- const chunk = _e;
6574
+ const chunk = _c;
6569
6575
  if (isValidResponse(chunk)) {
6570
- const content = (_b = (_a = chunk.candidates) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.content;
6576
+ const content = (_e = (_d = chunk.candidates) === null || _d === void 0 ? void 0 : _d[0]) === null || _e === void 0 ? void 0 : _e.content;
6571
6577
  if (content !== undefined) {
6572
6578
  outputContent.push(content);
6573
6579
  }
@@ -6578,7 +6584,7 @@ class Chat {
6578
6584
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
6579
6585
  finally {
6580
6586
  try {
6581
- if (!_f && !_c && (_d = streamResponse_1.return)) yield __await(_d.call(streamResponse_1));
6587
+ if (!_f && !_a && (_b = streamResponse_1.return)) yield __await(_b.call(streamResponse_1));
6582
6588
  }
6583
6589
  finally { if (e_1) throw e_1.error; }
6584
6590
  }
@@ -7732,14 +7738,14 @@ function sessionResumptionConfigToMldev$1(fromObject) {
7732
7738
  }
7733
7739
  function speechConfigToVertex$1(fromObject) {
7734
7740
  const toObject = {};
7735
- const fromLanguageCode = getValueByPath(fromObject, ['languageCode']);
7736
- if (fromLanguageCode != null) {
7737
- setValueByPath(toObject, ['languageCode'], fromLanguageCode);
7738
- }
7739
7741
  const fromVoiceConfig = getValueByPath(fromObject, ['voiceConfig']);
7740
7742
  if (fromVoiceConfig != null) {
7741
7743
  setValueByPath(toObject, ['voiceConfig'], fromVoiceConfig);
7742
7744
  }
7745
+ const fromLanguageCode = getValueByPath(fromObject, ['languageCode']);
7746
+ if (fromLanguageCode != null) {
7747
+ setValueByPath(toObject, ['languageCode'], fromLanguageCode);
7748
+ }
7743
7749
  if (getValueByPath(fromObject, ['multiSpeakerVoiceConfig']) !== undefined) {
7744
7750
  throw new Error('multiSpeakerVoiceConfig parameter is not supported in Vertex AI.');
7745
7751
  }
@@ -8835,6 +8841,12 @@ function generateContentConfigToMldev(apiClient, fromObject, parentObject) {
8835
8841
  if (fromImageConfig != null) {
8836
8842
  setValueByPath(toObject, ['imageConfig'], imageConfigToMldev(fromImageConfig));
8837
8843
  }
8844
+ const fromEnableEnhancedCivicAnswers = getValueByPath(fromObject, [
8845
+ 'enableEnhancedCivicAnswers',
8846
+ ]);
8847
+ if (fromEnableEnhancedCivicAnswers != null) {
8848
+ setValueByPath(toObject, ['enableEnhancedCivicAnswers'], fromEnableEnhancedCivicAnswers);
8849
+ }
8838
8850
  return toObject;
8839
8851
  }
8840
8852
  function generateContentConfigToVertex(apiClient, fromObject, parentObject) {
@@ -8999,6 +9011,10 @@ function generateContentConfigToVertex(apiClient, fromObject, parentObject) {
8999
9011
  if (fromImageConfig != null) {
9000
9012
  setValueByPath(toObject, ['imageConfig'], imageConfigToVertex(fromImageConfig));
9001
9013
  }
9014
+ if (getValueByPath(fromObject, ['enableEnhancedCivicAnswers']) !==
9015
+ undefined) {
9016
+ throw new Error('enableEnhancedCivicAnswers parameter is not supported in Vertex AI.');
9017
+ }
9002
9018
  return toObject;
9003
9019
  }
9004
9020
  function generateContentParametersToMldev(apiClient, fromObject) {
@@ -10727,14 +10743,14 @@ function segmentImageSourceToVertex(fromObject, parentObject) {
10727
10743
  }
10728
10744
  function speechConfigToVertex(fromObject) {
10729
10745
  const toObject = {};
10730
- const fromLanguageCode = getValueByPath(fromObject, ['languageCode']);
10731
- if (fromLanguageCode != null) {
10732
- setValueByPath(toObject, ['languageCode'], fromLanguageCode);
10733
- }
10734
10746
  const fromVoiceConfig = getValueByPath(fromObject, ['voiceConfig']);
10735
10747
  if (fromVoiceConfig != null) {
10736
10748
  setValueByPath(toObject, ['voiceConfig'], fromVoiceConfig);
10737
10749
  }
10750
+ const fromLanguageCode = getValueByPath(fromObject, ['languageCode']);
10751
+ if (fromLanguageCode != null) {
10752
+ setValueByPath(toObject, ['languageCode'], fromLanguageCode);
10753
+ }
10738
10754
  if (getValueByPath(fromObject, ['multiSpeakerVoiceConfig']) !== undefined) {
10739
10755
  throw new Error('multiSpeakerVoiceConfig parameter is not supported in Vertex AI.');
10740
10756
  }
@@ -11421,11 +11437,10 @@ const CONTENT_TYPE_HEADER = 'Content-Type';
11421
11437
  const SERVER_TIMEOUT_HEADER = 'X-Server-Timeout';
11422
11438
  const USER_AGENT_HEADER = 'User-Agent';
11423
11439
  const GOOGLE_API_CLIENT_HEADER = 'x-goog-api-client';
11424
- const SDK_VERSION = '1.31.0'; // x-release-please-version
11440
+ const SDK_VERSION = '1.32.0'; // x-release-please-version
11425
11441
  const LIBRARY_LABEL = `google-genai-sdk/${SDK_VERSION}`;
11426
11442
  const VERTEX_AI_API_DEFAULT_VERSION = 'v1beta1';
11427
11443
  const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
11428
- const responseLineRE = /^\s*data: (.*)(?:\n\n|\r\r|\r\n\r\n)/;
11429
11444
  /**
11430
11445
  * The ApiClient class is used to send requests to the Gemini API or Vertex AI
11431
11446
  * endpoints.
@@ -11705,8 +11720,8 @@ class ApiClient {
11705
11720
  });
11706
11721
  }
11707
11722
  processStreamResponse(response) {
11708
- var _a;
11709
11723
  return __asyncGenerator(this, arguments, function* processStreamResponse_1() {
11724
+ var _a;
11710
11725
  const reader = (_a = response === null || response === void 0 ? void 0 : response.body) === null || _a === void 0 ? void 0 : _a.getReader();
11711
11726
  const decoder = new TextDecoder('utf-8');
11712
11727
  if (!reader) {
@@ -11714,6 +11729,8 @@ class ApiClient {
11714
11729
  }
11715
11730
  try {
11716
11731
  let buffer = '';
11732
+ const dataPrefix = 'data:';
11733
+ const delimiters = ['\n\n', '\r\r', '\r\n\r\n'];
11717
11734
  while (true) {
11718
11735
  const { done, value } = yield __await(reader.read());
11719
11736
  if (done) {
@@ -11747,21 +11764,40 @@ class ApiClient {
11747
11764
  }
11748
11765
  }
11749
11766
  buffer += chunkString;
11750
- let match = buffer.match(responseLineRE);
11751
- while (match) {
11752
- const processedChunkString = match[1];
11753
- try {
11754
- const partialResponse = new Response(processedChunkString, {
11755
- headers: response === null || response === void 0 ? void 0 : response.headers,
11756
- status: response === null || response === void 0 ? void 0 : response.status,
11757
- statusText: response === null || response === void 0 ? void 0 : response.statusText,
11758
- });
11759
- yield yield __await(new HttpResponse(partialResponse));
11760
- buffer = buffer.slice(match[0].length);
11761
- match = buffer.match(responseLineRE);
11767
+ let delimiterIndex = -1;
11768
+ let delimiterLength = 0;
11769
+ while (true) {
11770
+ delimiterIndex = -1;
11771
+ delimiterLength = 0;
11772
+ for (const delimiter of delimiters) {
11773
+ const index = buffer.indexOf(delimiter);
11774
+ if (index !== -1 &&
11775
+ (delimiterIndex === -1 || index < delimiterIndex)) {
11776
+ delimiterIndex = index;
11777
+ delimiterLength = delimiter.length;
11778
+ }
11779
+ }
11780
+ if (delimiterIndex === -1) {
11781
+ break; // No complete event in buffer
11762
11782
  }
11763
- catch (e) {
11764
- throw new Error(`exception parsing stream chunk ${processedChunkString}. ${e}`);
11783
+ const eventString = buffer.substring(0, delimiterIndex);
11784
+ buffer = buffer.substring(delimiterIndex + delimiterLength);
11785
+ const trimmedEvent = eventString.trim();
11786
+ if (trimmedEvent.startsWith(dataPrefix)) {
11787
+ const processedChunkString = trimmedEvent
11788
+ .substring(dataPrefix.length)
11789
+ .trim();
11790
+ try {
11791
+ const partialResponse = new Response(processedChunkString, {
11792
+ headers: response === null || response === void 0 ? void 0 : response.headers,
11793
+ status: response === null || response === void 0 ? void 0 : response.status,
11794
+ statusText: response === null || response === void 0 ? void 0 : response.statusText,
11795
+ });
11796
+ yield yield __await(new HttpResponse(partialResponse));
11797
+ }
11798
+ catch (e) {
11799
+ throw new Error(`exception parsing stream chunk ${processedChunkString}. ${e}`);
11800
+ }
11765
11801
  }
11766
11802
  }
11767
11803
  }
@@ -11894,7 +11930,7 @@ class ApiClient {
11894
11930
  }
11895
11931
  else {
11896
11932
  httpOptions = {
11897
- apiVersion: '',
11933
+ apiVersion: '', // api-version is set in the path.
11898
11934
  headers: Object.assign({ 'Content-Type': 'application/json', 'X-Goog-Upload-Protocol': 'resumable', 'X-Goog-Upload-Command': 'start', 'X-Goog-Upload-Header-Content-Length': `${sizeBytes}`, 'X-Goog-Upload-Header-Content-Type': `${mimeType}` }, (fileName ? { 'X-Goog-Upload-File-Name': fileName } : {})),
11899
11935
  };
11900
11936
  }
@@ -12056,8 +12092,8 @@ function isMcpCallableTool(object) {
12056
12092
  object instanceof McpCallableTool);
12057
12093
  }
12058
12094
  // List all tools from the MCP client.
12059
- function listAllTools(mcpClient, maxTools = 100) {
12060
- return __asyncGenerator(this, arguments, function* listAllTools_1() {
12095
+ function listAllTools(mcpClient_1) {
12096
+ return __asyncGenerator(this, arguments, function* listAllTools_1(mcpClient, maxTools = 100) {
12061
12097
  let cursor = undefined;
12062
12098
  let numTools = 0;
12063
12099
  while (numTools < maxTools) {
@@ -13377,9 +13413,9 @@ class Models extends BaseModule {
13377
13413
  let remoteCallCount = 0;
13378
13414
  const afcToolsMap = await this.initAfcToolsMap(params);
13379
13415
  return (function (models, afcTools, params) {
13380
- var _a, _b;
13381
13416
  return __asyncGenerator(this, arguments, function* () {
13382
- var _c, e_1, _d, _e;
13417
+ var _a, e_1, _b, _c;
13418
+ var _d, _e;
13383
13419
  while (remoteCallCount < maxRemoteCalls) {
13384
13420
  if (wereFunctionsCalled) {
13385
13421
  remoteCallCount++;
@@ -13390,14 +13426,14 @@ class Models extends BaseModule {
13390
13426
  const functionResponses = [];
13391
13427
  const responseContents = [];
13392
13428
  try {
13393
- for (var _f = true, response_1 = (e_1 = void 0, __asyncValues(response)), response_1_1; response_1_1 = yield __await(response_1.next()), _c = response_1_1.done, !_c; _f = true) {
13394
- _e = response_1_1.value;
13429
+ for (var _f = true, response_1 = (e_1 = void 0, __asyncValues(response)), response_1_1; response_1_1 = yield __await(response_1.next()), _a = response_1_1.done, !_a; _f = true) {
13430
+ _c = response_1_1.value;
13395
13431
  _f = false;
13396
- const chunk = _e;
13432
+ const chunk = _c;
13397
13433
  yield yield __await(chunk);
13398
- if (chunk.candidates && ((_a = chunk.candidates[0]) === null || _a === void 0 ? void 0 : _a.content)) {
13434
+ if (chunk.candidates && ((_d = chunk.candidates[0]) === null || _d === void 0 ? void 0 : _d.content)) {
13399
13435
  responseContents.push(chunk.candidates[0].content);
13400
- for (const part of (_b = chunk.candidates[0].content.parts) !== null && _b !== void 0 ? _b : []) {
13436
+ for (const part of (_e = chunk.candidates[0].content.parts) !== null && _e !== void 0 ? _e : []) {
13401
13437
  if (remoteCallCount < maxRemoteCalls && part.functionCall) {
13402
13438
  if (!part.functionCall.name) {
13403
13439
  throw new Error('Function call name was not returned by the model.');
@@ -13419,7 +13455,7 @@ class Models extends BaseModule {
13419
13455
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
13420
13456
  finally {
13421
13457
  try {
13422
- if (!_f && !_c && (_d = response_1.return)) yield __await(_d.call(response_1));
13458
+ if (!_f && !_a && (_b = response_1.return)) yield __await(_b.call(response_1));
13423
13459
  }
13424
13460
  finally { if (e_1) throw e_1.error; }
13425
13461
  }