🙌 OpenHands: AI-Driven Development
feat: branch a conversation from any message (#1624)
Vasco Schiavo2ed2302a8c50
diff --git a/__tests__/components/features/chat/user-assistant-event-message.test.tsx b/__tests__/components/features/chat/user-assistant-event-message.test.tsxnew file mode 100644index 0000000000..06412cda07--- /dev/null+++ b/__tests__/components/features/chat/user-assistant-event-message.test.tsx@@ -0,0 +1,269 @@+import { fireEvent, screen, waitFor } from "@testing-library/react";+import { describe, it, expect, vi, beforeEach } from "vitest";+import { renderWithProviders } from "test-utils";+import type { MessageEvent } from "#/types/agent-server/core";+import { I18nKey } from "#/i18n/declaration";+import { UserAssistantEventMessage } from "#/components/conversation-events/chat/event-message-components/user-assistant-event-message";+import { useConversationStore } from "#/stores/conversation-store";+import ConversationService from "#/api/conversation-service/conversation-service.api";+import AgentServerConversationService from "#/api/conversation-service/agent-server-conversation-service.api";+import type { AppConversation } from "#/api/conversation-service/agent-server-conversation-service.types";+import type { DirectConversationInfo } from "#/api/agent-server-adapter";++const {+ useActiveBackendMock,+ useOptionalConversationIdMock,+ setMessageToSendMock,+ navigateMock,+} = vi.hoisted(() => ({+ useActiveBackendMock: vi.fn(),+ useOptionalConversationIdMock: vi.fn(),+ setMessageToSendMock: vi.fn(),+ navigateMock: vi.fn(),+}));++// These provide test context (backend kind, conversation id, navigation); the+// fork behaviour is exercised through the real hook against a mocked service+// (per the repo convention: mock the service, not the hook).+vi.mock("#/hooks/use-conversation-id", () => ({+ useOptionalConversationId: () => useOptionalConversationIdMock(),+}));++vi.mock("#/contexts/active-backend-context", () => ({+ useActiveBackend: () => useActiveBackendMock(),+}));++vi.mock("#/context/navigation-context", async (importActual) => ({+ ...(await importActual<object>()),+ useNavigation: () => ({ navigate: navigateMock }),+}));++// test-utils re-inits i18n with empty resources, so `t()` returns the key —+// which becomes the button's accessible name (aria-label).+const BRANCH_LABEL = I18nKey.CHAT_INTERFACE$BRANCH_FROM_HERE;+const forkResult = { id: "fork-123" } as DirectConversationInfo;++let forkSpy: ReturnType<typeof vi.spyOn>;+let parentSpy: ReturnType<typeof vi.spyOn>;++const makeEvent = (source: "user" | "agent", id: string): MessageEvent =>+ ({+ id,+ source,+ timestamp: "2024-01-01T00:00:00.000Z",+ llm_message: {+ role: source === "user" ? "user" : "assistant",+ content: [{ type: "text", text: "Hello world" }],+ },+ critic_result: null,+ }) as unknown as MessageEvent;++// A user message with only an image (no text) — parses to an empty string.+const makeImageOnlyEvent = (id: string): MessageEvent =>+ ({+ id,+ source: "user",+ timestamp: "2024-01-01T00:00:00.000Z",+ llm_message: {+ role: "user",+ content: [{ type: "image", image_urls: ["data:image/png;base64,AAAA"] }],+ },+ critic_result: null,+ }) as unknown as MessageEvent;++const renderMessage = (event: MessageEvent) =>+ renderWithProviders(+ <UserAssistantEventMessage+ event={event}+ isLastMessage={false}+ isFromPlanningAgent={false}+ />,+ );++describe("UserAssistantEventMessage — branch action", () => {+ beforeEach(() => {+ vi.restoreAllMocks();+ useActiveBackendMock.mockReset();+ useOptionalConversationIdMock.mockReset();+ setMessageToSendMock.mockReset();+ navigateMock.mockReset();++ useActiveBackendMock.mockReturnValue({+ backend: { kind: "local" },+ orgId: null,+ });+ useOptionalConversationIdMock.mockReturnValue({ conversationId: "conv-1" });++ useConversationStore.setState({ setMessageToSend: setMessageToSendMock });+ ConversationService.setCurrentConversation(null);++ forkSpy = vi+ .spyOn(AgentServerConversationService, "forkConversation")+ // Modern backend (>= 1.31.0): the fork's HEAD (leaf_event_id) is exactly+ // the requested branch point, confirming the message was excluded.+ .mockImplementation((_source, fromEventId) =>+ Promise.resolve({+ ...forkResult,+ leaf_event_id: fromEventId,+ } as unknown as DirectConversationInfo),+ );+ // Default: the message has a parent (the common case), so edit-mode+ // branches before it.+ parentSpy = vi+ .spyOn(AgentServerConversationService, "getEventParentId")+ .mockResolvedValue("evt-parent");+ });++ it("branches an assistant message inclusively, without a parent lookup or prefill", async () => {+ renderMessage(makeEvent("agent", "evt-agent"));++ // Actions only appear on hover.+ fireEvent.mouseEnter(screen.getByTestId("agent-message"));+ fireEvent.click(screen.getByRole("button", { name: BRANCH_LABEL }));++ await waitFor(() =>+ expect(navigateMock).toHaveBeenCalledWith("/conversations/fork-123"),+ );+ expect(parentSpy).not.toHaveBeenCalled();+ expect(forkSpy).toHaveBeenCalledWith("conv-1", "evt-agent", undefined);+ expect(setMessageToSendMock).not.toHaveBeenCalled();+ });++ it("edits a user message: branches at its parent and loads its text into the composer", async () => {+ renderMessage(makeEvent("user", "evt-user"));++ fireEvent.mouseEnter(screen.getByTestId("user-message"));+ fireEvent.click(screen.getByRole("button", { name: BRANCH_LABEL }));++ await waitFor(() =>+ expect(forkSpy).toHaveBeenCalledWith("conv-1", "evt-parent", undefined),+ );+ expect(parentSpy).toHaveBeenCalledWith("conv-1", "evt-user");+ expect(navigateMock).toHaveBeenCalledWith("/conversations/fork-123");+ await waitFor(() =>+ expect(setMessageToSendMock).toHaveBeenCalledWith(+ expect.stringContaining("Hello world"),+ ),+ );+ });++ it("does not prefill the composer when the message has no parent (inclusive fallback)", async () => {+ parentSpy.mockResolvedValue(undefined);+ renderMessage(makeEvent("user", "evt-user"));++ fireEvent.mouseEnter(screen.getByTestId("user-message"));+ fireEvent.click(screen.getByRole("button", { name: BRANCH_LABEL }));++ await waitFor(() =>+ expect(forkSpy).toHaveBeenCalledWith("conv-1", "evt-user", undefined),+ );+ expect(setMessageToSendMock).not.toHaveBeenCalled();+ });++ it("titles the fork distinctly from its source conversation", async () => {+ ConversationService.setCurrentConversation({+ id: "conv-1",+ title: "Trip planning",+ } as AppConversation);+ renderMessage(makeEvent("user", "evt-user"));++ fireEvent.mouseEnter(screen.getByTestId("user-message"));+ fireEvent.click(screen.getByRole("button", { name: BRANCH_LABEL }));++ await waitFor(() =>+ expect(forkSpy).toHaveBeenCalledWith(+ "conv-1",+ "evt-parent",+ "Trip planning (branch)",+ ),+ );+ });++ it("does not prefill when the backend ignored from_event_id (older agent-server)", async () => {+ // leaf_event_id != requested branch point => the message was NOT excluded+ // (the fork copied the whole conversation), so prefilling would duplicate.+ forkSpy.mockImplementation(() =>+ Promise.resolve({+ ...forkResult,+ leaf_event_id: "some-other-leaf",+ } as unknown as DirectConversationInfo),+ );+ renderMessage(makeEvent("user", "evt-user"));++ fireEvent.mouseEnter(screen.getByTestId("user-message"));+ fireEvent.click(screen.getByRole("button", { name: BRANCH_LABEL }));++ await waitFor(() =>+ expect(navigateMock).toHaveBeenCalledWith("/conversations/fork-123"),+ );+ expect(setMessageToSendMock).not.toHaveBeenCalled();+ });++ it("branches an image-only user message inclusively (keeps the image, no prefill)", async () => {+ renderMessage(makeImageOnlyEvent("evt-img"));++ fireEvent.mouseEnter(screen.getByTestId("user-message"));+ fireEvent.click(screen.getByRole("button", { name: BRANCH_LABEL }));++ // No text to edit → branch at the message (inclusive), no parent lookup,+ // no prefill, so the image is not dropped.+ await waitFor(() =>+ expect(forkSpy).toHaveBeenCalledWith("conv-1", "evt-img", undefined),+ );+ expect(parentSpy).not.toHaveBeenCalled();+ expect(setMessageToSendMock).not.toHaveBeenCalled();+ });++ it("omits the fork title when the tracked conversation is a different one", async () => {+ // Stale/other conversation in the shared singleton — must not be used.+ ConversationService.setCurrentConversation({+ id: "other-conv",+ title: "Stale title",+ } as AppConversation);+ renderMessage(makeEvent("user", "evt-user"));++ fireEvent.mouseEnter(screen.getByTestId("user-message"));+ fireEvent.click(screen.getByRole("button", { name: BRANCH_LABEL }));++ await waitFor(() =>+ expect(forkSpy).toHaveBeenCalledWith("conv-1", "evt-parent", undefined),+ );+ });++ it("ignores a second click while a fork is already in flight", async () => {+ renderMessage(makeEvent("user", "evt-user"));++ fireEvent.mouseEnter(screen.getByTestId("user-message"));+ const button = screen.getByRole("button", { name: BRANCH_LABEL });+ fireEvent.click(button);+ fireEvent.click(button);++ await waitFor(() => expect(forkSpy).toHaveBeenCalled());+ expect(forkSpy).toHaveBeenCalledTimes(1);+ });++ it("hides the branch action on the cloud backend", () => {+ useActiveBackendMock.mockReturnValue({+ backend: { kind: "cloud" },+ orgId: null,+ });++ renderMessage(makeEvent("user", "evt-user"));++ fireEvent.mouseEnter(screen.getByTestId("user-message"));+ expect(+ screen.queryByRole("button", { name: BRANCH_LABEL }),+ ).not.toBeInTheDocument();+ });++ it("hides the branch action outside of a conversation", () => {+ useOptionalConversationIdMock.mockReturnValue({ conversationId: undefined });++ renderMessage(makeEvent("agent", "evt-agent"));++ fireEvent.mouseEnter(screen.getByTestId("agent-message"));+ expect(+ screen.queryByRole("button", { name: BRANCH_LABEL }),+ ).not.toBeInTheDocument();+ });+});diff --git a/__tests__/hooks/use-auto-resize.test.tsx b/__tests__/hooks/use-auto-resize.test.tsxnew file mode 100644index 0000000000..75e22c986c--- /dev/null+++ b/__tests__/hooks/use-auto-resize.test.tsx@@ -0,0 +1,40 @@+import { renderHook, waitFor } from "@testing-library/react";+import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";+import { useAutoResize } from "#/hooks/use-auto-resize";+import type { IMessageToSend } from "#/stores/conversation-store";++// Focused coverage for the one-shot "consume" signal that backs the fix for a+// branch prefill leaking into another conversation's composer.+describe("useAutoResize — value application / onValueApplied", () => {+ let el: HTMLDivElement;++ beforeEach(() => {+ el = document.createElement("div");+ el.contentEditable = "true";+ document.body.appendChild(el);+ });++ afterEach(() => {+ el.remove();+ });++ it("applies value.text to the element and signals onValueApplied once", async () => {+ const ref = { current: el };+ const onValueApplied = vi.fn();++ const { rerender } = renderHook(+ ({ value }: { value: IMessageToSend | undefined }) =>+ useAutoResize(ref, { value, onValueApplied }),+ { initialProps: { value: undefined as IMessageToSend | undefined } },+ );++ // No value yet -> nothing applied, no signal.+ expect(el.textContent).toBe("");+ expect(onValueApplied).not.toHaveBeenCalled();++ rerender({ value: { text: "restored draft", timestamp: 1 } });++ await waitFor(() => expect(el.textContent).toBe("restored draft"));+ expect(onValueApplied).toHaveBeenCalledTimes(1);+ });+});diff --git a/src/api/conversation-service/agent-server-conversation-service.api.ts b/src/api/conversation-service/agent-server-conversation-service.api.tsindex 1b4ccafde1..ed0afcf710 100644--- a/src/api/conversation-service/agent-server-conversation-service.api.ts+++ b/src/api/conversation-service/agent-server-conversation-service.api.ts@@ -1,5 +1,6 @@import {ConversationSortOrder,+ type ForkConversationRequest,type LLMConfig,} from "@openhands/typescript-client";import {@@ -688,6 +689,58 @@ class AgentServerConversationService {return requireAppConversation(conversation, conversationId);}+ /**+ * Forks a conversation, copying event history up to and including+ * `fromEventId`. Local agent-server only; needs agent-server >= 1.31.0 for+ * `from_event_id` (older backends copy the whole conversation).+ */+ static async forkConversation(+ sourceConversationId: string,+ fromEventId: string,+ title?: string,+ ): Promise<DirectConversationInfo> {+ if (getActiveBackend().backend.kind === "cloud") {+ throw new Error(+ "Branching a conversation isn't supported on the cloud backend yet.",+ );+ }++ // `from_event_id` is accepted by `/fork` but not yet typed in+ // ForkConversationRequest (through client 1.32.0); the client forwards the+ // body verbatim, so cast to carry it. A title also suppresses the backend+ // auto-title, so the "(branch)" marker sticks.+ const data = await new ConversationClient(+ getAgentServerClientOptions(),+ ).forkConversation<DirectConversationInfo>(sourceConversationId, {+ from_event_id: fromEventId,+ ...(title ? { title } : {}),+ } as ForkConversationRequest & { from_event_id: string });++ // Carry over the source's client-side metadata (repo/branch/workspace/+ // profile/plugins) so the fork hydrates its chat-page badges the same way.+ const sourceMetadata = getStoredConversationMetadata(sourceConversationId);+ if (sourceMetadata) {+ setStoredConversationMetadata(data.id, sourceMetadata);+ }++ return data;+ }++ /**+ * Returns an event's `parent_id` (the fork point for branching *before* it),+ * or undefined at the root. Uses the single-event endpoint because the events+ * *search* API omits `parent_id`.+ */+ static async getEventParentId(+ conversationId: string,+ eventId: string,+ ): Promise<string | undefined> {+ const event = (await new ConversationClient(+ getAgentServerClientOptions(),+ ).getEvent(conversationId, eventId)) as { parent_id?: string | null };+ return event.parent_id ?? undefined;+ }+/*** Switches the LLM profile for the running conversation when one is open* (POST /switch_profile — per-conversation swap, doesn't change the user'sdiff --git a/src/api/conversation-service/conversation-service.api.ts b/src/api/conversation-service/conversation-service.api.tsindex 508267f280..249854cc47 100644--- a/src/api/conversation-service/conversation-service.api.ts+++ b/src/api/conversation-service/conversation-service.api.ts@@ -22,6 +22,10 @@ class ConversationService {this.currentConversation = currentConversation;}+ static getCurrentConversation(): AppConversation | null {+ return this.currentConversation;+ }+private static getClientOverrides() {return {sessionApiKey: this.currentConversation?.session_api_key,diff --git a/src/components/conversation-events/chat/event-message-components/user-assistant-event-message.tsx b/src/components/conversation-events/chat/event-message-components/user-assistant-event-message.tsxindex 98c210d673..f165deee5f 100644--- a/src/components/conversation-events/chat/event-message-components/user-assistant-event-message.tsx+++ b/src/components/conversation-events/chat/event-message-components/user-assistant-event-message.tsx@@ -1,4 +1,6 @@import React from "react";+import { useTranslation } from "react-i18next";+import { useNavigation } from "#/context/navigation-context";import { MessageEvent } from "#/types/agent-server/core";import { ChatMessage } from "../../../features/chat/chat-message";import { ImageCarousel } from "../../../features/images/image-carousel";@@ -7,6 +9,14 @@ import { parseMessageFromEvent } from "../event-content-helpers/parse-message-frimport { CriticResultDisplay } from "./critic-result-display";import { CollapsibleThinking } from "./collapsible-thinking";import { splitInlineThink } from "../event-thought-helpers";+import RepoForkedIcon from "#/icons/repo-forked.svg?react";+import { I18nKey } from "#/i18n/declaration";+import { useOptionalConversationId } from "#/hooks/use-conversation-id";+import { useActiveBackend } from "#/contexts/active-backend-context";+import { useForkConversation } from "#/hooks/mutation/use-fork-conversation";+import { useConversationStore } from "#/stores/conversation-store";+import ConversationService from "#/api/conversation-service/conversation-service.api";+import { displayErrorToast } from "#/utils/custom-toast-handlers";interface UserAssistantEventMessageProps {event: MessageEvent;@@ -19,6 +29,18 @@ export function UserAssistantEventMessage({isLastMessage,isFromPlanningAgent,}: UserAssistantEventMessageProps) {+ const { t } = useTranslation("openhands");+ const { navigate } = useNavigation();+ const { conversationId } = useOptionalConversationId();+ const isCloud = useActiveBackend().backend.kind === "cloud";+ const { mutate: forkConversation, isPending: isForking } =+ useForkConversation();+ const setMessageToSend = useConversationStore(+ (state) => state.setMessageToSend,+ );+ // Blocks a same-tick double-click, before `isForking` flips.+ const forkInFlightRef = React.useRef(false);+const parsed = parseMessageFromEvent(event);// Route an inline <think> block (e.g. from a streamed reply) to the thinking// section so reloaded conversations match the live rendering.@@ -36,6 +58,60 @@ export function UserAssistantEventMessage({});}+ // "Branch from here": a user message is "edit message" (excludes the message,+ // restores its text to the composer); an assistant message branches+ // inclusively. Local agent-server only, inside a conversation.+ const canBranch = !isCloud && !!conversationId;+ const handleBranch = () => {+ if (!conversationId || isForking || forkInFlightRef.current) return;+ forkInFlightRef.current = true;++ // Distinct title so the fork doesn't read identically to its source.+ // getCurrentConversation() is a shared singleton — match the id in case it+ // still holds the previously-viewed conversation.+ const source = ConversationService.getCurrentConversation();+ const sourceTitle =+ source?.id === conversationId ? source.title : undefined;+ const branchTitle = sourceTitle ? `${sourceTitle} (branch)` : undefined;++ // Only edit when there's text: an image-only message parses to "", so+ // branch it inclusively rather than dropping the image.+ const isEdit = event.source === "user" && message.length > 0;++ forkConversation(+ {+ sourceConversationId: conversationId,+ eventId: event.id,+ ...(isEdit ? { editText: message } : {}),+ ...(branchTitle ? { title: branchTitle } : {}),+ },+ {+ onSuccess: ({ info, excluded }) => {+ navigate(`/conversations/${info.id}`);+ // Prefill only when excluded (else the send duplicates it). Deferred+ // so the new conversation's composer receives it (as useLaunchSkillInChat).+ if (excluded) {+ window.setTimeout(() => setMessageToSend(message), 0);+ }+ },+ onError: (error) =>+ displayErrorToast(error instanceof Error ? error.message : null),+ onSettled: () => {+ forkInFlightRef.current = false;+ },+ },+ );+ };+ const actions = canBranch+ ? [+ {+ icon: <RepoForkedIcon width={15} height={15} aria-hidden />,+ onClick: handleBranch,+ tooltip: t(I18nKey.CHAT_INTERFACE$BRANCH_FROM_HERE),+ },+ ]+ : undefined;+return (<>{reasoning && <CollapsibleThinking content={reasoning} />}@@ -43,6 +119,7 @@ export function UserAssistantEventMessage({type={event.source}message={message}isFromPlanningAgent={isFromPlanningAgent}+ actions={actions}>{imageUrls.length > 0 && (<ImageCarousel size="small" images={imageUrls} />diff --git a/src/hooks/chat/use-grip-resize.ts b/src/hooks/chat/use-grip-resize.tsindex c3c572c9fb..c03a98b6e3 100644--- a/src/hooks/chat/use-grip-resize.ts+++ b/src/hooks/chat/use-grip-resize.ts@@ -17,7 +17,8 @@ export const useGripResize = (const [isGripVisible, setIsGripVisible] = useState(false);const [isGripDragging, setIsGripDragging] = useState(false);- const { setShouldHideSuggestions } = useConversationStore();+ const { setShouldHideSuggestions, clearMessageToSend } =+ useConversationStore();const gripRef = useRef<HTMLDivElement | null>(null);/** After a real resize drag, swallow the synthetic click so it doesn't toggle `isGripVisible`. */@@ -68,6 +69,7 @@ export const useGripResize = (onGripDragStart: handleGripDragStart,onGripDragEnd: handleGripDragEnd,value: messageToSend ?? undefined,+ onValueApplied: clearMessageToSend, // one-shot consume (see store action)enableManualResize: true,});diff --git a/src/hooks/mutation/use-fork-conversation.ts b/src/hooks/mutation/use-fork-conversation.tsnew file mode 100644index 0000000000..c220c5ab92--- /dev/null+++ b/src/hooks/mutation/use-fork-conversation.ts@@ -0,0 +1,77 @@+import { useMutation, useQueryClient } from "@tanstack/react-query";+import AgentServerConversationService from "#/api/conversation-service/agent-server-conversation-service.api";+import { DirectConversationInfo } from "#/api/agent-server-adapter";++interface ForkConversationVariables {+ /** The conversation being branched from. */+ sourceConversationId: string;+ /** The message the action was invoked on. */+ eventId: string;+ /** Set for an "edit message" branch: exclude the message and restore this text. */+ editText?: string | null;+ /** Optional title for the fork, so it reads distinctly from its source. */+ title?: string;+}++interface ForkConversationResult {+ info: DirectConversationInfo;+ /** Whether the message was excluded; the caller only prefills when true. */+ excluded: boolean;+}++/**+ * Branches a conversation from a message. Edit-mode (`editText` set) resolves+ * the message's parent (via getEventParentId) and branches there, excluding+ * the message; otherwise it branches at the message (inclusive). Local+ * agent-server only.+ */+export const useForkConversation = () => {+ const queryClient = useQueryClient();++ return useMutation({+ mutationKey: ["fork-conversation"],+ mutationFn: async ({+ sourceConversationId,+ eventId,+ editText,+ title,+ }: ForkConversationVariables): Promise<ForkConversationResult> => {+ let fromEventId = eventId;+ let excluded = false;++ if (editText != null) {+ const parentId = await AgentServerConversationService.getEventParentId(+ sourceConversationId,+ eventId,+ );+ if (parentId) {+ fromEventId = parentId;+ excluded = true;+ }+ }++ const info = await AgentServerConversationService.forkConversation(+ sourceConversationId,+ fromEventId,+ title,+ );++ // Older agent-servers (< 1.31.0) ignore `from_event_id` and copy the+ // whole conversation. When honored, the fork's HEAD is `fromEventId`; if+ // not, the message wasn't excluded — don't prefill (would duplicate).+ if (excluded) {+ const leafEventId = (info as { leaf_event_id?: string | null })+ .leaf_event_id;+ if (leafEventId !== fromEventId) {+ excluded = false;+ }+ }++ return { info, excluded };+ },+ onSuccess: () => {+ // Surface the fork in the sidebar without wiping loaded pages.+ queryClient.invalidateQueries({ queryKey: ["user", "conversations"] });+ },+ });+};diff --git a/src/hooks/use-auto-resize.ts b/src/hooks/use-auto-resize.tsindex ad51ca8801..7eec544a34 100644--- a/src/hooks/use-auto-resize.ts+++ b/src/hooks/use-auto-resize.ts@@ -26,6 +26,8 @@ interface UseAutoResizeOptions {onGripDragEnd?: () => void;onHeightChange?: (height: number) => void; // New callback for height changesvalue?: IMessageToSend;+ /** Called once `value` has been applied to the element (one-shot consume). */+ onValueApplied?: () => void;}interface UseAutoResizeReturn {@@ -129,6 +131,7 @@ export const useAutoResize = (maxHeight = DEFAULT_MAX_HEIGHT,enableManualResize = false,value,+ onValueApplied,onGripDragStart,onGripDragEnd,onHeightChange,@@ -344,6 +347,7 @@ export const useAutoResize = (element.textContent = value.text;smartResize();focusContentEditableAtEnd(element);+ onValueApplied?.(); // one-shot: let the caller clear the valuereturn true;};@@ -358,7 +362,7 @@ export const useAutoResize = (cancelAnimationFrame(rafId);}};- }, [value, smartResize]);+ }, [value, smartResize, onValueApplied]);// Initialize auto-resize on mountuseEffect(() => {diff --git a/src/i18n/translation.json b/src/i18n/translation.jsonindex 2a188913f4..292c61657d 100644--- a/src/i18n/translation.json+++ b/src/i18n/translation.json@@ -9604,6 +9604,23 @@"uk": "Не вдалося надіслати","ca": "Error en enviar"},+ "CHAT_INTERFACE$BRANCH_FROM_HERE": {+ "en": "Branch from here",+ "ja": "ここから分岐",+ "zh-CN": "从此处分支",+ "zh-TW": "從此處分支",+ "ko-KR": "여기서 분기",+ "no": "Forgren herfra",+ "it": "Dirama da qui",+ "pt": "Ramificar a partir daqui",+ "es": "Ramificar desde aquí",+ "ar": "تفريع من هنا",+ "fr": "Créer une branche ici",+ "tr": "Buradan dallandır",+ "de": "Ab hier verzweigen",+ "uk": "Відгалузити звідси",+ "ca": "Ramifica des d'aquí"+ },"CHAT_INTERFACE$MESSAGE_RETRY": {"en": "Retry","ja": "再試行",diff --git a/src/stores/conversation-store.ts b/src/stores/conversation-store.tsindex 9920723c99..60b405b121 100644--- a/src/stores/conversation-store.ts+++ b/src/stores/conversation-store.ts@@ -62,6 +62,7 @@ interface ConversationActions {removeImageLoading: (imageName: string) => void;clearAllLoading: () => void;setMessageToSend: (text: string) => void;+ clearMessageToSend: () => void;restoreMessageToInputIfEmpty: (text: string) => void;clearMessageRestoreIfEmpty: () => void;setSubmittedMessage: (message: string | null) => void;@@ -293,6 +294,11 @@ export const useConversationStore = create<ConversationStore>()("setMessageToSend",),+ // One-shot consume: clear after the composer applies it, so a never-sent+ // value can't replay into another conversation's composer on remount.+ clearMessageToSend: () =>+ set({ messageToSend: null }, false, "clearMessageToSend"),+restoreMessageToInputIfEmpty: (text) =>set({