From 86d2bb5ee2e4928ea9fca94fa97630ea02045611 Mon Sep 17 00:00:00 2001 From: Mirian Okradze Date: Tue, 21 Nov 2023 13:45:33 +0400 Subject: [PATCH] feat: display conversation voice in chat members info --- apps/server/controllers/chat.py | 10 ++++++- apps/server/models/chat.py | 29 +++++++++++++++++-- apps/server/typings/chat.py | 6 ++++ apps/ui/src/gql/chat/chatById.gql | 1 + apps/ui/src/gql/chat/chats.gql | 1 + .../components/ChatMembers/ChatMembers.tsx | 15 ++++++++++ apps/ui/src/routes/ChatRouteLayout.tsx | 6 +++- 7 files changed, 64 insertions(+), 4 deletions(-) diff --git a/apps/server/controllers/chat.py b/apps/server/controllers/chat.py index 3a64a111f..cb26eb46a 100644 --- a/apps/server/controllers/chat.py +++ b/apps/server/controllers/chat.py @@ -18,7 +18,7 @@ from typings.chat import (ChatInput, ChatMessageInput, ChatMessageOutput, ChatOutput, ChatStatus, ChatStopInput, ChatUserMessageInput, InsertChatMessagesInput, - NegotiateOutput) + NegotiateOutput, UpdateChatInput) from typings.config import ConfigOutput from utils.auth import authenticate, try_auth_user from utils.chat import (convert_chats_to_chat_list, convert_model_to_response, @@ -40,6 +40,14 @@ def create_chat( return convert_model_to_response(db_chat) +@router.patch("/{id}", status_code=200) +def update_chat( + id: UUID, chat: UpdateChatInput, auth: UserAccount = Depends(authenticate) +) -> ChatOutput: + db_chat = ChatModel.update_chat(db, id, chat, auth.user) + return convert_model_to_response(db_chat) + + @router.get("", response_model=List[ChatOutput]) def get_chats(auth: UserAccount = Depends(authenticate)) -> List[ChatOutput]: """ diff --git a/apps/server/models/chat.py b/apps/server/models/chat.py index 2054c7edd..abe48222a 100644 --- a/apps/server/models/chat.py +++ b/apps/server/models/chat.py @@ -1,7 +1,7 @@ import uuid from sqlalchemy import UUID, Boolean, Column, ForeignKey, Integer, String, or_ -from sqlalchemy.orm import joinedload, relationship +from sqlalchemy.orm import Session, joinedload, relationship from exceptions import ChatNotFoundException from models.account import AccountModel @@ -10,7 +10,7 @@ from models.team import TeamModel from models.user import UserModel from typings.account import AccountOutput -from typings.chat import ChatInput +from typings.chat import ChatInput, UpdateChatInput class ChatModel(BaseModel): @@ -29,6 +29,8 @@ class ChatModel(BaseModel): agent_id = Column(UUID, ForeignKey("agent.id", ondelete="CASCADE"), index=True) team_id = Column(UUID, ForeignKey("team.id", ondelete="CASCADE"), index=True) + voice_url = Column(String, nullable=True) + creator_user_id = Column( UUID, ForeignKey("user.id", name="fk_creator_user_id", ondelete="CASCADE"), @@ -177,6 +179,29 @@ def create_chat(cls, db, chat: ChatInput, user, account): return db_chat + @classmethod + def update_chat( + cls, + db, + id: UUID, + chat_input: UpdateChatInput, + user, + ): + db_chat = cls.get_chat_by_id(db=db, chat_id=id) + if not db_chat: + raise ChatNotFoundException("Chat not found!") + + for field in UpdateChatInput.__annotations__.keys(): + if hasattr(chat_input, field): + setattr(db_chat, field, getattr(chat_input, field)) + + db_chat.modified_by = user.id + + # db.session.add(db_chat) + db.session.commit() + + return db_chat + @classmethod def update_model_from_input(cls, chat_model: "ChatModel", chat_input: ChatInput): for field in ChatInput.__annotations__.keys(): diff --git a/apps/server/typings/chat.py b/apps/server/typings/chat.py index 1fd970cf9..7116534e3 100644 --- a/apps/server/typings/chat.py +++ b/apps/server/typings/chat.py @@ -51,6 +51,11 @@ class ChatInput(BaseModel): team_id: Optional[UUID] = None +class UpdateChatInput(BaseModel): + # name: Optional[str] + voice_url: Optional[str] + + class ChatOutput(BaseModel): id: str name: Optional[str] @@ -61,6 +66,7 @@ class ChatOutput(BaseModel): agent: Optional[Dict] = None creator_user: Optional[Dict] = None creator_account: Optional[Dict] = None + voice_url: Optional[str] = None # provider_user: Optional[Dict] = None # provider_account: Optional[Dict] = None # creator_user_id: Optional[UUID] diff --git a/apps/ui/src/gql/chat/chatById.gql b/apps/ui/src/gql/chat/chatById.gql index 46e4428ee..623d0f894 100644 --- a/apps/ui/src/gql/chat/chatById.gql +++ b/apps/ui/src/gql/chat/chatById.gql @@ -12,5 +12,6 @@ query chatById($id: id!) @api(name: "ai") { } creator_user creator_account + voice_url } } diff --git a/apps/ui/src/gql/chat/chats.gql b/apps/ui/src/gql/chat/chats.gql index bfa7fb60b..bd688ea32 100644 --- a/apps/ui/src/gql/chat/chats.gql +++ b/apps/ui/src/gql/chat/chats.gql @@ -11,5 +11,6 @@ query getChats @api(name: "ai") { } creator_user creator_account + voice_url } } diff --git a/apps/ui/src/modals/AIChatModal/components/ChatMembers/ChatMembers.tsx b/apps/ui/src/modals/AIChatModal/components/ChatMembers/ChatMembers.tsx index a79a9f1b1..cc58c34ab 100644 --- a/apps/ui/src/modals/AIChatModal/components/ChatMembers/ChatMembers.tsx +++ b/apps/ui/src/modals/AIChatModal/components/ChatMembers/ChatMembers.tsx @@ -23,15 +23,19 @@ import { StyledEyeOpenIcon, } from 'pages/TeamOfAgents/TeamOfAgentsCard/TeamOfAgentsCard' import { StyledTabListSpan, StyledTabListWrapper } from 'styles/tabStyles.css' +import AudioPlayer from 'components/AudioPlayer' +import { Nullable } from 'types' const ChatMembers = ({ agentById, teamOfAgents, isHistory, + voiceUrl, }: { agentById?: any teamOfAgents?: any isHistory?: boolean + voiceUrl?: Nullable }) => { const { t } = useTranslation() const { user } = React.useContext(AuthContext) @@ -67,6 +71,13 @@ const ChatMembers = ({ +
+ {voiceUrl && ( + + + + )} +
@@ -261,3 +272,7 @@ const StyledIconButtonWrapper = styled.div` display: flex; align-items: center; ` + +const StyledAudioPlayerWrapper = styled.div` + margin-top: 12px; +` diff --git a/apps/ui/src/routes/ChatRouteLayout.tsx b/apps/ui/src/routes/ChatRouteLayout.tsx index 97413e89f..1c8fa159f 100644 --- a/apps/ui/src/routes/ChatRouteLayout.tsx +++ b/apps/ui/src/routes/ChatRouteLayout.tsx @@ -311,7 +311,11 @@ const ChatRouteLayout = () => { - + )}