feat(ui): forking chat - retry any answer, copy, duplicate, branch (#10645)#10654
Merged
Conversation
Assisted-by: Claude:claude-opus-4-8 [Claude Code] Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
Assisted-by: Claude:claude-opus-4-8 [Claude Code] Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
Assisted-by: Claude:claude-opus-4-8 [Claude Code] Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
Assisted-by: Claude:claude-opus-4-8 [Claude Code] Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
Mid-conversation retry regenerated an answer with the downstream turns still in the model's context. handleRegenerate truncated the DOM history via updateChatSettings (a scheduled state update), but the synchronous sendMessage that followed read the stale, pre-truncation history from its closure to build the outbound API payload. Thread the intended base history explicitly through sendMessage's options.baseHistory so the request body matches the truncated view. Backward compatible: the normal send path (no baseHistory) is unchanged. Also guard two minor issues in Chat.jsx: the "Branch from here" button now renders under !isStreaming to match the retry button, and the duplicate toast only fires when forkChat returns a chat (not on a null result). Assisted-by: Claude:claude-opus-4-8 [Claude Code] Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Chat management for the built-in React chat UI, closing #10645. Adds the "forking" conversation tools requested in the issue: retry any answer, copy a whole chat, duplicate a chat, and branch a new chat from any answer - so you don't need to point a separate web frontend at your LocalAI instance.
Features
How
Entirely client-side, no backend changes. The three duplication behaviors collapse onto one
forkChat(chatId, uptoIndex?)mutator inuseChat(deep-clones history viastructuredClone, fresh id/name/timestamps, resets token usage).handleRegeneratewas generalized tohandleRegenerate(targetIndex). Message actions stay index-addressed (no stable message ids, no localStorage migration,saveChatswhitelist untouched). New i18n strings go inpublic/locales/en/chat.json(English is the fallback for all locales).Notable fix folded in
Generalizing retry surfaced a latent stale-closure bug:
sendMessagebuilt its API payload from the closurechats, so a mid-conversation retry would have regenerated the answer with the downstream conversation still in the model's context (the DOM truncated correctly, but the request body did not). Fixed by threading the truncated history explicitly viasendMessage(..., { baseHistory }), with an e2e test that asserts the outbound/v1/chat/completionspayload.Testing
e2e/forking-chat.spec.js(5 cases): duplicate, retry-any-answer, copy-chat (asserts clipboard contents), branch-from-message, and the retry payload assertion. All pass.chat-polling-selection,chat-errors,page-render-smoke) still green (19/19).Files
src/hooks/useChat.js-forkChatmutator,options.baseHistorysrc/pages/Chat.jsx- generalized retry, per-message retry + branch buttons, serializer split, copy-chatsrc/components/ChatsMenu.jsx- Duplicate + Copy chat per-item actionspublic/locales/en/chat.json- new stringse2e/forking-chat.spec.js- coverageCloses #10645
Assisted-by: Claude:claude-opus-4-8 [Claude Code]