foliko 1.0.81 → 1.0.82

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 (87) 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.js +958 -958
  64. package/src/core/framework.js +465 -465
  65. package/src/core/index.js +19 -19
  66. package/src/core/plugin-base.js +262 -262
  67. package/src/core/plugin-manager.js +863 -863
  68. package/src/core/provider.js +114 -114
  69. package/src/core/sub-agent-config.js +264 -264
  70. package/src/core/system-prompt-builder.js +120 -120
  71. package/src/core/tool-registry.js +517 -517
  72. package/src/core/tool-router.js +297 -297
  73. package/src/executors/executor-base.js +58 -58
  74. package/src/executors/mcp-executor.js +845 -845
  75. package/src/index.js +25 -25
  76. package/src/utils/circuit-breaker.js +301 -301
  77. package/src/utils/error-boundary.js +363 -363
  78. package/src/utils/error.js +374 -374
  79. package/src/utils/event-emitter.js +97 -97
  80. package/src/utils/id.js +133 -133
  81. package/src/utils/index.js +217 -217
  82. package/src/utils/logger.js +181 -181
  83. package/src/utils/plugin-helpers.js +90 -90
  84. package/src/utils/retry.js +122 -122
  85. package/src/utils/sandbox.js +292 -292
  86. package/test/tool-registry-validation.test.js +218 -218
  87. package/website/script.js +136 -136
@@ -1,196 +1,196 @@
1
- /**
2
- * 工具插件
3
- * 提供内置工具和热重载功能
4
- */
5
-
6
- const { Plugin } = require('../src/core/plugin-base')
7
- const { logger } = require('../src/utils/logger')
8
- const log = logger.child('Tools')
9
- const { z } = require('zod')
10
-
11
- class ToolsPlugin extends Plugin {
12
- constructor(config = {}) {
13
- super()
14
- this.name = 'tools'
15
- this.version = '1.0.0'
16
- this.description = '内置工具插件,提供热重载和工具管理功能'
17
- this.priority = 10
18
-
19
- this.system = true
20
-
21
- this._framework = null
22
- }
23
-
24
- install(framework) {
25
- this._framework = framework
26
- this._registerBuiltinTools()
27
- return this
28
- }
29
-
30
- start(framework) {
31
- // 工具已通过 install 注册
32
- }
33
-
34
- _registerBuiltinTools() {
35
- const framework = this._framework
36
-
37
- // 热重载插件工具
38
- framework.registerTool({
39
- name: 'reload_plugins',
40
- description: '热重载插件。可以重载单个指定插件,或重载所有插件。',
41
- inputSchema: z.object({
42
- pluginName: z.string().optional().describe('可选:指定要重载的插件名称,不指定则重载所有插件')
43
- }),
44
- execute: async (args) => {
45
- try {
46
- if (args.pluginName) {
47
- await framework.reloadPlugin(args.pluginName)
48
- return {
49
- success: true,
50
- message: `Plugin '${args.pluginName}' reloaded successfully`
51
- }
52
- } else {
53
- await framework.reloadAllPlugins()
54
- return {
55
- success: true,
56
- message: 'All plugins reloaded successfully'
57
- }
58
- }
59
- } catch (err) {
60
- return {
61
- success: false,
62
- error: err.message
63
- }
64
- }
65
- }
66
- })
67
-
68
- // 列出所有插件工具(包括未加载的)
69
- framework.registerTool({
70
- name: 'list_plugins',
71
- description: '列出所有插件(包括未加载的)',
72
- inputSchema: z.object({}),
73
- execute: async () => {
74
- const plugins = framework.pluginManager.getAllKnown()
75
- return {
76
- success: true,
77
- plugins: plugins.map(p => ({
78
- name: p.name,
79
- status: p.status,
80
- enabled: p.enabled,
81
- version: p.version,
82
- system: p.system
83
- }))
84
- }
85
- }
86
- })
87
-
88
- // 启用插件工具
89
- framework.registerTool({
90
- name: 'enable_plugin',
91
- description: '启用指定插件',
92
- inputSchema: z.object({
93
- name: z.string().describe('插件名称')
94
- }),
95
- execute: async (args) => {
96
- try {
97
- await framework.enablePlugin(args.name)
98
- return { success: true, message: `插件 '${args.name}' 已启用` }
99
- } catch (err) {
100
- return { success: false, error: err.message }
101
- }
102
- }
103
- })
104
-
105
- // 禁用插件工具
106
- framework.registerTool({
107
- name: 'disable_plugin',
108
- description: '禁用指定插件',
109
- inputSchema: z.object({
110
- name: z.string().describe('插件名称')
111
- }),
112
- execute: async (args) => {
113
- try {
114
- await framework.disablePlugin(args.name)
115
- return { success: true, message: `插件 '${args.name}' 已禁用` }
116
- } catch (err) {
117
- return { success: false, error: err.message }
118
- }
119
- }
120
- })
121
-
122
- // 获取工具列表
123
- framework.registerTool({
124
- name: 'list_tools',
125
- description: '列出所有已注册的工具',
126
- inputSchema: z.object({}),
127
- execute: async () => {
128
- const tools = framework.getTools()
129
- return {
130
- success: true,
131
- tools: tools.map(t => ({
132
- name: t.name,
133
- description: t.description
134
- }))
135
- }
136
- }
137
- })
138
-
139
- // 获取插件配置
140
- framework.registerTool({
141
- name: 'get_plugin_config',
142
- description: '获取指定插件的当前配置',
143
- inputSchema: z.object({
144
- name: z.string().describe('插件名称')
145
- }),
146
- execute: async (args) => {
147
- const plugin = framework.pluginManager.get(args.name)
148
- if (!plugin) {
149
- return { success: false, error: `Plugin '${args.name}' not found` }
150
- }
151
- return {
152
- success: true,
153
- config: plugin.config || {}
154
- }
155
- }
156
- })
157
-
158
- // 更新插件配置
159
- framework.registerTool({
160
- name: 'update_plugin_config',
161
- description: '更新指定插件的配置,会合并到现有配置并持久化保存',
162
- inputSchema: z.object({
163
- name: z.string().describe('插件名称'),
164
- config: z.record(z.any()).describe('要更新的配置(会合并到现有配置)')
165
- }),
166
- execute: async (args) => {
167
- try {
168
- const newConfig = framework.updatePluginConfig(args.name, args.config)
169
- return { success: true, message: `插件 '${args.name}' 配置已更新`, config: newConfig }
170
- } catch (err) {
171
- return { success: false, error: err.message }
172
- }
173
- }
174
- })
175
- }
176
-
177
- reload(framework) {
178
- log.info(' Reloading...')
179
- this._framework = framework
180
- this._registerBuiltinTools()
181
- }
182
-
183
- uninstall(framework) {
184
- // 注销内置工具
185
- framework.toolRegistry.unregister('reload_plugins')
186
- framework.toolRegistry.unregister('list_plugins')
187
- framework.toolRegistry.unregister('list_tools')
188
- framework.toolRegistry.unregister('enable_plugin')
189
- framework.toolRegistry.unregister('disable_plugin')
190
- framework.toolRegistry.unregister('get_plugin_config')
191
- framework.toolRegistry.unregister('update_plugin_config')
192
- this._framework = null
193
- }
194
- }
195
-
196
- module.exports = ToolsPlugin
1
+ /**
2
+ * 工具插件
3
+ * 提供内置工具和热重载功能
4
+ */
5
+
6
+ const { Plugin } = require('../src/core/plugin-base')
7
+ const { logger } = require('../src/utils/logger')
8
+ const log = logger.child('Tools')
9
+ const { z } = require('zod')
10
+
11
+ class ToolsPlugin extends Plugin {
12
+ constructor(config = {}) {
13
+ super()
14
+ this.name = 'tools'
15
+ this.version = '1.0.0'
16
+ this.description = '内置工具插件,提供热重载和工具管理功能'
17
+ this.priority = 10
18
+
19
+ this.system = true
20
+
21
+ this._framework = null
22
+ }
23
+
24
+ install(framework) {
25
+ this._framework = framework
26
+ this._registerBuiltinTools()
27
+ return this
28
+ }
29
+
30
+ start(framework) {
31
+ // 工具已通过 install 注册
32
+ }
33
+
34
+ _registerBuiltinTools() {
35
+ const framework = this._framework
36
+
37
+ // 热重载插件工具
38
+ framework.registerTool({
39
+ name: 'reload_plugins',
40
+ description: '热重载插件。可以重载单个指定插件,或重载所有插件。',
41
+ inputSchema: z.object({
42
+ pluginName: z.string().optional().describe('可选:指定要重载的插件名称,不指定则重载所有插件')
43
+ }),
44
+ execute: async (args) => {
45
+ try {
46
+ if (args.pluginName) {
47
+ await framework.reloadPlugin(args.pluginName)
48
+ return {
49
+ success: true,
50
+ message: `Plugin '${args.pluginName}' reloaded successfully`
51
+ }
52
+ } else {
53
+ await framework.reloadAllPlugins()
54
+ return {
55
+ success: true,
56
+ message: 'All plugins reloaded successfully'
57
+ }
58
+ }
59
+ } catch (err) {
60
+ return {
61
+ success: false,
62
+ error: err.message
63
+ }
64
+ }
65
+ }
66
+ })
67
+
68
+ // 列出所有插件工具(包括未加载的)
69
+ framework.registerTool({
70
+ name: 'list_plugins',
71
+ description: '列出所有插件(包括未加载的)',
72
+ inputSchema: z.object({}),
73
+ execute: async () => {
74
+ const plugins = framework.pluginManager.getAllKnown()
75
+ return {
76
+ success: true,
77
+ plugins: plugins.map(p => ({
78
+ name: p.name,
79
+ status: p.status,
80
+ enabled: p.enabled,
81
+ version: p.version,
82
+ system: p.system
83
+ }))
84
+ }
85
+ }
86
+ })
87
+
88
+ // 启用插件工具
89
+ framework.registerTool({
90
+ name: 'enable_plugin',
91
+ description: '启用指定插件',
92
+ inputSchema: z.object({
93
+ name: z.string().describe('插件名称')
94
+ }),
95
+ execute: async (args) => {
96
+ try {
97
+ await framework.enablePlugin(args.name)
98
+ return { success: true, message: `插件 '${args.name}' 已启用` }
99
+ } catch (err) {
100
+ return { success: false, error: err.message }
101
+ }
102
+ }
103
+ })
104
+
105
+ // 禁用插件工具
106
+ framework.registerTool({
107
+ name: 'disable_plugin',
108
+ description: '禁用指定插件',
109
+ inputSchema: z.object({
110
+ name: z.string().describe('插件名称')
111
+ }),
112
+ execute: async (args) => {
113
+ try {
114
+ await framework.disablePlugin(args.name)
115
+ return { success: true, message: `插件 '${args.name}' 已禁用` }
116
+ } catch (err) {
117
+ return { success: false, error: err.message }
118
+ }
119
+ }
120
+ })
121
+
122
+ // 获取工具列表
123
+ framework.registerTool({
124
+ name: 'list_tools',
125
+ description: '列出所有已注册的工具',
126
+ inputSchema: z.object({}),
127
+ execute: async () => {
128
+ const tools = framework.getTools()
129
+ return {
130
+ success: true,
131
+ tools: tools.map(t => ({
132
+ name: t.name,
133
+ description: t.description
134
+ }))
135
+ }
136
+ }
137
+ })
138
+
139
+ // 获取插件配置
140
+ framework.registerTool({
141
+ name: 'get_plugin_config',
142
+ description: '获取指定插件的当前配置',
143
+ inputSchema: z.object({
144
+ name: z.string().describe('插件名称')
145
+ }),
146
+ execute: async (args) => {
147
+ const plugin = framework.pluginManager.get(args.name)
148
+ if (!plugin) {
149
+ return { success: false, error: `Plugin '${args.name}' not found` }
150
+ }
151
+ return {
152
+ success: true,
153
+ config: plugin.config || {}
154
+ }
155
+ }
156
+ })
157
+
158
+ // 更新插件配置
159
+ framework.registerTool({
160
+ name: 'update_plugin_config',
161
+ description: '更新指定插件的配置,会合并到现有配置并持久化保存',
162
+ inputSchema: z.object({
163
+ name: z.string().describe('插件名称'),
164
+ config: z.record(z.any()).describe('要更新的配置(会合并到现有配置)')
165
+ }),
166
+ execute: async (args) => {
167
+ try {
168
+ const newConfig = framework.updatePluginConfig(args.name, args.config)
169
+ return { success: true, message: `插件 '${args.name}' 配置已更新`, config: newConfig }
170
+ } catch (err) {
171
+ return { success: false, error: err.message }
172
+ }
173
+ }
174
+ })
175
+ }
176
+
177
+ reload(framework) {
178
+ log.info(' Reloading...')
179
+ this._framework = framework
180
+ this._registerBuiltinTools()
181
+ }
182
+
183
+ uninstall(framework) {
184
+ // 注销内置工具
185
+ framework.toolRegistry.unregister('reload_plugins')
186
+ framework.toolRegistry.unregister('list_plugins')
187
+ framework.toolRegistry.unregister('list_tools')
188
+ framework.toolRegistry.unregister('enable_plugin')
189
+ framework.toolRegistry.unregister('disable_plugin')
190
+ framework.toolRegistry.unregister('get_plugin_config')
191
+ framework.toolRegistry.unregister('update_plugin_config')
192
+ this._framework = null
193
+ }
194
+ }
195
+
196
+ module.exports = ToolsPlugin