@@ -42,12 +42,17 @@ type MessageType = "user" | "raw";
42
42
43
43
export type ServerStatus = "stable" | "running" | "offline" | "unknown" ;
44
44
45
+ export interface FileUploadResponse {
46
+ ok : boolean ;
47
+ filePath ?: string ;
48
+ }
49
+
45
50
interface ChatContextValue {
46
51
messages : ( Message | DraftMessage ) [ ] ;
47
52
loading : boolean ;
48
53
serverStatus : ServerStatus ;
49
54
sendMessage : ( message : string , type ?: MessageType ) => void ;
50
- uploadFiles : ( formData : FormData ) => Promise < boolean > ;
55
+ uploadFiles : ( formData : FormData ) => Promise < FileUploadResponse > ;
51
56
}
52
57
53
58
const ChatContext = createContext < ChatContextValue | undefined > ( undefined ) ;
@@ -270,16 +275,16 @@ export function ChatProvider({ children }: PropsWithChildren) {
270
275
} ;
271
276
272
277
// 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 } ;
275
280
try {
276
281
const response = await fetch ( `${ agentAPIUrl } /upload` , {
277
282
method : 'POST' ,
278
283
body : formData ,
279
284
} ) ;
280
285
281
286
if ( ! response . ok ) {
282
- success = false ;
287
+ result . ok = false ;
283
288
const errorData = await response . json ( ) ;
284
289
console . error ( "Failed to send message:" , errorData ) ;
285
290
const detail = errorData . detail ;
@@ -293,10 +298,12 @@ export function ChatProvider({ children }: PropsWithChildren) {
293
298
toast . error ( `Failed to upload files` , {
294
299
description : fullDetail ,
295
300
} ) ;
301
+ } else {
302
+ result = ( await response . json ( ) ) as FileUploadResponse ;
296
303
}
297
304
// eslint-disable-next-line @typescript-eslint/no-explicit-any
298
305
} catch ( error : any ) {
299
- success = false ;
306
+ result . ok = false ;
300
307
console . error ( "Error uploading files:" , error ) ;
301
308
const detail = error . detail ;
302
309
const messages =
@@ -311,10 +318,9 @@ export function ChatProvider({ children }: PropsWithChildren) {
311
318
description : fullDetail ,
312
319
} ) ;
313
320
}
314
- return success ;
321
+ return result ;
315
322
}
316
323
317
-
318
324
return (
319
325
< ChatContext . Provider
320
326
value = { {
0 commit comments