diff --git a/apps/server/controllers/chat.py b/apps/server/controllers/chat.py index 29ad5ea77..9ed3a9bcb 100644 --- a/apps/server/controllers/chat.py +++ b/apps/server/controllers/chat.py @@ -250,7 +250,7 @@ def get_chat_messages(is_private_chat: bool, agent_id: Optional[UUID] = None, te .filter(ChatMessageModel.session_id == session_id) .order_by(ChatMessageModel.created_on.desc()) .limit(50) - .options(joinedload(ChatMessageModel.agent), joinedload(ChatMessageModel.team), joinedload(ChatMessageModel.parent)) + .options(joinedload(ChatMessageModel.agent), joinedload(ChatMessageModel.team), joinedload(ChatMessageModel.parent), joinedload(ChatMessageModel.creator)) .all()) chat_messages = [chat_message.to_dict() for chat_message in chat_messages] @@ -286,7 +286,7 @@ def get_chat_messages(agent_id: Optional[UUID] = None, team_id: Optional[UUID] = .filter(ChatMessageModel.session_id == session_id) .order_by(ChatMessageModel.created_on.desc()) .limit(50) - .options(joinedload(ChatMessageModel.agent), joinedload(ChatMessageModel.team), joinedload(ChatMessageModel.parent)) + .options(joinedload(ChatMessageModel.agent), joinedload(ChatMessageModel.team), joinedload(ChatMessageModel.parent), joinedload(ChatMessageModel.creator)) .all()) chat_messages = [chat_message.to_dict() for chat_message in chat_messages] diff --git a/apps/server/models/chat_message.py b/apps/server/models/chat_message.py index 8980aa4a3..c32b00a8d 100644 --- a/apps/server/models/chat_message.py +++ b/apps/server/models/chat_message.py @@ -32,7 +32,7 @@ class ChatMessage(BaseModel): created_by = Column(UUID, ForeignKey('user.id', name='fk_created_by', ondelete='CASCADE'), nullable=True, index=True) modified_by = Column(UUID, ForeignKey('user.id', name='fk_modified_by', ondelete='CASCADE'), nullable=True, index=True) - creator = relationship("UserModel", foreign_keys=[created_by], lazy='select') + creator = relationship("UserModel", foreign_keys=[user_id], lazy='select') @classmethod def get_chat_message_by_id(cls, db, chat_message_id: UUID, account: AccountOutput): @@ -72,4 +72,7 @@ def to_dict(self): if self.parent: data['parent'] = self.parent.to_dict() + if self.creator: + data['creator'] = self.creator.to_dict() + return data \ No newline at end of file diff --git a/apps/server/typings/chat.py b/apps/server/typings/chat.py index ba90d003d..736aa2e40 100644 --- a/apps/server/typings/chat.py +++ b/apps/server/typings/chat.py @@ -28,6 +28,7 @@ class ChatMessageOutput(BaseModel): team_id: Optional[UUID] = None team: Optional[Dict] = None user_id: UUID + creator: Optional[Dict] = None account_id: UUID message: Dict thoughts: Optional[List[Dict]] = None diff --git a/apps/ui/src/gql/chat/chatMessages.gql b/apps/ui/src/gql/chat/chatMessages.gql index 3938cf43e..0c2242d43 100644 --- a/apps/ui/src/gql/chat/chatMessages.gql +++ b/apps/ui/src/gql/chat/chatMessages.gql @@ -15,5 +15,6 @@ query chatMessages($is_private_chat: Boolean!, $agent_id: String!, $team_id: Str agent team_id team + creator } } diff --git a/apps/ui/src/gql/chat/chatMessagesHistory.gql b/apps/ui/src/gql/chat/chatMessagesHistory.gql index 4a4df453a..2f4f4f233 100644 --- a/apps/ui/src/gql/chat/chatMessagesHistory.gql +++ b/apps/ui/src/gql/chat/chatMessagesHistory.gql @@ -15,5 +15,6 @@ query chatMessages($is_private_chat: Boolean!, $agent_id: String!, $team_id: Str agent team_id team + creator } } diff --git a/apps/ui/src/modals/AIChatModal/components/ChatHistory.tsx b/apps/ui/src/modals/AIChatModal/components/ChatHistory.tsx index cb95e95dd..e64cf3295 100644 --- a/apps/ui/src/modals/AIChatModal/components/ChatHistory.tsx +++ b/apps/ui/src/modals/AIChatModal/components/ChatHistory.tsx @@ -79,7 +79,7 @@ const ChatHistory = () => { {(agentById || teamById) && ( - + )} diff --git a/apps/ui/src/modals/AIChatModal/components/ChatMembers/ChatMembers.tsx b/apps/ui/src/modals/AIChatModal/components/ChatMembers/ChatMembers.tsx index d081e21da..b24a5f17e 100644 --- a/apps/ui/src/modals/AIChatModal/components/ChatMembers/ChatMembers.tsx +++ b/apps/ui/src/modals/AIChatModal/components/ChatMembers/ChatMembers.tsx @@ -25,11 +25,11 @@ import MemberText from './components/MemberText' const ChatMembers = ({ agentById, teamOfAgents, - userName, + isHistory, }: { agentById?: any teamOfAgents?: any - userName?: string + isHistory?: boolean }) => { const { user } = React.useContext(AuthContext) @@ -57,10 +57,10 @@ const ChatMembers = ({ - {userName && ( + {!isHistory && user?.name && ( - - + + )} @@ -129,10 +129,10 @@ const ChatMembers = ({ - {userName && ( + {!isHistory && user?.name && ( - - + + )} diff --git a/apps/ui/src/modals/AIChatModal/components/ChatMessageList/ChatMessageListV2.tsx b/apps/ui/src/modals/AIChatModal/components/ChatMessageList/ChatMessageListV2.tsx index 2ece1c9df..96114bb3b 100644 --- a/apps/ui/src/modals/AIChatModal/components/ChatMessageList/ChatMessageListV2.tsx +++ b/apps/ui/src/modals/AIChatModal/components/ChatMessageList/ChatMessageListV2.tsx @@ -58,6 +58,7 @@ const ChatMessageListV2 = ({ agentName: chat.agent?.name, teamName: chat.team?.name, avatar: chat?.agent?.avatar, + creator: chat?.creator, } }) @@ -169,7 +170,7 @@ const ChatMessageListV2 = ({ ))} - + diff --git a/apps/ui/src/modals/AIChatModal/components/ChatV2.tsx b/apps/ui/src/modals/AIChatModal/components/ChatV2.tsx index 12fbb8ad3..49d96915e 100644 --- a/apps/ui/src/modals/AIChatModal/components/ChatV2.tsx +++ b/apps/ui/src/modals/AIChatModal/components/ChatV2.tsx @@ -292,7 +292,7 @@ const ChatV2 = ({ isPrivate = false }: ChatV2Props) => { return ( - +