refactor: enhance stream processing in Adapter class#28
Conversation
eldadfux
commented
Mar 26, 2026
- Introduced methods for managing streaming buffers and processing lines from chunks.
- Added constants and properties to handle incomplete SSE fragments.
- Updated adapter implementations (Anthropic, Deepseek, Gemini, OpenAI, Perplexity, XAI) to utilize new stream processing methods, improving code clarity and maintainability.
- Introduced methods for managing streaming buffers and processing lines from chunks. - Added constants and properties to handle incomplete SSE fragments. - Updated adapter implementations (Anthropic, Deepseek, Gemini, OpenAI, Perplexity, XAI) to utilize new stream processing methods, improving code clarity and maintainability.
Greptile SummaryThis PR centralises SSE stream processing in the base Confidence Score: 4/5Safe to merge after addressing the empty-object edge case in The core refactor is sound and well-tested. The
Important Files Changed
Reviews (1): Last reviewed commit: "fixes" | Re-trigger Greptile |
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
- Updated the Adapter class to enhance stream state management with a dedicated reset method. - Refactored JSON decoding in Deepseek, Gemini, OpenAI, Perplexity, and XAI adapters to prioritize chunk data, improving error handling and data integrity. - Adjusted stream line preparation to ensure only complete lines are returned, enhancing overall processing reliability.
- Introduced a new method `consumeStreamBufferLine` in the Adapter class to handle remaining buffered stream fragments. - Added `flushBufferedStreamData` method in each adapter to process any buffered data after chunk processing. - Refactored the `process` method in each adapter to utilize the new stream processing methods, improving data handling and integrity.
…sses - Replaced the Text and Image message classes with a unified Message class to streamline message handling. - Updated all relevant code and tests to utilize the new Message class, ensuring compatibility and functionality. - Enhanced the Message class to include MIME type detection for better attachment management.