@@ -10,7 +10,7 @@ import { BeatLoader } from "react-spinners";
1010import { useDebouncedCallback } from "use-debounce" ;
1111import { Input } from "@chakra-ui/react" ;
1212import SimpleMarkdown from "@/markdown/SimpleMarkdown" ;
13- import type { Chat , Conversation , SharedApi } from "@/types/shared " ;
13+ import type { Chat , Conversation , LlmServiceApi } from "@/types/llmServiceApi " ;
1414
1515const ChatInput = styled ( "input" ) `
1616 background: #ffffff;
@@ -75,22 +75,13 @@ const ChatSendButton = styled("button")`
7575 outline: none;
7676` ;
7777
78- interface ChatRoomProps extends Omit < SharedApi , "isLoggedInApi" > {
78+ interface ChatRoomProps {
7979 setIsLoggedIn : Dispatch < SetStateAction < boolean > > ;
8080 initMessage ?: string ;
81+ llmServiceApi : Omit < LlmServiceApi , "isLoggedIn" > ;
8182}
8283
83- export const ChatRoom = ( {
84- setIsLoggedIn,
85- initMessage,
86- changeConversationNameApi,
87- createConversationApi,
88- getChatsByConversationIdApi,
89- deleteConversationApi,
90- deleteAllConversationsApi,
91- sendMsgWithStreamResApi,
92- logoutApi,
93- } : ChatRoomProps ) => {
84+ export const ChatRoom = ( { setIsLoggedIn, initMessage, llmServiceApi } : ChatRoomProps ) => {
9485 const chatsWrapper = React . useRef < HTMLDivElement > ( null ) ;
9586 const [ disable , setDisable ] = React . useState ( false ) ;
9687 const [ chatHistory , setChatHistory ] = React . useState < Chat [ ] > ( [ ] ) ;
@@ -143,7 +134,7 @@ export const ChatRoom = ({
143134 } ;
144135
145136 async function createConversation ( ) {
146- const data = await createConversationApi ( ) ;
137+ const data = await llmServiceApi . createConversation ( ) ;
147138 if ( ! data ) {
148139 return ;
149140 }
@@ -153,7 +144,7 @@ export const ChatRoom = ({
153144 }
154145
155146 async function changeConversationName ( conversationId : number , name : string ) {
156- await changeConversationNameApi ( conversationId , name ) ;
147+ await changeConversationName ( conversationId , name ) ;
157148
158149 setConversations ( ( c ) =>
159150 c . map ( ( conversation ) => {
@@ -189,7 +180,7 @@ export const ChatRoom = ({
189180
190181 try {
191182 setCurrentConversation ( conversationId ) ;
192- const data = await getChatsByConversationIdApi ( conversationId ) ;
183+ const data = await llmServiceApi . getChatsByConversationId ( conversationId ) ;
193184 if ( ! data ) {
194185 return ;
195186 }
@@ -204,15 +195,15 @@ export const ChatRoom = ({
204195 ) ;
205196
206197 async function deleteConversation ( conversationId : number ) {
207- const data = await deleteConversationApi ( conversationId ) ;
198+ const data = await llmServiceApi . deleteConversation ( conversationId ) ;
208199 if ( ! data ) {
209200 return ;
210201 }
211202 setConversations ( conversations . filter ( ( conversation ) => conversation . id !== conversationId ) ) ;
212203 }
213204
214205 async function deleteAllConversations ( ) {
215- const data = await deleteAllConversationsApi ( ) ;
206+ const data = await llmServiceApi . deleteAllConversations ( ) ;
216207 if ( ! data ) {
217208 return ;
218209 }
@@ -246,7 +237,7 @@ export const ChatRoom = ({
246237
247238 setChatHistory ( [ ...updatedHistory ] ) ;
248239
249- const data = await sendMsgWithStreamResApi ( currentConversation as number , message ) ;
240+ const data = await llmServiceApi . sendMsgWithStreamRes ( currentConversation as number , message ) ;
250241 if ( ! data ) {
251242 setDisable ( false ) ;
252243 setChatHistory ( [ ...updatedHistory . slice ( 0 , updatedHistory . length - 1 ) ] ) ;
@@ -296,7 +287,7 @@ export const ChatRoom = ({
296287 }
297288
298289 async function logout ( ) {
299- await logoutApi ( ) ;
290+ await logout ( ) ;
300291 setIsLoggedIn ( false ) ;
301292 }
302293
0 commit comments