foliko 1.0.81 → 1.0.83

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 (88) hide show
  1. package/cli/bin/foliko.js +12 -12
  2. package/cli/src/commands/chat.js +143 -143
  3. package/cli/src/commands/list.js +93 -93
  4. package/cli/src/index.js +75 -75
  5. package/cli/src/ui/chat-ui.js +201 -201
  6. package/cli/src/utils/ansi.js +40 -40
  7. package/cli/src/utils/markdown.js +292 -292
  8. package/examples/ambient-example.js +194 -194
  9. package/examples/basic.js +115 -115
  10. package/examples/bootstrap.js +121 -121
  11. package/examples/mcp-example.js +56 -56
  12. package/examples/skill-example.js +49 -49
  13. package/examples/test-chat.js +137 -137
  14. package/examples/test-mcp.js +85 -85
  15. package/examples/test-reload.js +59 -59
  16. package/examples/test-telegram.js +50 -50
  17. package/examples/test-tg-bot.js +45 -45
  18. package/examples/test-tg-simple.js +47 -47
  19. package/examples/test-tg.js +62 -62
  20. package/examples/test-think.js +43 -43
  21. package/examples/test-web-plugin.js +103 -103
  22. package/examples/test-weixin-feishu.js +103 -103
  23. package/examples/workflow.js +158 -158
  24. package/package.json +83 -83
  25. package/plugins/ai-plugin.js +102 -102
  26. package/plugins/ambient-agent/EventWatcher.js +113 -113
  27. package/plugins/ambient-agent/ExplorerLoop.js +640 -640
  28. package/plugins/ambient-agent/GoalManager.js +197 -197
  29. package/plugins/ambient-agent/Reflector.js +95 -95
  30. package/plugins/ambient-agent/StateStore.js +90 -90
  31. package/plugins/ambient-agent/constants.js +101 -101
  32. package/plugins/ambient-agent/index.js +579 -579
  33. package/plugins/audit-plugin.js +187 -187
  34. package/plugins/default-plugins.js +548 -548
  35. package/plugins/email/constants.js +64 -64
  36. package/plugins/email/handlers.js +461 -461
  37. package/plugins/email/index.js +278 -278
  38. package/plugins/email/monitor.js +269 -269
  39. package/plugins/email/parser.js +138 -138
  40. package/plugins/email/reply.js +151 -151
  41. package/plugins/email/utils.js +124 -124
  42. package/plugins/extension-executor-plugin.js +326 -326
  43. package/plugins/feishu-plugin.js +481 -481
  44. package/plugins/file-system-plugin.js +920 -920
  45. package/plugins/gate-trading.js +747 -747
  46. package/plugins/install-plugin.js +199 -199
  47. package/plugins/python-executor-plugin.js +367 -367
  48. package/plugins/python-plugin-loader.js +651 -651
  49. package/plugins/rules-plugin.js +294 -294
  50. package/plugins/scheduler-plugin.js +691 -691
  51. package/plugins/session-plugin.js +494 -494
  52. package/plugins/shell-executor-plugin.js +197 -197
  53. package/plugins/storage-plugin.js +263 -263
  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 +637 -637
  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 +1 -1
  64. package/src/core/agent.js +958 -958
  65. package/src/core/framework.js +465 -465
  66. package/src/core/index.js +19 -19
  67. package/src/core/plugin-base.js +262 -262
  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 +845 -845
  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
@@ -1,103 +1,103 @@
1
- /**
2
- * 微信/飞书插件测试
3
- * 测试 chat() 方法(非流式)
4
- */
5
-
6
- const { Framework } = require('../src');
7
-
8
- async function main() {
9
- console.log('=== Weixin/Feishu Plugin Test ===\n');
10
-
11
- const framework = new Framework({ debug: true });
12
-
13
- // Bootstrap 加载默认插件
14
- await framework.bootstrap({
15
- agentDir: './.agent',
16
- aiConfig: {
17
- provider: 'deepseek',
18
- model: 'deepseek-chat',
19
- apiKey: process.env.DEEPSEEK_API_KEY || 'your-api-key',
20
- },
21
- });
22
-
23
- // 加载微信插件
24
- const { WeixinPlugin } = require('../plugins/weixin-plugin');
25
- const weixinPlugin = new WeixinPlugin({
26
- forceLogin: false,
27
- allowedUsers: [], // 空数组表示允许所有人
28
- });
29
-
30
- // 加载飞书插件
31
- const { FeishuPlugin } = require('../plugins/feishu-plugin');
32
- const feishuPlugin = new FeishuPlugin({
33
- // appId: 'your-app-id',
34
- // appSecret: 'your-app-secret',
35
- allowedUsers: [],
36
- });
37
-
38
- // 注册插件(不自动加载)
39
- // framework.registerPlugin(weixinPlugin)
40
- // framework.registerPlugin(feishuPlugin)
41
-
42
- console.log('\n--- Plugins Registered ---');
43
- console.log(
44
- 'Plugins:',
45
- framework.pluginManager.getAll().map((p) => p.name)
46
- );
47
-
48
- // 创建测试 Agent
49
- const agent = framework.createAgent({
50
- name: 'TestAgent',
51
- systemPrompt: '你是一个测试助手,回复要简洁。',
52
- });
53
-
54
- // 测试 chat() 方法(模拟消息处理)
55
- console.log('\n--- Test chat() method ---');
56
-
57
- // 模拟飞书的消息处理流程
58
- const mockOpenId = 'test_user_001';
59
- const mockText = '你好,请介绍一下你自己';
60
-
61
- // 获取 session agent(内部逻辑)
62
- const sessionInfo = {
63
- agent: framework.createSessionAgent(`test_${mockOpenId}`, {
64
- systemPrompt: feishuPlugin.systemPrompt,
65
- }),
66
- sessionId: `test_${mockOpenId}`,
67
- };
68
-
69
- try {
70
- // 使用 chat() 而非 chatStream()
71
- const result = await sessionInfo.agent.chat(mockText, {
72
- sessionId: sessionInfo.sessionId,
73
- });
74
-
75
- console.log('Result:', result);
76
- console.log('Message:', result.message);
77
- console.log('StepCount:', result.stepCount);
78
- } catch (err) {
79
- console.error('Chat error:', err.message);
80
- }
81
-
82
- // 测试 chatStream() 对比
83
- console.log('\n--- Test chatStream() for comparison ---');
84
- try {
85
- let fullResponse = '';
86
- for await (const chunk of sessionInfo.agent.chatStream('今天天气怎么样?', {
87
- sessionId: sessionInfo.sessionId,
88
- })) {
89
- if (chunk.type === 'text' && chunk.text) {
90
- fullResponse += chunk.text;
91
- }
92
- }
93
- console.log('Stream result:', fullResponse);
94
- } catch (err) {
95
- console.error('Stream error:', err.message);
96
- }
97
-
98
- // 清理
99
- await framework.destroy();
100
- console.log('\n[Done]');
101
- }
102
-
103
- main().catch(console.error);
1
+ /**
2
+ * 微信/飞书插件测试
3
+ * 测试 chat() 方法(非流式)
4
+ */
5
+
6
+ const { Framework } = require('../src');
7
+
8
+ async function main() {
9
+ console.log('=== Weixin/Feishu Plugin Test ===\n');
10
+
11
+ const framework = new Framework({ debug: true });
12
+
13
+ // Bootstrap 加载默认插件
14
+ await framework.bootstrap({
15
+ agentDir: './.agent',
16
+ aiConfig: {
17
+ provider: 'deepseek',
18
+ model: 'deepseek-chat',
19
+ apiKey: process.env.DEEPSEEK_API_KEY || 'your-api-key',
20
+ },
21
+ });
22
+
23
+ // 加载微信插件
24
+ const { WeixinPlugin } = require('../plugins/weixin-plugin');
25
+ const weixinPlugin = new WeixinPlugin({
26
+ forceLogin: false,
27
+ allowedUsers: [], // 空数组表示允许所有人
28
+ });
29
+
30
+ // 加载飞书插件
31
+ const { FeishuPlugin } = require('../plugins/feishu-plugin');
32
+ const feishuPlugin = new FeishuPlugin({
33
+ // appId: 'your-app-id',
34
+ // appSecret: 'your-app-secret',
35
+ allowedUsers: [],
36
+ });
37
+
38
+ // 注册插件(不自动加载)
39
+ // framework.registerPlugin(weixinPlugin)
40
+ // framework.registerPlugin(feishuPlugin)
41
+
42
+ console.log('\n--- Plugins Registered ---');
43
+ console.log(
44
+ 'Plugins:',
45
+ framework.pluginManager.getAll().map((p) => p.name)
46
+ );
47
+
48
+ // 创建测试 Agent
49
+ const agent = framework.createAgent({
50
+ name: 'TestAgent',
51
+ systemPrompt: '你是一个测试助手,回复要简洁。',
52
+ });
53
+
54
+ // 测试 chat() 方法(模拟消息处理)
55
+ console.log('\n--- Test chat() method ---');
56
+
57
+ // 模拟飞书的消息处理流程
58
+ const mockOpenId = 'test_user_001';
59
+ const mockText = '你好,请介绍一下你自己';
60
+
61
+ // 获取 session agent(内部逻辑)
62
+ const sessionInfo = {
63
+ agent: framework.createSessionAgent(`test_${mockOpenId}`, {
64
+ systemPrompt: feishuPlugin.systemPrompt,
65
+ }),
66
+ sessionId: `test_${mockOpenId}`,
67
+ };
68
+
69
+ try {
70
+ // 使用 chat() 而非 chatStream()
71
+ const result = await sessionInfo.agent.chat(mockText, {
72
+ sessionId: sessionInfo.sessionId,
73
+ });
74
+
75
+ console.log('Result:', result);
76
+ console.log('Message:', result.message);
77
+ console.log('StepCount:', result.stepCount);
78
+ } catch (err) {
79
+ console.error('Chat error:', err.message);
80
+ }
81
+
82
+ // 测试 chatStream() 对比
83
+ console.log('\n--- Test chatStream() for comparison ---');
84
+ try {
85
+ let fullResponse = '';
86
+ for await (const chunk of sessionInfo.agent.chatStream('今天天气怎么样?', {
87
+ sessionId: sessionInfo.sessionId,
88
+ })) {
89
+ if (chunk.type === 'text' && chunk.text) {
90
+ fullResponse += chunk.text;
91
+ }
92
+ }
93
+ console.log('Stream result:', fullResponse);
94
+ } catch (err) {
95
+ console.error('Stream error:', err.message);
96
+ }
97
+
98
+ // 清理
99
+ await framework.destroy();
100
+ console.log('\n[Done]');
101
+ }
102
+
103
+ main().catch(console.error);
@@ -1,158 +1,158 @@
1
- /**
2
- * 工作流示例
3
- * 展示如何使用工作流引擎
4
- */
5
-
6
- const { Framework } = require('../src');
7
- const { WorkflowPlugin } = require('../src/capabilities/workflow-engine');
8
-
9
- async function main() {
10
- console.log('=== Workflow Example ===\n');
11
-
12
- // 创建框架
13
- const framework = new Framework({ debug: true });
14
-
15
- // 加载工作流插件
16
- await framework.loadPlugin(new WorkflowPlugin());
17
-
18
- console.log('\n--- Testing Script Step ---');
19
-
20
- // 直接执行工作流
21
- const result1 = await framework.executeTool('execute_workflow', {
22
- workflow: JSON.stringify({
23
- steps: [
24
- {
25
- type: 'script',
26
- name: 'Calculate',
27
- script: `
28
- const a = 10;
29
- const b = 20;
30
- context.variables.sum = a + b;
31
- return a + b;
32
- `,
33
- },
34
- {
35
- type: 'script',
36
- name: 'Multiply',
37
- script: `
38
- const sum = context.variables.sum;
39
- context.variables.product = sum * 2;
40
- return sum * 2;
41
- `,
42
- },
43
- ],
44
- }),
45
- input: {},
46
- });
47
-
48
- console.log('Result:', result1);
49
-
50
- console.log('\n--- Testing Loop Step ---');
51
-
52
- const result2 = await framework.executeTool('execute_workflow', {
53
- workflow: JSON.stringify({
54
- steps: [
55
- {
56
- type: 'loop',
57
- name: 'Loop 3 times',
58
- maxIterations: 3,
59
- loopVariable: 'i',
60
- steps: [
61
- {
62
- type: 'script',
63
- name: 'Log iteration',
64
- script: `
65
- console.log('Iteration ' + context.variables.i);
66
- return context.variables.i;
67
- `,
68
- },
69
- ],
70
- },
71
- ],
72
- }),
73
- input: {},
74
- });
75
-
76
- console.log('Result:', result2);
77
-
78
- console.log('\n--- Testing Condition Step ---');
79
-
80
- const result3 = await framework.executeTool('execute_workflow', {
81
- workflow: JSON.stringify({
82
- steps: [
83
- {
84
- type: 'script',
85
- name: 'Set value',
86
- outputVariable: 'value',
87
- script: `
88
- context.variables.value = 15;
89
- return 15;
90
- `,
91
- },
92
- {
93
- type: 'condition',
94
- name: 'Check value',
95
- branches: [
96
- {
97
- name: 'Greater than 10',
98
- condition: 'context.variables.value > 10',
99
- steps: [
100
- {
101
- type: 'script',
102
- name: 'Log greater',
103
- script: `console.log('Value is greater than 10'); return 'greater';`,
104
- },
105
- ],
106
- },
107
- {
108
- name: 'Less than or equal 10',
109
- condition: 'context.variables.value <= 10',
110
- steps: [
111
- {
112
- type: 'script',
113
- name: 'Log less',
114
- script: `console.log('Value is less than or equal 10'); return 'less-or-equal';`,
115
- },
116
- ],
117
- },
118
- ],
119
- },
120
- ],
121
- }),
122
- input: {},
123
- });
124
-
125
- console.log('Result:', result3);
126
-
127
- console.log('\n--- Testing Delay ---');
128
-
129
- const startTime = Date.now();
130
- const result4 = await framework.executeTool('execute_workflow', {
131
- workflow: JSON.stringify({
132
- steps: [
133
- {
134
- type: 'delay',
135
- name: 'Wait 500ms',
136
- delayMs: 500,
137
- },
138
- {
139
- type: 'script',
140
- name: 'Check elapsed',
141
- script: `
142
- const elapsed = Date.now() - context.variables.startTime;
143
- return { elapsed: elapsed, expected: 500 };
144
- `,
145
- },
146
- ],
147
- }),
148
- input: {},
149
- });
150
-
151
- console.log('Result:', result4);
152
-
153
- // 清理
154
- await framework.destroy();
155
- console.log('\n[Done]');
156
- }
157
-
158
- main().catch(console.error);
1
+ /**
2
+ * 工作流示例
3
+ * 展示如何使用工作流引擎
4
+ */
5
+
6
+ const { Framework } = require('../src');
7
+ const { WorkflowPlugin } = require('../src/capabilities/workflow-engine');
8
+
9
+ async function main() {
10
+ console.log('=== Workflow Example ===\n');
11
+
12
+ // 创建框架
13
+ const framework = new Framework({ debug: true });
14
+
15
+ // 加载工作流插件
16
+ await framework.loadPlugin(new WorkflowPlugin());
17
+
18
+ console.log('\n--- Testing Script Step ---');
19
+
20
+ // 直接执行工作流
21
+ const result1 = await framework.executeTool('execute_workflow', {
22
+ workflow: JSON.stringify({
23
+ steps: [
24
+ {
25
+ type: 'script',
26
+ name: 'Calculate',
27
+ script: `
28
+ const a = 10;
29
+ const b = 20;
30
+ context.variables.sum = a + b;
31
+ return a + b;
32
+ `,
33
+ },
34
+ {
35
+ type: 'script',
36
+ name: 'Multiply',
37
+ script: `
38
+ const sum = context.variables.sum;
39
+ context.variables.product = sum * 2;
40
+ return sum * 2;
41
+ `,
42
+ },
43
+ ],
44
+ }),
45
+ input: {},
46
+ });
47
+
48
+ console.log('Result:', result1);
49
+
50
+ console.log('\n--- Testing Loop Step ---');
51
+
52
+ const result2 = await framework.executeTool('execute_workflow', {
53
+ workflow: JSON.stringify({
54
+ steps: [
55
+ {
56
+ type: 'loop',
57
+ name: 'Loop 3 times',
58
+ maxIterations: 3,
59
+ loopVariable: 'i',
60
+ steps: [
61
+ {
62
+ type: 'script',
63
+ name: 'Log iteration',
64
+ script: `
65
+ console.log('Iteration ' + context.variables.i);
66
+ return context.variables.i;
67
+ `,
68
+ },
69
+ ],
70
+ },
71
+ ],
72
+ }),
73
+ input: {},
74
+ });
75
+
76
+ console.log('Result:', result2);
77
+
78
+ console.log('\n--- Testing Condition Step ---');
79
+
80
+ const result3 = await framework.executeTool('execute_workflow', {
81
+ workflow: JSON.stringify({
82
+ steps: [
83
+ {
84
+ type: 'script',
85
+ name: 'Set value',
86
+ outputVariable: 'value',
87
+ script: `
88
+ context.variables.value = 15;
89
+ return 15;
90
+ `,
91
+ },
92
+ {
93
+ type: 'condition',
94
+ name: 'Check value',
95
+ branches: [
96
+ {
97
+ name: 'Greater than 10',
98
+ condition: 'context.variables.value > 10',
99
+ steps: [
100
+ {
101
+ type: 'script',
102
+ name: 'Log greater',
103
+ script: `console.log('Value is greater than 10'); return 'greater';`,
104
+ },
105
+ ],
106
+ },
107
+ {
108
+ name: 'Less than or equal 10',
109
+ condition: 'context.variables.value <= 10',
110
+ steps: [
111
+ {
112
+ type: 'script',
113
+ name: 'Log less',
114
+ script: `console.log('Value is less than or equal 10'); return 'less-or-equal';`,
115
+ },
116
+ ],
117
+ },
118
+ ],
119
+ },
120
+ ],
121
+ }),
122
+ input: {},
123
+ });
124
+
125
+ console.log('Result:', result3);
126
+
127
+ console.log('\n--- Testing Delay ---');
128
+
129
+ const startTime = Date.now();
130
+ const result4 = await framework.executeTool('execute_workflow', {
131
+ workflow: JSON.stringify({
132
+ steps: [
133
+ {
134
+ type: 'delay',
135
+ name: 'Wait 500ms',
136
+ delayMs: 500,
137
+ },
138
+ {
139
+ type: 'script',
140
+ name: 'Check elapsed',
141
+ script: `
142
+ const elapsed = Date.now() - context.variables.startTime;
143
+ return { elapsed: elapsed, expected: 500 };
144
+ `,
145
+ },
146
+ ],
147
+ }),
148
+ input: {},
149
+ });
150
+
151
+ console.log('Result:', result4);
152
+
153
+ // 清理
154
+ await framework.destroy();
155
+ console.log('\n[Done]');
156
+ }
157
+
158
+ main().catch(console.error);