@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.
package/dist/genai.d.ts CHANGED
@@ -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. */
@@ -6699,6 +6703,17 @@ export declare class ReplayResponse {
6699
6703
  sdkResponseSegments?: Record<string, unknown>[];
6700
6704
  }
6701
6705
 
6706
+ /** ReplicatedVoiceConfig is used to configure replicated voice. */
6707
+ export declare interface ReplicatedVoiceConfig {
6708
+ /** The mime type of the replicated voice.
6709
+ */
6710
+ mimeType?: string;
6711
+ /** The sample audio of the replicated voice.
6712
+
6713
+ * @remarks Encoded as base64 string. */
6714
+ voiceSampleAudio?: string;
6715
+ }
6716
+
6702
6717
  /** Defines a retrieval tool that model can call to access external knowledge. This data type is not supported in Gemini API. */
6703
6718
  export declare interface Retrieval {
6704
6719
  /** Optional. Deprecated. This option is no longer supported. */
@@ -7189,12 +7204,11 @@ export declare interface SpeakerVoiceConfig {
7189
7204
  voiceConfig?: VoiceConfig;
7190
7205
  }
7191
7206
 
7192
- /** The speech generation config. */
7193
7207
  export declare interface SpeechConfig {
7208
+ /** Configuration for the voice of the response. */
7209
+ voiceConfig?: VoiceConfig;
7194
7210
  /** Optional. Language code (ISO 639. e.g. en-US) for the speech synthesization. */
7195
7211
  languageCode?: string;
7196
- /** The configuration for the speaker to use. */
7197
- voiceConfig?: VoiceConfig;
7198
7212
  /** 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. */
7199
7213
  multiSpeakerVoiceConfig?: MultiSpeakerVoiceConfig;
7200
7214
  }
@@ -8044,6 +8058,12 @@ declare namespace types {
8044
8058
  LatLng,
8045
8059
  RetrievalConfig,
8046
8060
  ToolConfig,
8061
+ ReplicatedVoiceConfig,
8062
+ PrebuiltVoiceConfig,
8063
+ VoiceConfig,
8064
+ SpeakerVoiceConfig,
8065
+ MultiSpeakerVoiceConfig,
8066
+ SpeechConfig,
8047
8067
  AutomaticFunctionCallingConfig,
8048
8068
  ThinkingConfig,
8049
8069
  ImageConfig,
@@ -8131,11 +8151,6 @@ declare namespace types {
8131
8151
  DeleteModelConfig,
8132
8152
  DeleteModelParameters,
8133
8153
  DeleteModelResponse,
8134
- PrebuiltVoiceConfig,
8135
- VoiceConfig,
8136
- SpeakerVoiceConfig,
8137
- MultiSpeakerVoiceConfig,
8138
- SpeechConfig,
8139
8154
  GenerationConfig,
8140
8155
  CountTokensConfig,
8141
8156
  CountTokensParameters,
@@ -8844,8 +8859,9 @@ export declare interface VideoMetadata {
8844
8859
  startOffset?: string;
8845
8860
  }
8846
8861
 
8847
- /** The configuration for the voice to use. */
8848
8862
  export declare interface VoiceConfig {
8863
+ /** If true, the model will use a replicated voice for the response. */
8864
+ replicatedVoiceConfig?: ReplicatedVoiceConfig;
8849
8865
  /** The configuration for the prebuilt voice to use. */
8850
8866
  prebuiltVoiceConfig?: PrebuiltVoiceConfig;
8851
8867
  }
package/dist/index.cjs CHANGED
@@ -4085,6 +4085,12 @@ function generateContentConfigToMldev$1(apiClient, fromObject, parentObject) {
4085
4085
  if (fromImageConfig != null) {
4086
4086
  setValueByPath(toObject, ['imageConfig'], imageConfigToMldev$1(fromImageConfig));
4087
4087
  }
4088
+ const fromEnableEnhancedCivicAnswers = getValueByPath(fromObject, [
4089
+ 'enableEnhancedCivicAnswers',
4090
+ ]);
4091
+ if (fromEnableEnhancedCivicAnswers != null) {
4092
+ setValueByPath(toObject, ['enableEnhancedCivicAnswers'], fromEnableEnhancedCivicAnswers);
4093
+ }
4088
4094
  return toObject;
4089
4095
  }
4090
4096
  function generateContentResponseFromMldev$1(fromObject) {
@@ -6529,17 +6535,17 @@ class Chat {
6529
6535
  return structuredClone(history);
6530
6536
  }
6531
6537
  processStreamResponse(streamResponse, inputContent) {
6532
- var _a, _b;
6533
6538
  return __asyncGenerator(this, arguments, function* processStreamResponse_1() {
6534
- var _c, e_1, _d, _e;
6539
+ var _a, e_1, _b, _c;
6540
+ var _d, _e;
6535
6541
  const outputContent = [];
6536
6542
  try {
6537
- 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) {
6538
- _e = streamResponse_1_1.value;
6543
+ 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) {
6544
+ _c = streamResponse_1_1.value;
6539
6545
  _f = false;
6540
- const chunk = _e;
6546
+ const chunk = _c;
6541
6547
  if (isValidResponse(chunk)) {
6542
- const content = (_b = (_a = chunk.candidates) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.content;
6548
+ const content = (_e = (_d = chunk.candidates) === null || _d === void 0 ? void 0 : _d[0]) === null || _e === void 0 ? void 0 : _e.content;
6543
6549
  if (content !== undefined) {
6544
6550
  outputContent.push(content);
6545
6551
  }
@@ -6550,7 +6556,7 @@ class Chat {
6550
6556
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
6551
6557
  finally {
6552
6558
  try {
6553
- if (!_f && !_c && (_d = streamResponse_1.return)) yield __await(_d.call(streamResponse_1));
6559
+ if (!_f && !_a && (_b = streamResponse_1.return)) yield __await(_b.call(streamResponse_1));
6554
6560
  }
6555
6561
  finally { if (e_1) throw e_1.error; }
6556
6562
  }
@@ -6843,11 +6849,10 @@ const CONTENT_TYPE_HEADER = 'Content-Type';
6843
6849
  const SERVER_TIMEOUT_HEADER = 'X-Server-Timeout';
6844
6850
  const USER_AGENT_HEADER = 'User-Agent';
6845
6851
  const GOOGLE_API_CLIENT_HEADER = 'x-goog-api-client';
6846
- const SDK_VERSION = '1.31.0'; // x-release-please-version
6852
+ const SDK_VERSION = '1.32.0'; // x-release-please-version
6847
6853
  const LIBRARY_LABEL = `google-genai-sdk/${SDK_VERSION}`;
6848
6854
  const VERTEX_AI_API_DEFAULT_VERSION = 'v1beta1';
6849
6855
  const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
6850
- const responseLineRE = /^\s*data: (.*)(?:\n\n|\r\r|\r\n\r\n)/;
6851
6856
  /**
6852
6857
  * The ApiClient class is used to send requests to the Gemini API or Vertex AI
6853
6858
  * endpoints.
@@ -7127,8 +7132,8 @@ class ApiClient {
7127
7132
  });
7128
7133
  }
7129
7134
  processStreamResponse(response) {
7130
- var _a;
7131
7135
  return __asyncGenerator(this, arguments, function* processStreamResponse_1() {
7136
+ var _a;
7132
7137
  const reader = (_a = response === null || response === void 0 ? void 0 : response.body) === null || _a === void 0 ? void 0 : _a.getReader();
7133
7138
  const decoder = new TextDecoder('utf-8');
7134
7139
  if (!reader) {
@@ -7136,6 +7141,8 @@ class ApiClient {
7136
7141
  }
7137
7142
  try {
7138
7143
  let buffer = '';
7144
+ const dataPrefix = 'data:';
7145
+ const delimiters = ['\n\n', '\r\r', '\r\n\r\n'];
7139
7146
  while (true) {
7140
7147
  const { done, value } = yield __await(reader.read());
7141
7148
  if (done) {
@@ -7169,21 +7176,40 @@ class ApiClient {
7169
7176
  }
7170
7177
  }
7171
7178
  buffer += chunkString;
7172
- let match = buffer.match(responseLineRE);
7173
- while (match) {
7174
- const processedChunkString = match[1];
7175
- try {
7176
- const partialResponse = new Response(processedChunkString, {
7177
- headers: response === null || response === void 0 ? void 0 : response.headers,
7178
- status: response === null || response === void 0 ? void 0 : response.status,
7179
- statusText: response === null || response === void 0 ? void 0 : response.statusText,
7180
- });
7181
- yield yield __await(new HttpResponse(partialResponse));
7182
- buffer = buffer.slice(match[0].length);
7183
- match = buffer.match(responseLineRE);
7179
+ let delimiterIndex = -1;
7180
+ let delimiterLength = 0;
7181
+ while (true) {
7182
+ delimiterIndex = -1;
7183
+ delimiterLength = 0;
7184
+ for (const delimiter of delimiters) {
7185
+ const index = buffer.indexOf(delimiter);
7186
+ if (index !== -1 &&
7187
+ (delimiterIndex === -1 || index < delimiterIndex)) {
7188
+ delimiterIndex = index;
7189
+ delimiterLength = delimiter.length;
7190
+ }
7184
7191
  }
7185
- catch (e) {
7186
- throw new Error(`exception parsing stream chunk ${processedChunkString}. ${e}`);
7192
+ if (delimiterIndex === -1) {
7193
+ break; // No complete event in buffer
7194
+ }
7195
+ const eventString = buffer.substring(0, delimiterIndex);
7196
+ buffer = buffer.substring(delimiterIndex + delimiterLength);
7197
+ const trimmedEvent = eventString.trim();
7198
+ if (trimmedEvent.startsWith(dataPrefix)) {
7199
+ const processedChunkString = trimmedEvent
7200
+ .substring(dataPrefix.length)
7201
+ .trim();
7202
+ try {
7203
+ const partialResponse = new Response(processedChunkString, {
7204
+ headers: response === null || response === void 0 ? void 0 : response.headers,
7205
+ status: response === null || response === void 0 ? void 0 : response.status,
7206
+ statusText: response === null || response === void 0 ? void 0 : response.statusText,
7207
+ });
7208
+ yield yield __await(new HttpResponse(partialResponse));
7209
+ }
7210
+ catch (e) {
7211
+ throw new Error(`exception parsing stream chunk ${processedChunkString}. ${e}`);
7212
+ }
7187
7213
  }
7188
7214
  }
7189
7215
  }
@@ -7316,7 +7342,7 @@ class ApiClient {
7316
7342
  }
7317
7343
  else {
7318
7344
  httpOptions = {
7319
- apiVersion: '',
7345
+ apiVersion: '', // api-version is set in the path.
7320
7346
  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 } : {})),
7321
7347
  };
7322
7348
  }
@@ -9193,14 +9219,14 @@ function sessionResumptionConfigToMldev$1(fromObject) {
9193
9219
  }
9194
9220
  function speechConfigToVertex$1(fromObject) {
9195
9221
  const toObject = {};
9196
- const fromLanguageCode = getValueByPath(fromObject, ['languageCode']);
9197
- if (fromLanguageCode != null) {
9198
- setValueByPath(toObject, ['languageCode'], fromLanguageCode);
9199
- }
9200
9222
  const fromVoiceConfig = getValueByPath(fromObject, ['voiceConfig']);
9201
9223
  if (fromVoiceConfig != null) {
9202
9224
  setValueByPath(toObject, ['voiceConfig'], fromVoiceConfig);
9203
9225
  }
9226
+ const fromLanguageCode = getValueByPath(fromObject, ['languageCode']);
9227
+ if (fromLanguageCode != null) {
9228
+ setValueByPath(toObject, ['languageCode'], fromLanguageCode);
9229
+ }
9204
9230
  if (getValueByPath(fromObject, ['multiSpeakerVoiceConfig']) !== undefined) {
9205
9231
  throw new Error('multiSpeakerVoiceConfig parameter is not supported in Vertex AI.');
9206
9232
  }
@@ -10296,6 +10322,12 @@ function generateContentConfigToMldev(apiClient, fromObject, parentObject) {
10296
10322
  if (fromImageConfig != null) {
10297
10323
  setValueByPath(toObject, ['imageConfig'], imageConfigToMldev(fromImageConfig));
10298
10324
  }
10325
+ const fromEnableEnhancedCivicAnswers = getValueByPath(fromObject, [
10326
+ 'enableEnhancedCivicAnswers',
10327
+ ]);
10328
+ if (fromEnableEnhancedCivicAnswers != null) {
10329
+ setValueByPath(toObject, ['enableEnhancedCivicAnswers'], fromEnableEnhancedCivicAnswers);
10330
+ }
10299
10331
  return toObject;
10300
10332
  }
10301
10333
  function generateContentConfigToVertex(apiClient, fromObject, parentObject) {
@@ -10460,6 +10492,10 @@ function generateContentConfigToVertex(apiClient, fromObject, parentObject) {
10460
10492
  if (fromImageConfig != null) {
10461
10493
  setValueByPath(toObject, ['imageConfig'], imageConfigToVertex(fromImageConfig));
10462
10494
  }
10495
+ if (getValueByPath(fromObject, ['enableEnhancedCivicAnswers']) !==
10496
+ undefined) {
10497
+ throw new Error('enableEnhancedCivicAnswers parameter is not supported in Vertex AI.');
10498
+ }
10463
10499
  return toObject;
10464
10500
  }
10465
10501
  function generateContentParametersToMldev(apiClient, fromObject) {
@@ -12188,14 +12224,14 @@ function segmentImageSourceToVertex(fromObject, parentObject) {
12188
12224
  }
12189
12225
  function speechConfigToVertex(fromObject) {
12190
12226
  const toObject = {};
12191
- const fromLanguageCode = getValueByPath(fromObject, ['languageCode']);
12192
- if (fromLanguageCode != null) {
12193
- setValueByPath(toObject, ['languageCode'], fromLanguageCode);
12194
- }
12195
12227
  const fromVoiceConfig = getValueByPath(fromObject, ['voiceConfig']);
12196
12228
  if (fromVoiceConfig != null) {
12197
12229
  setValueByPath(toObject, ['voiceConfig'], fromVoiceConfig);
12198
12230
  }
12231
+ const fromLanguageCode = getValueByPath(fromObject, ['languageCode']);
12232
+ if (fromLanguageCode != null) {
12233
+ setValueByPath(toObject, ['languageCode'], fromLanguageCode);
12234
+ }
12199
12235
  if (getValueByPath(fromObject, ['multiSpeakerVoiceConfig']) !== undefined) {
12200
12236
  throw new Error('multiSpeakerVoiceConfig parameter is not supported in Vertex AI.');
12201
12237
  }
@@ -12673,8 +12709,8 @@ function isMcpCallableTool(object) {
12673
12709
  object instanceof McpCallableTool);
12674
12710
  }
12675
12711
  // List all tools from the MCP client.
12676
- function listAllTools(mcpClient, maxTools = 100) {
12677
- return __asyncGenerator(this, arguments, function* listAllTools_1() {
12712
+ function listAllTools(mcpClient_1) {
12713
+ return __asyncGenerator(this, arguments, function* listAllTools_1(mcpClient, maxTools = 100) {
12678
12714
  let cursor = undefined;
12679
12715
  let numTools = 0;
12680
12716
  while (numTools < maxTools) {
@@ -13994,9 +14030,9 @@ class Models extends BaseModule {
13994
14030
  let remoteCallCount = 0;
13995
14031
  const afcToolsMap = await this.initAfcToolsMap(params);
13996
14032
  return (function (models, afcTools, params) {
13997
- var _a, _b;
13998
14033
  return __asyncGenerator(this, arguments, function* () {
13999
- var _c, e_1, _d, _e;
14034
+ var _a, e_1, _b, _c;
14035
+ var _d, _e;
14000
14036
  while (remoteCallCount < maxRemoteCalls) {
14001
14037
  if (wereFunctionsCalled) {
14002
14038
  remoteCallCount++;
@@ -14007,14 +14043,14 @@ class Models extends BaseModule {
14007
14043
  const functionResponses = [];
14008
14044
  const responseContents = [];
14009
14045
  try {
14010
- 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) {
14011
- _e = response_1_1.value;
14046
+ 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) {
14047
+ _c = response_1_1.value;
14012
14048
  _f = false;
14013
- const chunk = _e;
14049
+ const chunk = _c;
14014
14050
  yield yield __await(chunk);
14015
- if (chunk.candidates && ((_a = chunk.candidates[0]) === null || _a === void 0 ? void 0 : _a.content)) {
14051
+ if (chunk.candidates && ((_d = chunk.candidates[0]) === null || _d === void 0 ? void 0 : _d.content)) {
14016
14052
  responseContents.push(chunk.candidates[0].content);
14017
- for (const part of (_b = chunk.candidates[0].content.parts) !== null && _b !== void 0 ? _b : []) {
14053
+ for (const part of (_e = chunk.candidates[0].content.parts) !== null && _e !== void 0 ? _e : []) {
14018
14054
  if (remoteCallCount < maxRemoteCalls && part.functionCall) {
14019
14055
  if (!part.functionCall.name) {
14020
14056
  throw new Error('Function call name was not returned by the model.');
@@ -14036,7 +14072,7 @@ class Models extends BaseModule {
14036
14072
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
14037
14073
  finally {
14038
14074
  try {
14039
- if (!_f && !_c && (_d = response_1.return)) yield __await(_d.call(response_1));
14075
+ if (!_f && !_a && (_b = response_1.return)) yield __await(_b.call(response_1));
14040
14076
  }
14041
14077
  finally { if (e_1) throw e_1.error; }
14042
14078
  }
package/dist/index.mjs CHANGED
@@ -4083,6 +4083,12 @@ function generateContentConfigToMldev$1(apiClient, fromObject, parentObject) {
4083
4083
  if (fromImageConfig != null) {
4084
4084
  setValueByPath(toObject, ['imageConfig'], imageConfigToMldev$1(fromImageConfig));
4085
4085
  }
4086
+ const fromEnableEnhancedCivicAnswers = getValueByPath(fromObject, [
4087
+ 'enableEnhancedCivicAnswers',
4088
+ ]);
4089
+ if (fromEnableEnhancedCivicAnswers != null) {
4090
+ setValueByPath(toObject, ['enableEnhancedCivicAnswers'], fromEnableEnhancedCivicAnswers);
4091
+ }
4086
4092
  return toObject;
4087
4093
  }
4088
4094
  function generateContentResponseFromMldev$1(fromObject) {
@@ -6527,17 +6533,17 @@ class Chat {
6527
6533
  return structuredClone(history);
6528
6534
  }
6529
6535
  processStreamResponse(streamResponse, inputContent) {
6530
- var _a, _b;
6531
6536
  return __asyncGenerator(this, arguments, function* processStreamResponse_1() {
6532
- var _c, e_1, _d, _e;
6537
+ var _a, e_1, _b, _c;
6538
+ var _d, _e;
6533
6539
  const outputContent = [];
6534
6540
  try {
6535
- 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) {
6536
- _e = streamResponse_1_1.value;
6541
+ 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) {
6542
+ _c = streamResponse_1_1.value;
6537
6543
  _f = false;
6538
- const chunk = _e;
6544
+ const chunk = _c;
6539
6545
  if (isValidResponse(chunk)) {
6540
- const content = (_b = (_a = chunk.candidates) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.content;
6546
+ const content = (_e = (_d = chunk.candidates) === null || _d === void 0 ? void 0 : _d[0]) === null || _e === void 0 ? void 0 : _e.content;
6541
6547
  if (content !== undefined) {
6542
6548
  outputContent.push(content);
6543
6549
  }
@@ -6548,7 +6554,7 @@ class Chat {
6548
6554
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
6549
6555
  finally {
6550
6556
  try {
6551
- if (!_f && !_c && (_d = streamResponse_1.return)) yield __await(_d.call(streamResponse_1));
6557
+ if (!_f && !_a && (_b = streamResponse_1.return)) yield __await(_b.call(streamResponse_1));
6552
6558
  }
6553
6559
  finally { if (e_1) throw e_1.error; }
6554
6560
  }
@@ -6841,11 +6847,10 @@ const CONTENT_TYPE_HEADER = 'Content-Type';
6841
6847
  const SERVER_TIMEOUT_HEADER = 'X-Server-Timeout';
6842
6848
  const USER_AGENT_HEADER = 'User-Agent';
6843
6849
  const GOOGLE_API_CLIENT_HEADER = 'x-goog-api-client';
6844
- const SDK_VERSION = '1.31.0'; // x-release-please-version
6850
+ const SDK_VERSION = '1.32.0'; // x-release-please-version
6845
6851
  const LIBRARY_LABEL = `google-genai-sdk/${SDK_VERSION}`;
6846
6852
  const VERTEX_AI_API_DEFAULT_VERSION = 'v1beta1';
6847
6853
  const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
6848
- const responseLineRE = /^\s*data: (.*)(?:\n\n|\r\r|\r\n\r\n)/;
6849
6854
  /**
6850
6855
  * The ApiClient class is used to send requests to the Gemini API or Vertex AI
6851
6856
  * endpoints.
@@ -7125,8 +7130,8 @@ class ApiClient {
7125
7130
  });
7126
7131
  }
7127
7132
  processStreamResponse(response) {
7128
- var _a;
7129
7133
  return __asyncGenerator(this, arguments, function* processStreamResponse_1() {
7134
+ var _a;
7130
7135
  const reader = (_a = response === null || response === void 0 ? void 0 : response.body) === null || _a === void 0 ? void 0 : _a.getReader();
7131
7136
  const decoder = new TextDecoder('utf-8');
7132
7137
  if (!reader) {
@@ -7134,6 +7139,8 @@ class ApiClient {
7134
7139
  }
7135
7140
  try {
7136
7141
  let buffer = '';
7142
+ const dataPrefix = 'data:';
7143
+ const delimiters = ['\n\n', '\r\r', '\r\n\r\n'];
7137
7144
  while (true) {
7138
7145
  const { done, value } = yield __await(reader.read());
7139
7146
  if (done) {
@@ -7167,21 +7174,40 @@ class ApiClient {
7167
7174
  }
7168
7175
  }
7169
7176
  buffer += chunkString;
7170
- let match = buffer.match(responseLineRE);
7171
- while (match) {
7172
- const processedChunkString = match[1];
7173
- try {
7174
- const partialResponse = new Response(processedChunkString, {
7175
- headers: response === null || response === void 0 ? void 0 : response.headers,
7176
- status: response === null || response === void 0 ? void 0 : response.status,
7177
- statusText: response === null || response === void 0 ? void 0 : response.statusText,
7178
- });
7179
- yield yield __await(new HttpResponse(partialResponse));
7180
- buffer = buffer.slice(match[0].length);
7181
- match = buffer.match(responseLineRE);
7177
+ let delimiterIndex = -1;
7178
+ let delimiterLength = 0;
7179
+ while (true) {
7180
+ delimiterIndex = -1;
7181
+ delimiterLength = 0;
7182
+ for (const delimiter of delimiters) {
7183
+ const index = buffer.indexOf(delimiter);
7184
+ if (index !== -1 &&
7185
+ (delimiterIndex === -1 || index < delimiterIndex)) {
7186
+ delimiterIndex = index;
7187
+ delimiterLength = delimiter.length;
7188
+ }
7182
7189
  }
7183
- catch (e) {
7184
- throw new Error(`exception parsing stream chunk ${processedChunkString}. ${e}`);
7190
+ if (delimiterIndex === -1) {
7191
+ break; // No complete event in buffer
7192
+ }
7193
+ const eventString = buffer.substring(0, delimiterIndex);
7194
+ buffer = buffer.substring(delimiterIndex + delimiterLength);
7195
+ const trimmedEvent = eventString.trim();
7196
+ if (trimmedEvent.startsWith(dataPrefix)) {
7197
+ const processedChunkString = trimmedEvent
7198
+ .substring(dataPrefix.length)
7199
+ .trim();
7200
+ try {
7201
+ const partialResponse = new Response(processedChunkString, {
7202
+ headers: response === null || response === void 0 ? void 0 : response.headers,
7203
+ status: response === null || response === void 0 ? void 0 : response.status,
7204
+ statusText: response === null || response === void 0 ? void 0 : response.statusText,
7205
+ });
7206
+ yield yield __await(new HttpResponse(partialResponse));
7207
+ }
7208
+ catch (e) {
7209
+ throw new Error(`exception parsing stream chunk ${processedChunkString}. ${e}`);
7210
+ }
7185
7211
  }
7186
7212
  }
7187
7213
  }
@@ -7314,7 +7340,7 @@ class ApiClient {
7314
7340
  }
7315
7341
  else {
7316
7342
  httpOptions = {
7317
- apiVersion: '',
7343
+ apiVersion: '', // api-version is set in the path.
7318
7344
  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 } : {})),
7319
7345
  };
7320
7346
  }
@@ -9191,14 +9217,14 @@ function sessionResumptionConfigToMldev$1(fromObject) {
9191
9217
  }
9192
9218
  function speechConfigToVertex$1(fromObject) {
9193
9219
  const toObject = {};
9194
- const fromLanguageCode = getValueByPath(fromObject, ['languageCode']);
9195
- if (fromLanguageCode != null) {
9196
- setValueByPath(toObject, ['languageCode'], fromLanguageCode);
9197
- }
9198
9220
  const fromVoiceConfig = getValueByPath(fromObject, ['voiceConfig']);
9199
9221
  if (fromVoiceConfig != null) {
9200
9222
  setValueByPath(toObject, ['voiceConfig'], fromVoiceConfig);
9201
9223
  }
9224
+ const fromLanguageCode = getValueByPath(fromObject, ['languageCode']);
9225
+ if (fromLanguageCode != null) {
9226
+ setValueByPath(toObject, ['languageCode'], fromLanguageCode);
9227
+ }
9202
9228
  if (getValueByPath(fromObject, ['multiSpeakerVoiceConfig']) !== undefined) {
9203
9229
  throw new Error('multiSpeakerVoiceConfig parameter is not supported in Vertex AI.');
9204
9230
  }
@@ -10294,6 +10320,12 @@ function generateContentConfigToMldev(apiClient, fromObject, parentObject) {
10294
10320
  if (fromImageConfig != null) {
10295
10321
  setValueByPath(toObject, ['imageConfig'], imageConfigToMldev(fromImageConfig));
10296
10322
  }
10323
+ const fromEnableEnhancedCivicAnswers = getValueByPath(fromObject, [
10324
+ 'enableEnhancedCivicAnswers',
10325
+ ]);
10326
+ if (fromEnableEnhancedCivicAnswers != null) {
10327
+ setValueByPath(toObject, ['enableEnhancedCivicAnswers'], fromEnableEnhancedCivicAnswers);
10328
+ }
10297
10329
  return toObject;
10298
10330
  }
10299
10331
  function generateContentConfigToVertex(apiClient, fromObject, parentObject) {
@@ -10458,6 +10490,10 @@ function generateContentConfigToVertex(apiClient, fromObject, parentObject) {
10458
10490
  if (fromImageConfig != null) {
10459
10491
  setValueByPath(toObject, ['imageConfig'], imageConfigToVertex(fromImageConfig));
10460
10492
  }
10493
+ if (getValueByPath(fromObject, ['enableEnhancedCivicAnswers']) !==
10494
+ undefined) {
10495
+ throw new Error('enableEnhancedCivicAnswers parameter is not supported in Vertex AI.');
10496
+ }
10461
10497
  return toObject;
10462
10498
  }
10463
10499
  function generateContentParametersToMldev(apiClient, fromObject) {
@@ -12186,14 +12222,14 @@ function segmentImageSourceToVertex(fromObject, parentObject) {
12186
12222
  }
12187
12223
  function speechConfigToVertex(fromObject) {
12188
12224
  const toObject = {};
12189
- const fromLanguageCode = getValueByPath(fromObject, ['languageCode']);
12190
- if (fromLanguageCode != null) {
12191
- setValueByPath(toObject, ['languageCode'], fromLanguageCode);
12192
- }
12193
12225
  const fromVoiceConfig = getValueByPath(fromObject, ['voiceConfig']);
12194
12226
  if (fromVoiceConfig != null) {
12195
12227
  setValueByPath(toObject, ['voiceConfig'], fromVoiceConfig);
12196
12228
  }
12229
+ const fromLanguageCode = getValueByPath(fromObject, ['languageCode']);
12230
+ if (fromLanguageCode != null) {
12231
+ setValueByPath(toObject, ['languageCode'], fromLanguageCode);
12232
+ }
12197
12233
  if (getValueByPath(fromObject, ['multiSpeakerVoiceConfig']) !== undefined) {
12198
12234
  throw new Error('multiSpeakerVoiceConfig parameter is not supported in Vertex AI.');
12199
12235
  }
@@ -12671,8 +12707,8 @@ function isMcpCallableTool(object) {
12671
12707
  object instanceof McpCallableTool);
12672
12708
  }
12673
12709
  // List all tools from the MCP client.
12674
- function listAllTools(mcpClient, maxTools = 100) {
12675
- return __asyncGenerator(this, arguments, function* listAllTools_1() {
12710
+ function listAllTools(mcpClient_1) {
12711
+ return __asyncGenerator(this, arguments, function* listAllTools_1(mcpClient, maxTools = 100) {
12676
12712
  let cursor = undefined;
12677
12713
  let numTools = 0;
12678
12714
  while (numTools < maxTools) {
@@ -13992,9 +14028,9 @@ class Models extends BaseModule {
13992
14028
  let remoteCallCount = 0;
13993
14029
  const afcToolsMap = await this.initAfcToolsMap(params);
13994
14030
  return (function (models, afcTools, params) {
13995
- var _a, _b;
13996
14031
  return __asyncGenerator(this, arguments, function* () {
13997
- var _c, e_1, _d, _e;
14032
+ var _a, e_1, _b, _c;
14033
+ var _d, _e;
13998
14034
  while (remoteCallCount < maxRemoteCalls) {
13999
14035
  if (wereFunctionsCalled) {
14000
14036
  remoteCallCount++;
@@ -14005,14 +14041,14 @@ class Models extends BaseModule {
14005
14041
  const functionResponses = [];
14006
14042
  const responseContents = [];
14007
14043
  try {
14008
- 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) {
14009
- _e = response_1_1.value;
14044
+ 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) {
14045
+ _c = response_1_1.value;
14010
14046
  _f = false;
14011
- const chunk = _e;
14047
+ const chunk = _c;
14012
14048
  yield yield __await(chunk);
14013
- if (chunk.candidates && ((_a = chunk.candidates[0]) === null || _a === void 0 ? void 0 : _a.content)) {
14049
+ if (chunk.candidates && ((_d = chunk.candidates[0]) === null || _d === void 0 ? void 0 : _d.content)) {
14014
14050
  responseContents.push(chunk.candidates[0].content);
14015
- for (const part of (_b = chunk.candidates[0].content.parts) !== null && _b !== void 0 ? _b : []) {
14051
+ for (const part of (_e = chunk.candidates[0].content.parts) !== null && _e !== void 0 ? _e : []) {
14016
14052
  if (remoteCallCount < maxRemoteCalls && part.functionCall) {
14017
14053
  if (!part.functionCall.name) {
14018
14054
  throw new Error('Function call name was not returned by the model.');
@@ -14034,7 +14070,7 @@ class Models extends BaseModule {
14034
14070
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
14035
14071
  finally {
14036
14072
  try {
14037
- if (!_f && !_c && (_d = response_1.return)) yield __await(_d.call(response_1));
14073
+ if (!_f && !_a && (_b = response_1.return)) yield __await(_b.call(response_1));
14038
14074
  }
14039
14075
  finally { if (e_1) throw e_1.error; }
14040
14076
  }