foliko 1.0.2 → 1.0.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "foliko",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "简约的插件化 Agent 框架",
5
5
  "main": "src/index.js",
6
6
  "bin": {
@@ -103,6 +103,14 @@ class ThinkPlugin extends Plugin {
103
103
  return { success: false, error: 'No active agent found' }
104
104
  }
105
105
 
106
+ // 检查 agent 是否有 AI 配置
107
+ if (!agent.apiKey && !this._framework.pluginManager.get('ai')) {
108
+ return {
109
+ success: false,
110
+ error: 'AI 未配置。请在 .agent/ai.json 或环境变量中配置 AI API Key。'
111
+ }
112
+ }
113
+
106
114
  const reflectPrompt = this._buildReflectPrompt(mode, depth, topic)
107
115
  const result = await agent.chat(reflectPrompt)
108
116
 
@@ -296,6 +304,12 @@ ${topic || '接下来的行动'}
296
304
  * 获取当前活跃的 Agent
297
305
  */
298
306
  _getActiveAgent() {
307
+ // 优先使用主 Agent
308
+ if (this._framework._mainAgent) {
309
+ return this._framework._mainAgent
310
+ }
311
+
312
+ // 否则找一个空闲的 Agent
299
313
  if (this._framework._agents && this._framework._agents.length > 0) {
300
314
  for (let i = this._framework._agents.length - 1; i >= 0; i--) {
301
315
  const agent = this._framework._agents[i]
@@ -0,0 +1,50 @@
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
+ // 检查 telegram 插件
18
+ const tgPlugin = framework.pluginManager.get('telegram');
19
+ console.log('Telegram plugin loaded:', !!tgPlugin);
20
+
21
+ if (tgPlugin) {
22
+ const status = tgPlugin.getStatus();
23
+ console.log('Telegram status:', status);
24
+
25
+ // 检查 Bot 状态
26
+ if (tgPlugin._bot) {
27
+ console.log('Bot is running');
28
+
29
+ // 添加一个测试处理器来查看接收到的消息
30
+ tgPlugin._bot.on('message', (msg) => {
31
+ console.log('=== Received message ===');
32
+ console.log('Chat ID:', msg.chat?.id);
33
+ console.log('Chat type:', msg.chat?.type);
34
+ console.log('From:', msg.from?.username);
35
+ console.log('Text:', msg.text);
36
+ console.log('=========================');
37
+ });
38
+ } else {
39
+ console.log('Bot is NOT running');
40
+ }
41
+ }
42
+
43
+ console.log('\nBot is running. Send a message to test...');
44
+ console.log('Press Ctrl+C to stop.\n');
45
+
46
+ // 保持进程运行
47
+ await new Promise(() => {});
48
+ }
49
+
50
+ main().catch(console.error);
@@ -0,0 +1,46 @@
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.sendMessage(msg.chat.id, 'Bot is working! Received: ' + msg.text)
42
+ .then(() => console.log('Reply sent'))
43
+ .catch(err => console.log('Reply error:', err.message));
44
+ });
45
+
46
+ console.log('Waiting for messages...');
package/test-tg.js ADDED
@@ -0,0 +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);
package/test-think.js ADDED
@@ -0,0 +1,37 @@
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('_mainAgent provider:', framework._mainAgent ? framework._mainAgent.provider : 'none');
23
+ console.log('_mainAgent has apiKey:', framework._mainAgent && framework._mainAgent.apiKey ? 'yes' : 'no');
24
+
25
+ const tools = framework.getTools();
26
+ const thinkTool = tools.find(t => t.name === 'think_now');
27
+
28
+ if (thinkTool) {
29
+ const result = await thinkTool.execute({ mode: 'reflect', topic: '测试' });
30
+ console.log('think_now success:', result.success);
31
+ if (result.success === false) console.log('Error:', result.error);
32
+ }
33
+
34
+ await framework.destroy();
35
+ }
36
+
37
+ main().catch(console.error);