Skip to content

Feature: implement editable assistant messages - #6397

Merged
Imagineer99 merged 13 commits into
unslothai:mainfrom
CelesteHeartsong:feat-editable-messages
Jun 17, 2026
Merged

Imagineer99 merged 13 commits into
unslothai:mainfrom
CelesteHeartsong:feat-editable-messages

Conversation

@CelesteHeartsong

Copy link
Copy Markdown
Contributor

This PR introduces the ability for users to edit assistant messages directly within the thread.

Key Technical Implementation:

  • Structured Content Round-Trip: Assistant messages often contain structured data (Reasoning/Thinking blocks and Tool outputs). To allow editing while preserving this schema, I implemented a "tagged-text" system:
    • Extraction: Structured content is converted into tagged strings (e.g., <THINK>...</THINK> and <TOOL>...</TOOL>) when entering edit mode.
    • Parsing: Upon saving, these tags are parsed back into the structured ThreadMessage["content"] format required by @assistant-ui/react.
  • State Management: Integrated editing state into the ChatRuntimeStore (editingMessageId). This ensures a single source of truth and avoids the use of global window events, aligning with the project's existing state patterns.
  • UI Consistency: The implementation utilizes MessagePrimitive.Parts for rendering. This ensures that edited messages maintain the exact same professional styling, Markdown rendering, and component hierarchy as original AI responses.
  • Temporary Chat Support: Added logic to detect local temporary IDs (__LOCALID_). Edits to incognito chats are updated in the local memory store but skip the backend sync to prevent 404 errors, as these threads are intentionally not persisted.

Changes:

  • chat-runtime-store.ts: Added editingMessageId state and setEditingMessageId action.
  • update-thread-message.ts: Added utility functions for parsing/extracting tagged text and a handler to sync updates to the backend via saveChatMessage.
  • thread.tsx: Implemented the inline edit UI, a height-adjusting textarea, and the edit trigger in the assistant action bar.

How to Test:

  1. Standard Chat: Open a chat with an assistant response containing reasoning or tool calls. Click "Edit response" $\rightarrow$ Modify text $\rightarrow$ Save. Verify the styling remains consistent and the change persists after refresh.
  2. Temporary Chat: Enter "Incognito" mode and start a chat. Edit a message and save. Verify the UI updates immediately and no 404 errors appear in the console.
  3. Structured Content: Verify that editing text inside <THINK> or <TOOL> tags correctly updates the respective reasoning/tool blocks in the final rendered message.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces inline-editing capabilities for assistant messages in the chat interface, adding an edit button to the action bar, managing the editing state via the global chat runtime store, and implementing utility functions to convert structured message content to tagged text and back. Feedback on these changes highlights several critical issues: structured content like tool calls is stripped during editing and deleted upon saving, which requires a merge strategy to preserve non-editable parts; retrieving the thread ID via aui.thread() fails because it returns the store instance rather than the state; a backend sync failure leaves the UI in an inconsistent state, requiring a rollback mechanism; the custom window event listener for refreshing messages is redundant; and an Escape key handler should be added to the textarea for better UX.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

@Imagineer99 Imagineer99 self-assigned this Jun 17, 2026
@CelesteHeartsong

Copy link
Copy Markdown
Contributor Author

Completed a full pass of the implementation to address all feedback from the code review and resolve several critical edge cases discovered during testing.

Key Improvements & Fixes:

  • Data Preservation (Merge Strategy): Implemented a "First-Slot Merge Strategy" in update-thread-message.ts. This ensures that structured, non-editable content (like tool_call and tool_response) is preserved in its original relative order, preventing the data loss previously identified in the review.
  • Persistence Logic: Refined the backend sync trigger. Instead of relying on the Thread ID (which can be a __LOCALID_ for new chats), the utility now uses the incognito flag from the ChatRuntimeStore. This ensures that all permanent chats are persisted to the DB, while temporary chats are correctly handled in-memory.
  • State Management: Fully migrated the editing state to the ChatRuntimeStore (editingMessageId), removing redundant window event listeners and ensuring a single source of truth.
  • Robustness & Rollbacks: Added a state snapshot and rollback mechanism. If the backend sync fails, the UI now automatically reverts to the original state to prevent inconsistent "ghost" saves.
  • UX & Polish:
    • Added an Escape key handler to exit the editor.
    • Implemented whitespace normalization (trimming) at both ends of the tagged-text round-trip to prevent newline accumulation.
    • Integrated an auto-growing textarea for a smoother editing experience.

@Imagineer99

Copy link
Copy Markdown
Member

CI passes on staging CI fork except for failing tests inherited from main, I also resolved a html preview regression and tested the assistant message editing manually.

good first PR @CelesteHeartsong, merging.

@Imagineer99
Imagineer99 merged commit 9666e5d into unslothai:main Jun 17, 2026
1 check was pending
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants