@@ -723,7 +723,8 @@ export const configValidators = {
723723 [ CONFIG_KEYS . OCO_API_URL ] ( value : any ) {
724724 validateConfig (
725725 CONFIG_KEYS . OCO_API_URL ,
726- typeof value === 'string' ,
726+ typeof value === 'string' &&
727+ / ^ ( h t t p s ? : \/ \/ ) / . test ( value ) ,
727728 `${ value } is not a valid URL. It should start with 'http://' or 'https://'.`
728729 ) ;
729730 return value ;
@@ -732,7 +733,8 @@ export const configValidators = {
732733 [ CONFIG_KEYS . OCO_PROXY ] ( value : any ) {
733734 validateConfig (
734735 CONFIG_KEYS . OCO_PROXY ,
735- typeof value === 'string' ,
736+ value === null ||
737+ ( typeof value === 'string' && / ^ ( h t t p s ? : \/ \/ ) / . test ( value ) ) ,
736738 `${ value } is not a valid URL. It should start with 'http://' or 'https://'.`
737739 ) ;
738740 return value ;
@@ -900,7 +902,7 @@ export type ConfigType = {
900902 [ CONFIG_KEYS . OCO_TOKENS_MAX_INPUT ] : number ;
901903 [ CONFIG_KEYS . OCO_TOKENS_MAX_OUTPUT ] : number ;
902904 [ CONFIG_KEYS . OCO_API_URL ] ?: string ;
903- [ CONFIG_KEYS . OCO_PROXY ] ?: string ;
905+ [ CONFIG_KEYS . OCO_PROXY ] ?: string | null ;
904906 [ CONFIG_KEYS . OCO_API_CUSTOM_HEADERS ] ?: string ;
905907 [ CONFIG_KEYS . OCO_DESCRIPTION ] : boolean ;
906908 [ CONFIG_KEYS . OCO_EMOJI ] : boolean ;
@@ -986,10 +988,7 @@ const getEnvConfig = (envPath: string) => {
986988 return {
987989 OCO_MODEL : process . env . OCO_MODEL ,
988990 OCO_API_URL : process . env . OCO_API_URL ,
989- OCO_PROXY :
990- process . env . OCO_PROXY ||
991- process . env . HTTPS_PROXY ||
992- process . env . HTTP_PROXY ,
991+ OCO_PROXY : process . env . OCO_PROXY ,
993992 OCO_API_KEY : process . env . OCO_API_KEY ,
994993 OCO_API_CUSTOM_HEADERS : process . env . OCO_API_CUSTOM_HEADERS ,
995994 OCO_AI_PROVIDER : process . env . OCO_AI_PROVIDER as OCO_AI_PROVIDER_ENUM ,
@@ -1027,16 +1026,13 @@ export const getIsGlobalConfigFileExist = (
10271026} ;
10281027
10291028export const getGlobalConfig = ( configPath : string = defaultConfigPath ) => {
1030- let globalConfig : ConfigType ;
1031-
10321029 const isGlobalConfigFileExist = getIsGlobalConfigFileExist ( configPath ) ;
1033- if ( ! isGlobalConfigFileExist ) globalConfig = initGlobalConfig ( configPath ) ;
1034- else {
1035- const configFile = readFileSync ( configPath , 'utf8' ) ;
1036- globalConfig = iniParse ( configFile ) as ConfigType ;
1030+ if ( ! isGlobalConfigFileExist ) {
1031+ return { ...DEFAULT_CONFIG } ;
10371032 }
10381033
1039- return globalConfig ;
1034+ const configFile = readFileSync ( configPath , 'utf8' ) ;
1035+ return iniParse ( configFile ) as ConfigType ;
10401036} ;
10411037
10421038/**
@@ -1049,7 +1045,10 @@ export const getGlobalConfig = (configPath: string = defaultConfigPath) => {
10491045const mergeConfigs = ( main : Partial < ConfigType > , fallback : ConfigType ) => {
10501046 const allKeys = new Set ( [ ...Object . keys ( main ) , ...Object . keys ( fallback ) ] ) ;
10511047 return Array . from ( allKeys ) . reduce ( ( acc , key ) => {
1052- acc [ key ] = parseConfigVarValue ( main [ key ] ?? fallback [ key ] ) ;
1048+ const mainValue = main [ key ] ;
1049+ acc [ key ] = parseConfigVarValue (
1050+ mainValue !== undefined ? mainValue : fallback [ key ]
1051+ ) ;
10531052 return acc ;
10541053 } , { } as ConfigType ) ;
10551054} ;
@@ -1218,7 +1217,10 @@ function getConfigKeyDetails(key) {
12181217 case CONFIG_KEYS . OCO_PROXY :
12191218 return {
12201219 description : 'HTTP/HTTPS Proxy URL' ,
1221- values : [ "URL string (must start with 'http://' or 'https://')" ]
1220+ values : [
1221+ "URL string (must start with 'http://' or 'https://')" ,
1222+ 'null (disable proxy even when HTTP_PROXY/HTTPS_PROXY are set)'
1223+ ]
12221224 } ;
12231225 case CONFIG_KEYS . OCO_MESSAGE_TEMPLATE_PLACEHOLDER :
12241226 return {
0 commit comments