@@ -33,7 +33,9 @@ export enum CONFIG_KEYS {
33
33
OCO_AZURE_ENDPOINT = 'OCO_AZURE_ENDPOINT' ,
34
34
OCO_TEST_MOCK_TYPE = 'OCO_TEST_MOCK_TYPE' ,
35
35
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'
37
39
}
38
40
39
41
export enum CONFIG_MODES {
@@ -119,7 +121,7 @@ const validateConfig = (
119
121
}
120
122
} ;
121
123
122
- export const configValidators = {
124
+ export const configValidators = {
123
125
[ CONFIG_KEYS . OCO_OPENAI_API_KEY ] ( value : any , config : any = { } ) {
124
126
if ( config . OCO_AI_PROVIDER == 'gemini' ) return value ;
125
127
@@ -130,7 +132,8 @@ export const configValidators = {
130
132
config . OCO_ANTHROPIC_API_KEY ||
131
133
config . OCO_AI_PROVIDER . startsWith ( 'ollama' ) ||
132
134
config . OCO_AZURE_API_KEY ||
133
- config . OCO_AI_PROVIDER == 'test' ,
135
+ config . OCO_AI_PROVIDER == 'test' ||
136
+ config . OCO_AI_PROVIDER == 'flowise' ,
134
137
'You need to provide an OpenAI/Anthropic/Azure API key'
135
138
) ;
136
139
validateConfig (
@@ -149,7 +152,8 @@ export const configValidators = {
149
152
config . OCO_OPENAI_API_KEY ||
150
153
config . OCO_AZURE_API_KEY ||
151
154
config . OCO_AI_PROVIDER == 'ollama' ||
152
- config . OCO_AI_PROVIDER == 'test' ,
155
+ config . OCO_AI_PROVIDER == 'test' ||
156
+ config . OCO_AI_PROVIDER == 'flowise' ,
153
157
'You need to provide an OpenAI/Anthropic/Azure API key'
154
158
) ;
155
159
@@ -175,13 +179,25 @@ export const configValidators = {
175
179
value ||
176
180
config . OCO_OPENAI_API_KEY ||
177
181
config . OCO_AI_PROVIDER == 'ollama' ||
178
- config . OCO_AI_PROVIDER == 'test' ,
182
+ config . OCO_AI_PROVIDER == 'test' ||
183
+ config . OCO_AI_PROVIDER == 'flowise' ,
179
184
'You need to provide an OpenAI/Anthropic API key'
180
185
) ;
181
186
182
187
return value ;
183
188
} ,
184
189
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
+
185
201
[ CONFIG_KEYS . OCO_DESCRIPTION ] ( value : any ) {
186
202
validateConfig (
187
203
CONFIG_KEYS . OCO_DESCRIPTION ,
@@ -268,7 +284,8 @@ export const configValidators = {
268
284
] . includes ( value ) ||
269
285
config . OCO_AI_PROVIDER == 'ollama' ||
270
286
config . OCO_AI_PROVIDER == 'azure' ||
271
- config . OCO_AI_PROVIDER == 'test' ,
287
+ config . OCO_AI_PROVIDER == 'test' ||
288
+ config . OCO_AI_PROVIDER == 'flowise' ,
272
289
`${ value } is not supported yet, use:\n\n ${ [
273
290
...MODEL_LIST . openai ,
274
291
...MODEL_LIST . anthropic ,
@@ -308,9 +325,9 @@ export const configValidators = {
308
325
[ CONFIG_KEYS . OCO_AI_PROVIDER ] ( value : any ) {
309
326
validateConfig (
310
327
CONFIG_KEYS . OCO_AI_PROVIDER ,
311
- [ '' , 'openai' , 'anthropic' , 'gemini' , 'azure' , 'test' ] . includes ( value ) ||
328
+ [ '' , 'openai' , 'anthropic' , 'gemini' , 'azure' , 'test' , 'flowise' ] . includes ( value ) ||
312
329
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)`
314
331
) ;
315
332
return value ;
316
333
} ,
@@ -324,6 +341,7 @@ export const configValidators = {
324
341
325
342
return value ;
326
343
} ,
344
+
327
345
[ CONFIG_KEYS . OCO_AZURE_ENDPOINT ] ( value : any ) {
328
346
validateConfig (
329
347
CONFIG_KEYS . OCO_AZURE_ENDPOINT ,
@@ -333,6 +351,17 @@ export const configValidators = {
333
351
334
352
return value ;
335
353
} ,
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
+
336
365
[ CONFIG_KEYS . OCO_TEST_MOCK_TYPE ] ( value : any ) {
337
366
validateConfig (
338
367
CONFIG_KEYS . OCO_TEST_MOCK_TYPE ,
@@ -361,7 +390,6 @@ export type ConfigType = {
361
390
362
391
const defaultConfigPath = pathJoin ( homedir ( ) , '.opencommit' ) ;
363
392
const defaultEnvPath = pathResolve ( process . cwd ( ) , '.env' ) ;
364
-
365
393
export const getConfig = ( {
366
394
configPath = defaultConfigPath ,
367
395
envPath = defaultEnvPath
@@ -396,9 +424,10 @@ export const getConfig = ({
396
424
OCO_ONE_LINE_COMMIT :
397
425
process . env . OCO_ONE_LINE_COMMIT === 'true' ? true : false ,
398
426
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'
400
430
} ;
401
-
402
431
const configExists = existsSync ( configPath ) ;
403
432
if ( ! configExists ) return configFromEnv ;
404
433
@@ -437,7 +466,7 @@ export const setConfig = (
437
466
const config = getConfig ( ) || { } ;
438
467
439
468
for ( const [ configKey , configValue ] of keyValues ) {
440
- if ( ! configValidators . hasOwnProperty ( configKey ) ) {
469
+ if ( ! configValidators . hasOwnProperty ( configKey ) ) {
441
470
throw new Error ( `Unsupported config key: ${ configKey } ` ) ;
442
471
}
443
472
0 commit comments