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-chat.js
CHANGED
|
@@ -1,137 +1,137 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 持续聊天测试
|
|
3
|
-
* 运行后可以在终端输入消息与 Agent 对话
|
|
4
|
-
* 支持多行输入:连续按两次回车结束输入
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
const { Framework } = require('../src');
|
|
8
|
-
const readline = require('readline');
|
|
9
|
-
require('dotenv').config();
|
|
10
|
-
|
|
11
|
-
async function main() {
|
|
12
|
-
console.log('=== Foliko 持续聊天测试 ===\n');
|
|
13
|
-
console.log('输入消息与 Agent 对话,输入 exit 或 quit 退出');
|
|
14
|
-
console.log('多行输入:按两次回车结束,或输入 !! 立即结束\n');
|
|
15
|
-
|
|
16
|
-
// 创建框架
|
|
17
|
-
const framework = new Framework({ debug: false });
|
|
18
|
-
|
|
19
|
-
// Bootstrap
|
|
20
|
-
await framework.bootstrap({
|
|
21
|
-
agentDir: './.agent',
|
|
22
|
-
aiConfig: {
|
|
23
|
-
provider: 'minimax',
|
|
24
|
-
model: 'MiniMax-M2.7',
|
|
25
|
-
baseURL: 'https://api.minimaxi.com/v1',
|
|
26
|
-
apiKey: process.env.MINIMAX_API_KEY,
|
|
27
|
-
},
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
console.log('框架已就绪\n');
|
|
31
|
-
|
|
32
|
-
// 创建 Agent
|
|
33
|
-
const agent = framework.createAgent({
|
|
34
|
-
name: 'TestAgent',
|
|
35
|
-
systemPrompt: '你是一个有帮助的助手,擅长回答问题和执行任务。',
|
|
36
|
-
sharedPrompt: '工作目录: {{WORK_DIR}}',
|
|
37
|
-
metadata: {
|
|
38
|
-
projectName: 'Foliko',
|
|
39
|
-
version: '1.0.0',
|
|
40
|
-
},
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
// 创建命令行界面
|
|
44
|
-
const rl = readline.createInterface({
|
|
45
|
-
input: process.stdin,
|
|
46
|
-
output: process.stdout,
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
// 多行输入函数
|
|
50
|
-
const readMultiline = () => {
|
|
51
|
-
return new Promise((resolve) => {
|
|
52
|
-
const lines = [];
|
|
53
|
-
|
|
54
|
-
const question = () => {
|
|
55
|
-
rl.question(lines.length === 0 ? '> ' : '- ', (input) => {
|
|
56
|
-
// 输入 !! 立即结束
|
|
57
|
-
if (input.trim() === '!!') {
|
|
58
|
-
const result = lines.join('\n').trim();
|
|
59
|
-
resolve(result);
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
// 空行结束输入
|
|
63
|
-
if (input.trim() === '') {
|
|
64
|
-
const result = lines.join('\n').trim();
|
|
65
|
-
resolve(result);
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
lines.push(input);
|
|
69
|
-
question();
|
|
70
|
-
});
|
|
71
|
-
};
|
|
72
|
-
question();
|
|
73
|
-
});
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
// 提问函数
|
|
77
|
-
const ask = async (question) => {
|
|
78
|
-
try {
|
|
79
|
-
console.log('\n[Agent 思考中...]\n');
|
|
80
|
-
|
|
81
|
-
// 使用流式响应
|
|
82
|
-
let fullResponse = '';
|
|
83
|
-
for await (const chunk of agent.chatStream(question)) {
|
|
84
|
-
if (chunk.type === 'text') {
|
|
85
|
-
process.stdout.write(chunk.text);
|
|
86
|
-
fullResponse += chunk.text;
|
|
87
|
-
} else if (chunk.type === 'tool-call') {
|
|
88
|
-
console.log('\n\n[工具调用]', chunk.toolName);
|
|
89
|
-
} else if (chunk.type === 'tool-result') {
|
|
90
|
-
console.log('\n[工具结果]', JSON.stringify(chunk.result).substring(0, 100));
|
|
91
|
-
} else if (chunk.type === 'error') {
|
|
92
|
-
console.error('\n[错误]', chunk.error);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
console.log('\n');
|
|
97
|
-
return fullResponse;
|
|
98
|
-
} catch (err) {
|
|
99
|
-
console.error('\n[错误]', err.message);
|
|
100
|
-
return '';
|
|
101
|
-
}
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
// 欢迎消息
|
|
105
|
-
console.log('Agent: 你好!有什么可以帮助你的吗?\n');
|
|
106
|
-
|
|
107
|
-
// 初始任务:让 LLM 注册一个测试路由
|
|
108
|
-
console.log('\n[系统] 指示 Agent 注册一个 GET /test 路由,返回 "1232432"\n');
|
|
109
|
-
await ask(
|
|
110
|
-
'请帮我注册一个 GET 路由:\n- 路径:/test\n- 处理函数:return "1232432"\n\n注册完成后,用 web_request 工具测试访问这个路由,确认返回 "1232432"'
|
|
111
|
-
);
|
|
112
|
-
|
|
113
|
-
console.log('\n--- 测试完成,现在你可以继续对话 ---\n');
|
|
114
|
-
|
|
115
|
-
// 主循环
|
|
116
|
-
const promptUser = async () => {
|
|
117
|
-
const input = await readMultiline();
|
|
118
|
-
const trimmed = input.trim();
|
|
119
|
-
|
|
120
|
-
if (trimmed.toLowerCase() === 'exit' || trimmed.toLowerCase() === 'quit') {
|
|
121
|
-
console.log('\n再见!');
|
|
122
|
-
await framework.destroy();
|
|
123
|
-
rl.close();
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
if (trimmed) {
|
|
128
|
-
await ask(trimmed);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
promptUser();
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
promptUser();
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
main().catch(console.error);
|
|
1
|
+
/**
|
|
2
|
+
* 持续聊天测试
|
|
3
|
+
* 运行后可以在终端输入消息与 Agent 对话
|
|
4
|
+
* 支持多行输入:连续按两次回车结束输入
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const { Framework } = require('../src');
|
|
8
|
+
const readline = require('readline');
|
|
9
|
+
require('dotenv').config();
|
|
10
|
+
|
|
11
|
+
async function main() {
|
|
12
|
+
console.log('=== Foliko 持续聊天测试 ===\n');
|
|
13
|
+
console.log('输入消息与 Agent 对话,输入 exit 或 quit 退出');
|
|
14
|
+
console.log('多行输入:按两次回车结束,或输入 !! 立即结束\n');
|
|
15
|
+
|
|
16
|
+
// 创建框架
|
|
17
|
+
const framework = new Framework({ debug: false });
|
|
18
|
+
|
|
19
|
+
// Bootstrap
|
|
20
|
+
await framework.bootstrap({
|
|
21
|
+
agentDir: './.agent',
|
|
22
|
+
aiConfig: {
|
|
23
|
+
provider: 'minimax',
|
|
24
|
+
model: 'MiniMax-M2.7',
|
|
25
|
+
baseURL: 'https://api.minimaxi.com/v1',
|
|
26
|
+
apiKey: process.env.MINIMAX_API_KEY,
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
console.log('框架已就绪\n');
|
|
31
|
+
|
|
32
|
+
// 创建 Agent
|
|
33
|
+
const agent = framework.createAgent({
|
|
34
|
+
name: 'TestAgent',
|
|
35
|
+
systemPrompt: '你是一个有帮助的助手,擅长回答问题和执行任务。',
|
|
36
|
+
sharedPrompt: '工作目录: {{WORK_DIR}}',
|
|
37
|
+
metadata: {
|
|
38
|
+
projectName: 'Foliko',
|
|
39
|
+
version: '1.0.0',
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
// 创建命令行界面
|
|
44
|
+
const rl = readline.createInterface({
|
|
45
|
+
input: process.stdin,
|
|
46
|
+
output: process.stdout,
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
// 多行输入函数
|
|
50
|
+
const readMultiline = () => {
|
|
51
|
+
return new Promise((resolve) => {
|
|
52
|
+
const lines = [];
|
|
53
|
+
|
|
54
|
+
const question = () => {
|
|
55
|
+
rl.question(lines.length === 0 ? '> ' : '- ', (input) => {
|
|
56
|
+
// 输入 !! 立即结束
|
|
57
|
+
if (input.trim() === '!!') {
|
|
58
|
+
const result = lines.join('\n').trim();
|
|
59
|
+
resolve(result);
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
// 空行结束输入
|
|
63
|
+
if (input.trim() === '') {
|
|
64
|
+
const result = lines.join('\n').trim();
|
|
65
|
+
resolve(result);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
lines.push(input);
|
|
69
|
+
question();
|
|
70
|
+
});
|
|
71
|
+
};
|
|
72
|
+
question();
|
|
73
|
+
});
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
// 提问函数
|
|
77
|
+
const ask = async (question) => {
|
|
78
|
+
try {
|
|
79
|
+
console.log('\n[Agent 思考中...]\n');
|
|
80
|
+
|
|
81
|
+
// 使用流式响应
|
|
82
|
+
let fullResponse = '';
|
|
83
|
+
for await (const chunk of agent.chatStream(question)) {
|
|
84
|
+
if (chunk.type === 'text') {
|
|
85
|
+
process.stdout.write(chunk.text);
|
|
86
|
+
fullResponse += chunk.text;
|
|
87
|
+
} else if (chunk.type === 'tool-call') {
|
|
88
|
+
console.log('\n\n[工具调用]', chunk.toolName);
|
|
89
|
+
} else if (chunk.type === 'tool-result') {
|
|
90
|
+
console.log('\n[工具结果]', JSON.stringify(chunk.result).substring(0, 100));
|
|
91
|
+
} else if (chunk.type === 'error') {
|
|
92
|
+
console.error('\n[错误]', chunk.error);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
console.log('\n');
|
|
97
|
+
return fullResponse;
|
|
98
|
+
} catch (err) {
|
|
99
|
+
console.error('\n[错误]', err.message);
|
|
100
|
+
return '';
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
// 欢迎消息
|
|
105
|
+
console.log('Agent: 你好!有什么可以帮助你的吗?\n');
|
|
106
|
+
|
|
107
|
+
// 初始任务:让 LLM 注册一个测试路由
|
|
108
|
+
console.log('\n[系统] 指示 Agent 注册一个 GET /test 路由,返回 "1232432"\n');
|
|
109
|
+
await ask(
|
|
110
|
+
'请帮我注册一个 GET 路由:\n- 路径:/test\n- 处理函数:return "1232432"\n\n注册完成后,用 web_request 工具测试访问这个路由,确认返回 "1232432"'
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
console.log('\n--- 测试完成,现在你可以继续对话 ---\n');
|
|
114
|
+
|
|
115
|
+
// 主循环
|
|
116
|
+
const promptUser = async () => {
|
|
117
|
+
const input = await readMultiline();
|
|
118
|
+
const trimmed = input.trim();
|
|
119
|
+
|
|
120
|
+
if (trimmed.toLowerCase() === 'exit' || trimmed.toLowerCase() === 'quit') {
|
|
121
|
+
console.log('\n再见!');
|
|
122
|
+
await framework.destroy();
|
|
123
|
+
rl.close();
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (trimmed) {
|
|
128
|
+
await ask(trimmed);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
promptUser();
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
promptUser();
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
main().catch(console.error);
|
package/examples/test-mcp.js
CHANGED
|
@@ -1,85 +1,85 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* MCP 插件测试脚本
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
const { Framework } = require('../src');
|
|
6
|
-
const { MCPExecutorPlugin } = require('../src/executors/mcp-executor');
|
|
7
|
-
|
|
8
|
-
async function test() {
|
|
9
|
-
console.log('=== MCP Plugin Test ===\n');
|
|
10
|
-
|
|
11
|
-
console.log('1. Creating framework...');
|
|
12
|
-
const framework = new Framework({ debug: true });
|
|
13
|
-
|
|
14
|
-
console.log('2. Creating MCP plugin with fetch server...');
|
|
15
|
-
const mcpPlugin = new MCPExecutorPlugin({
|
|
16
|
-
servers: [
|
|
17
|
-
{
|
|
18
|
-
name: 'fetch',
|
|
19
|
-
command: 'uvx',
|
|
20
|
-
args: ['mcp-server-fetch'],
|
|
21
|
-
},
|
|
22
|
-
],
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
console.log('3. Loading MCP plugin...');
|
|
26
|
-
await framework.loadPlugin(mcpPlugin);
|
|
27
|
-
|
|
28
|
-
console.log('4. Starting framework...');
|
|
29
|
-
await framework.pluginManager.startAll();
|
|
30
|
-
|
|
31
|
-
// 等待 MCP 服务器连接
|
|
32
|
-
console.log('\n5. Waiting for MCP connection...');
|
|
33
|
-
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
34
|
-
|
|
35
|
-
console.log('\n6. Listing MCP servers...');
|
|
36
|
-
const servers = mcpPlugin.getServers();
|
|
37
|
-
console.log('Servers:', JSON.stringify(servers, null, 2));
|
|
38
|
-
|
|
39
|
-
console.log('\n7. Listing MCP tools...');
|
|
40
|
-
const mcpTools = framework.getTools().filter((t) => t.name.startsWith('mcp_'));
|
|
41
|
-
console.log(
|
|
42
|
-
'MCP Tools:',
|
|
43
|
-
mcpTools.map((t) => t.name)
|
|
44
|
-
);
|
|
45
|
-
|
|
46
|
-
if (mcpTools.length > 0) {
|
|
47
|
-
console.log('\n8. Testing mcp_list_servers...');
|
|
48
|
-
const listResult = await framework.executeTool('mcp_list_servers', {});
|
|
49
|
-
console.log('List Servers Result:', JSON.stringify(listResult, null, 2));
|
|
50
|
-
|
|
51
|
-
console.log('\n9. Testing mcp_tool_schema...');
|
|
52
|
-
const schemaResult = await framework.executeTool('mcp_tool_schema', {
|
|
53
|
-
server: 'fetch',
|
|
54
|
-
tool: 'fetch',
|
|
55
|
-
});
|
|
56
|
-
console.log('Tool Schema:', JSON.stringify(schemaResult, null, 2));
|
|
57
|
-
|
|
58
|
-
console.log('\n10. Testing mcp_call (fetch a webpage)...');
|
|
59
|
-
const callResult = await framework.executeTool('mcp_call', {
|
|
60
|
-
server: 'fetch',
|
|
61
|
-
tool: 'fetch',
|
|
62
|
-
args_json: JSON.stringify({ url: 'https://httpbin.org/get' }),
|
|
63
|
-
});
|
|
64
|
-
console.log(
|
|
65
|
-
'Fetch Result (truncated):',
|
|
66
|
-
JSON.stringify(callResult, null, 2).substring(0, 500) + '...'
|
|
67
|
-
);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
console.log('\n11. Destroying framework...');
|
|
71
|
-
await framework.destroy();
|
|
72
|
-
|
|
73
|
-
console.log('\n=== Test Complete ===');
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
test()
|
|
77
|
-
.then(() => {
|
|
78
|
-
console.log('\n✓ Test completed successfully');
|
|
79
|
-
process.exit(0);
|
|
80
|
-
})
|
|
81
|
-
.catch((err) => {
|
|
82
|
-
console.error('\n✗ Test failed:', err.message);
|
|
83
|
-
console.error(err.stack);
|
|
84
|
-
process.exit(1);
|
|
85
|
-
});
|
|
1
|
+
/**
|
|
2
|
+
* MCP 插件测试脚本
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
const { Framework } = require('../src');
|
|
6
|
+
const { MCPExecutorPlugin } = require('../src/executors/mcp-executor');
|
|
7
|
+
|
|
8
|
+
async function test() {
|
|
9
|
+
console.log('=== MCP Plugin Test ===\n');
|
|
10
|
+
|
|
11
|
+
console.log('1. Creating framework...');
|
|
12
|
+
const framework = new Framework({ debug: true });
|
|
13
|
+
|
|
14
|
+
console.log('2. Creating MCP plugin with fetch server...');
|
|
15
|
+
const mcpPlugin = new MCPExecutorPlugin({
|
|
16
|
+
servers: [
|
|
17
|
+
{
|
|
18
|
+
name: 'fetch',
|
|
19
|
+
command: 'uvx',
|
|
20
|
+
args: ['mcp-server-fetch'],
|
|
21
|
+
},
|
|
22
|
+
],
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
console.log('3. Loading MCP plugin...');
|
|
26
|
+
await framework.loadPlugin(mcpPlugin);
|
|
27
|
+
|
|
28
|
+
console.log('4. Starting framework...');
|
|
29
|
+
await framework.pluginManager.startAll();
|
|
30
|
+
|
|
31
|
+
// 等待 MCP 服务器连接
|
|
32
|
+
console.log('\n5. Waiting for MCP connection...');
|
|
33
|
+
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
34
|
+
|
|
35
|
+
console.log('\n6. Listing MCP servers...');
|
|
36
|
+
const servers = mcpPlugin.getServers();
|
|
37
|
+
console.log('Servers:', JSON.stringify(servers, null, 2));
|
|
38
|
+
|
|
39
|
+
console.log('\n7. Listing MCP tools...');
|
|
40
|
+
const mcpTools = framework.getTools().filter((t) => t.name.startsWith('mcp_'));
|
|
41
|
+
console.log(
|
|
42
|
+
'MCP Tools:',
|
|
43
|
+
mcpTools.map((t) => t.name)
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
if (mcpTools.length > 0) {
|
|
47
|
+
console.log('\n8. Testing mcp_list_servers...');
|
|
48
|
+
const listResult = await framework.executeTool('mcp_list_servers', {});
|
|
49
|
+
console.log('List Servers Result:', JSON.stringify(listResult, null, 2));
|
|
50
|
+
|
|
51
|
+
console.log('\n9. Testing mcp_tool_schema...');
|
|
52
|
+
const schemaResult = await framework.executeTool('mcp_tool_schema', {
|
|
53
|
+
server: 'fetch',
|
|
54
|
+
tool: 'fetch',
|
|
55
|
+
});
|
|
56
|
+
console.log('Tool Schema:', JSON.stringify(schemaResult, null, 2));
|
|
57
|
+
|
|
58
|
+
console.log('\n10. Testing mcp_call (fetch a webpage)...');
|
|
59
|
+
const callResult = await framework.executeTool('mcp_call', {
|
|
60
|
+
server: 'fetch',
|
|
61
|
+
tool: 'fetch',
|
|
62
|
+
args_json: JSON.stringify({ url: 'https://httpbin.org/get' }),
|
|
63
|
+
});
|
|
64
|
+
console.log(
|
|
65
|
+
'Fetch Result (truncated):',
|
|
66
|
+
JSON.stringify(callResult, null, 2).substring(0, 500) + '...'
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
console.log('\n11. Destroying framework...');
|
|
71
|
+
await framework.destroy();
|
|
72
|
+
|
|
73
|
+
console.log('\n=== Test Complete ===');
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
test()
|
|
77
|
+
.then(() => {
|
|
78
|
+
console.log('\n✓ Test completed successfully');
|
|
79
|
+
process.exit(0);
|
|
80
|
+
})
|
|
81
|
+
.catch((err) => {
|
|
82
|
+
console.error('\n✗ Test failed:', err.message);
|
|
83
|
+
console.error(err.stack);
|
|
84
|
+
process.exit(1);
|
|
85
|
+
});
|
package/examples/test-reload.js
CHANGED
|
@@ -1,59 +1,59 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* MCP mcp_reload 功能测试
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
const { Framework } = require('../src');
|
|
6
|
-
const { MCPExecutorPlugin } = require('../src/executors/mcp-executor');
|
|
7
|
-
const fs = require('fs');
|
|
8
|
-
const path = require('path');
|
|
9
|
-
|
|
10
|
-
async function test() {
|
|
11
|
-
console.log('=== Testing mcp_reload ===\n');
|
|
12
|
-
|
|
13
|
-
// 创建框架
|
|
14
|
-
const framework = new Framework({ debug: true });
|
|
15
|
-
|
|
16
|
-
// 创建 MCP 插件
|
|
17
|
-
const mcpPlugin = new MCPExecutorPlugin({
|
|
18
|
-
servers: [{ name: 'fetch', command: 'uvx', args: ['mcp-server-fetch'] }],
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
// 加载并启动
|
|
22
|
-
await framework.loadPlugin(mcpPlugin);
|
|
23
|
-
await framework.pluginManager.startAll();
|
|
24
|
-
|
|
25
|
-
// 等待连接
|
|
26
|
-
await new Promise((r) => setTimeout(r, 2000));
|
|
27
|
-
|
|
28
|
-
console.log('\n1. 初始服务器列表:');
|
|
29
|
-
const initialServers = mcpPlugin.getServers();
|
|
30
|
-
console.log(JSON.stringify(initialServers, null, 2));
|
|
31
|
-
|
|
32
|
-
// 测试 mcp_reload
|
|
33
|
-
console.log('\n2. 调用 mcp_reload...');
|
|
34
|
-
const result = await framework.executeTool('mcp_reload', {});
|
|
35
|
-
console.log('mcp_reload 结果:');
|
|
36
|
-
console.log(JSON.stringify(result, null, 2));
|
|
37
|
-
|
|
38
|
-
// 检查配置
|
|
39
|
-
console.log('\n3. 当前配置文件:');
|
|
40
|
-
const configPath = path.resolve('.agent/mcp_config.json');
|
|
41
|
-
if (fs.existsSync(configPath)) {
|
|
42
|
-
const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
|
|
43
|
-
console.log(JSON.stringify(config, null, 2));
|
|
44
|
-
} else {
|
|
45
|
-
console.log('配置文件不存在: ' + configPath);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// 清理
|
|
49
|
-
await framework.destroy();
|
|
50
|
-
|
|
51
|
-
console.log('\n=== 测试完成 ===');
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
test()
|
|
55
|
-
.then(() => process.exit(0))
|
|
56
|
-
.catch((err) => {
|
|
57
|
-
console.error('测试失败:', err);
|
|
58
|
-
process.exit(1);
|
|
59
|
-
});
|
|
1
|
+
/**
|
|
2
|
+
* MCP mcp_reload 功能测试
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
const { Framework } = require('../src');
|
|
6
|
+
const { MCPExecutorPlugin } = require('../src/executors/mcp-executor');
|
|
7
|
+
const fs = require('fs');
|
|
8
|
+
const path = require('path');
|
|
9
|
+
|
|
10
|
+
async function test() {
|
|
11
|
+
console.log('=== Testing mcp_reload ===\n');
|
|
12
|
+
|
|
13
|
+
// 创建框架
|
|
14
|
+
const framework = new Framework({ debug: true });
|
|
15
|
+
|
|
16
|
+
// 创建 MCP 插件
|
|
17
|
+
const mcpPlugin = new MCPExecutorPlugin({
|
|
18
|
+
servers: [{ name: 'fetch', command: 'uvx', args: ['mcp-server-fetch'] }],
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
// 加载并启动
|
|
22
|
+
await framework.loadPlugin(mcpPlugin);
|
|
23
|
+
await framework.pluginManager.startAll();
|
|
24
|
+
|
|
25
|
+
// 等待连接
|
|
26
|
+
await new Promise((r) => setTimeout(r, 2000));
|
|
27
|
+
|
|
28
|
+
console.log('\n1. 初始服务器列表:');
|
|
29
|
+
const initialServers = mcpPlugin.getServers();
|
|
30
|
+
console.log(JSON.stringify(initialServers, null, 2));
|
|
31
|
+
|
|
32
|
+
// 测试 mcp_reload
|
|
33
|
+
console.log('\n2. 调用 mcp_reload...');
|
|
34
|
+
const result = await framework.executeTool('mcp_reload', {});
|
|
35
|
+
console.log('mcp_reload 结果:');
|
|
36
|
+
console.log(JSON.stringify(result, null, 2));
|
|
37
|
+
|
|
38
|
+
// 检查配置
|
|
39
|
+
console.log('\n3. 当前配置文件:');
|
|
40
|
+
const configPath = path.resolve('.agent/mcp_config.json');
|
|
41
|
+
if (fs.existsSync(configPath)) {
|
|
42
|
+
const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
|
|
43
|
+
console.log(JSON.stringify(config, null, 2));
|
|
44
|
+
} else {
|
|
45
|
+
console.log('配置文件不存在: ' + configPath);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// 清理
|
|
49
|
+
await framework.destroy();
|
|
50
|
+
|
|
51
|
+
console.log('\n=== 测试完成 ===');
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
test()
|
|
55
|
+
.then(() => process.exit(0))
|
|
56
|
+
.catch((err) => {
|
|
57
|
+
console.error('测试失败:', err);
|
|
58
|
+
process.exit(1);
|
|
59
|
+
});
|
|
@@ -1,50 +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);
|
|
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);
|