-
Notifications
You must be signed in to change notification settings - Fork 30
feat(chat): implement branching functionality and context management #2138
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
Conversation
- Introduced ChatInputContext to manage input state and branching context for chat messages. - Added BranchPreview component to display original message when editing from a branch. - Enhanced MessageUser component with branching capabilities, allowing users to create new threads from existing messages. - Updated ChatPanel and AssistantChatPanel to utilize the new context and handle branching logic. - Refactored input handling in ChatInput to support controlled and uncontrolled states.
🧪 BenchmarkShould we run the MCP Gateway benchmark for this PR? React with 👍 to run the benchmark.
Benchmark will run on the next push after you react. |
Release OptionsShould a new version be published when this PR is merged? React with an emoji to vote on the release type:
Current version: Deployment
|
- Updated the useChatInputContext function to be non-exported, encapsulating its usage within the module for better context management.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3 issues found across 6 files
Prompt for AI agents (all issues)
Check if these issues are valid — if so, understand the root cause of each and fix them.
<file name="apps/mesh/src/web/components/chat/side-panel-chat.tsx">
<violation number="1" location="apps/mesh/src/web/components/chat/side-panel-chat.tsx:218">
P2: Branch context is cleared before `sendMessage` completes, contradicting the comment "Clear editing state after sending". If the message fails to send, the user loses their editing state. Move `clearBranchContext()` after the `await`.</violation>
</file>
<file name="apps/mesh/src/web/components/chat/chat-input-context.tsx">
<violation number="1" location="apps/mesh/src/web/components/chat/chat-input-context.tsx:124">
P2: Input is cleared before the async submission completes. If `onSubmit` fails, the user loses their typed message. Consider clearing the input only after successful submission, or restore it on error.</violation>
</file>
<file name="apps/mesh/src/web/components/details/assistant/index.tsx">
<violation number="1" location="apps/mesh/src/web/components/details/assistant/index.tsx:297">
P2: Branch context is cleared before `sendMessage` completes, contradicting the comment "Clear editing state after sending". If the send fails, the user loses their editing context. Move `clearBranchContext()` after the await.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
- Revised comment to clarify that the editing state is cleared after a successful message send in the AssistantChatPanel component.
- Revised comment to clarify that the editing state is cleared after a successful message send in the ChatPanel component.
| onValueChange?: (value: string) => void; | ||
| }>) { | ||
| const [input, setInput] = useState(""); | ||
| const [internalInput, setInternalInput] = useState(""); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
- Removed internal state management for input, transitioning to a fully controlled component using the provided value and onValueChange props. - Updated submission logic to directly utilize the controlled value, enhancing clarity and consistency in input handling.
- Eliminated the unused `useState` import from the Chat component, streamlining the code and improving clarity.
What is this contribution about?
Screenshots/Demonstration
https://www.loom.com/share/6f294db4798c4fd88b9cea23b380cd0e
Review Checklist
Summary by cubic
Adds chat branching (“Edit from here”) so users can fork a conversation from any message and edit the original text with a clear preview. Also introduces a lightweight input context and makes Chat.Input controllable without re-rendering the parent.
New Features
Refactors
Written for commit 73970d6. Summary will update on new commits.