foliko 1.1.93 → 2.0.0

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 (212) hide show
  1. package/.claude/settings.local.json +2 -1
  2. package/CLAUDE.md +56 -30
  3. package/REFACTORING_PLAN.md +645 -0
  4. package/docs/architecture.md +131 -0
  5. package/docs/migration.md +57 -0
  6. package/docs/public-api.md +138 -0
  7. package/docs/usage.md +385 -0
  8. package/examples/ambient-example.js +20 -137
  9. package/examples/basic.js +21 -48
  10. package/examples/bootstrap.js +16 -74
  11. package/examples/mcp-example.js +6 -29
  12. package/examples/skill-example.js +6 -19
  13. package/examples/workflow.js +8 -56
  14. package/package.json +8 -4
  15. package/plugins/README.md +49 -0
  16. package/plugins/{ambient-agent → ambient}/EventWatcher.js +1 -1
  17. package/plugins/{ambient-agent → ambient}/ExplorerLoop.js +3 -3
  18. package/plugins/{ambient-agent → ambient}/GoalManager.js +2 -2
  19. package/plugins/ambient/README.md +14 -0
  20. package/plugins/{ambient-agent → ambient}/Reflector.js +1 -1
  21. package/plugins/{ambient-agent → ambient}/StateStore.js +1 -1
  22. package/plugins/{ambient-agent → ambient}/index.js +2 -2
  23. package/plugins/{ai-plugin.js → core/ai/index.js} +14 -30
  24. package/plugins/{audit-plugin.js → core/audit/index.js} +3 -30
  25. package/plugins/{coordinator-plugin.js → core/coordinator/index.js} +3 -35
  26. package/plugins/core/default/bootstrap.js +202 -0
  27. package/plugins/core/default/config.js +220 -0
  28. package/plugins/core/default/index.js +58 -0
  29. package/plugins/core/mcp/index.js +1 -0
  30. package/plugins/{python-plugin-loader.js → core/python-loader/index.js} +7 -187
  31. package/plugins/{rules-plugin.js → core/rules/index.js} +121 -64
  32. package/plugins/{scheduler-plugin.js → core/scheduler/index.js} +12 -114
  33. package/plugins/{session-plugin.js → core/session/index.js} +9 -73
  34. package/{src/capabilities/skill-manager.js → plugins/core/skill-manager/index.js} +64 -18
  35. package/plugins/{storage-plugin.js → core/storage/index.js} +5 -29
  36. package/plugins/{subagent-plugin.js → core/sub-agent/index.js} +10 -171
  37. package/plugins/{think-plugin.js → core/think/index.js} +24 -91
  38. package/{src/capabilities/workflow-engine.js → plugins/core/workflow/index.js} +87 -85
  39. package/plugins/default-plugins.js +6 -720
  40. package/plugins/{data-splitter-plugin.js → executors/data-splitter/index.js} +9 -83
  41. package/plugins/{extension-executor-plugin.js → executors/extension/index.js} +13 -97
  42. package/plugins/{python-executor-plugin.js → executors/python/index.js} +6 -31
  43. package/plugins/{shell-executor-plugin.js → executors/shell/index.js} +2 -5
  44. package/plugins/install/README.md +9 -0
  45. package/plugins/{install-plugin.js → install/index.js} +3 -3
  46. package/plugins/{file-system-plugin.js → io/file-system/index.js} +34 -236
  47. package/plugins/{web-plugin.js → io/web/index.js} +11 -113
  48. package/plugins/memory/README.md +13 -0
  49. package/plugins/{memory-plugin.js → memory/index.js} +4 -18
  50. package/plugins/messaging/email/README.md +19 -0
  51. package/plugins/{email → messaging/email}/index.js +2 -2
  52. package/plugins/{feishu-plugin.js → messaging/feishu/index.js} +3 -3
  53. package/plugins/{qq-plugin.js → messaging/qq/index.js} +5 -16
  54. package/plugins/{telegram-plugin.js → messaging/telegram/index.js} +3 -3
  55. package/plugins/{weixin-plugin.js → messaging/weixin/index.js} +15 -15
  56. package/plugins/{plugin-manager-plugin.js → plugin-manager/index.js} +36 -180
  57. package/plugins/{tools-plugin.js → tools/index.js} +68 -116
  58. package/plugins/trading/README.md +15 -0
  59. package/plugins/{gate-trading.js → trading/index.js} +8 -8
  60. package/{examples → sandbox}/test-concurrent-chat.js +2 -2
  61. package/{examples → sandbox}/test-long-chat.js +2 -2
  62. package/{examples → sandbox}/test-session-chat.js +2 -2
  63. package/{examples → sandbox}/test-web-plugin.js +1 -1
  64. package/{examples → sandbox}/test-weixin-feishu.js +2 -2
  65. package/src/agent/base.js +56 -0
  66. package/src/{core/agent-chat.js → agent/chat.js} +11 -11
  67. package/src/{core/coordinator-manager.js → agent/coordinator.js} +3 -3
  68. package/src/agent/index.js +111 -0
  69. package/src/agent/main.js +337 -0
  70. package/src/agent/prompt.js +78 -0
  71. package/src/agent/sub.js +198 -0
  72. package/src/agent/worker.js +104 -0
  73. package/{cli/bin/foliko.js → src/cli/bin.js} +1 -1
  74. package/{cli/src → src/cli}/commands/chat.js +25 -21
  75. package/{cli/src → src/cli}/index.js +1 -0
  76. package/{cli/src → src/cli}/ui/chat-ui-old.js +40 -178
  77. package/{cli/src → src/cli}/ui/chat-ui.js +3 -3
  78. package/{cli/src → src/cli}/ui/components/footer-bar.js +1 -1
  79. package/src/common/errors.js +402 -0
  80. package/src/{utils → common}/logger.js +33 -0
  81. package/src/{utils/chat-queue.js → common/queue.js} +2 -2
  82. package/src/config/plugin-config.js +50 -0
  83. package/src/context/agent.js +32 -0
  84. package/src/context/compaction-prompts.js +170 -0
  85. package/src/context/compaction-utils.js +191 -0
  86. package/src/context/compressor.js +413 -0
  87. package/src/context/index.js +9 -0
  88. package/src/{core/context-manager.js → context/manager.js} +1 -1
  89. package/src/context/request.js +50 -0
  90. package/src/context/session.js +33 -0
  91. package/src/context/storage.js +30 -0
  92. package/src/executors/mcp-client.js +153 -0
  93. package/src/executors/mcp-desc.js +236 -0
  94. package/src/executors/mcp-executor.js +91 -956
  95. package/src/{core → framework}/command-registry.js +1 -1
  96. package/src/framework/framework.js +300 -0
  97. package/src/framework/index.js +18 -0
  98. package/src/framework/lifecycle.js +203 -0
  99. package/src/framework/loader.js +78 -0
  100. package/src/framework/registry.js +86 -0
  101. package/src/{core/ui-extension-context.js → framework/ui-extension.js} +1 -1
  102. package/src/index.js +130 -15
  103. package/src/llm/index.js +26 -0
  104. package/src/llm/provider.js +212 -0
  105. package/src/llm/registry.js +11 -0
  106. package/src/{core/token-counter.js → llm/tokens.js} +4 -37
  107. package/src/{core/plugin-base.js → plugin/base.js} +10 -136
  108. package/src/plugin/index.js +14 -0
  109. package/src/plugin/loader.js +101 -0
  110. package/src/plugin/manager.js +261 -0
  111. package/src/{core → session}/branch-summary-auto.js +2 -2
  112. package/src/{core/chat-session.js → session/chat.js} +2 -2
  113. package/src/session/index.js +7 -0
  114. package/src/{core/session-manager.js → session/session.js} +2 -2
  115. package/src/session/ttl.js +92 -0
  116. package/src/{core/jsonl-storage.js → storage/jsonl.js} +1 -1
  117. package/src/tool/executor.js +85 -0
  118. package/src/tool/index.js +15 -0
  119. package/src/tool/registry.js +143 -0
  120. package/src/{core/tool-router.js → tool/router.js} +17 -124
  121. package/src/tool/schema.js +108 -0
  122. package/src/utils/data-splitter.js +1 -1
  123. package/src/utils/download.js +1 -1
  124. package/src/utils/index.js +6 -6
  125. package/src/utils/message-validator.js +1 -1
  126. package/tests/core/context-storage.test.js +46 -0
  127. package/tests/core/llm.test.js +54 -0
  128. package/tests/core/plugin.test.js +42 -0
  129. package/tests/core/tool.test.js +60 -0
  130. package/tests/setup.js +10 -0
  131. package/tests/smoke.test.js +58 -0
  132. package/vitest.config.js +9 -0
  133. package/cli/src/daemon.js +0 -149
  134. package/docs/CONTEXT_DESIGN.md +0 -1596
  135. package/docs/ai-sdk-optimization.md +0 -655
  136. package/docs/features.md +0 -120
  137. package/docs/qq-bot.md +0 -976
  138. package/docs/quick-reference.md +0 -160
  139. package/docs/user-manual.md +0 -1391
  140. package/images/geometric_shapes.jpg +0 -0
  141. package/images/sunset_mountain_lake.jpg +0 -0
  142. package/skills/poster-guide/SKILL.md +0 -792
  143. package/src/capabilities/index.js +0 -11
  144. package/src/core/agent.js +0 -808
  145. package/src/core/context-compressor.js +0 -959
  146. package/src/core/enhanced-context-compressor.js +0 -210
  147. package/src/core/framework.js +0 -1422
  148. package/src/core/index.js +0 -30
  149. package/src/core/plugin-manager.js +0 -961
  150. package/src/core/provider-registry.js +0 -159
  151. package/src/core/provider.js +0 -156
  152. package/src/core/request-context.js +0 -98
  153. package/src/core/subagent.js +0 -442
  154. package/src/core/system-prompt-builder.js +0 -120
  155. package/src/core/tool-executor.js +0 -202
  156. package/src/core/tool-registry.js +0 -517
  157. package/src/core/worker-agent.js +0 -192
  158. package/src/executors/executor-base.js +0 -58
  159. package/src/utils/error-boundary.js +0 -363
  160. package/src/utils/error.js +0 -374
  161. package/system.md +0 -1645
  162. package/website_v2/README.md +0 -57
  163. package/website_v2/SPEC.md +0 -1
  164. package/website_v2/docs/api.html +0 -128
  165. package/website_v2/docs/configuration.html +0 -147
  166. package/website_v2/docs/plugin-development.html +0 -129
  167. package/website_v2/docs/project-structure.html +0 -89
  168. package/website_v2/docs/skill-development.html +0 -85
  169. package/website_v2/index.html +0 -489
  170. package/website_v2/scripts/main.js +0 -93
  171. package/website_v2/styles/animations.css +0 -8
  172. package/website_v2/styles/docs.css +0 -83
  173. package/website_v2/styles/main.css +0 -417
  174. package/xhs_auth.json +0 -268
  175. package//346/265/267/346/212/245/346/217/222/344/273/266.md +0 -621
  176. /package/plugins/{ambient-agent → ambient}/constants.js +0 -0
  177. /package/plugins/{email → messaging/email}/constants.js +0 -0
  178. /package/plugins/{email → messaging/email}/handlers.js +0 -0
  179. /package/plugins/{email → messaging/email}/monitor.js +0 -0
  180. /package/plugins/{email → messaging/email}/parser.js +0 -0
  181. /package/plugins/{email → messaging/email}/reply.js +0 -0
  182. /package/plugins/{email → messaging/email}/utils.js +0 -0
  183. /package/{examples → sandbox}/test-chat.js +0 -0
  184. /package/{examples → sandbox}/test-mcp.js +0 -0
  185. /package/{examples → sandbox}/test-reload.js +0 -0
  186. /package/{examples → sandbox}/test-telegram.js +0 -0
  187. /package/{examples → sandbox}/test-tg-bot.js +0 -0
  188. /package/{examples → sandbox}/test-tg-simple.js +0 -0
  189. /package/{examples → sandbox}/test-tg.js +0 -0
  190. /package/{examples → sandbox}/test-think.js +0 -0
  191. /package/src/{core/sub-agent-config.js → agent/sub-config.js} +0 -0
  192. /package/{cli/src → src/cli}/commands/daemon.js +0 -0
  193. /package/{cli/src → src/cli}/commands/list.js +0 -0
  194. /package/{cli/src → src/cli}/commands/plugin.js +0 -0
  195. /package/{cli/src → src/cli}/ui/components/agent-mention-provider.js +0 -0
  196. /package/{cli/src → src/cli}/ui/components/chained-autocomplete-provider.js +0 -0
  197. /package/{cli/src → src/cli}/ui/components/message-bubble.js +0 -0
  198. /package/{cli/src → src/cli}/ui/components/status-bar.js +0 -0
  199. /package/{cli/src → src/cli}/utils/ansi.js +0 -0
  200. /package/{cli/src → src/cli}/utils/config.js +0 -0
  201. /package/{cli/src → src/cli}/utils/markdown.js +0 -0
  202. /package/{cli/src → src/cli}/utils/plugin-config.js +0 -0
  203. /package/{cli/src → src/cli}/utils/render-diff.js +0 -0
  204. /package/src/{utils/circuit-breaker.js → common/circuit.js} +0 -0
  205. /package/src/{core → common}/constants.js +0 -0
  206. /package/src/{utils/edit-diff.js → common/diff.js} +0 -0
  207. /package/src/{utils/event-emitter.js → common/events.js} +0 -0
  208. /package/src/{utils → common}/id.js +0 -0
  209. /package/src/{utils → common}/retry.js +0 -0
  210. /package/src/{core/notification-manager.js → notification/manager.js} +0 -0
  211. /package/src/{core/session-entry.js → session/entry.js} +0 -0
  212. /package/src/{core/storage-manager.js → storage/manager.js} +0 -0
@@ -1,29 +1,27 @@
1
1
  /**
2
2
  * Ambient Agent Example
3
- * Demonstrates how to use the Ambient Agent plugin for autonomous monitoring and actions
3
+ * Demonstrates how to use the Ambient Agent plugin via the new facade
4
4
  */
5
5
 
6
- const { Framework } = require('../src/core/framework');
6
+ const foliko = require('../src');
7
7
 
8
8
  async function main() {
9
9
  console.log('=== Ambient Agent Example ===\n');
10
10
 
11
- // Create framework
12
- const framework = new Framework({
13
- debug: true,
14
- });
15
-
16
11
  // Bootstrap with default plugins (including ambient)
17
- await framework.bootstrap({
18
- agentDir: './.foliko',
19
- aiConfig: {
20
- provider: 'deepseek',
21
- model: 'deepseek-chat',
22
- apiKey: process.env.DEEPSEEK_API_KEY || 'your-api-key',
12
+ const framework = await foliko.bootstrap({
13
+ _config: {
14
+ agentDir: './.foliko',
15
+ ai: {
16
+ provider: 'deepseek',
17
+ model: 'deepseek-chat',
18
+ apiKey: process.env.DEEPSEEK_API_KEY || 'your-api-key',
19
+ },
23
20
  },
24
21
  });
25
22
 
26
23
  console.log('\n=== Framework Ready ===\n');
24
+ console.log('Plugins:', framework.pluginManager.getNames());
27
25
 
28
26
  // Wait for plugins to start
29
27
  await new Promise((resolve) => setTimeout(resolve, 1000));
@@ -36,12 +34,10 @@ async function main() {
36
34
  }
37
35
 
38
36
  console.log('=== Ambient Plugin Tools Available ===');
39
- const tools = framework.getTools();
40
- const ambientTools = tools.filter((t) => t.name.startsWith('ambient_'));
37
+ const ambientTools = framework.getTools().filter((t) => t.name.startsWith('ambient_'));
41
38
  console.log('Ambient tools:', ambientTools.map((t) => t.name).join(', '));
42
39
 
43
- console.log('\n=== Example 1: Create a Goal ===');
44
- // Use ambient_goals to create a simple goal
40
+ console.log('\n=== Example: Create a Goal ===');
45
41
  const createResult = await framework.executeTool('ambient_goals', {
46
42
  action: 'create',
47
43
  title: 'Monitor System Health',
@@ -51,141 +47,28 @@ async function main() {
51
47
  });
52
48
  console.log('Create goal result:', JSON.stringify(createResult, null, 2));
53
49
 
54
- console.log('\n=== Example 2: Create a Thinking Goal ===');
55
- // Create a goal that triggers LLM thinking
56
- const thinkGoal = await framework.executeTool('ambient_goals', {
57
- action: 'create',
58
- title: 'Periodic Reflection',
59
- description: 'Regularly reflect on system state and suggest improvements',
60
- priority: 5,
61
- actions: [
62
- { id: 'reflect_1', type: 'think', topic: 'System state review', mode: 'reflect', depth: 3 },
63
- ],
64
- });
65
- console.log('Create thinking goal result:', JSON.stringify(thinkGoal, null, 2));
66
-
67
- console.log('\n=== Example 3: List All Goals ===');
68
- const listResult = await framework.executeTool('ambient_goals', {
69
- action: 'list',
70
- });
50
+ console.log('\n=== Example: List All Goals ===');
51
+ const listResult = await framework.executeTool('ambient_goals', { action: 'list' });
71
52
  console.log('Goals list:', JSON.stringify(listResult, null, 2));
72
53
 
73
- console.log('\n=== Example 4: Get Ambient Status ===');
74
- const statusResult = await framework.executeTool('ambient_status', {});
75
- console.log('Status:', JSON.stringify(statusResult, null, 2));
76
-
77
- console.log('\n=== Example 5: Store a Memory ===');
78
- const storeResult = await framework.executeTool('ambient_remember', {
54
+ console.log('\n=== Example: Store and Retrieve Memories ===');
55
+ await framework.executeTool('ambient_remember', {
79
56
  action: 'store',
80
57
  content: 'Important: System check showed high CPU usage at 14:30',
81
58
  key: 'cpu_alert_1',
82
59
  });
83
- console.log('Store memory result:', JSON.stringify(storeResult, null, 2));
84
-
85
- console.log('\n=== Example 6: Retrieve Memories ===');
86
60
  const retrieveResult = await framework.executeTool('ambient_remember', {
87
61
  action: 'retrieve',
88
62
  limit: 5,
89
63
  });
90
- console.log('Retrieve memories result:', JSON.stringify(retrieveResult, null, 2));
91
-
92
- console.log('\n=== Example 7: Search Memories ===');
93
- const searchResult = await framework.executeTool('ambient_remember', {
94
- action: 'search',
95
- query: 'CPU',
96
- });
97
- console.log('Search memories result:', JSON.stringify(searchResult, null, 2));
98
-
99
- console.log('\n=== Example 8: Trigger Thinking ===');
100
- const thinkResult = await framework.executeTool('ambient_think', {
101
- mode: 'brainstorm',
102
- topic: 'What improvements could be made to the current system?',
103
- depth: 3,
104
- });
105
- console.log('Think result:', JSON.stringify(thinkResult, null, 2));
106
-
107
- console.log('\n=== Example 9: Control Loop ===');
108
- console.log('Pausing loop...');
109
- const pauseResult = await framework.executeTool('ambient_control', {
110
- action: 'pause',
111
- });
112
- console.log('Pause result:', JSON.stringify(pauseResult, null, 2));
113
-
114
- await new Promise((resolve) => setTimeout(resolve, 1000));
115
-
116
- console.log('Resuming loop...');
117
- const resumeResult = await framework.executeTool('ambient_control', {
118
- action: 'resume',
119
- });
120
- console.log('Resume result:', JSON.stringify(resumeResult, null, 2));
121
-
122
- console.log('\n=== Example 10: Adjust Loop Settings ===');
123
- const adjustResult = await framework.executeTool('ambient_control', {
124
- action: 'adjust',
125
- tickInterval: 10000, // 10 seconds
126
- cooldownPeriod: 5000, // 5 seconds
127
- });
128
- console.log('Adjust result:', JSON.stringify(adjustResult, null, 2));
129
-
130
- console.log('\n=== Example 11: Get Final Status ===');
131
- const finalStatus = await framework.executeTool('ambient_status', {});
132
- console.log('Final status:', JSON.stringify(finalStatus, null, 2));
133
-
134
- console.log('\n=== Example 12: Activate a Pending Goal ===');
135
- // First create a pending goal (without auto-activation conditions)
136
- const newGoal = await framework.executeTool('ambient_goals', {
137
- action: 'create',
138
- title: 'Inactive Test Goal',
139
- description: 'A goal that starts inactive',
140
- priority: 3,
141
- actions: [],
142
- });
143
- console.log('Created inactive goal:', newGoal.goal ? newGoal.goal.id : 'N/A');
144
-
145
- if (newGoal.goal) {
146
- console.log('Activating goal...');
147
- const activateResult = await framework.executeTool('ambient_goals', {
148
- action: 'activate',
149
- goalId: newGoal.goal.id,
150
- });
151
- console.log('Activate result:', JSON.stringify(activateResult, null, 2));
152
- }
153
-
154
- console.log('\n=== Example 13: Update a Goal ===');
155
- const goals = await framework.executeTool('ambient_goals', { action: 'list' });
156
- if (goals.goals && goals.goals.length > 0) {
157
- const goalToUpdate = goals.goals[0];
158
- console.log(`Updating goal ${goalToUpdate.id}...`);
159
- const updateResult = await framework.executeTool('ambient_goals', {
160
- action: 'update',
161
- goalId: goalToUpdate.id,
162
- priority: 10,
163
- });
164
- console.log('Update result:', JSON.stringify(updateResult, null, 2));
165
- }
166
-
167
- console.log('\n=== Example 14: Delete a Goal ===');
168
- const deleteGoal = await framework.executeTool('ambient_goals', {
169
- action: 'create',
170
- title: 'Goal to Delete',
171
- description: 'This will be deleted',
172
- priority: 1,
173
- });
174
- if (deleteGoal.goal) {
175
- console.log(`Created goal to delete: ${deleteGoal.goal.id}`);
176
- const deleteResult = await framework.executeTool('ambient_goals', {
177
- action: 'delete',
178
- goalId: deleteGoal.goal.id,
179
- });
180
- console.log('Delete result:', JSON.stringify(deleteResult, null, 2));
181
- }
64
+ console.log('Memories:', JSON.stringify(retrieveResult, null, 2));
182
65
 
183
66
  console.log('\n=== All Examples Completed ===');
184
67
  console.log('Check .foliko/data/ambient/ for persisted data');
185
68
 
186
69
  // Cleanup
187
- console.log('\nShutting down...');
188
- await framework.destroy();
70
+ await foliko.destroy(framework);
71
+ console.log('\n[Done]');
189
72
  }
190
73
 
191
74
  main().catch((err) => {
package/examples/basic.js CHANGED
@@ -1,39 +1,33 @@
1
1
  /**
2
2
  * 基础示例
3
- * 展示如何使用 Framework 和 Agent
3
+ * 展示如何使用新门面 API 创建 Framework 和 Agent
4
4
  */
5
5
 
6
- const { Framework } = require('../src');
7
- const AIPlugin = require('../plugins/ai-plugin');
6
+ const foliko = require('../src');
8
7
  const { z } = require('zod');
9
8
 
10
9
  async function main() {
11
- // 创建框架实例
12
- const framework = new Framework({ debug: true });
10
+ // 方式一:使用 createApp 链式加载插件
11
+ const app = foliko.createApp({ debug: true });
12
+ await app.use(foliko.withAI({
13
+ provider: 'deepseek',
14
+ model: 'deepseek-chat',
15
+ apiKey: process.env.DEEPSEEK_API_KEY || 'your-api-key',
16
+ }));
17
+ const { bootstrap } = require('../src/framework/lifecycle');
18
+ await bootstrap(app, { _config: { ai: {} } });
13
19
 
14
- // 加载 AI 插件
15
- await framework.loadPlugin(
16
- new AIPlugin({
17
- provider: 'deepseek',
18
- model: 'deepseek-chat',
19
- apiKey: process.env.DEEPSEEK_API_KEY || 'your-api-key',
20
- })
21
- );
22
-
23
- // 注册自定义工具(使用 inputSchema 格式)
24
- framework.registerTool({
20
+ // 注册自定义工具
21
+ app.registerTool({
25
22
  name: 'hello',
26
23
  description: '打招呼工具',
27
24
  inputSchema: z.object({
28
25
  name: z.string().optional().describe('姓名'),
29
26
  }),
30
- execute: async (args) => {
31
- return `Hello, ${args.name || 'World'}!`;
32
- },
27
+ execute: async (args) => `Hello, ${args.name || 'World'}!`,
33
28
  });
34
29
 
35
- // 注册计算器工具
36
- framework.registerTool({
30
+ app.registerTool({
37
31
  name: 'calculate',
38
32
  description: '简单的计算器',
39
33
  inputSchema: z.object({
@@ -41,7 +35,6 @@ async function main() {
41
35
  }),
42
36
  execute: async (args) => {
43
37
  try {
44
- // 安全计算(仅支持基本运算)
45
38
  const result = Function(`"use strict"; return (${args.expression})`)();
46
39
  return { result };
47
40
  } catch (e) {
@@ -51,13 +44,10 @@ async function main() {
51
44
  });
52
45
 
53
46
  console.log('[Framework] Ready!');
54
- console.log(
55
- '[Tools]',
56
- framework.getTools().map((t) => t.name)
57
- );
47
+ console.log('[Tools]', app.getTools().map((t) => t.name));
58
48
 
59
49
  // 创建 Agent
60
- const agent = framework.createAgent({
50
+ const agent = foliko.createAgent(app, {
61
51
  name: 'MyAgent',
62
52
  systemPrompt: '你是一个有帮助的助手。当需要计算时,使用 calculate 工具。',
63
53
  });
@@ -66,12 +56,11 @@ async function main() {
66
56
  agent.on('tool-call', (tool) => {
67
57
  console.log('[Agent] Tool call:', tool.name, tool.args);
68
58
  });
69
-
70
59
  agent.on('tool-result', (result) => {
71
60
  console.log('[Agent] Tool result:', result.name, result.result);
72
61
  });
73
62
 
74
- // AI 对话示例
63
+ // AI 对话
75
64
  console.log('\n=== AI Chat Example ===');
76
65
  try {
77
66
  const response = await agent.chat('你好!');
@@ -80,35 +69,19 @@ async function main() {
80
69
  console.error('[Agent] Error:', err.message);
81
70
  }
82
71
 
83
- // 使用工具的对话示例
84
- console.log('\n=== AI Chat with Tool Call ===');
85
- try {
86
- const response = await agent.chat('请帮我计算 (15 + 25) * 2 等于多少?');
87
- console.log('[Agent] Response:', response.message);
88
- } catch (err) {
89
- console.error('[Agent] Error:', err.message);
90
- }
91
-
92
- // 流式对话示例
72
+ // 流式对话
93
73
  console.log('\n=== Streaming Chat ===');
94
74
  try {
95
75
  for await (const chunk of agent.chatStream('请用中文介绍一下你自己')) {
96
- if (chunk.type === 'text') {
97
- process.stdout.write(chunk.text);
98
- }
76
+ if (chunk.type === 'text') process.stdout.write(chunk.text);
99
77
  }
100
78
  console.log('\n');
101
79
  } catch (err) {
102
80
  console.error('[Agent] Stream Error:', err.message);
103
81
  }
104
82
 
105
- // 热重载示例
106
- console.log('\n=== Hot Reload ===');
107
- await framework.reloadPlugin('ai');
108
- console.log('AI plugin reloaded!');
109
-
110
83
  // 清理
111
- await framework.destroy();
84
+ await foliko.destroy(app);
112
85
  console.log('\n[Done]');
113
86
  }
114
87
 
@@ -1,31 +1,28 @@
1
1
  /**
2
2
  * Bootstrap 示例
3
- * 使用 framework.bootstrap() 自动加载 .foliko/ 目录配置
3
+ * 使用 foliko.bootstrap() 自动加载配置
4
4
  */
5
5
 
6
- const { Framework } = require('../src');
6
+ const foliko = require('../src');
7
7
  const { z } = require('zod');
8
8
 
9
9
  async function main() {
10
10
  console.log('=== Bootstrap Example ===\n');
11
11
 
12
- // 创建框架
13
- const framework = new Framework({ debug: true });
14
-
15
- // 使用 bootstrap 自动加载所有默认插件
16
- // 会自动检测 .foliko/ 目录下的配置
17
- await framework.bootstrap({
18
- agentDir: './.foliko', // 配置目录
19
- aiConfig: {
20
- // 可选:覆盖 AI 配置
21
- provider: 'deepseek',
22
- model: 'deepseek-chat',
23
- apiKey: process.env.DEEPSEEK_API_KEY || 'your-api-key',
12
+ // 使用新门面 bootstrap — 创建 Framework 并加载所有默认插件
13
+ const framework = await foliko.bootstrap({
14
+ _config: {
15
+ agentDir: './.foliko',
16
+ ai: {
17
+ provider: 'deepseek',
18
+ model: 'deepseek-chat',
19
+ apiKey: process.env.DEEPSEEK_API_KEY || 'your-api-key',
20
+ },
24
21
  },
25
22
  });
26
23
 
27
24
  // 注册 hello 工具(演示用)
28
- framework.registerTool({
25
+ foliko.registerTool(framework, {
29
26
  name: 'hello',
30
27
  description: '打招呼',
31
28
  inputSchema: z.object({
@@ -37,84 +34,29 @@ async function main() {
37
34
  console.log('\n--- Framework Ready ---');
38
35
  console.log(
39
36
  'Plugins:',
40
- framework.pluginManager.getAll().map((p) => p.name)
37
+ framework.pluginManager.getNames()
41
38
  );
42
39
  console.log(
43
40
  'Tools:',
44
41
  framework.getTools().map((t) => t.name)
45
42
  );
46
43
 
47
- // 创建 Agent (支持 sharedPrompt 和 metadata)
48
- const agent = framework.createAgent({
44
+ // 创建 Agent
45
+ const agent = foliko.createAgent(framework, {
49
46
  name: 'MyAgent',
50
47
  systemPrompt: '你是一个有帮助的助手。',
51
- sharedPrompt: '工作目录: {{WORK_DIR}}\n用户名: {{USER_NAME}}\n当前时间: {{TIME}}',
52
- metadata: {
53
- projectName: 'Foliko',
54
- version: '1.0.0',
55
- },
56
48
  });
57
49
 
58
50
  console.log('\n--- Agent Context ---');
59
51
  console.log(agent.systemPrompt);
60
52
 
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
53
  // 测试工具调用
86
54
  console.log('\n--- Tool Call Test ---');
87
55
  const result = await framework.executeTool('hello', { name: 'Bootstrap' });
88
56
  console.log('Tool result:', result);
89
57
 
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
58
  // 清理
117
- await framework.destroy();
59
+ await foliko.destroy(framework);
118
60
  console.log('\n[Done]');
119
61
  }
120
62
 
@@ -1,55 +1,32 @@
1
1
  /**
2
2
  * MCP 执行器示例
3
- * 展示如何连接 MCP 服务器
4
3
  */
5
4
 
6
- const { Framework } = require('../src');
5
+ const foliko = require('../src');
7
6
  const { MCPExecutorPlugin } = require('../src/executors/mcp-executor');
8
7
 
9
8
  async function main() {
10
9
  console.log('=== MCP Executor Example ===\n');
11
10
 
12
- // 创建框架
13
- const framework = new Framework({ debug: true });
11
+ const framework = foliko.createApp({ debug: true });
14
12
 
15
13
  // 创建 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
- });
14
+ const mcpPlugin = new MCPExecutorPlugin({ servers: [] });
27
15
 
28
16
  // 加载插件
29
17
  await framework.loadPlugin(mcpPlugin);
30
18
 
31
19
  // 列出服务器
32
20
  console.log('\n--- MCP Servers ---');
33
- const servers = mcpPlugin.getServers();
34
- console.log('Servers:', servers);
21
+ console.log('Servers:', mcpPlugin.getServers());
35
22
 
36
23
  // 列出所有 MCP 工具
37
24
  console.log('\n--- MCP Tools ---');
38
25
  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
- // })
26
+ console.log('MCP tools:', tools.map((t) => t.name));
50
27
 
51
28
  // 清理
52
- await framework.destroy();
29
+ await foliko.destroy(framework);
53
30
  console.log('\n[Done]');
54
31
  }
55
32
 
@@ -1,16 +1,14 @@
1
1
  /**
2
2
  * Skill 管理器示例
3
- * 展示如何加载和使用 Skill
4
3
  */
5
4
 
6
- const { Framework } = require('../src');
7
- const { SkillManagerPlugin } = require('../src/capabilities/skill-manager');
5
+ const foliko = require('../src');
6
+ const { SkillManagerPlugin } = require('../plugins/core/skill-manager');
8
7
 
9
8
  async function main() {
10
9
  console.log('=== Skill Manager Example ===\n');
11
10
 
12
- // 创建框架
13
- const framework = new Framework({ debug: true });
11
+ const framework = foliko.createApp({ debug: true });
14
12
 
15
13
  // 创建 skills 目录(如果没有)
16
14
  const fs = require('fs');
@@ -20,29 +18,18 @@ async function main() {
20
18
  }
21
19
 
22
20
  // 加载 Skill 管理器插件
23
- const skillPlugin = new SkillManagerPlugin({
24
- skillsDir: skillsDir,
25
- });
26
-
27
- await framework.loadPlugin(skillPlugin);
21
+ await framework.loadPlugin(new SkillManagerPlugin({ skillsDir }));
28
22
 
29
23
  // 列出所有加载的 skills
30
24
  console.log('\n--- Loaded Skills ---');
31
- const skills = skillPlugin.getAllSkills();
25
+ const skills = framework.getPluginInstance('skill-manager').getAllSkills();
32
26
  console.log(`Found ${skills.length} skills:`);
33
27
  for (const skill of skills) {
34
28
  console.log(` - ${skill.name}: ${skill.metadata.description}`);
35
29
  }
36
30
 
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
31
  // 清理
45
- await framework.destroy();
32
+ await foliko.destroy(framework);
46
33
  console.log('\n[Done]');
47
34
  }
48
35