@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.
@@ -4144,6 +4144,12 @@ function generateContentConfigToMldev$1(apiClient, fromObject, parentObject) {
4144
4144
  if (fromImageConfig != null) {
4145
4145
  setValueByPath(toObject, ['imageConfig'], imageConfigToMldev$1(fromImageConfig));
4146
4146
  }
4147
+ const fromEnableEnhancedCivicAnswers = getValueByPath(fromObject, [
4148
+ 'enableEnhancedCivicAnswers',
4149
+ ]);
4150
+ if (fromEnableEnhancedCivicAnswers != null) {
4151
+ setValueByPath(toObject, ['enableEnhancedCivicAnswers'], fromEnableEnhancedCivicAnswers);
4152
+ }
4147
4153
  return toObject;
4148
4154
  }
4149
4155
  function generateContentResponseFromMldev$1(fromObject) {
@@ -6588,17 +6594,17 @@ class Chat {
6588
6594
  return structuredClone(history);
6589
6595
  }
6590
6596
  processStreamResponse(streamResponse, inputContent) {
6591
- var _a, _b;
6592
6597
  return __asyncGenerator(this, arguments, function* processStreamResponse_1() {
6593
- var _c, e_1, _d, _e;
6598
+ var _a, e_1, _b, _c;
6599
+ var _d, _e;
6594
6600
  const outputContent = [];
6595
6601
  try {
6596
- 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) {
6597
- _e = streamResponse_1_1.value;
6602
+ 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) {
6603
+ _c = streamResponse_1_1.value;
6598
6604
  _f = false;
6599
- const chunk = _e;
6605
+ const chunk = _c;
6600
6606
  if (isValidResponse(chunk)) {
6601
- const content = (_b = (_a = chunk.candidates) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.content;
6607
+ const content = (_e = (_d = chunk.candidates) === null || _d === void 0 ? void 0 : _d[0]) === null || _e === void 0 ? void 0 : _e.content;
6602
6608
  if (content !== undefined) {
6603
6609
  outputContent.push(content);
6604
6610
  }
@@ -6609,7 +6615,7 @@ class Chat {
6609
6615
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
6610
6616
  finally {
6611
6617
  try {
6612
- if (!_f && !_c && (_d = streamResponse_1.return)) yield __await(_d.call(streamResponse_1));
6618
+ if (!_f && !_a && (_b = streamResponse_1.return)) yield __await(_b.call(streamResponse_1));
6613
6619
  }
6614
6620
  finally { if (e_1) throw e_1.error; }
6615
6621
  }
@@ -7763,14 +7769,14 @@ function sessionResumptionConfigToMldev$1(fromObject) {
7763
7769
  }
7764
7770
  function speechConfigToVertex$1(fromObject) {
7765
7771
  const toObject = {};
7766
- const fromLanguageCode = getValueByPath(fromObject, ['languageCode']);
7767
- if (fromLanguageCode != null) {
7768
- setValueByPath(toObject, ['languageCode'], fromLanguageCode);
7769
- }
7770
7772
  const fromVoiceConfig = getValueByPath(fromObject, ['voiceConfig']);
7771
7773
  if (fromVoiceConfig != null) {
7772
7774
  setValueByPath(toObject, ['voiceConfig'], fromVoiceConfig);
7773
7775
  }
7776
+ const fromLanguageCode = getValueByPath(fromObject, ['languageCode']);
7777
+ if (fromLanguageCode != null) {
7778
+ setValueByPath(toObject, ['languageCode'], fromLanguageCode);
7779
+ }
7774
7780
  if (getValueByPath(fromObject, ['multiSpeakerVoiceConfig']) !== undefined) {
7775
7781
  throw new Error('multiSpeakerVoiceConfig parameter is not supported in Vertex AI.');
7776
7782
  }
@@ -8866,6 +8872,12 @@ function generateContentConfigToMldev(apiClient, fromObject, parentObject) {
8866
8872
  if (fromImageConfig != null) {
8867
8873
  setValueByPath(toObject, ['imageConfig'], imageConfigToMldev(fromImageConfig));
8868
8874
  }
8875
+ const fromEnableEnhancedCivicAnswers = getValueByPath(fromObject, [
8876
+ 'enableEnhancedCivicAnswers',
8877
+ ]);
8878
+ if (fromEnableEnhancedCivicAnswers != null) {
8879
+ setValueByPath(toObject, ['enableEnhancedCivicAnswers'], fromEnableEnhancedCivicAnswers);
8880
+ }
8869
8881
  return toObject;
8870
8882
  }
8871
8883
  function generateContentConfigToVertex(apiClient, fromObject, parentObject) {
@@ -9030,6 +9042,10 @@ function generateContentConfigToVertex(apiClient, fromObject, parentObject) {
9030
9042
  if (fromImageConfig != null) {
9031
9043
  setValueByPath(toObject, ['imageConfig'], imageConfigToVertex(fromImageConfig));
9032
9044
  }
9045
+ if (getValueByPath(fromObject, ['enableEnhancedCivicAnswers']) !==
9046
+ undefined) {
9047
+ throw new Error('enableEnhancedCivicAnswers parameter is not supported in Vertex AI.');
9048
+ }
9033
9049
  return toObject;
9034
9050
  }
9035
9051
  function generateContentParametersToMldev(apiClient, fromObject) {
@@ -10758,14 +10774,14 @@ function segmentImageSourceToVertex(fromObject, parentObject) {
10758
10774
  }
10759
10775
  function speechConfigToVertex(fromObject) {
10760
10776
  const toObject = {};
10761
- const fromLanguageCode = getValueByPath(fromObject, ['languageCode']);
10762
- if (fromLanguageCode != null) {
10763
- setValueByPath(toObject, ['languageCode'], fromLanguageCode);
10764
- }
10765
10777
  const fromVoiceConfig = getValueByPath(fromObject, ['voiceConfig']);
10766
10778
  if (fromVoiceConfig != null) {
10767
10779
  setValueByPath(toObject, ['voiceConfig'], fromVoiceConfig);
10768
10780
  }
10781
+ const fromLanguageCode = getValueByPath(fromObject, ['languageCode']);
10782
+ if (fromLanguageCode != null) {
10783
+ setValueByPath(toObject, ['languageCode'], fromLanguageCode);
10784
+ }
10769
10785
  if (getValueByPath(fromObject, ['multiSpeakerVoiceConfig']) !== undefined) {
10770
10786
  throw new Error('multiSpeakerVoiceConfig parameter is not supported in Vertex AI.');
10771
10787
  }
@@ -11452,11 +11468,10 @@ const CONTENT_TYPE_HEADER = 'Content-Type';
11452
11468
  const SERVER_TIMEOUT_HEADER = 'X-Server-Timeout';
11453
11469
  const USER_AGENT_HEADER = 'User-Agent';
11454
11470
  const GOOGLE_API_CLIENT_HEADER = 'x-goog-api-client';
11455
- const SDK_VERSION = '1.31.0'; // x-release-please-version
11471
+ const SDK_VERSION = '1.32.0'; // x-release-please-version
11456
11472
  const LIBRARY_LABEL = `google-genai-sdk/${SDK_VERSION}`;
11457
11473
  const VERTEX_AI_API_DEFAULT_VERSION = 'v1beta1';
11458
11474
  const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
11459
- const responseLineRE = /^\s*data: (.*)(?:\n\n|\r\r|\r\n\r\n)/;
11460
11475
  /**
11461
11476
  * The ApiClient class is used to send requests to the Gemini API or Vertex AI
11462
11477
  * endpoints.
@@ -11736,8 +11751,8 @@ class ApiClient {
11736
11751
  });
11737
11752
  }
11738
11753
  processStreamResponse(response) {
11739
- var _a;
11740
11754
  return __asyncGenerator(this, arguments, function* processStreamResponse_1() {
11755
+ var _a;
11741
11756
  const reader = (_a = response === null || response === void 0 ? void 0 : response.body) === null || _a === void 0 ? void 0 : _a.getReader();
11742
11757
  const decoder = new TextDecoder('utf-8');
11743
11758
  if (!reader) {
@@ -11745,6 +11760,8 @@ class ApiClient {
11745
11760
  }
11746
11761
  try {
11747
11762
  let buffer = '';
11763
+ const dataPrefix = 'data:';
11764
+ const delimiters = ['\n\n', '\r\r', '\r\n\r\n'];
11748
11765
  while (true) {
11749
11766
  const { done, value } = yield __await(reader.read());
11750
11767
  if (done) {
@@ -11778,21 +11795,40 @@ class ApiClient {
11778
11795
  }
11779
11796
  }
11780
11797
  buffer += chunkString;
11781
- let match = buffer.match(responseLineRE);
11782
- while (match) {
11783
- const processedChunkString = match[1];
11784
- try {
11785
- const partialResponse = new Response(processedChunkString, {
11786
- headers: response === null || response === void 0 ? void 0 : response.headers,
11787
- status: response === null || response === void 0 ? void 0 : response.status,
11788
- statusText: response === null || response === void 0 ? void 0 : response.statusText,
11789
- });
11790
- yield yield __await(new HttpResponse(partialResponse));
11791
- buffer = buffer.slice(match[0].length);
11792
- match = buffer.match(responseLineRE);
11798
+ let delimiterIndex = -1;
11799
+ let delimiterLength = 0;
11800
+ while (true) {
11801
+ delimiterIndex = -1;
11802
+ delimiterLength = 0;
11803
+ for (const delimiter of delimiters) {
11804
+ const index = buffer.indexOf(delimiter);
11805
+ if (index !== -1 &&
11806
+ (delimiterIndex === -1 || index < delimiterIndex)) {
11807
+ delimiterIndex = index;
11808
+ delimiterLength = delimiter.length;
11809
+ }
11810
+ }
11811
+ if (delimiterIndex === -1) {
11812
+ break; // No complete event in buffer
11793
11813
  }
11794
- catch (e) {
11795
- throw new Error(`exception parsing stream chunk ${processedChunkString}. ${e}`);
11814
+ const eventString = buffer.substring(0, delimiterIndex);
11815
+ buffer = buffer.substring(delimiterIndex + delimiterLength);
11816
+ const trimmedEvent = eventString.trim();
11817
+ if (trimmedEvent.startsWith(dataPrefix)) {
11818
+ const processedChunkString = trimmedEvent
11819
+ .substring(dataPrefix.length)
11820
+ .trim();
11821
+ try {
11822
+ const partialResponse = new Response(processedChunkString, {
11823
+ headers: response === null || response === void 0 ? void 0 : response.headers,
11824
+ status: response === null || response === void 0 ? void 0 : response.status,
11825
+ statusText: response === null || response === void 0 ? void 0 : response.statusText,
11826
+ });
11827
+ yield yield __await(new HttpResponse(partialResponse));
11828
+ }
11829
+ catch (e) {
11830
+ throw new Error(`exception parsing stream chunk ${processedChunkString}. ${e}`);
11831
+ }
11796
11832
  }
11797
11833
  }
11798
11834
  }
@@ -11925,7 +11961,7 @@ class ApiClient {
11925
11961
  }
11926
11962
  else {
11927
11963
  httpOptions = {
11928
- apiVersion: '',
11964
+ apiVersion: '', // api-version is set in the path.
11929
11965
  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 } : {})),
11930
11966
  };
11931
11967
  }
@@ -12087,8 +12123,8 @@ function isMcpCallableTool(object) {
12087
12123
  object instanceof McpCallableTool);
12088
12124
  }
12089
12125
  // List all tools from the MCP client.
12090
- function listAllTools(mcpClient, maxTools = 100) {
12091
- return __asyncGenerator(this, arguments, function* listAllTools_1() {
12126
+ function listAllTools(mcpClient_1) {
12127
+ return __asyncGenerator(this, arguments, function* listAllTools_1(mcpClient, maxTools = 100) {
12092
12128
  let cursor = undefined;
12093
12129
  let numTools = 0;
12094
12130
  while (numTools < maxTools) {
@@ -13408,9 +13444,9 @@ class Models extends BaseModule {
13408
13444
  let remoteCallCount = 0;
13409
13445
  const afcToolsMap = await this.initAfcToolsMap(params);
13410
13446
  return (function (models, afcTools, params) {
13411
- var _a, _b;
13412
13447
  return __asyncGenerator(this, arguments, function* () {
13413
- var _c, e_1, _d, _e;
13448
+ var _a, e_1, _b, _c;
13449
+ var _d, _e;
13414
13450
  while (remoteCallCount < maxRemoteCalls) {
13415
13451
  if (wereFunctionsCalled) {
13416
13452
  remoteCallCount++;
@@ -13421,14 +13457,14 @@ class Models extends BaseModule {
13421
13457
  const functionResponses = [];
13422
13458
  const responseContents = [];
13423
13459
  try {
13424
- 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) {
13425
- _e = response_1_1.value;
13460
+ 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) {
13461
+ _c = response_1_1.value;
13426
13462
  _f = false;
13427
- const chunk = _e;
13463
+ const chunk = _c;
13428
13464
  yield yield __await(chunk);
13429
- if (chunk.candidates && ((_a = chunk.candidates[0]) === null || _a === void 0 ? void 0 : _a.content)) {
13465
+ if (chunk.candidates && ((_d = chunk.candidates[0]) === null || _d === void 0 ? void 0 : _d.content)) {
13430
13466
  responseContents.push(chunk.candidates[0].content);
13431
- for (const part of (_b = chunk.candidates[0].content.parts) !== null && _b !== void 0 ? _b : []) {
13467
+ for (const part of (_e = chunk.candidates[0].content.parts) !== null && _e !== void 0 ? _e : []) {
13432
13468
  if (remoteCallCount < maxRemoteCalls && part.functionCall) {
13433
13469
  if (!part.functionCall.name) {
13434
13470
  throw new Error('Function call name was not returned by the model.');
@@ -13450,7 +13486,7 @@ class Models extends BaseModule {
13450
13486
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
13451
13487
  finally {
13452
13488
  try {
13453
- if (!_f && !_c && (_d = response_1.return)) yield __await(_d.call(response_1));
13489
+ if (!_f && !_a && (_b = response_1.return)) yield __await(_b.call(response_1));
13454
13490
  }
13455
13491
  finally { if (e_1) throw e_1.error; }
13456
13492
  }
@@ -4122,6 +4122,12 @@ function generateContentConfigToMldev$1(apiClient, fromObject, parentObject) {
4122
4122
  if (fromImageConfig != null) {
4123
4123
  setValueByPath(toObject, ['imageConfig'], imageConfigToMldev$1(fromImageConfig));
4124
4124
  }
4125
+ const fromEnableEnhancedCivicAnswers = getValueByPath(fromObject, [
4126
+ 'enableEnhancedCivicAnswers',
4127
+ ]);
4128
+ if (fromEnableEnhancedCivicAnswers != null) {
4129
+ setValueByPath(toObject, ['enableEnhancedCivicAnswers'], fromEnableEnhancedCivicAnswers);
4130
+ }
4125
4131
  return toObject;
4126
4132
  }
4127
4133
  function generateContentResponseFromMldev$1(fromObject) {
@@ -6566,17 +6572,17 @@ class Chat {
6566
6572
  return structuredClone(history);
6567
6573
  }
6568
6574
  processStreamResponse(streamResponse, inputContent) {
6569
- var _a, _b;
6570
6575
  return __asyncGenerator(this, arguments, function* processStreamResponse_1() {
6571
- var _c, e_1, _d, _e;
6576
+ var _a, e_1, _b, _c;
6577
+ var _d, _e;
6572
6578
  const outputContent = [];
6573
6579
  try {
6574
- 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) {
6575
- _e = streamResponse_1_1.value;
6580
+ 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) {
6581
+ _c = streamResponse_1_1.value;
6576
6582
  _f = false;
6577
- const chunk = _e;
6583
+ const chunk = _c;
6578
6584
  if (isValidResponse(chunk)) {
6579
- const content = (_b = (_a = chunk.candidates) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.content;
6585
+ const content = (_e = (_d = chunk.candidates) === null || _d === void 0 ? void 0 : _d[0]) === null || _e === void 0 ? void 0 : _e.content;
6580
6586
  if (content !== undefined) {
6581
6587
  outputContent.push(content);
6582
6588
  }
@@ -6587,7 +6593,7 @@ class Chat {
6587
6593
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
6588
6594
  finally {
6589
6595
  try {
6590
- if (!_f && !_c && (_d = streamResponse_1.return)) yield __await(_d.call(streamResponse_1));
6596
+ if (!_f && !_a && (_b = streamResponse_1.return)) yield __await(_b.call(streamResponse_1));
6591
6597
  }
6592
6598
  finally { if (e_1) throw e_1.error; }
6593
6599
  }
@@ -7741,14 +7747,14 @@ function sessionResumptionConfigToMldev$1(fromObject) {
7741
7747
  }
7742
7748
  function speechConfigToVertex$1(fromObject) {
7743
7749
  const toObject = {};
7744
- const fromLanguageCode = getValueByPath(fromObject, ['languageCode']);
7745
- if (fromLanguageCode != null) {
7746
- setValueByPath(toObject, ['languageCode'], fromLanguageCode);
7747
- }
7748
7750
  const fromVoiceConfig = getValueByPath(fromObject, ['voiceConfig']);
7749
7751
  if (fromVoiceConfig != null) {
7750
7752
  setValueByPath(toObject, ['voiceConfig'], fromVoiceConfig);
7751
7753
  }
7754
+ const fromLanguageCode = getValueByPath(fromObject, ['languageCode']);
7755
+ if (fromLanguageCode != null) {
7756
+ setValueByPath(toObject, ['languageCode'], fromLanguageCode);
7757
+ }
7752
7758
  if (getValueByPath(fromObject, ['multiSpeakerVoiceConfig']) !== undefined) {
7753
7759
  throw new Error('multiSpeakerVoiceConfig parameter is not supported in Vertex AI.');
7754
7760
  }
@@ -8844,6 +8850,12 @@ function generateContentConfigToMldev(apiClient, fromObject, parentObject) {
8844
8850
  if (fromImageConfig != null) {
8845
8851
  setValueByPath(toObject, ['imageConfig'], imageConfigToMldev(fromImageConfig));
8846
8852
  }
8853
+ const fromEnableEnhancedCivicAnswers = getValueByPath(fromObject, [
8854
+ 'enableEnhancedCivicAnswers',
8855
+ ]);
8856
+ if (fromEnableEnhancedCivicAnswers != null) {
8857
+ setValueByPath(toObject, ['enableEnhancedCivicAnswers'], fromEnableEnhancedCivicAnswers);
8858
+ }
8847
8859
  return toObject;
8848
8860
  }
8849
8861
  function generateContentConfigToVertex(apiClient, fromObject, parentObject) {
@@ -9008,6 +9020,10 @@ function generateContentConfigToVertex(apiClient, fromObject, parentObject) {
9008
9020
  if (fromImageConfig != null) {
9009
9021
  setValueByPath(toObject, ['imageConfig'], imageConfigToVertex(fromImageConfig));
9010
9022
  }
9023
+ if (getValueByPath(fromObject, ['enableEnhancedCivicAnswers']) !==
9024
+ undefined) {
9025
+ throw new Error('enableEnhancedCivicAnswers parameter is not supported in Vertex AI.');
9026
+ }
9011
9027
  return toObject;
9012
9028
  }
9013
9029
  function generateContentParametersToMldev(apiClient, fromObject) {
@@ -10736,14 +10752,14 @@ function segmentImageSourceToVertex(fromObject, parentObject) {
10736
10752
  }
10737
10753
  function speechConfigToVertex(fromObject) {
10738
10754
  const toObject = {};
10739
- const fromLanguageCode = getValueByPath(fromObject, ['languageCode']);
10740
- if (fromLanguageCode != null) {
10741
- setValueByPath(toObject, ['languageCode'], fromLanguageCode);
10742
- }
10743
10755
  const fromVoiceConfig = getValueByPath(fromObject, ['voiceConfig']);
10744
10756
  if (fromVoiceConfig != null) {
10745
10757
  setValueByPath(toObject, ['voiceConfig'], fromVoiceConfig);
10746
10758
  }
10759
+ const fromLanguageCode = getValueByPath(fromObject, ['languageCode']);
10760
+ if (fromLanguageCode != null) {
10761
+ setValueByPath(toObject, ['languageCode'], fromLanguageCode);
10762
+ }
10747
10763
  if (getValueByPath(fromObject, ['multiSpeakerVoiceConfig']) !== undefined) {
10748
10764
  throw new Error('multiSpeakerVoiceConfig parameter is not supported in Vertex AI.');
10749
10765
  }
@@ -11430,11 +11446,10 @@ const CONTENT_TYPE_HEADER = 'Content-Type';
11430
11446
  const SERVER_TIMEOUT_HEADER = 'X-Server-Timeout';
11431
11447
  const USER_AGENT_HEADER = 'User-Agent';
11432
11448
  const GOOGLE_API_CLIENT_HEADER = 'x-goog-api-client';
11433
- const SDK_VERSION = '1.31.0'; // x-release-please-version
11449
+ const SDK_VERSION = '1.32.0'; // x-release-please-version
11434
11450
  const LIBRARY_LABEL = `google-genai-sdk/${SDK_VERSION}`;
11435
11451
  const VERTEX_AI_API_DEFAULT_VERSION = 'v1beta1';
11436
11452
  const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
11437
- const responseLineRE = /^\s*data: (.*)(?:\n\n|\r\r|\r\n\r\n)/;
11438
11453
  /**
11439
11454
  * The ApiClient class is used to send requests to the Gemini API or Vertex AI
11440
11455
  * endpoints.
@@ -11714,8 +11729,8 @@ class ApiClient {
11714
11729
  });
11715
11730
  }
11716
11731
  processStreamResponse(response) {
11717
- var _a;
11718
11732
  return __asyncGenerator(this, arguments, function* processStreamResponse_1() {
11733
+ var _a;
11719
11734
  const reader = (_a = response === null || response === void 0 ? void 0 : response.body) === null || _a === void 0 ? void 0 : _a.getReader();
11720
11735
  const decoder = new TextDecoder('utf-8');
11721
11736
  if (!reader) {
@@ -11723,6 +11738,8 @@ class ApiClient {
11723
11738
  }
11724
11739
  try {
11725
11740
  let buffer = '';
11741
+ const dataPrefix = 'data:';
11742
+ const delimiters = ['\n\n', '\r\r', '\r\n\r\n'];
11726
11743
  while (true) {
11727
11744
  const { done, value } = yield __await(reader.read());
11728
11745
  if (done) {
@@ -11756,21 +11773,40 @@ class ApiClient {
11756
11773
  }
11757
11774
  }
11758
11775
  buffer += chunkString;
11759
- let match = buffer.match(responseLineRE);
11760
- while (match) {
11761
- const processedChunkString = match[1];
11762
- try {
11763
- const partialResponse = new Response(processedChunkString, {
11764
- headers: response === null || response === void 0 ? void 0 : response.headers,
11765
- status: response === null || response === void 0 ? void 0 : response.status,
11766
- statusText: response === null || response === void 0 ? void 0 : response.statusText,
11767
- });
11768
- yield yield __await(new HttpResponse(partialResponse));
11769
- buffer = buffer.slice(match[0].length);
11770
- match = buffer.match(responseLineRE);
11776
+ let delimiterIndex = -1;
11777
+ let delimiterLength = 0;
11778
+ while (true) {
11779
+ delimiterIndex = -1;
11780
+ delimiterLength = 0;
11781
+ for (const delimiter of delimiters) {
11782
+ const index = buffer.indexOf(delimiter);
11783
+ if (index !== -1 &&
11784
+ (delimiterIndex === -1 || index < delimiterIndex)) {
11785
+ delimiterIndex = index;
11786
+ delimiterLength = delimiter.length;
11787
+ }
11788
+ }
11789
+ if (delimiterIndex === -1) {
11790
+ break; // No complete event in buffer
11771
11791
  }
11772
- catch (e) {
11773
- throw new Error(`exception parsing stream chunk ${processedChunkString}. ${e}`);
11792
+ const eventString = buffer.substring(0, delimiterIndex);
11793
+ buffer = buffer.substring(delimiterIndex + delimiterLength);
11794
+ const trimmedEvent = eventString.trim();
11795
+ if (trimmedEvent.startsWith(dataPrefix)) {
11796
+ const processedChunkString = trimmedEvent
11797
+ .substring(dataPrefix.length)
11798
+ .trim();
11799
+ try {
11800
+ const partialResponse = new Response(processedChunkString, {
11801
+ headers: response === null || response === void 0 ? void 0 : response.headers,
11802
+ status: response === null || response === void 0 ? void 0 : response.status,
11803
+ statusText: response === null || response === void 0 ? void 0 : response.statusText,
11804
+ });
11805
+ yield yield __await(new HttpResponse(partialResponse));
11806
+ }
11807
+ catch (e) {
11808
+ throw new Error(`exception parsing stream chunk ${processedChunkString}. ${e}`);
11809
+ }
11774
11810
  }
11775
11811
  }
11776
11812
  }
@@ -11903,7 +11939,7 @@ class ApiClient {
11903
11939
  }
11904
11940
  else {
11905
11941
  httpOptions = {
11906
- apiVersion: '',
11942
+ apiVersion: '', // api-version is set in the path.
11907
11943
  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 } : {})),
11908
11944
  };
11909
11945
  }
@@ -12065,8 +12101,8 @@ function isMcpCallableTool(object) {
12065
12101
  object instanceof McpCallableTool);
12066
12102
  }
12067
12103
  // List all tools from the MCP client.
12068
- function listAllTools(mcpClient, maxTools = 100) {
12069
- return __asyncGenerator(this, arguments, function* listAllTools_1() {
12104
+ function listAllTools(mcpClient_1) {
12105
+ return __asyncGenerator(this, arguments, function* listAllTools_1(mcpClient, maxTools = 100) {
12070
12106
  let cursor = undefined;
12071
12107
  let numTools = 0;
12072
12108
  while (numTools < maxTools) {
@@ -13386,9 +13422,9 @@ class Models extends BaseModule {
13386
13422
  let remoteCallCount = 0;
13387
13423
  const afcToolsMap = await this.initAfcToolsMap(params);
13388
13424
  return (function (models, afcTools, params) {
13389
- var _a, _b;
13390
13425
  return __asyncGenerator(this, arguments, function* () {
13391
- var _c, e_1, _d, _e;
13426
+ var _a, e_1, _b, _c;
13427
+ var _d, _e;
13392
13428
  while (remoteCallCount < maxRemoteCalls) {
13393
13429
  if (wereFunctionsCalled) {
13394
13430
  remoteCallCount++;
@@ -13399,14 +13435,14 @@ class Models extends BaseModule {
13399
13435
  const functionResponses = [];
13400
13436
  const responseContents = [];
13401
13437
  try {
13402
- 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) {
13403
- _e = response_1_1.value;
13438
+ 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) {
13439
+ _c = response_1_1.value;
13404
13440
  _f = false;
13405
- const chunk = _e;
13441
+ const chunk = _c;
13406
13442
  yield yield __await(chunk);
13407
- if (chunk.candidates && ((_a = chunk.candidates[0]) === null || _a === void 0 ? void 0 : _a.content)) {
13443
+ if (chunk.candidates && ((_d = chunk.candidates[0]) === null || _d === void 0 ? void 0 : _d.content)) {
13408
13444
  responseContents.push(chunk.candidates[0].content);
13409
- for (const part of (_b = chunk.candidates[0].content.parts) !== null && _b !== void 0 ? _b : []) {
13445
+ for (const part of (_e = chunk.candidates[0].content.parts) !== null && _e !== void 0 ? _e : []) {
13410
13446
  if (remoteCallCount < maxRemoteCalls && part.functionCall) {
13411
13447
  if (!part.functionCall.name) {
13412
13448
  throw new Error('Function call name was not returned by the model.');
@@ -13428,7 +13464,7 @@ class Models extends BaseModule {
13428
13464
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
13429
13465
  finally {
13430
13466
  try {
13431
- if (!_f && !_c && (_d = response_1.return)) yield __await(_d.call(response_1));
13467
+ if (!_f && !_a && (_b = response_1.return)) yield __await(_b.call(response_1));
13432
13468
  }
13433
13469
  finally { if (e_1) throw e_1.error; }
13434
13470
  }