@@ -33,7 +33,9 @@ export enum CONFIG_KEYS {
3333 OCO_AZURE_ENDPOINT = 'OCO_AZURE_ENDPOINT' ,
3434 OCO_TEST_MOCK_TYPE = 'OCO_TEST_MOCK_TYPE' ,
3535 OCO_API_URL = 'OCO_API_URL' ,
36- OCO_OLLAMA_API_URL = 'OCO_OLLAMA_API_URL'
36+ OCO_OLLAMA_API_URL = 'OCO_OLLAMA_API_URL' ,
37+ OCO_FLOWISE_ENDPOINT = 'OCO_FLOWISE_ENDPOINT' ,
38+ OCO_FLOWISE_API_KEY = 'OCO_FLOWISE_API_KEY'
3739}
3840
3941export enum CONFIG_MODES {
@@ -119,7 +121,7 @@ const validateConfig = (
119121 }
120122} ;
121123
122- export const configValidators = {
124+ export const configValidators = {
123125 [ CONFIG_KEYS . OCO_OPENAI_API_KEY ] ( value : any , config : any = { } ) {
124126 if ( config . OCO_AI_PROVIDER == 'gemini' ) return value ;
125127
@@ -130,7 +132,8 @@ export const configValidators = {
130132 config . OCO_ANTHROPIC_API_KEY ||
131133 config . OCO_AI_PROVIDER . startsWith ( 'ollama' ) ||
132134 config . OCO_AZURE_API_KEY ||
133- config . OCO_AI_PROVIDER == 'test' ,
135+ config . OCO_AI_PROVIDER == 'test' ||
136+ config . OCO_AI_PROVIDER == 'flowise' ,
134137 'You need to provide an OpenAI/Anthropic/Azure API key'
135138 ) ;
136139 validateConfig (
@@ -149,7 +152,8 @@ export const configValidators = {
149152 config . OCO_OPENAI_API_KEY ||
150153 config . OCO_AZURE_API_KEY ||
151154 config . OCO_AI_PROVIDER == 'ollama' ||
152- config . OCO_AI_PROVIDER == 'test' ,
155+ config . OCO_AI_PROVIDER == 'test' ||
156+ config . OCO_AI_PROVIDER == 'flowise' ,
153157 'You need to provide an OpenAI/Anthropic/Azure API key'
154158 ) ;
155159
@@ -175,13 +179,25 @@ export const configValidators = {
175179 value ||
176180 config . OCO_OPENAI_API_KEY ||
177181 config . OCO_AI_PROVIDER == 'ollama' ||
178- config . OCO_AI_PROVIDER == 'test' ,
182+ config . OCO_AI_PROVIDER == 'test' ||
183+ config . OCO_AI_PROVIDER == 'flowise' ,
179184 'You need to provide an OpenAI/Anthropic API key'
180185 ) ;
181186
182187 return value ;
183188 } ,
184189
190+ [ CONFIG_KEYS . OCO_FLOWISE_API_KEY ] ( value : any , config : any = { } ) {
191+ validateConfig (
192+ CONFIG_KEYS . OCO_FLOWISE_API_KEY ,
193+ value || config . OCO_AI_PROVIDER != 'flowise' ,
194+ 'You need to provide a flowise API key'
195+ ) ;
196+
197+ return value ;
198+ } ,
199+
200+
185201 [ CONFIG_KEYS . OCO_DESCRIPTION ] ( value : any ) {
186202 validateConfig (
187203 CONFIG_KEYS . OCO_DESCRIPTION ,
@@ -268,7 +284,8 @@ export const configValidators = {
268284 ] . includes ( value ) ||
269285 config . OCO_AI_PROVIDER == 'ollama' ||
270286 config . OCO_AI_PROVIDER == 'azure' ||
271- config . OCO_AI_PROVIDER == 'test' ,
287+ config . OCO_AI_PROVIDER == 'test' ||
288+ config . OCO_AI_PROVIDER == 'flowise' ,
272289 `${ value } is not supported yet, use:\n\n ${ [
273290 ...MODEL_LIST . openai ,
274291 ...MODEL_LIST . anthropic ,
@@ -308,9 +325,9 @@ export const configValidators = {
308325 [ CONFIG_KEYS . OCO_AI_PROVIDER ] ( value : any ) {
309326 validateConfig (
310327 CONFIG_KEYS . OCO_AI_PROVIDER ,
311- [ '' , 'openai' , 'anthropic' , 'gemini' , 'azure' , 'test' ] . includes ( value ) ||
328+ [ '' , 'openai' , 'anthropic' , 'gemini' , 'azure' , 'test' , 'flowise' ] . includes ( value ) ||
312329 value . startsWith ( 'ollama' ) ,
313- `${ value } is not supported yet, use 'ollama', 'anthropic', 'azure', 'gemini' or 'openai' (default)`
330+ `${ value } is not supported yet, use 'ollama', 'anthropic', 'azure', 'gemini', 'flowise' or 'openai' (default)`
314331 ) ;
315332 return value ;
316333 } ,
@@ -324,6 +341,7 @@ export const configValidators = {
324341
325342 return value ;
326343 } ,
344+
327345 [ CONFIG_KEYS . OCO_AZURE_ENDPOINT ] ( value : any ) {
328346 validateConfig (
329347 CONFIG_KEYS . OCO_AZURE_ENDPOINT ,
@@ -333,6 +351,17 @@ export const configValidators = {
333351
334352 return value ;
335353 } ,
354+
355+ [ CONFIG_KEYS . OCO_FLOWISE_ENDPOINT ] ( value : any ) {
356+ validateConfig (
357+ CONFIG_KEYS . OCO_FLOWISE_ENDPOINT ,
358+ typeof value === 'string' && value . includes ( ':' ) ,
359+ 'Value must be string and should include both I.P. and port number' // Considering the possibility of DNS lookup or feeding the I.P. explicitely, there is no pattern to verify, except a column for the port number
360+ ) ;
361+
362+ return value ;
363+ } ,
364+
336365 [ CONFIG_KEYS . OCO_TEST_MOCK_TYPE ] ( value : any ) {
337366 validateConfig (
338367 CONFIG_KEYS . OCO_TEST_MOCK_TYPE ,
@@ -361,7 +390,6 @@ export type ConfigType = {
361390
362391const defaultConfigPath = pathJoin ( homedir ( ) , '.opencommit' ) ;
363392const defaultEnvPath = pathResolve ( process . cwd ( ) , '.env' ) ;
364-
365393export const getConfig = ( {
366394 configPath = defaultConfigPath ,
367395 envPath = defaultEnvPath
@@ -396,9 +424,10 @@ export const getConfig = ({
396424 OCO_ONE_LINE_COMMIT :
397425 process . env . OCO_ONE_LINE_COMMIT === 'true' ? true : false ,
398426 OCO_AZURE_ENDPOINT : process . env . OCO_AZURE_ENDPOINT || '' ,
399- OCO_TEST_MOCK_TYPE : process . env . OCO_TEST_MOCK_TYPE || 'commit-message'
427+ OCO_TEST_MOCK_TYPE : process . env . OCO_TEST_MOCK_TYPE || 'commit-message' ,
428+ OCO_FLOWISE_ENDPOINT : process . env . OCO_FLOWISE_ENDPOINT || ':' ,
429+ OCO_FLOWISE_API_KEY : process . env . OCO_FLOWISE_API_KEY || 'undefined'
400430 } ;
401-
402431 const configExists = existsSync ( configPath ) ;
403432 if ( ! configExists ) return configFromEnv ;
404433
@@ -437,7 +466,7 @@ export const setConfig = (
437466 const config = getConfig ( ) || { } ;
438467
439468 for ( const [ configKey , configValue ] of keyValues ) {
440- if ( ! configValidators . hasOwnProperty ( configKey ) ) {
469+ if ( ! configValidators . hasOwnProperty ( configKey ) ) {
441470 throw new Error ( `Unsupported config key: ${ configKey } ` ) ;
442471 }
443472
0 commit comments