Skip to content

PRD-2007: Edit AI message logic#8

Merged
veliseev93 merged 3 commits into
developmentfrom
PRD-2007-edit-ai-message-logic
Dec 18, 2025
Merged

PRD-2007: Edit AI message logic#8
veliseev93 merged 3 commits into
developmentfrom
PRD-2007-edit-ai-message-logic

Conversation

@Tomass673
Copy link
Copy Markdown
Collaborator

@Tomass673 Tomass673 changed the title Prd 2007: Edit AI message logic PRD-2007: Edit AI message logic Dec 8, 2025
@Tomass673
Copy link
Copy Markdown
Collaborator Author

@veliseev93 could you please take a look?

let preparedChat: ChatResponse;

if (editedMessage.role === Role.ASSISTANT) {
preparedChat = prepareEditAssistantMessagePayload(chat, editingMessageId, message);
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.

@Tomass673 Could you please check the logic for “Save as copy”? When the “Save as copy” button is clicked, the history and history.currentId should be updated (similar to what happens after clicking the “Submit” button when editing a user message).

Also, in order to update the history branch, the prepareEditAssistantMessagePayload should look approximately as follows:


import uuid from 'react-native-uuid';
import { Role } from '@open-webui-react-native/shared/data-access/common';
import { ChatResponse, History } from '../models';
import { createMessagesList } from './create-messages-list';

export function prepareEditAssistantMessagePayload(
  oldData: ChatResponse,
  messageId: string,
  newContent: string,
): ChatResponse {
  const history = oldData.chat.history;
  const messagesMap = { ...history.messages };
  const newAssistantMessageId = uuid.v4()
  const parentId = history?.messages?.[messageId]?.parentId

  const target = messagesMap[messageId];
  if (!target || target.role !== Role.ASSISTANT) return oldData;

  const updatedMessage = {
    ...target,
    childrenIs: [],
    id: newAssistantMessageId,
    content: newContent,
    done: true,
  };

  const updatedHistory: History = {
    ...history,
    currentId: newAssistantMessageId,
    messages: {
      ...history.messages,
      [newAssistantMessageId]: updatedMessage,
    },
    lastAssistantMessage:
      history.lastAssistantMessage?.id === messageId ? updatedMessage : history.lastAssistantMessage,
  };
  updatedHistory.messages[parentId || ''].childrenIds?.push(newAssistantMessageId);

  const lastAssistantMessage =
    updatedHistory.lastAssistantMessage?.id === messageId ? updatedMessage : updatedHistory.lastAssistantMessage;
  
  return {
    ...oldData,
    chat: {
      ...oldData.chat,
      history: {
        ...updatedHistory,
        lastAssistantMessage,
      },
      messages: createMessagesList(updatedHistory, newAssistantMessageId),
    },
  };
}

This comment briefly describes the flow for editing an AI message, with links to the relevant code in the web application – https://app.clickup.com/t/24336023/PRD-1965?comment=90150163295336
We need to implement it in a similar way.

If implemented correctly, "Save As Copy" should work like this:

Simulator.Screen.Recording.-.iPhone.17.-.2025-12-09.at.11.23.25.mov

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

fixed

@veliseev93 veliseev93 removed their assignment Dec 10, 2025
@Tomass673 Tomass673 assigned veliseev93 and unassigned Tomass673 Dec 11, 2025
}

const preparedChat = prepareUpdateMessageInChatPayload(chat, editingMessageId, message);
const preparedChat = prepareCopyEditedMessagePayload(chat, editingMessageId, message);
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.

It seems that due to changes in this logic, we can no longer change the text of the user's message when pressing the "Save" button.

Simulator.Screen.Recording.-.iPhone.17.-.2025-12-15.at.10.50.17.mov

Could you please check?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Restored this functionality

@veliseev93 veliseev93 assigned Tomass673 and unassigned veliseev93 Dec 15, 2025
@Tomass673 Tomass673 assigned veliseev93 and unassigned Tomass673 Dec 16, 2025
@veliseev93 veliseev93 merged commit 18e78d8 into development Dec 18, 2025
1 check passed
@veliseev93 veliseev93 deleted the PRD-2007-edit-ai-message-logic branch December 18, 2025 10:08
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