@@ -42,12 +42,17 @@ type MessageType = "user" | "raw";
4242
4343export type ServerStatus = "stable" | "running" | "offline" | "unknown" ;
4444
45+ export interface FileUploadResponse {
46+ ok : boolean ;
47+ filePath ?: string ;
48+ }
49+
4550interface ChatContextValue {
4651 messages : ( Message | DraftMessage ) [ ] ;
4752 loading : boolean ;
4853 serverStatus : ServerStatus ;
4954 sendMessage : ( message : string , type ?: MessageType ) => void ;
50- uploadFiles : ( formData : FormData ) => Promise < boolean > ;
55+ uploadFiles : ( formData : FormData ) => Promise < FileUploadResponse > ;
5156}
5257
5358const ChatContext = createContext < ChatContextValue | undefined > ( undefined ) ;
@@ -270,16 +275,16 @@ export function ChatProvider({ children }: PropsWithChildren) {
270275 } ;
271276
272277 // Upload files to workspace
273- const uploadFiles = async ( formData : FormData ) : Promise < boolean > => {
274- let success = true ;
278+ const uploadFiles = async ( formData : FormData ) : Promise < FileUploadResponse > => {
279+ let result : FileUploadResponse = { ok : true } ;
275280 try {
276281 const response = await fetch ( `${ agentAPIUrl } /upload` , {
277282 method : 'POST' ,
278283 body : formData ,
279284 } ) ;
280285
281286 if ( ! response . ok ) {
282- success = false ;
287+ result . ok = false ;
283288 const errorData = await response . json ( ) ;
284289 console . error ( "Failed to send message:" , errorData ) ;
285290 const detail = errorData . detail ;
@@ -293,10 +298,12 @@ export function ChatProvider({ children }: PropsWithChildren) {
293298 toast . error ( `Failed to upload files` , {
294299 description : fullDetail ,
295300 } ) ;
301+ } else {
302+ result = ( await response . json ( ) ) as FileUploadResponse ;
296303 }
297304 // eslint-disable-next-line @typescript-eslint/no-explicit-any
298305 } catch ( error : any ) {
299- success = false ;
306+ result . ok = false ;
300307 console . error ( "Error uploading files:" , error ) ;
301308 const detail = error . detail ;
302309 const messages =
@@ -311,10 +318,9 @@ export function ChatProvider({ children }: PropsWithChildren) {
311318 description : fullDetail ,
312319 } ) ;
313320 }
314- return success ;
321+ return result ;
315322 }
316323
317-
318324 return (
319325 < ChatContext . Provider
320326 value = { {
0 commit comments