foliko 1.0.75 → 1.0.76
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/.claude/settings.local.json +159 -157
- package/cli/bin/foliko.js +12 -12
- package/cli/src/commands/chat.js +143 -143
- package/cli/src/commands/list.js +93 -93
- package/cli/src/index.js +75 -75
- package/cli/src/ui/chat-ui.js +201 -201
- package/cli/src/utils/ansi.js +40 -40
- package/cli/src/utils/markdown.js +292 -292
- package/examples/ambient-example.js +194 -194
- package/examples/basic.js +115 -115
- package/examples/bootstrap.js +121 -121
- package/examples/mcp-example.js +56 -56
- package/examples/skill-example.js +49 -49
- package/examples/test-chat.js +137 -137
- package/examples/test-mcp.js +85 -85
- package/examples/test-reload.js +59 -59
- package/examples/test-telegram.js +50 -50
- package/examples/test-tg-bot.js +45 -45
- package/examples/test-tg-simple.js +47 -47
- package/examples/test-tg.js +62 -62
- package/examples/test-think.js +43 -43
- package/examples/test-web-plugin.js +103 -103
- package/examples/test-weixin-feishu.js +103 -103
- package/examples/workflow.js +158 -158
- package/package.json +1 -1
- package/plugins/ai-plugin.js +102 -102
- package/plugins/ambient-agent/EventWatcher.js +113 -113
- package/plugins/ambient-agent/ExplorerLoop.js +640 -640
- package/plugins/ambient-agent/GoalManager.js +197 -197
- package/plugins/ambient-agent/Reflector.js +95 -95
- package/plugins/ambient-agent/StateStore.js +90 -90
- package/plugins/ambient-agent/constants.js +101 -101
- package/plugins/ambient-agent/index.js +579 -579
- package/plugins/audit-plugin.js +187 -187
- package/plugins/default-plugins.js +662 -662
- package/plugins/email/constants.js +64 -64
- package/plugins/email/handlers.js +461 -461
- package/plugins/email/index.js +278 -278
- package/plugins/email/monitor.js +269 -269
- package/plugins/email/parser.js +138 -138
- package/plugins/email/reply.js +151 -151
- package/plugins/email/utils.js +124 -124
- package/plugins/feishu-plugin.js +481 -481
- package/plugins/file-system-plugin.js +826 -826
- package/plugins/install-plugin.js +199 -199
- package/plugins/python-executor-plugin.js +367 -367
- package/plugins/python-plugin-loader.js +481 -481
- package/plugins/rules-plugin.js +294 -294
- package/plugins/scheduler-plugin.js +691 -691
- package/plugins/session-plugin.js +369 -369
- package/plugins/shell-executor-plugin.js +197 -197
- package/plugins/storage-plugin.js +240 -240
- package/plugins/subagent-plugin.js +845 -845
- package/plugins/telegram-plugin.js +482 -482
- package/plugins/think-plugin.js +345 -345
- package/plugins/tools-plugin.js +196 -196
- package/plugins/web-plugin.js +606 -606
- package/plugins/weixin-plugin.js +545 -545
- package/src/capabilities/index.js +11 -11
- package/src/capabilities/skill-manager.js +609 -609
- package/src/capabilities/workflow-engine.js +1109 -1109
- package/src/core/agent-chat.js +882 -882
- package/src/core/agent.js +892 -892
- package/src/core/framework.js +465 -465
- package/src/core/index.js +19 -19
- package/src/core/plugin-base.js +219 -219
- package/src/core/plugin-manager.js +863 -863
- package/src/core/provider.js +114 -114
- package/src/core/sub-agent-config.js +264 -264
- package/src/core/system-prompt-builder.js +120 -120
- package/src/core/tool-registry.js +517 -517
- package/src/core/tool-router.js +297 -297
- package/src/executors/executor-base.js +58 -58
- package/src/executors/mcp-executor.js +741 -741
- package/src/index.js +25 -25
- package/src/utils/circuit-breaker.js +301 -301
- package/src/utils/error-boundary.js +363 -363
- package/src/utils/error.js +374 -374
- package/src/utils/event-emitter.js +97 -97
- package/src/utils/id.js +133 -133
- package/src/utils/index.js +217 -217
- package/src/utils/logger.js +181 -181
- package/src/utils/plugin-helpers.js +90 -90
- package/src/utils/retry.js +122 -122
- package/src/utils/sandbox.js +292 -292
- package/test/tool-registry-validation.test.js +218 -218
- package/website/script.js +136 -136
- package/foliko-1.0.75.tgz +0 -0
package/examples/test-tg-bot.js
CHANGED
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
require('dotenv').config();
|
|
2
|
-
const { Framework } = require('../src');
|
|
3
|
-
|
|
4
|
-
async function main() {
|
|
5
|
-
console.log('Starting test...\n');
|
|
6
|
-
|
|
7
|
-
const framework = new Framework({ debug: false });
|
|
8
|
-
|
|
9
|
-
await framework.bootstrap({
|
|
10
|
-
agentDir: process.cwd() + '/.agent',
|
|
11
|
-
aiConfig: {
|
|
12
|
-
provider: process.env.FOLIKO_PROVIDER || 'minimax',
|
|
13
|
-
model: process.env.FOLIKO_MODEL || 'MiniMax-M2.7',
|
|
14
|
-
baseURL: process.env.FOLIKO_BASE_URL || 'https://api.minimaxi.com/v1',
|
|
15
|
-
apiKey: process.env.MINIMAX_API_KEY || process.env.DEEPSEEK_API_KEY,
|
|
16
|
-
},
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
// 检查主 Agent
|
|
20
|
-
const mainAgent = framework._mainAgent;
|
|
21
|
-
console.log('Main Agent:', mainAgent ? mainAgent.name : 'NOT FOUND');
|
|
22
|
-
console.log('Agent apiKey:', mainAgent?.apiKey ? 'set' : 'NOT SET');
|
|
23
|
-
console.log('Agent _chatHandler:', mainAgent?._chatHandler ? 'exists' : 'NOT EXISTS');
|
|
24
|
-
console.log(
|
|
25
|
-
'Agent _chatHandler._aiClient:',
|
|
26
|
-
mainAgent?._chatHandler?._aiClient ? 'exists' : 'NOT EXISTS'
|
|
27
|
-
);
|
|
28
|
-
|
|
29
|
-
// 检查 Telegram 插件
|
|
30
|
-
const tgPlugin = framework.pluginManager.get('telegram');
|
|
31
|
-
console.log('\nTelegram Plugin:', tgPlugin ? 'loaded' : 'NOT LOADED');
|
|
32
|
-
|
|
33
|
-
if (tgPlugin) {
|
|
34
|
-
console.log('Telegram _bot:', tgPlugin._bot ? 'exists' : 'NOT EXISTS');
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
console.log('\n========================================');
|
|
38
|
-
console.log('Bot is running. Send a message to test!');
|
|
39
|
-
console.log('========================================\n');
|
|
40
|
-
|
|
41
|
-
// 保持运行
|
|
42
|
-
await new Promise(() => {});
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
main().catch(console.error);
|
|
1
|
+
require('dotenv').config();
|
|
2
|
+
const { Framework } = require('../src');
|
|
3
|
+
|
|
4
|
+
async function main() {
|
|
5
|
+
console.log('Starting test...\n');
|
|
6
|
+
|
|
7
|
+
const framework = new Framework({ debug: false });
|
|
8
|
+
|
|
9
|
+
await framework.bootstrap({
|
|
10
|
+
agentDir: process.cwd() + '/.agent',
|
|
11
|
+
aiConfig: {
|
|
12
|
+
provider: process.env.FOLIKO_PROVIDER || 'minimax',
|
|
13
|
+
model: process.env.FOLIKO_MODEL || 'MiniMax-M2.7',
|
|
14
|
+
baseURL: process.env.FOLIKO_BASE_URL || 'https://api.minimaxi.com/v1',
|
|
15
|
+
apiKey: process.env.MINIMAX_API_KEY || process.env.DEEPSEEK_API_KEY,
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
// 检查主 Agent
|
|
20
|
+
const mainAgent = framework._mainAgent;
|
|
21
|
+
console.log('Main Agent:', mainAgent ? mainAgent.name : 'NOT FOUND');
|
|
22
|
+
console.log('Agent apiKey:', mainAgent?.apiKey ? 'set' : 'NOT SET');
|
|
23
|
+
console.log('Agent _chatHandler:', mainAgent?._chatHandler ? 'exists' : 'NOT EXISTS');
|
|
24
|
+
console.log(
|
|
25
|
+
'Agent _chatHandler._aiClient:',
|
|
26
|
+
mainAgent?._chatHandler?._aiClient ? 'exists' : 'NOT EXISTS'
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
// 检查 Telegram 插件
|
|
30
|
+
const tgPlugin = framework.pluginManager.get('telegram');
|
|
31
|
+
console.log('\nTelegram Plugin:', tgPlugin ? 'loaded' : 'NOT LOADED');
|
|
32
|
+
|
|
33
|
+
if (tgPlugin) {
|
|
34
|
+
console.log('Telegram _bot:', tgPlugin._bot ? 'exists' : 'NOT EXISTS');
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
console.log('\n========================================');
|
|
38
|
+
console.log('Bot is running. Send a message to test!');
|
|
39
|
+
console.log('========================================\n');
|
|
40
|
+
|
|
41
|
+
// 保持运行
|
|
42
|
+
await new Promise(() => {});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
main().catch(console.error);
|
|
@@ -1,47 +1,47 @@
|
|
|
1
|
-
require('dotenv').config();
|
|
2
|
-
|
|
3
|
-
// 添加 .agent/node_modules 到搜索路径
|
|
4
|
-
const path = require('path');
|
|
5
|
-
const agentNodeModules = path.join(process.cwd(), '.agent', 'node_modules');
|
|
6
|
-
if (!module.paths.includes(agentNodeModules)) {
|
|
7
|
-
module.paths.unshift(agentNodeModules);
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
const TelegramBot = require('node-telegram-bot-api');
|
|
11
|
-
|
|
12
|
-
const token = process.env.TELEGRAM_BOT_TOKEN;
|
|
13
|
-
|
|
14
|
-
console.log('Token:', token ? token.substring(0, 10) + '...' : 'NOT SET');
|
|
15
|
-
|
|
16
|
-
if (!token) {
|
|
17
|
-
console.log('ERROR: No token!');
|
|
18
|
-
process.exit(1);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const bot = new TelegramBot(token, { polling: true });
|
|
22
|
-
|
|
23
|
-
console.log('Bot created, starting polling...');
|
|
24
|
-
|
|
25
|
-
bot.on('polling_error', (err) => {
|
|
26
|
-
console.log('Polling error:', err.message);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
bot.on('error', (err) => {
|
|
30
|
-
console.log('Error:', err.message);
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
bot.on('message', (msg) => {
|
|
34
|
-
console.log('\n=== MESSAGE RECEIVED ===');
|
|
35
|
-
console.log('Chat ID:', msg.chat.id);
|
|
36
|
-
console.log('From:', msg.from.username);
|
|
37
|
-
console.log('Text:', msg.text);
|
|
38
|
-
console.log('========================\n');
|
|
39
|
-
|
|
40
|
-
// 回复测试
|
|
41
|
-
bot
|
|
42
|
-
.sendMessage(msg.chat.id, 'Bot is working! Received: ' + msg.text)
|
|
43
|
-
.then(() => console.log('Reply sent'))
|
|
44
|
-
.catch((err) => console.log('Reply error:', err.message));
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
console.log('Waiting for messages...');
|
|
1
|
+
require('dotenv').config();
|
|
2
|
+
|
|
3
|
+
// 添加 .agent/node_modules 到搜索路径
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const agentNodeModules = path.join(process.cwd(), '.agent', 'node_modules');
|
|
6
|
+
if (!module.paths.includes(agentNodeModules)) {
|
|
7
|
+
module.paths.unshift(agentNodeModules);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const TelegramBot = require('node-telegram-bot-api');
|
|
11
|
+
|
|
12
|
+
const token = process.env.TELEGRAM_BOT_TOKEN;
|
|
13
|
+
|
|
14
|
+
console.log('Token:', token ? token.substring(0, 10) + '...' : 'NOT SET');
|
|
15
|
+
|
|
16
|
+
if (!token) {
|
|
17
|
+
console.log('ERROR: No token!');
|
|
18
|
+
process.exit(1);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const bot = new TelegramBot(token, { polling: true });
|
|
22
|
+
|
|
23
|
+
console.log('Bot created, starting polling...');
|
|
24
|
+
|
|
25
|
+
bot.on('polling_error', (err) => {
|
|
26
|
+
console.log('Polling error:', err.message);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
bot.on('error', (err) => {
|
|
30
|
+
console.log('Error:', err.message);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
bot.on('message', (msg) => {
|
|
34
|
+
console.log('\n=== MESSAGE RECEIVED ===');
|
|
35
|
+
console.log('Chat ID:', msg.chat.id);
|
|
36
|
+
console.log('From:', msg.from.username);
|
|
37
|
+
console.log('Text:', msg.text);
|
|
38
|
+
console.log('========================\n');
|
|
39
|
+
|
|
40
|
+
// 回复测试
|
|
41
|
+
bot
|
|
42
|
+
.sendMessage(msg.chat.id, 'Bot is working! Received: ' + msg.text)
|
|
43
|
+
.then(() => console.log('Reply sent'))
|
|
44
|
+
.catch((err) => console.log('Reply error:', err.message));
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
console.log('Waiting for messages...');
|
package/examples/test-tg.js
CHANGED
|
@@ -1,62 +1,62 @@
|
|
|
1
|
-
require('dotenv').config();
|
|
2
|
-
const { Framework } = require('../src');
|
|
3
|
-
|
|
4
|
-
async function main() {
|
|
5
|
-
const framework = new Framework({ debug: true });
|
|
6
|
-
|
|
7
|
-
await framework.bootstrap({
|
|
8
|
-
agentDir: process.cwd() + '/.agent',
|
|
9
|
-
aiConfig: {
|
|
10
|
-
provider: process.env.FOLIKO_PROVIDER || 'minimax',
|
|
11
|
-
model: process.env.FOLIKO_MODEL || 'MiniMax-M2.7',
|
|
12
|
-
baseURL: process.env.FOLIKO_BASE_URL || 'https://api.minimaxi.com/v1',
|
|
13
|
-
apiKey: process.env.MINIMAX_API_KEY || process.env.DEEPSEEK_API_KEY,
|
|
14
|
-
},
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
// 检查 telegram 插件
|
|
18
|
-
const tgPlugin = framework.pluginManager.get('telegram');
|
|
19
|
-
|
|
20
|
-
if (!tgPlugin) {
|
|
21
|
-
console.log('Telegram plugin NOT loaded!');
|
|
22
|
-
await framework.destroy();
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
console.log('\n=== Telegram Plugin Debug ===');
|
|
27
|
-
console.log('Bot token:', tgPlugin.config.botToken ? 'set' : 'NOT set');
|
|
28
|
-
console.log('Bot instance:', tgPlugin._bot ? 'exists' : 'NOT exists');
|
|
29
|
-
console.log('Group mode:', tgPlugin.config.groupMode);
|
|
30
|
-
console.log('===========================\n');
|
|
31
|
-
|
|
32
|
-
if (!tgPlugin._bot) {
|
|
33
|
-
console.log('Bot is not initialized. Check if TELEGRAM_BOT_TOKEN is valid.');
|
|
34
|
-
await framework.destroy();
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// 监听所有事件
|
|
39
|
-
tgPlugin._bot.on('message', (msg) => {
|
|
40
|
-
console.log('\n[MESSAGE RECEIVED]');
|
|
41
|
-
console.log(' chat.id:', msg.chat?.id);
|
|
42
|
-
console.log(' chat.type:', msg.chat?.type);
|
|
43
|
-
console.log(' from.username:', msg.from?.username);
|
|
44
|
-
console.log(' text:', msg.text);
|
|
45
|
-
console.log('===================\n');
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
tgPlugin._bot.on('polling_error', (err) => {
|
|
49
|
-
console.log('\n[POLLING ERROR]', err.message);
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
tgPlugin._bot.on('error', (err) => {
|
|
53
|
-
console.log('\n[BOT ERROR]', err.message);
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
console.log('Waiting for messages... Send a message to your bot.\n');
|
|
57
|
-
|
|
58
|
-
// 保持运行
|
|
59
|
-
await new Promise(() => {});
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
main().catch(console.error);
|
|
1
|
+
require('dotenv').config();
|
|
2
|
+
const { Framework } = require('../src');
|
|
3
|
+
|
|
4
|
+
async function main() {
|
|
5
|
+
const framework = new Framework({ debug: true });
|
|
6
|
+
|
|
7
|
+
await framework.bootstrap({
|
|
8
|
+
agentDir: process.cwd() + '/.agent',
|
|
9
|
+
aiConfig: {
|
|
10
|
+
provider: process.env.FOLIKO_PROVIDER || 'minimax',
|
|
11
|
+
model: process.env.FOLIKO_MODEL || 'MiniMax-M2.7',
|
|
12
|
+
baseURL: process.env.FOLIKO_BASE_URL || 'https://api.minimaxi.com/v1',
|
|
13
|
+
apiKey: process.env.MINIMAX_API_KEY || process.env.DEEPSEEK_API_KEY,
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
// 检查 telegram 插件
|
|
18
|
+
const tgPlugin = framework.pluginManager.get('telegram');
|
|
19
|
+
|
|
20
|
+
if (!tgPlugin) {
|
|
21
|
+
console.log('Telegram plugin NOT loaded!');
|
|
22
|
+
await framework.destroy();
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
console.log('\n=== Telegram Plugin Debug ===');
|
|
27
|
+
console.log('Bot token:', tgPlugin.config.botToken ? 'set' : 'NOT set');
|
|
28
|
+
console.log('Bot instance:', tgPlugin._bot ? 'exists' : 'NOT exists');
|
|
29
|
+
console.log('Group mode:', tgPlugin.config.groupMode);
|
|
30
|
+
console.log('===========================\n');
|
|
31
|
+
|
|
32
|
+
if (!tgPlugin._bot) {
|
|
33
|
+
console.log('Bot is not initialized. Check if TELEGRAM_BOT_TOKEN is valid.');
|
|
34
|
+
await framework.destroy();
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// 监听所有事件
|
|
39
|
+
tgPlugin._bot.on('message', (msg) => {
|
|
40
|
+
console.log('\n[MESSAGE RECEIVED]');
|
|
41
|
+
console.log(' chat.id:', msg.chat?.id);
|
|
42
|
+
console.log(' chat.type:', msg.chat?.type);
|
|
43
|
+
console.log(' from.username:', msg.from?.username);
|
|
44
|
+
console.log(' text:', msg.text);
|
|
45
|
+
console.log('===================\n');
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
tgPlugin._bot.on('polling_error', (err) => {
|
|
49
|
+
console.log('\n[POLLING ERROR]', err.message);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
tgPlugin._bot.on('error', (err) => {
|
|
53
|
+
console.log('\n[BOT ERROR]', err.message);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
console.log('Waiting for messages... Send a message to your bot.\n');
|
|
57
|
+
|
|
58
|
+
// 保持运行
|
|
59
|
+
await new Promise(() => {});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
main().catch(console.error);
|
package/examples/test-think.js
CHANGED
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
require('dotenv').config();
|
|
2
|
-
const { Framework } = require('../src');
|
|
3
|
-
|
|
4
|
-
async function main() {
|
|
5
|
-
const framework = new Framework({ debug: false });
|
|
6
|
-
|
|
7
|
-
await framework.bootstrap({
|
|
8
|
-
agentDir: process.cwd() + '/.agent',
|
|
9
|
-
aiConfig: {
|
|
10
|
-
provider: process.env.FOLIKO_PROVIDER || 'minimax',
|
|
11
|
-
model: process.env.FOLIKO_MODEL || 'MiniMax-M2.7',
|
|
12
|
-
baseURL: process.env.FOLIKO_BASE_URL || 'https://api.minimaxi.com/v1',
|
|
13
|
-
apiKey: process.env.MINIMAX_API_KEY || process.env.DEEPSEEK_API_KEY,
|
|
14
|
-
},
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
const agent = framework.createAgent({
|
|
18
|
-
name: 'FolikoAgent',
|
|
19
|
-
systemPrompt: '你是一个有帮助的助手。',
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
console.log(
|
|
23
|
-
'_mainAgent provider:',
|
|
24
|
-
framework._mainAgent ? framework._mainAgent.provider : 'none'
|
|
25
|
-
);
|
|
26
|
-
console.log(
|
|
27
|
-
'_mainAgent has apiKey:',
|
|
28
|
-
framework._mainAgent && framework._mainAgent.apiKey ? 'yes' : 'no'
|
|
29
|
-
);
|
|
30
|
-
|
|
31
|
-
const tools = framework.getTools();
|
|
32
|
-
const thinkTool = tools.find((t) => t.name === 'think_now');
|
|
33
|
-
|
|
34
|
-
if (thinkTool) {
|
|
35
|
-
const result = await thinkTool.execute({ mode: 'reflect', topic: '测试' });
|
|
36
|
-
console.log('think_now success:', result.success);
|
|
37
|
-
if (result.success === false) console.log('Error:', result.error);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
await framework.destroy();
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
main().catch(console.error);
|
|
1
|
+
require('dotenv').config();
|
|
2
|
+
const { Framework } = require('../src');
|
|
3
|
+
|
|
4
|
+
async function main() {
|
|
5
|
+
const framework = new Framework({ debug: false });
|
|
6
|
+
|
|
7
|
+
await framework.bootstrap({
|
|
8
|
+
agentDir: process.cwd() + '/.agent',
|
|
9
|
+
aiConfig: {
|
|
10
|
+
provider: process.env.FOLIKO_PROVIDER || 'minimax',
|
|
11
|
+
model: process.env.FOLIKO_MODEL || 'MiniMax-M2.7',
|
|
12
|
+
baseURL: process.env.FOLIKO_BASE_URL || 'https://api.minimaxi.com/v1',
|
|
13
|
+
apiKey: process.env.MINIMAX_API_KEY || process.env.DEEPSEEK_API_KEY,
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
const agent = framework.createAgent({
|
|
18
|
+
name: 'FolikoAgent',
|
|
19
|
+
systemPrompt: '你是一个有帮助的助手。',
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
console.log(
|
|
23
|
+
'_mainAgent provider:',
|
|
24
|
+
framework._mainAgent ? framework._mainAgent.provider : 'none'
|
|
25
|
+
);
|
|
26
|
+
console.log(
|
|
27
|
+
'_mainAgent has apiKey:',
|
|
28
|
+
framework._mainAgent && framework._mainAgent.apiKey ? 'yes' : 'no'
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
const tools = framework.getTools();
|
|
32
|
+
const thinkTool = tools.find((t) => t.name === 'think_now');
|
|
33
|
+
|
|
34
|
+
if (thinkTool) {
|
|
35
|
+
const result = await thinkTool.execute({ mode: 'reflect', topic: '测试' });
|
|
36
|
+
console.log('think_now success:', result.success);
|
|
37
|
+
if (result.success === false) console.log('Error:', result.error);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
await framework.destroy();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
main().catch(console.error);
|
|
@@ -1,103 +1,103 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Web 插件测试示例
|
|
3
|
-
* 测试路由注册和请求响应
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
const { WebPlugin } = require('../plugins/web-plugin');
|
|
7
|
-
|
|
8
|
-
async function test() {
|
|
9
|
-
console.log('=== Web 插件测试 ===\n');
|
|
10
|
-
|
|
11
|
-
// 1. 创建插件
|
|
12
|
-
const plugin = new WebPlugin();
|
|
13
|
-
const mockFramework = {
|
|
14
|
-
registerTool: (tool) => console.log(`[工具注册] ${tool.name}`),
|
|
15
|
-
_agents: [],
|
|
16
|
-
pluginManager: { get: () => null },
|
|
17
|
-
};
|
|
18
|
-
plugin.install(mockFramework);
|
|
19
|
-
|
|
20
|
-
// 2. 启动服务
|
|
21
|
-
console.log('\n[1] 启动 Web 服务...');
|
|
22
|
-
const startResult = await plugin._startServer(3099);
|
|
23
|
-
console.log('启动结果:', startResult.success ? '成功' : '失败');
|
|
24
|
-
console.log('服务地址: http://localhost:3099\n');
|
|
25
|
-
|
|
26
|
-
// 3. 注册测试路由
|
|
27
|
-
console.log('[2] 注册测试路由...');
|
|
28
|
-
|
|
29
|
-
// 返回固定字符串
|
|
30
|
-
await plugin._registerRoute('GET', '/test', 'return "1232432"', '返回固定字符串');
|
|
31
|
-
console.log('注册: GET /test -> return "1232432"');
|
|
32
|
-
|
|
33
|
-
// 返回 JSON
|
|
34
|
-
await plugin._registerRoute('GET', '/json', 'return { hello: "world", code: 200 }', '返回 JSON');
|
|
35
|
-
console.log('注册: GET /json -> return { hello: "world", code: 200 }');
|
|
36
|
-
|
|
37
|
-
// 带参数
|
|
38
|
-
await plugin._registerRoute(
|
|
39
|
-
'GET',
|
|
40
|
-
'/user/:id',
|
|
41
|
-
'return { userId: context.params.id }',
|
|
42
|
-
'路径参数'
|
|
43
|
-
);
|
|
44
|
-
console.log('注册: GET /user/:id -> return { userId: context.params.id }');
|
|
45
|
-
|
|
46
|
-
// POST 路由
|
|
47
|
-
await plugin._registerRoute('POST', '/echo', 'return { received: context.body }', '回显 body');
|
|
48
|
-
console.log('注册: POST /echo -> return { received: context.body }');
|
|
49
|
-
|
|
50
|
-
// 4. 等待服务就绪
|
|
51
|
-
await new Promise((r) => setTimeout(r, 500));
|
|
52
|
-
|
|
53
|
-
// 5. 测试各路由
|
|
54
|
-
console.log('\n[3] 测试路由响应...\n');
|
|
55
|
-
|
|
56
|
-
// GET /test
|
|
57
|
-
console.log('GET /test:');
|
|
58
|
-
const r1 = await plugin._sendRequest('GET', '/test');
|
|
59
|
-
console.log(' 状态:', r1.status);
|
|
60
|
-
console.log(' 响应:', JSON.stringify(r1.body));
|
|
61
|
-
console.log();
|
|
62
|
-
|
|
63
|
-
// GET /json
|
|
64
|
-
console.log('GET /json:');
|
|
65
|
-
const r2 = await plugin._sendRequest('GET', '/json');
|
|
66
|
-
console.log(' 状态:', r2.status);
|
|
67
|
-
console.log(' 响应:', JSON.stringify(r2.body));
|
|
68
|
-
console.log();
|
|
69
|
-
|
|
70
|
-
// GET /user/123
|
|
71
|
-
console.log('GET /user/123:');
|
|
72
|
-
const r3 = await plugin._sendRequest('GET', '/user/123');
|
|
73
|
-
console.log(' 状态:', r3.status);
|
|
74
|
-
console.log(' 响应:', JSON.stringify(r3.body));
|
|
75
|
-
console.log();
|
|
76
|
-
|
|
77
|
-
// POST /echo
|
|
78
|
-
console.log('POST /echo (body: { name: "test" }):');
|
|
79
|
-
const r4 = await plugin._sendRequest('POST', '/echo', { name: 'test' });
|
|
80
|
-
console.log(' 状态:', r4.status);
|
|
81
|
-
console.log(' 响应:', JSON.stringify(r4.body));
|
|
82
|
-
console.log();
|
|
83
|
-
|
|
84
|
-
// 6. 列出所有路由
|
|
85
|
-
console.log('[4] 已注册的路由:');
|
|
86
|
-
const routes = plugin._listRoutes();
|
|
87
|
-
routes.routes.forEach((r) => {
|
|
88
|
-
console.log(` ${r.method} ${r.path} - ${r.description}`);
|
|
89
|
-
});
|
|
90
|
-
routes.webhooks.forEach((w) => {
|
|
91
|
-
console.log(` WEBHOOK ${w.path}`);
|
|
92
|
-
});
|
|
93
|
-
routes.statics.forEach((s) => {
|
|
94
|
-
console.log(` STATIC ${s.path} -> ${s.folder}`);
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
// 7. 停止服务
|
|
98
|
-
console.log('\n[5] 停止服务...');
|
|
99
|
-
await plugin._stopServer();
|
|
100
|
-
console.log('测试完成!');
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
test().catch(console.error);
|
|
1
|
+
/**
|
|
2
|
+
* Web 插件测试示例
|
|
3
|
+
* 测试路由注册和请求响应
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
const { WebPlugin } = require('../plugins/web-plugin');
|
|
7
|
+
|
|
8
|
+
async function test() {
|
|
9
|
+
console.log('=== Web 插件测试 ===\n');
|
|
10
|
+
|
|
11
|
+
// 1. 创建插件
|
|
12
|
+
const plugin = new WebPlugin();
|
|
13
|
+
const mockFramework = {
|
|
14
|
+
registerTool: (tool) => console.log(`[工具注册] ${tool.name}`),
|
|
15
|
+
_agents: [],
|
|
16
|
+
pluginManager: { get: () => null },
|
|
17
|
+
};
|
|
18
|
+
plugin.install(mockFramework);
|
|
19
|
+
|
|
20
|
+
// 2. 启动服务
|
|
21
|
+
console.log('\n[1] 启动 Web 服务...');
|
|
22
|
+
const startResult = await plugin._startServer(3099);
|
|
23
|
+
console.log('启动结果:', startResult.success ? '成功' : '失败');
|
|
24
|
+
console.log('服务地址: http://localhost:3099\n');
|
|
25
|
+
|
|
26
|
+
// 3. 注册测试路由
|
|
27
|
+
console.log('[2] 注册测试路由...');
|
|
28
|
+
|
|
29
|
+
// 返回固定字符串
|
|
30
|
+
await plugin._registerRoute('GET', '/test', 'return "1232432"', '返回固定字符串');
|
|
31
|
+
console.log('注册: GET /test -> return "1232432"');
|
|
32
|
+
|
|
33
|
+
// 返回 JSON
|
|
34
|
+
await plugin._registerRoute('GET', '/json', 'return { hello: "world", code: 200 }', '返回 JSON');
|
|
35
|
+
console.log('注册: GET /json -> return { hello: "world", code: 200 }');
|
|
36
|
+
|
|
37
|
+
// 带参数
|
|
38
|
+
await plugin._registerRoute(
|
|
39
|
+
'GET',
|
|
40
|
+
'/user/:id',
|
|
41
|
+
'return { userId: context.params.id }',
|
|
42
|
+
'路径参数'
|
|
43
|
+
);
|
|
44
|
+
console.log('注册: GET /user/:id -> return { userId: context.params.id }');
|
|
45
|
+
|
|
46
|
+
// POST 路由
|
|
47
|
+
await plugin._registerRoute('POST', '/echo', 'return { received: context.body }', '回显 body');
|
|
48
|
+
console.log('注册: POST /echo -> return { received: context.body }');
|
|
49
|
+
|
|
50
|
+
// 4. 等待服务就绪
|
|
51
|
+
await new Promise((r) => setTimeout(r, 500));
|
|
52
|
+
|
|
53
|
+
// 5. 测试各路由
|
|
54
|
+
console.log('\n[3] 测试路由响应...\n');
|
|
55
|
+
|
|
56
|
+
// GET /test
|
|
57
|
+
console.log('GET /test:');
|
|
58
|
+
const r1 = await plugin._sendRequest('GET', '/test');
|
|
59
|
+
console.log(' 状态:', r1.status);
|
|
60
|
+
console.log(' 响应:', JSON.stringify(r1.body));
|
|
61
|
+
console.log();
|
|
62
|
+
|
|
63
|
+
// GET /json
|
|
64
|
+
console.log('GET /json:');
|
|
65
|
+
const r2 = await plugin._sendRequest('GET', '/json');
|
|
66
|
+
console.log(' 状态:', r2.status);
|
|
67
|
+
console.log(' 响应:', JSON.stringify(r2.body));
|
|
68
|
+
console.log();
|
|
69
|
+
|
|
70
|
+
// GET /user/123
|
|
71
|
+
console.log('GET /user/123:');
|
|
72
|
+
const r3 = await plugin._sendRequest('GET', '/user/123');
|
|
73
|
+
console.log(' 状态:', r3.status);
|
|
74
|
+
console.log(' 响应:', JSON.stringify(r3.body));
|
|
75
|
+
console.log();
|
|
76
|
+
|
|
77
|
+
// POST /echo
|
|
78
|
+
console.log('POST /echo (body: { name: "test" }):');
|
|
79
|
+
const r4 = await plugin._sendRequest('POST', '/echo', { name: 'test' });
|
|
80
|
+
console.log(' 状态:', r4.status);
|
|
81
|
+
console.log(' 响应:', JSON.stringify(r4.body));
|
|
82
|
+
console.log();
|
|
83
|
+
|
|
84
|
+
// 6. 列出所有路由
|
|
85
|
+
console.log('[4] 已注册的路由:');
|
|
86
|
+
const routes = plugin._listRoutes();
|
|
87
|
+
routes.routes.forEach((r) => {
|
|
88
|
+
console.log(` ${r.method} ${r.path} - ${r.description}`);
|
|
89
|
+
});
|
|
90
|
+
routes.webhooks.forEach((w) => {
|
|
91
|
+
console.log(` WEBHOOK ${w.path}`);
|
|
92
|
+
});
|
|
93
|
+
routes.statics.forEach((s) => {
|
|
94
|
+
console.log(` STATIC ${s.path} -> ${s.folder}`);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
// 7. 停止服务
|
|
98
|
+
console.log('\n[5] 停止服务...');
|
|
99
|
+
await plugin._stopServer();
|
|
100
|
+
console.log('测试完成!');
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
test().catch(console.error);
|