foliko 1.0.75 → 1.0.77

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.
Files changed (89) hide show
  1. package/.claude/settings.local.json +159 -157
  2. package/.env.example +3 -1
  3. package/cli/bin/foliko.js +12 -12
  4. package/cli/src/commands/chat.js +143 -143
  5. package/cli/src/commands/list.js +93 -93
  6. package/cli/src/index.js +75 -75
  7. package/cli/src/ui/chat-ui.js +201 -201
  8. package/cli/src/utils/ansi.js +40 -40
  9. package/cli/src/utils/markdown.js +292 -292
  10. package/examples/ambient-example.js +194 -194
  11. package/examples/basic.js +115 -115
  12. package/examples/bootstrap.js +121 -121
  13. package/examples/mcp-example.js +56 -56
  14. package/examples/skill-example.js +49 -49
  15. package/examples/test-chat.js +137 -137
  16. package/examples/test-mcp.js +85 -85
  17. package/examples/test-reload.js +59 -59
  18. package/examples/test-telegram.js +50 -50
  19. package/examples/test-tg-bot.js +45 -45
  20. package/examples/test-tg-simple.js +47 -47
  21. package/examples/test-tg.js +62 -62
  22. package/examples/test-think.js +43 -43
  23. package/examples/test-web-plugin.js +103 -103
  24. package/examples/test-weixin-feishu.js +103 -103
  25. package/examples/workflow.js +158 -158
  26. package/package.json +81 -81
  27. package/plugins/ai-plugin.js +102 -102
  28. package/plugins/ambient-agent/EventWatcher.js +113 -113
  29. package/plugins/ambient-agent/ExplorerLoop.js +640 -640
  30. package/plugins/ambient-agent/GoalManager.js +197 -197
  31. package/plugins/ambient-agent/Reflector.js +95 -95
  32. package/plugins/ambient-agent/StateStore.js +90 -90
  33. package/plugins/ambient-agent/constants.js +101 -101
  34. package/plugins/ambient-agent/index.js +579 -579
  35. package/plugins/audit-plugin.js +187 -187
  36. package/plugins/default-plugins.js +662 -662
  37. package/plugins/email/constants.js +64 -64
  38. package/plugins/email/handlers.js +461 -461
  39. package/plugins/email/index.js +278 -278
  40. package/plugins/email/monitor.js +269 -269
  41. package/plugins/email/parser.js +138 -138
  42. package/plugins/email/reply.js +151 -151
  43. package/plugins/email/utils.js +124 -124
  44. package/plugins/feishu-plugin.js +481 -481
  45. package/plugins/file-system-plugin.js +826 -826
  46. package/plugins/install-plugin.js +199 -199
  47. package/plugins/python-executor-plugin.js +367 -367
  48. package/plugins/python-plugin-loader.js +481 -481
  49. package/plugins/rules-plugin.js +294 -294
  50. package/plugins/scheduler-plugin.js +691 -691
  51. package/plugins/session-plugin.js +369 -369
  52. package/plugins/shell-executor-plugin.js +197 -197
  53. package/plugins/storage-plugin.js +240 -240
  54. package/plugins/subagent-plugin.js +845 -845
  55. package/plugins/telegram-plugin.js +482 -482
  56. package/plugins/think-plugin.js +345 -345
  57. package/plugins/tools-plugin.js +196 -196
  58. package/plugins/web-plugin.js +606 -606
  59. package/plugins/weixin-plugin.js +545 -545
  60. package/src/capabilities/index.js +11 -11
  61. package/src/capabilities/skill-manager.js +609 -609
  62. package/src/capabilities/workflow-engine.js +1109 -1109
  63. package/src/core/agent-chat.js +882 -882
  64. package/src/core/agent.js +892 -892
  65. package/src/core/framework.js +465 -465
  66. package/src/core/index.js +19 -19
  67. package/src/core/plugin-base.js +219 -219
  68. package/src/core/plugin-manager.js +863 -863
  69. package/src/core/provider.js +114 -114
  70. package/src/core/sub-agent-config.js +264 -264
  71. package/src/core/system-prompt-builder.js +120 -120
  72. package/src/core/tool-registry.js +517 -517
  73. package/src/core/tool-router.js +297 -297
  74. package/src/executors/executor-base.js +58 -58
  75. package/src/executors/mcp-executor.js +741 -741
  76. package/src/index.js +25 -25
  77. package/src/utils/circuit-breaker.js +301 -301
  78. package/src/utils/error-boundary.js +363 -363
  79. package/src/utils/error.js +374 -374
  80. package/src/utils/event-emitter.js +97 -97
  81. package/src/utils/id.js +133 -133
  82. package/src/utils/index.js +217 -217
  83. package/src/utils/logger.js +181 -181
  84. package/src/utils/plugin-helpers.js +90 -90
  85. package/src/utils/retry.js +122 -122
  86. package/src/utils/sandbox.js +292 -292
  87. package/test/tool-registry-validation.test.js +218 -218
  88. package/website/script.js +136 -136
  89. package/foliko-1.0.75.tgz +0 -0
@@ -1,121 +1,121 @@
1
- /**
2
- * Bootstrap 示例
3
- * 使用 framework.bootstrap() 自动加载 .agent/ 目录配置
4
- */
5
-
6
- const { Framework } = require('../src');
7
- const { z } = require('zod');
8
-
9
- async function main() {
10
- console.log('=== Bootstrap Example ===\n');
11
-
12
- // 创建框架
13
- const framework = new Framework({ debug: true });
14
-
15
- // 使用 bootstrap 自动加载所有默认插件
16
- // 会自动检测 .agent/ 目录下的配置
17
- await framework.bootstrap({
18
- agentDir: './.agent', // 配置目录
19
- aiConfig: {
20
- // 可选:覆盖 AI 配置
21
- provider: 'deepseek',
22
- model: 'deepseek-chat',
23
- apiKey: process.env.DEEPSEEK_API_KEY || 'your-api-key',
24
- },
25
- });
26
-
27
- // 注册 hello 工具(演示用)
28
- framework.registerTool({
29
- name: 'hello',
30
- description: '打招呼',
31
- inputSchema: z.object({
32
- name: z.string().optional().describe('姓名'),
33
- }),
34
- execute: async (args) => `Hello, ${args.name || 'World'}!`,
35
- });
36
-
37
- console.log('\n--- Framework Ready ---');
38
- console.log(
39
- 'Plugins:',
40
- framework.pluginManager.getAll().map((p) => p.name)
41
- );
42
- console.log(
43
- 'Tools:',
44
- framework.getTools().map((t) => t.name)
45
- );
46
-
47
- // 创建 Agent (支持 sharedPrompt 和 metadata)
48
- const agent = framework.createAgent({
49
- name: 'MyAgent',
50
- systemPrompt: '你是一个有帮助的助手。',
51
- sharedPrompt: '工作目录: {{WORK_DIR}}\n用户名: {{USER_NAME}}\n当前时间: {{TIME}}',
52
- metadata: {
53
- projectName: 'Foliko',
54
- version: '1.0.0',
55
- },
56
- });
57
-
58
- console.log('\n--- Agent Context ---');
59
- console.log(agent.systemPrompt);
60
-
61
- // 测试对话
62
- console.log('\n--- AI Chat Test ---');
63
- // try {
64
- // const response = await agent.chat('帮我开发一个获取系统信息的插件')
65
- // console.log('Agent:', response.message)
66
- // } catch (err) {
67
- // console.error('Chat error:', err.message)
68
- // }
69
-
70
- try {
71
- for await (const chunk of agent.chatStream('帮我开发一个获取系统信息的插件')) {
72
- if (chunk.type === 'text') {
73
- process.stdout.write(chunk.text);
74
- } else if (chunk?.type === 'tool-call') {
75
- console.log(`\n[工具调用: ${chunk.toolName}]`);
76
- } else if (chunk?.type === 'tool-result') {
77
- console.log(`\n[工具结果: ${chunk.toolName}]`);
78
- }
79
- }
80
- console.log('\n');
81
- } catch (err) {
82
- console.error('[Agent] Stream Error:', err.message);
83
- }
84
-
85
- // 测试工具调用
86
- console.log('\n--- Tool Call Test ---');
87
- const result = await framework.executeTool('hello', { name: 'Bootstrap' });
88
- console.log('Tool result:', result);
89
-
90
- // 测试内置工具
91
- console.log('\n--- Built-in Tools Test ---');
92
- const listResult = await framework.executeTool('list_plugins', {});
93
- console.log('list_plugins:', listResult);
94
-
95
- // 测试 Web 插件 - 让 LLM 注册路由并测试
96
- console.log('\n--- Web Plugin Test ---');
97
- console.log('指示 LLM 注册一个 GET /test 路由...\n');
98
-
99
- try {
100
- for await (const chunk of agent.chatStream(
101
- '请帮我注册一个 GET 路由 /test,handler 写:return "1232432"。只调用工具不要解释。'
102
- )) {
103
- if (chunk.type === 'text') {
104
- process.stdout.write(chunk.text);
105
- } else if (chunk?.type === 'tool-call') {
106
- console.log(`\n[工具调用: ${chunk.toolName}]`);
107
- } else if (chunk?.type === 'tool-result') {
108
- console.log(`\n[工具结果] ${JSON.stringify(chunk.result).substring(0, 200)}...`);
109
- }
110
- }
111
- console.log('\n');
112
- } catch (err) {
113
- console.error('[Agent] Web Plugin Test Error:', err.message);
114
- }
115
-
116
- // 清理
117
- await framework.destroy();
118
- console.log('\n[Done]');
119
- }
120
-
121
- main().catch(console.error);
1
+ /**
2
+ * Bootstrap 示例
3
+ * 使用 framework.bootstrap() 自动加载 .agent/ 目录配置
4
+ */
5
+
6
+ const { Framework } = require('../src');
7
+ const { z } = require('zod');
8
+
9
+ async function main() {
10
+ console.log('=== Bootstrap Example ===\n');
11
+
12
+ // 创建框架
13
+ const framework = new Framework({ debug: true });
14
+
15
+ // 使用 bootstrap 自动加载所有默认插件
16
+ // 会自动检测 .agent/ 目录下的配置
17
+ await framework.bootstrap({
18
+ agentDir: './.agent', // 配置目录
19
+ aiConfig: {
20
+ // 可选:覆盖 AI 配置
21
+ provider: 'deepseek',
22
+ model: 'deepseek-chat',
23
+ apiKey: process.env.DEEPSEEK_API_KEY || 'your-api-key',
24
+ },
25
+ });
26
+
27
+ // 注册 hello 工具(演示用)
28
+ framework.registerTool({
29
+ name: 'hello',
30
+ description: '打招呼',
31
+ inputSchema: z.object({
32
+ name: z.string().optional().describe('姓名'),
33
+ }),
34
+ execute: async (args) => `Hello, ${args.name || 'World'}!`,
35
+ });
36
+
37
+ console.log('\n--- Framework Ready ---');
38
+ console.log(
39
+ 'Plugins:',
40
+ framework.pluginManager.getAll().map((p) => p.name)
41
+ );
42
+ console.log(
43
+ 'Tools:',
44
+ framework.getTools().map((t) => t.name)
45
+ );
46
+
47
+ // 创建 Agent (支持 sharedPrompt 和 metadata)
48
+ const agent = framework.createAgent({
49
+ name: 'MyAgent',
50
+ systemPrompt: '你是一个有帮助的助手。',
51
+ sharedPrompt: '工作目录: {{WORK_DIR}}\n用户名: {{USER_NAME}}\n当前时间: {{TIME}}',
52
+ metadata: {
53
+ projectName: 'Foliko',
54
+ version: '1.0.0',
55
+ },
56
+ });
57
+
58
+ console.log('\n--- Agent Context ---');
59
+ console.log(agent.systemPrompt);
60
+
61
+ // 测试对话
62
+ console.log('\n--- AI Chat Test ---');
63
+ // try {
64
+ // const response = await agent.chat('帮我开发一个获取系统信息的插件')
65
+ // console.log('Agent:', response.message)
66
+ // } catch (err) {
67
+ // console.error('Chat error:', err.message)
68
+ // }
69
+
70
+ try {
71
+ for await (const chunk of agent.chatStream('帮我开发一个获取系统信息的插件')) {
72
+ if (chunk.type === 'text') {
73
+ process.stdout.write(chunk.text);
74
+ } else if (chunk?.type === 'tool-call') {
75
+ console.log(`\n[工具调用: ${chunk.toolName}]`);
76
+ } else if (chunk?.type === 'tool-result') {
77
+ console.log(`\n[工具结果: ${chunk.toolName}]`);
78
+ }
79
+ }
80
+ console.log('\n');
81
+ } catch (err) {
82
+ console.error('[Agent] Stream Error:', err.message);
83
+ }
84
+
85
+ // 测试工具调用
86
+ console.log('\n--- Tool Call Test ---');
87
+ const result = await framework.executeTool('hello', { name: 'Bootstrap' });
88
+ console.log('Tool result:', result);
89
+
90
+ // 测试内置工具
91
+ console.log('\n--- Built-in Tools Test ---');
92
+ const listResult = await framework.executeTool('list_plugins', {});
93
+ console.log('list_plugins:', listResult);
94
+
95
+ // 测试 Web 插件 - 让 LLM 注册路由并测试
96
+ console.log('\n--- Web Plugin Test ---');
97
+ console.log('指示 LLM 注册一个 GET /test 路由...\n');
98
+
99
+ try {
100
+ for await (const chunk of agent.chatStream(
101
+ '请帮我注册一个 GET 路由 /test,handler 写:return "1232432"。只调用工具不要解释。'
102
+ )) {
103
+ if (chunk.type === 'text') {
104
+ process.stdout.write(chunk.text);
105
+ } else if (chunk?.type === 'tool-call') {
106
+ console.log(`\n[工具调用: ${chunk.toolName}]`);
107
+ } else if (chunk?.type === 'tool-result') {
108
+ console.log(`\n[工具结果] ${JSON.stringify(chunk.result).substring(0, 200)}...`);
109
+ }
110
+ }
111
+ console.log('\n');
112
+ } catch (err) {
113
+ console.error('[Agent] Web Plugin Test Error:', err.message);
114
+ }
115
+
116
+ // 清理
117
+ await framework.destroy();
118
+ console.log('\n[Done]');
119
+ }
120
+
121
+ main().catch(console.error);
@@ -1,56 +1,56 @@
1
- /**
2
- * MCP 执行器示例
3
- * 展示如何连接 MCP 服务器
4
- */
5
-
6
- const { Framework } = require('../src');
7
- const { MCPExecutorPlugin } = require('../src/executors/mcp-executor');
8
-
9
- async function main() {
10
- console.log('=== MCP Executor Example ===\n');
11
-
12
- // 创建框架
13
- const framework = new Framework({ debug: true });
14
-
15
- // 创建 MCP 执行器插件
16
- const mcpPlugin = new MCPExecutorPlugin({
17
- servers: [
18
- // 示例:添加一个 MCP 服务器
19
- // {
20
- // name: 'example',
21
- // command: 'uvx',
22
- // args: ['example-mcp-server'],
23
- // env: {}
24
- // }
25
- ],
26
- });
27
-
28
- // 加载插件
29
- await framework.loadPlugin(mcpPlugin);
30
-
31
- // 列出服务器
32
- console.log('\n--- MCP Servers ---');
33
- const servers = mcpPlugin.getServers();
34
- console.log('Servers:', servers);
35
-
36
- // 列出所有 MCP 工具
37
- console.log('\n--- MCP Tools ---');
38
- const tools = framework.getTools().filter((t) => t.name.startsWith('mcp_'));
39
- console.log(
40
- 'MCP tools:',
41
- tools.map((t) => t.name)
42
- );
43
-
44
- // 如果有配置的服务器,可以这样调用:
45
- // const result = await framework.executeTool('mcp_call', {
46
- // server: 'example',
47
- // tool: 'tool_name',
48
- // args: { /* tool arguments */ }
49
- // })
50
-
51
- // 清理
52
- await framework.destroy();
53
- console.log('\n[Done]');
54
- }
55
-
56
- main().catch(console.error);
1
+ /**
2
+ * MCP 执行器示例
3
+ * 展示如何连接 MCP 服务器
4
+ */
5
+
6
+ const { Framework } = require('../src');
7
+ const { MCPExecutorPlugin } = require('../src/executors/mcp-executor');
8
+
9
+ async function main() {
10
+ console.log('=== MCP Executor Example ===\n');
11
+
12
+ // 创建框架
13
+ const framework = new Framework({ debug: true });
14
+
15
+ // 创建 MCP 执行器插件
16
+ const mcpPlugin = new MCPExecutorPlugin({
17
+ servers: [
18
+ // 示例:添加一个 MCP 服务器
19
+ // {
20
+ // name: 'example',
21
+ // command: 'uvx',
22
+ // args: ['example-mcp-server'],
23
+ // env: {}
24
+ // }
25
+ ],
26
+ });
27
+
28
+ // 加载插件
29
+ await framework.loadPlugin(mcpPlugin);
30
+
31
+ // 列出服务器
32
+ console.log('\n--- MCP Servers ---');
33
+ const servers = mcpPlugin.getServers();
34
+ console.log('Servers:', servers);
35
+
36
+ // 列出所有 MCP 工具
37
+ console.log('\n--- MCP Tools ---');
38
+ const tools = framework.getTools().filter((t) => t.name.startsWith('mcp_'));
39
+ console.log(
40
+ 'MCP tools:',
41
+ tools.map((t) => t.name)
42
+ );
43
+
44
+ // 如果有配置的服务器,可以这样调用:
45
+ // const result = await framework.executeTool('mcp_call', {
46
+ // server: 'example',
47
+ // tool: 'tool_name',
48
+ // args: { /* tool arguments */ }
49
+ // })
50
+
51
+ // 清理
52
+ await framework.destroy();
53
+ console.log('\n[Done]');
54
+ }
55
+
56
+ main().catch(console.error);
@@ -1,49 +1,49 @@
1
- /**
2
- * Skill 管理器示例
3
- * 展示如何加载和使用 Skill
4
- */
5
-
6
- const { Framework } = require('../src');
7
- const { SkillManagerPlugin } = require('../src/capabilities/skill-manager');
8
-
9
- async function main() {
10
- console.log('=== Skill Manager Example ===\n');
11
-
12
- // 创建框架
13
- const framework = new Framework({ debug: true });
14
-
15
- // 创建 skills 目录(如果没有)
16
- const fs = require('fs');
17
- const skillsDir = './skills';
18
- if (!fs.existsSync(skillsDir)) {
19
- fs.mkdirSync(skillsDir, { recursive: true });
20
- }
21
-
22
- // 加载 Skill 管理器插件
23
- const skillPlugin = new SkillManagerPlugin({
24
- skillsDir: skillsDir,
25
- });
26
-
27
- await framework.loadPlugin(skillPlugin);
28
-
29
- // 列出所有加载的 skills
30
- console.log('\n--- Loaded Skills ---');
31
- const skills = skillPlugin.getAllSkills();
32
- console.log(`Found ${skills.length} skills:`);
33
- for (const skill of skills) {
34
- console.log(` - ${skill.name}: ${skill.metadata.description}`);
35
- }
36
-
37
- // 获取单个 skill
38
- if (skillPlugin.hasSkill('hello-skill')) {
39
- console.log('\n--- Hello Skill ---');
40
- const helloSkill = skillPlugin.getSkill('hello-skill');
41
- console.log('Content preview:', helloSkill.content.substring(0, 100) + '...');
42
- }
43
-
44
- // 清理
45
- await framework.destroy();
46
- console.log('\n[Done]');
47
- }
48
-
49
- main().catch(console.error);
1
+ /**
2
+ * Skill 管理器示例
3
+ * 展示如何加载和使用 Skill
4
+ */
5
+
6
+ const { Framework } = require('../src');
7
+ const { SkillManagerPlugin } = require('../src/capabilities/skill-manager');
8
+
9
+ async function main() {
10
+ console.log('=== Skill Manager Example ===\n');
11
+
12
+ // 创建框架
13
+ const framework = new Framework({ debug: true });
14
+
15
+ // 创建 skills 目录(如果没有)
16
+ const fs = require('fs');
17
+ const skillsDir = './skills';
18
+ if (!fs.existsSync(skillsDir)) {
19
+ fs.mkdirSync(skillsDir, { recursive: true });
20
+ }
21
+
22
+ // 加载 Skill 管理器插件
23
+ const skillPlugin = new SkillManagerPlugin({
24
+ skillsDir: skillsDir,
25
+ });
26
+
27
+ await framework.loadPlugin(skillPlugin);
28
+
29
+ // 列出所有加载的 skills
30
+ console.log('\n--- Loaded Skills ---');
31
+ const skills = skillPlugin.getAllSkills();
32
+ console.log(`Found ${skills.length} skills:`);
33
+ for (const skill of skills) {
34
+ console.log(` - ${skill.name}: ${skill.metadata.description}`);
35
+ }
36
+
37
+ // 获取单个 skill
38
+ if (skillPlugin.hasSkill('hello-skill')) {
39
+ console.log('\n--- Hello Skill ---');
40
+ const helloSkill = skillPlugin.getSkill('hello-skill');
41
+ console.log('Content preview:', helloSkill.content.substring(0, 100) + '...');
42
+ }
43
+
44
+ // 清理
45
+ await framework.destroy();
46
+ console.log('\n[Done]');
47
+ }
48
+
49
+ main().catch(console.error);