@@ -10,6 +10,7 @@ import { Send } from "lucide-react";
10
10
import { io , Socket } from "socket.io-client" ;
11
11
import { useAuth } from "@/app/auth/auth-context" ;
12
12
import LoadingScreen from "@/components/common/loading-screen" ;
13
+ import { sendAiMessage } from "@/lib/api/openai/send-ai-message" ;
13
14
import { getChatHistory } from "@/lib/api/collab-service/get-chat-history" ;
14
15
15
16
interface Message {
@@ -134,7 +135,7 @@ export default function Chat({ roomId }: { roomId: string }) {
134
135
scrollWithDelay ( ) ;
135
136
} , [ partnerMessages , aiMessages , chatTarget ] ) ;
136
137
137
- const sendMessage = ( ) => {
138
+ const sendMessage = async ( ) => {
138
139
if ( ! newMessage . trim ( ) || ! socket || ! isConnected || ! own_user_id ) return ;
139
140
140
141
if ( chatTarget === "partner" ) {
@@ -151,6 +152,18 @@ export default function Chat({ roomId }: { roomId: string }) {
151
152
timestamp : new Date ( ) ,
152
153
} ;
153
154
setAiMessages ( ( prev ) => [ ...prev , message ] ) ;
155
+ const response = await sendAiMessage ( newMessage ) ;
156
+ const data = await response . json ( ) ;
157
+ const aiMessage = {
158
+ id : crypto . randomUUID ( ) ,
159
+ userId : "ai" ,
160
+ text :
161
+ data . data . choices && data . data . choices [ 0 ] ?. message ?. content
162
+ ? data . data . choices [ 0 ] . message . content
163
+ : "An error occurred. Please try again." ,
164
+ timestamp : new Date ( ) ,
165
+ } ;
166
+ setAiMessages ( ( prev ) => [ ...prev , aiMessage ] ) ;
154
167
}
155
168
156
169
setNewMessage ( "" ) ;
0 commit comments