@@ -115,21 +115,34 @@ pub async fn cancel_session_chat(
115115pub async fn chat_create (
116116 app_handle : AppHandle ,
117117 server_id : String ,
118- message : String ,
118+ message : Option < String > ,
119+ attachments : Option < Vec < String > > ,
119120 query_params : Option < HashMap < String , Value > > ,
120121 client_id : String ,
121122) -> Result < ( ) , String > {
122- let body = if !message. is_empty ( ) {
123- let message = ChatRequestMessage {
124- message : Some ( message) ,
123+ println ! ( "chat_create message: {:?}" , message) ;
124+ println ! ( "chat_create attachments: {:?}" , attachments) ;
125+
126+ let message_empty = message. as_ref ( ) . map_or ( true , |m| m. is_empty ( ) ) ;
127+ let attachments_empty = attachments. as_ref ( ) . map_or ( true , |a| a. is_empty ( ) ) ;
128+
129+ if message_empty && attachments_empty {
130+ return Err ( "Message and attachments are empty" . to_string ( ) ) ;
131+ }
132+
133+ let body = {
134+ let request_message: ChatRequestMessage = ChatRequestMessage {
135+ message,
136+ attachments,
125137 } ;
138+
139+ println ! ( "chat_create body: {:?}" , request_message) ;
140+
126141 Some (
127- serde_json:: to_string ( & message )
142+ serde_json:: to_string ( & request_message )
128143 . map_err ( |e| format ! ( "Failed to serialize message: {}" , e) ) ?
129144 . into ( ) ,
130145 )
131- } else {
132- None
133146 } ;
134147
135148 let response = HttpClient :: advanced_post (
@@ -165,8 +178,6 @@ pub async fn chat_create(
165178 if let Err ( err) = app_handle. emit ( & client_id, line) {
166179 log:: error!( "Emit failed: {:?}" , err) ;
167180
168- print ! ( "Error sending message: {:?}" , err) ;
169-
170181 let _ = app_handle. emit ( "chat-create-error" , format ! ( "Emit failed: {:?}" , err) ) ;
171182 }
172183 }
@@ -179,21 +190,34 @@ pub async fn chat_chat(
179190 app_handle : AppHandle ,
180191 server_id : String ,
181192 session_id : String ,
182- message : String ,
193+ message : Option < String > ,
194+ attachments : Option < Vec < String > > ,
183195 query_params : Option < HashMap < String , Value > > , //search,deep_thinking
184196 client_id : String ,
185197) -> Result < ( ) , String > {
186- let body = if !message. is_empty ( ) {
187- let message = ChatRequestMessage {
188- message : Some ( message) ,
198+ println ! ( "chat_chat message: {:?}" , message) ;
199+ println ! ( "chat_chat attachments: {:?}" , attachments) ;
200+
201+ let message_empty = message. as_ref ( ) . map_or ( true , |m| m. is_empty ( ) ) ;
202+ let attachments_empty = attachments. as_ref ( ) . map_or ( true , |a| a. is_empty ( ) ) ;
203+
204+ if message_empty && attachments_empty {
205+ return Err ( "Message and attachments are empty" . to_string ( ) ) ;
206+ }
207+
208+ let body = {
209+ let request_message = ChatRequestMessage {
210+ message,
211+ attachments,
189212 } ;
213+
214+ println ! ( "chat_chat body: {:?}" , request_message) ;
215+
190216 Some (
191- serde_json:: to_string ( & message )
217+ serde_json:: to_string ( & request_message )
192218 . map_err ( |e| format ! ( "Failed to serialize message: {}" , e) ) ?
193219 . into ( ) ,
194220 )
195- } else {
196- None
197221 } ;
198222
199223 let path = format ! ( "/chat/{}/_chat" , session_id) ;
@@ -235,6 +259,9 @@ pub async fn chat_chat(
235259
236260 if let Err ( err) = app_handle. emit ( & client_id, line) {
237261 log:: error!( "Emit failed: {:?}" , err) ;
262+
263+ print ! ( "Error sending message: {:?}" , err) ;
264+
238265 let _ = app_handle. emit ( "chat-create-error" , format ! ( "Emit failed: {:?}" , err) ) ;
239266 }
240267 }
0 commit comments