1
- // Code Files
2
1
const axios = require ( 'axios' ) ;
3
2
const FormData = require ( 'form-data' ) ;
4
3
const { getCodeBaseURL } = require ( '@librechat/agents' ) ;
@@ -16,7 +15,8 @@ const MAX_FILE_SIZE = 150 * 1024 * 1024;
16
15
async function getCodeOutputDownloadStream ( fileIdentifier , apiKey ) {
17
16
try {
18
17
const baseURL = getCodeBaseURL ( ) ;
19
- const response = await axios ( {
18
+ /** @type {import('axios').AxiosRequestConfig } */
19
+ const options = {
20
20
method : 'get' ,
21
21
url : `${ baseURL } /download/${ fileIdentifier } ` ,
22
22
responseType : 'stream' ,
@@ -25,10 +25,22 @@ async function getCodeOutputDownloadStream(fileIdentifier, apiKey) {
25
25
'X-API-Key' : apiKey ,
26
26
} ,
27
27
timeout : 15000 ,
28
- } ) ;
28
+ } ;
29
+
30
+ if ( process . env . PROXY ) {
31
+ options . proxy = {
32
+ host : process . env . PROXY ,
33
+ protocol : process . env . PROXY . startsWith ( 'https' ) ? 'https' : 'http' ,
34
+ } ;
35
+ }
29
36
37
+ const response = await axios ( options ) ;
30
38
return response ;
31
39
} catch ( error ) {
40
+ logAxiosError ( {
41
+ message : `Error downloading code environment file stream: ${ error . message } ` ,
42
+ error,
43
+ } ) ;
32
44
throw new Error ( `Error downloading file: ${ error . message } ` ) ;
33
45
}
34
46
}
@@ -54,7 +66,8 @@ async function uploadCodeEnvFile({ req, stream, filename, apiKey, entity_id = ''
54
66
form . append ( 'file' , stream , filename ) ;
55
67
56
68
const baseURL = getCodeBaseURL ( ) ;
57
- const response = await axios . post ( `${ baseURL } /upload` , form , {
69
+ /** @type {import('axios').AxiosRequestConfig } */
70
+ const options = {
58
71
headers : {
59
72
...form . getHeaders ( ) ,
60
73
'Content-Type' : 'multipart/form-data' ,
@@ -64,7 +77,16 @@ async function uploadCodeEnvFile({ req, stream, filename, apiKey, entity_id = ''
64
77
} ,
65
78
maxContentLength : MAX_FILE_SIZE ,
66
79
maxBodyLength : MAX_FILE_SIZE ,
67
- } ) ;
80
+ } ;
81
+
82
+ if ( process . env . PROXY ) {
83
+ options . proxy = {
84
+ host : process . env . PROXY ,
85
+ protocol : process . env . PROXY . startsWith ( 'https' ) ? 'https' : 'http' ,
86
+ } ;
87
+ }
88
+
89
+ const response = await axios . post ( `${ baseURL } /upload` , form , options ) ;
68
90
69
91
/** @type {{ message: string; session_id: string; files: Array<{ fileId: string; filename: string }> } } */
70
92
const result = response . data ;
0 commit comments