foliko 1.1.48 → 1.1.49
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cli/src/daemon.js +61 -6
- package/package.json +1 -1
package/cli/src/daemon.js
CHANGED
|
@@ -7,6 +7,26 @@
|
|
|
7
7
|
const fs = require('fs');
|
|
8
8
|
const path = require('path');
|
|
9
9
|
|
|
10
|
+
// 默认配置
|
|
11
|
+
const DEFAULT_CONFIG = {
|
|
12
|
+
model: 'MiniMax-M2.7',
|
|
13
|
+
provider: 'minimax',
|
|
14
|
+
baseURL: 'https://api.minimaxi.com/v1',
|
|
15
|
+
apiKey: null,
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
// Provider 默认配置
|
|
19
|
+
const PROVIDER_DEFAULTS = {
|
|
20
|
+
minimax: {
|
|
21
|
+
model: 'MiniMax-M2.7',
|
|
22
|
+
baseURL: 'https://api.minimaxi.com/v1',
|
|
23
|
+
},
|
|
24
|
+
deepseek: {
|
|
25
|
+
model: 'deepseek-chat',
|
|
26
|
+
baseURL: 'https://api.deepseek.com/v1',
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
|
|
10
30
|
// 解析命令行参数 --cwd <path>
|
|
11
31
|
const cwdArg = process.argv.find((arg) => arg === '--cwd');
|
|
12
32
|
const daemonCwd = cwdArg ? process.argv[process.argv.indexOf(cwdArg) + 1] : process.cwd();
|
|
@@ -55,9 +75,44 @@ console.log('[DEBUG] process.env.QQ_APP_ID =', process.env.QQ_APP_ID);
|
|
|
55
75
|
console.log('[DEBUG] process.env.QQ_CLIENT_SECRET =', process.env.QQ_CLIENT_SECRET ? '***' + process.env.QQ_CLIENT_SECRET.slice(-6) : 'undefined');
|
|
56
76
|
console.log('[DEBUG] process.env.FOLIKO_API_KEY =', process.env.FOLIKO_API_KEY ? '***' + process.env.FOLIKO_API_KEY.slice(-6) : 'undefined');
|
|
57
77
|
|
|
58
|
-
|
|
59
|
-
|
|
78
|
+
/**
|
|
79
|
+
* 获取环境变量配置
|
|
80
|
+
*/
|
|
81
|
+
function getEnvConfig() {
|
|
82
|
+
const provider = process.env.FOLIKO_PROVIDER || DEFAULT_CONFIG.provider;
|
|
83
|
+
const providerDefaults = PROVIDER_DEFAULTS[provider] || PROVIDER_DEFAULTS.minimax;
|
|
84
|
+
|
|
85
|
+
// 支持多种 API key 环境变量名
|
|
86
|
+
let apiKey = process.env.FOLIKO_API_KEY || null;
|
|
87
|
+
if (!apiKey) {
|
|
88
|
+
// 根据 provider 查找对应的 API key
|
|
89
|
+
const upperProvider = provider.toUpperCase().replace(/-/g, '_');
|
|
90
|
+
apiKey = process.env[`${upperProvider}_API_KEY`] || null;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return {
|
|
94
|
+
model: process.env.FOLIKO_MODEL || providerDefaults.model,
|
|
95
|
+
provider: provider,
|
|
96
|
+
baseURL: process.env.FOLIKO_BASE_URL || providerDefaults.baseURL,
|
|
97
|
+
apiKey: apiKey,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* 解析命令行参数(命令行参数优先于环境变量)
|
|
103
|
+
*/
|
|
104
|
+
function parseArgs(args) {
|
|
105
|
+
// 先获取环境变量配置(作为默认值)
|
|
106
|
+
const envConfig = getEnvConfig();
|
|
107
|
+
const options = { ...envConfig };
|
|
60
108
|
|
|
109
|
+
return options;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
async function main(args = process.argv.slice(2)) {
|
|
114
|
+
console.log('[Foliko] 启动后台服务...');
|
|
115
|
+
const options = parseArgs(args);
|
|
61
116
|
// 创建框架
|
|
62
117
|
const framework = new Framework({ debug: false });
|
|
63
118
|
|
|
@@ -65,10 +120,10 @@ async function main() {
|
|
|
65
120
|
await framework.bootstrap({
|
|
66
121
|
agentDir: './.agent',
|
|
67
122
|
aiConfig: {
|
|
68
|
-
provider:
|
|
69
|
-
model:
|
|
70
|
-
apiKey:
|
|
71
|
-
baseURL:
|
|
123
|
+
provider: options.provider,
|
|
124
|
+
model: options.model,
|
|
125
|
+
apiKey: options.apiKey,
|
|
126
|
+
baseURL: options.baseURL,
|
|
72
127
|
},
|
|
73
128
|
});
|
|
74
129
|
|