66 LLMConfig ,
77 AccountConfig ,
88 PluginConfig ,
9+ DriverConfig ,
910} from '../types' ;
1011import { CTX_APP_ID , CTX_INSTANCE_ID } from '../constants' ;
1112
@@ -41,6 +42,18 @@ export class ConfigController {
4142 config = await Config . create ( {
4243 global : true ,
4344 } ) ;
45+ } else {
46+ const globalConfig = await Config . findOne ( {
47+ where : { global : true } ,
48+ } ) ;
49+
50+ // 这三个配置项是全局配置,需要合并到实例配置中
51+ if ( globalConfig ) {
52+ config . has_keyword_match = globalConfig . has_keyword_match ;
53+ config . has_paused = globalConfig . has_paused ;
54+ config . has_use_gpt = globalConfig . has_use_gpt ;
55+ config . has_mouse_close = globalConfig . has_mouse_close ;
56+ }
4457 }
4558
4659 return config ;
@@ -156,9 +169,14 @@ export class ConfigController {
156169 } : {
157170 appId : string | undefined ;
158171 instanceId : string | undefined ;
159- type : string ;
172+ type : 'generic' | 'llm' | 'plugin' | 'driver' | 'account' ;
160173 } ) : Promise <
161- GenericConfig | LLMConfig | AccountConfig | PluginConfig | undefined
174+ | GenericConfig
175+ | LLMConfig
176+ | AccountConfig
177+ | PluginConfig
178+ | DriverConfig
179+ | undefined
162180 > {
163181 let config = null ;
164182 if ( instanceId ) {
@@ -206,6 +224,7 @@ export class ConfigController {
206224 defaultReply : config ?. default_reply || '' ,
207225 } ;
208226 }
227+
209228 if ( type === 'llm' ) {
210229 return {
211230 appId : config ?. platform_id || '' ,
@@ -216,6 +235,7 @@ export class ConfigController {
216235 model : config ?. model || 'gpt-3.5-turbo' ,
217236 } ;
218237 }
238+
219239 if ( type === 'plugin' ) {
220240 let pluginCode = '' ;
221241
@@ -232,6 +252,15 @@ export class ConfigController {
232252 } ;
233253 }
234254
255+ if ( type === 'driver' ) {
256+ return {
257+ hasPaused : config ?. has_paused || false ,
258+ hasKeywordMatch : config ?. has_keyword_match || false ,
259+ hasUseGpt : config ?. has_use_gpt || false ,
260+ hasMouseClose : config ?. has_mouse_close || false ,
261+ } ;
262+ }
263+
235264 return {
236265 activationCode : config ?. activation_code || '' ,
237266 } ;
@@ -250,7 +279,12 @@ export class ConfigController {
250279 appId : string | undefined ;
251280 instanceId : string | undefined ;
252281 type : string ;
253- cfg : GenericConfig | LLMConfig | AccountConfig | PluginConfig ;
282+ cfg :
283+ | GenericConfig
284+ | LLMConfig
285+ | AccountConfig
286+ | PluginConfig
287+ | DriverConfig ;
254288 } ) {
255289 let dbConfig = null ;
256290 if ( instanceId ) {
@@ -328,11 +362,53 @@ export class ConfigController {
328362 use_plugin : config . usePlugin ,
329363 plugin_id : pluginId ,
330364 } ) ;
365+ } else if ( type === 'driver' ) {
366+ // TODO: 目前只有全局配置,后续再实现实例配置
367+ const config = cfg as DriverConfig ;
368+ dbConfig = await Config . findOne ( {
369+ where : { global : true } ,
370+ } ) ;
371+ if ( ! dbConfig ) {
372+ throw new Error ( 'Driver config not found' ) ;
373+ }
374+ await dbConfig . update ( {
375+ has_paused : config . hasPaused ,
376+ has_keyword_match : config . hasKeywordMatch ,
377+ has_use_gpt : config . hasUseGpt ,
378+ has_mouse_close : config . hasMouseClose ,
379+ } ) ;
331380 } else {
332381 const config = cfg as AccountConfig ;
333382 await dbConfig . update ( {
334383 activation_code : config . activationCode ,
335384 } ) ;
336385 }
337386 }
387+
388+ /**
389+ * 更新配置
390+ * @param
391+ */
392+ public async moveMouseHandler ( ) : Promise < boolean > {
393+ const dbConfig = await Config . findOne ( {
394+ where : { global : true } ,
395+ } ) ;
396+
397+ if ( ! dbConfig ) {
398+ return false ;
399+ }
400+
401+ // 检查是否开启了鼠标移动自动暂停功能
402+ if ( dbConfig . has_mouse_close ) {
403+ if ( ! dbConfig . has_paused ) {
404+ await dbConfig . update ( {
405+ has_paused : true ,
406+ } ) ;
407+
408+ return true ;
409+ }
410+ }
411+
412+ return false ;
413+ }
338414}
0 commit comments