Skip to content

refactor: streamline Chat component and introduce useStreamingChat hook #141

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jul 14, 2025

Conversation

nickytonline
Copy link
Member

This update refactors the Chat component by removing unused state and logic, consolidating streaming functionality into a new custom hook, useStreamingChat. The new hook manages stream events, error handling, and user messages more efficiently, improving code readability and maintainability. Additionally, tests for the useStreamingChat hook have been added to ensure its functionality and reliability.

Visually there are no changes.

Closes #87

This update refactors the Chat component by removing unused state and logic, consolidating streaming functionality into a new custom hook, useStreamingChat. The new hook manages stream events, error handling, and user messages more efficiently, improving code readability and maintainability. Additionally, tests for the useStreamingChat hook have been added to ensure its functionality and reliability.
…nd response validation

This update improves the test suite for the useStreamingChat hook by adding cases for handling empty and whitespace-only user messages, ensuring that the stream buffer behaves correctly under these conditions. Additionally, it introduces validation for timestamps in user messages and refactors mock response creation for better clarity and maintainability. These changes enhance the robustness of the tests and ensure comprehensive coverage of the hook's functionality.
…ge validation

This update improves the test suite for the useStreamingChat hook by introducing type guards for stream events, enhancing type safety and readability. Additionally, it refactors error message handling to use constants for better maintainability and clarity. The tests now validate the correct behavior of the stream buffer under various conditions, ensuring comprehensive coverage of the hook's functionality.
…essage, and WebSearchMessage components

This refactor enhances type safety by replacing the previous Message type with specific stream event types (AssistantStreamEvent, UserStreamEvent, ReasoningStreamEvent, and WebSearchStreamEvent) in the respective components. This change improves clarity and maintainability of the code, ensuring that each message component accurately reflects the structure of the data it handles. Additionally, the use of type guards in the useStreamingChat hook has been streamlined to support these updates.
…, and ReasoningMessage components

This refactor improves type safety by introducing a new Message interface in BotMessage and UserMessage components, which extends the respective stream event types. The ReasoningMessage component has also been updated to use an interface that omits the 'type' property. These changes enhance clarity and maintainability, ensuring that message components accurately reflect the structure of the data they handle.
… input validation

This update refines the test suite for the useStreamingChat hook by removing redundant type guards and adding comprehensive validation for various input scenarios, including empty and whitespace-only messages. It also enhances error handling by ensuring that appropriate console warnings and errors are logged for invalid inputs and malformed responses. These changes improve the robustness and clarity of the tests, ensuring thorough coverage of the hook's functionality.
This update improves the test suite for streaming functionality by removing unnecessary comments that clutter the code. It also enhances error handling in the tests, ensuring that errors during streaming are properly logged to the console. These changes contribute to cleaner, more maintainable tests while ensuring comprehensive coverage of the streaming logic.
Copy link

netlify bot commented Jul 14, 2025

Deploy Preview for mcp-storybook ready!

Name Link
🔨 Latest commit 044dc52
🔍 Latest deploy log https://app.netlify.com/projects/mcp-storybook/deploys/68752225bb22bc000821a1a9
😎 Deploy Preview https://deploy-preview-141--mcp-storybook.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

…ent code

This refactor streamlines the message type definitions by moving the MessageStatus type to UserMessage and removing the unused MCPRequest and Message types from the client module. The changes enhance code clarity and maintainability by ensuring that only relevant types are retained, while also cleaning up the MCP client file to focus on its core functionality.
@nickytonline nickytonline requested a review from wasaga July 14, 2025 16:49
@nickytonline nickytonline marked this pull request as ready for review July 14, 2025 16:49
@wasaga wasaga merged commit 78a936c into main Jul 14, 2025
6 checks passed
@wasaga wasaga deleted the nickytonline/streaming-custom-hook branch July 14, 2025 16:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants