Merged 3 months agoAugust 22, 2025
Related#4053This pull request refactors the content consolidation logic in GeminiChat to correctly merge multi-part text content, especially during streaming responses.
What was done
- Updated the content consolidation logic within the GeminiChat class for streaming responses to ensure text is appended to the correct part.
- Changed the text appending mechanism from the first part to the last part of existing content when merging.
- Introduced new private helper methods, isFirstPartText and isLastPartText, to precisely check the type and position of text content within multi-part responses.
- The
packages/core/src/core/geminiChat.tsfile was modified to implement these changes, improving the accuracy of text merging.
Impact
- Ensures accurate merging of text into multi-part content, preventing incorrect concatenation of text within streaming responses.
- Addresses scenarios where streaming responses contain mixed content types, requiring careful and precise text merging.
- Improves the robustness of content parsing within Gemini chat interactions, reducing potential data corruption or malformed responses.
Technical details
- The
consolidateStreamingContentmethod inGeminiChatwas updated to utilize the newisFirstPartTextandisLastPartTexthelpers. - The
isFirstPartTexthelper now explicitly checks if the first part of a content object is a text string and excludes non-text part types like functionCall, inlineData, etc. - The
isLastPartTexthelper was added to verify if the last part of a content object is a text string, also ensuring it's for a 'model' role and excluding non-text part types. - Text merging now targets
lastContent.parts[lastContent.parts.length - 1].textinstead oflastContent.parts[0].textwhen appropriate. - These changes were implemented in
packages/core/src/core/geminiChat.ts.
Related issues
Metadata
- Source: github
- Repo: google-gemini/gemini-cli
- URL: https://github.com/google-gemini/gemini-cli/pull/6235
- Merged: 2025-08-22T18:20:30Z