File size: 1,747 Bytes
b88ce1b
 
 
 
bcd4897
b88ce1b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8f3a455
 
 
 
 
b88ce1b
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import fs from 'fs';
import log from '../utils/logger.js';

const defaultConfig = {
  server: { port: parseInt(process.env.PORT) || 8045, host: '0.0.0.0' },
  api: {
    url: 'https://daily-cloudcode-pa.sandbox.googleapis.com/v1internal:streamGenerateContent?alt=sse',
    modelsUrl: 'https://daily-cloudcode-pa.sandbox.googleapis.com/v1internal:fetchAvailableModels',
    host: 'daily-cloudcode-pa.sandbox.googleapis.com',
    userAgent: 'antigravity/1.11.3 windows/amd64'
  },
  defaults: { temperature: 1, top_p: 0.85, top_k: 50, max_tokens: 8096 },
  security: { maxRequestSize: '50mb', apiKey: null },
  systemInstruction: '你是聊天机器人,专门为用户提供聊天和情绪价值,协助进行小说创作或者角色扮演,也可以提供数学或者代码上的建议'
};

let config = JSON.parse(JSON.stringify(defaultConfig));

export function reloadConfig() {
  try {
    const newConfig = JSON.parse(fs.readFileSync('./config.json', 'utf8'));

    // 递归合并配置
    // 1. 基础合并
    Object.assign(config, newConfig);

    // 2. 深度合并关键部分
    if (newConfig.server) Object.assign(config.server, newConfig.server);
    if (newConfig.api) Object.assign(config.api, newConfig.api);
    if (newConfig.defaults) Object.assign(config.defaults, newConfig.defaults);
    if (newConfig.security) Object.assign(config.security, newConfig.security);

    // 3. 环境变量优先级最高
    if (process.env.PORT) {
      config.server.port = parseInt(process.env.PORT);
    }

    log.info('✓ 配置文件已重载');
    return true;
  } catch (error) {
    log.error('⚠ 重载配置文件失败:', error.message);
    return false;
  }
}

// 初始化加载
reloadConfig();

export default config;