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,241 +1,241 @@
1
- /**
2
- * Storage 存储插件
3
- * 提供数据持久化存储,支持 JSON 文件存储
4
- */
5
-
6
- const { Plugin } = require('../src/core/plugin-base')
7
- const { logger } = require('../src/utils/logger')
8
- const log = logger.child('Storage')
9
- const { z } = require('zod')
10
- const fs = require('fs')
11
- const path = require('path')
12
-
13
- class StoragePlugin extends Plugin {
14
- constructor(config = {}) {
15
- super()
16
- this.name = 'storage'
17
- this.version = '1.0.0'
18
- this.description = '数据持久化存储插件,支持键值对存储'
19
- this.priority = 3
20
-
21
- this.system = true
22
-
23
- this.config = {
24
- type: config.type || 'json', // json 或 memory
25
- path: config.path || '.agent/data',
26
- namespace: config.namespace || 'default'
27
- }
28
-
29
- this._framework = null
30
- this._store = new Map()
31
- this._filePath = null
32
- }
33
-
34
- install(framework) {
35
- this._framework = framework
36
- return this
37
- }
38
-
39
- start(framework) {
40
- // 初始化存储
41
- if (this.config.type === 'json') {
42
- this._initJsonStore()
43
- }
44
-
45
- // 注册存储工具
46
- framework.registerTool({
47
- name: 'storage_set',
48
- description: '存储数据到键值存储',
49
- inputSchema: z.object({
50
- key: z.string().describe('存储键名'),
51
- value: z.any().describe('存储值'),
52
- namespace: z.string().optional().describe('命名空间,默认使用全局命名空间')
53
- }),
54
- execute: async (args) => {
55
- try {
56
- const ns = args.namespace || this.config.namespace
57
- const fullKey = `${ns}:${args.key}`
58
- this._store.set(fullKey, {
59
- value: args.value,
60
- updatedAt: new Date()
61
- })
62
-
63
- if (this.config.type === 'json') {
64
- await this._persistToFile()
65
- }
66
-
67
- return { success: true, key: args.key, namespace: ns }
68
- } catch (err) {
69
- return { success: false, error: err.message }
70
- }
71
- }
72
- })
73
-
74
- framework.registerTool({
75
- name: 'storage_get',
76
- description: '从键值存储获取数据',
77
- inputSchema: z.object({
78
- key: z.string().describe('存储键名'),
79
- namespace: z.string().optional().describe('命名空间')
80
- }),
81
- execute: async (args) => {
82
- const ns = args.namespace || this.config.namespace
83
- const fullKey = `${ns}:${args.key}`
84
- const entry = this._store.get(fullKey)
85
-
86
- if (!entry) {
87
- return { success: false, error: 'Key not found', key: args.key }
88
- }
89
-
90
- return {
91
- success: true,
92
- key: args.key,
93
- namespace: ns,
94
- value: entry.value,
95
- updatedAt: entry.updatedAt
96
- }
97
- }
98
- })
99
-
100
- framework.registerTool({
101
- name: 'storage_delete',
102
- description: '删除存储的数据',
103
- inputSchema: z.object({
104
- key: z.string().describe('存储键名'),
105
- namespace: z.string().optional().describe('命名空间')
106
- }),
107
- execute: async (args) => {
108
- const ns = args.namespace || this.config.namespace
109
- const fullKey = `${ns}:${args.key}`
110
- const existed = this._store.has(fullKey)
111
- this._store.delete(fullKey)
112
-
113
- if (this.config.type === 'json') {
114
- await this._persistToFile()
115
- }
116
-
117
- return { success: true, deleted: existed, key: args.key }
118
- }
119
- })
120
-
121
- framework.registerTool({
122
- name: 'storage_list',
123
- description: '列出命名空间下的所有键',
124
- inputSchema: z.object({
125
- namespace: z.string().optional().describe('命名空间,默认全局')
126
- }),
127
- execute: async (args) => {
128
- const ns = args.namespace || this.config.namespace
129
- const prefix = `${ns}:`
130
- const keys = []
131
-
132
- for (const key of this._store.keys()) {
133
- if (key.startsWith(prefix)) {
134
- keys.push(key.substring(prefix.length))
135
- }
136
- }
137
-
138
- return {
139
- success: true,
140
- namespace: ns,
141
- keys,
142
- count: keys.length
143
- }
144
- }
145
- })
146
-
147
- framework.registerTool({
148
- name: 'storage_clear',
149
- description: '清空命名空间下的所有数据',
150
- inputSchema: z.object({
151
- namespace: z.string().optional().describe('命名空间,默认全局')
152
- }),
153
- execute: async (args) => {
154
- const ns = args.namespace || this.config.namespace
155
- const prefix = `${ns}:`
156
- let count = 0
157
-
158
- for (const key of this._store.keys()) {
159
- if (key.startsWith(prefix)) {
160
- this._store.delete(key)
161
- count++
162
- }
163
- }
164
-
165
- if (this.config.type === 'json') {
166
- await this._persistToFile()
167
- }
168
-
169
- return { success: true, namespace: ns, cleared: count }
170
- }
171
- })
172
-
173
- return this
174
- }
175
-
176
- /**
177
- * 初始化 JSON 文件存储
178
- */
179
- _initJsonStore() {
180
- this._filePath = path.resolve(process.cwd(), this.config.path, `${this.config.namespace}.json`)
181
-
182
- // 确保目录存在
183
- const dir = path.dirname(this._filePath)
184
- if (!fs.existsSync(dir)) {
185
- fs.mkdirSync(dir, { recursive: true })
186
- }
187
-
188
- // 加载已有数据
189
- if (fs.existsSync(this._filePath)) {
190
- try {
191
- const content = fs.readFileSync(this._filePath, 'utf-8')
192
- const data = JSON.parse(content)
193
-
194
- for (const [key, entry] of Object.entries(data)) {
195
- this._store.set(key, entry)
196
- }
197
-
198
- log.info(` Loaded ${this._store.size} entries from ${this._filePath}`)
199
- } catch (err) {
200
- log.warn(` Failed to load storage file: ${err.message}`)
201
- }
202
- }
203
- }
204
-
205
- /**
206
- * 持久化到文件
207
- */
208
- async _persistToFile() {
209
- if (!this._filePath) return
210
-
211
- try {
212
- const data = Object.fromEntries(this._store)
213
- fs.writeFileSync(this._filePath, JSON.stringify(data, null, 2), 'utf-8')
214
- } catch (err) {
215
- log.error(` Failed to persist: ${err.message}`)
216
- }
217
- }
218
-
219
- /**
220
- * 获取存储实例(供其他插件使用)
221
- */
222
- getStore() {
223
- return this._store
224
- }
225
-
226
- reload(framework) {
227
- this._framework = framework
228
- this._store.clear()
229
-
230
- if (this.config.type === 'json') {
231
- this._initJsonStore()
232
- }
233
- }
234
-
235
- uninstall(framework) {
236
- this._store.clear()
237
- this._framework = null
238
- }
239
- }
240
-
1
+ /**
2
+ * Storage 存储插件
3
+ * 提供数据持久化存储,支持 JSON 文件存储
4
+ */
5
+
6
+ const { Plugin } = require('../src/core/plugin-base')
7
+ const { logger } = require('../src/utils/logger')
8
+ const log = logger.child('Storage')
9
+ const { z } = require('zod')
10
+ const fs = require('fs')
11
+ const path = require('path')
12
+
13
+ class StoragePlugin extends Plugin {
14
+ constructor(config = {}) {
15
+ super()
16
+ this.name = 'storage'
17
+ this.version = '1.0.0'
18
+ this.description = '数据持久化存储插件,支持键值对存储'
19
+ this.priority = 3
20
+
21
+ this.system = true
22
+
23
+ this.config = {
24
+ type: config.type || 'json', // json 或 memory
25
+ path: config.path || '.agent/data',
26
+ namespace: config.namespace || 'default'
27
+ }
28
+
29
+ this._framework = null
30
+ this._store = new Map()
31
+ this._filePath = null
32
+ }
33
+
34
+ install(framework) {
35
+ this._framework = framework
36
+ return this
37
+ }
38
+
39
+ start(framework) {
40
+ // 初始化存储
41
+ if (this.config.type === 'json') {
42
+ this._initJsonStore()
43
+ }
44
+
45
+ // 注册存储工具
46
+ framework.registerTool({
47
+ name: 'storage_set',
48
+ description: '存储数据到键值存储',
49
+ inputSchema: z.object({
50
+ key: z.string().describe('存储键名'),
51
+ value: z.any().describe('存储值'),
52
+ namespace: z.string().optional().describe('命名空间,默认使用全局命名空间')
53
+ }),
54
+ execute: async (args) => {
55
+ try {
56
+ const ns = args.namespace || this.config.namespace
57
+ const fullKey = `${ns}:${args.key}`
58
+ this._store.set(fullKey, {
59
+ value: args.value,
60
+ updatedAt: new Date()
61
+ })
62
+
63
+ if (this.config.type === 'json') {
64
+ await this._persistToFile()
65
+ }
66
+
67
+ return { success: true, key: args.key, namespace: ns }
68
+ } catch (err) {
69
+ return { success: false, error: err.message }
70
+ }
71
+ }
72
+ })
73
+
74
+ framework.registerTool({
75
+ name: 'storage_get',
76
+ description: '从键值存储获取数据',
77
+ inputSchema: z.object({
78
+ key: z.string().describe('存储键名'),
79
+ namespace: z.string().optional().describe('命名空间')
80
+ }),
81
+ execute: async (args) => {
82
+ const ns = args.namespace || this.config.namespace
83
+ const fullKey = `${ns}:${args.key}`
84
+ const entry = this._store.get(fullKey)
85
+
86
+ if (!entry) {
87
+ return { success: false, error: 'Key not found', key: args.key }
88
+ }
89
+
90
+ return {
91
+ success: true,
92
+ key: args.key,
93
+ namespace: ns,
94
+ value: entry.value,
95
+ updatedAt: entry.updatedAt
96
+ }
97
+ }
98
+ })
99
+
100
+ framework.registerTool({
101
+ name: 'storage_delete',
102
+ description: '删除存储的数据',
103
+ inputSchema: z.object({
104
+ key: z.string().describe('存储键名'),
105
+ namespace: z.string().optional().describe('命名空间')
106
+ }),
107
+ execute: async (args) => {
108
+ const ns = args.namespace || this.config.namespace
109
+ const fullKey = `${ns}:${args.key}`
110
+ const existed = this._store.has(fullKey)
111
+ this._store.delete(fullKey)
112
+
113
+ if (this.config.type === 'json') {
114
+ await this._persistToFile()
115
+ }
116
+
117
+ return { success: true, deleted: existed, key: args.key }
118
+ }
119
+ })
120
+
121
+ framework.registerTool({
122
+ name: 'storage_list',
123
+ description: '列出命名空间下的所有键',
124
+ inputSchema: z.object({
125
+ namespace: z.string().optional().describe('命名空间,默认全局')
126
+ }),
127
+ execute: async (args) => {
128
+ const ns = args.namespace || this.config.namespace
129
+ const prefix = `${ns}:`
130
+ const keys = []
131
+
132
+ for (const key of this._store.keys()) {
133
+ if (key.startsWith(prefix)) {
134
+ keys.push(key.substring(prefix.length))
135
+ }
136
+ }
137
+
138
+ return {
139
+ success: true,
140
+ namespace: ns,
141
+ keys,
142
+ count: keys.length
143
+ }
144
+ }
145
+ })
146
+
147
+ framework.registerTool({
148
+ name: 'storage_clear',
149
+ description: '清空命名空间下的所有数据',
150
+ inputSchema: z.object({
151
+ namespace: z.string().optional().describe('命名空间,默认全局')
152
+ }),
153
+ execute: async (args) => {
154
+ const ns = args.namespace || this.config.namespace
155
+ const prefix = `${ns}:`
156
+ let count = 0
157
+
158
+ for (const key of this._store.keys()) {
159
+ if (key.startsWith(prefix)) {
160
+ this._store.delete(key)
161
+ count++
162
+ }
163
+ }
164
+
165
+ if (this.config.type === 'json') {
166
+ await this._persistToFile()
167
+ }
168
+
169
+ return { success: true, namespace: ns, cleared: count }
170
+ }
171
+ })
172
+
173
+ return this
174
+ }
175
+
176
+ /**
177
+ * 初始化 JSON 文件存储
178
+ */
179
+ _initJsonStore() {
180
+ this._filePath = path.resolve(process.cwd(), this.config.path, `${this.config.namespace}.json`)
181
+
182
+ // 确保目录存在
183
+ const dir = path.dirname(this._filePath)
184
+ if (!fs.existsSync(dir)) {
185
+ fs.mkdirSync(dir, { recursive: true })
186
+ }
187
+
188
+ // 加载已有数据
189
+ if (fs.existsSync(this._filePath)) {
190
+ try {
191
+ const content = fs.readFileSync(this._filePath, 'utf-8')
192
+ const data = JSON.parse(content)
193
+
194
+ for (const [key, entry] of Object.entries(data)) {
195
+ this._store.set(key, entry)
196
+ }
197
+
198
+ log.info(` Loaded ${this._store.size} entries from ${this._filePath}`)
199
+ } catch (err) {
200
+ log.warn(` Failed to load storage file: ${err.message}`)
201
+ }
202
+ }
203
+ }
204
+
205
+ /**
206
+ * 持久化到文件
207
+ */
208
+ async _persistToFile() {
209
+ if (!this._filePath) return
210
+
211
+ try {
212
+ const data = Object.fromEntries(this._store)
213
+ fs.writeFileSync(this._filePath, JSON.stringify(data, null, 2), 'utf-8')
214
+ } catch (err) {
215
+ log.error(` Failed to persist: ${err.message}`)
216
+ }
217
+ }
218
+
219
+ /**
220
+ * 获取存储实例(供其他插件使用)
221
+ */
222
+ getStore() {
223
+ return this._store
224
+ }
225
+
226
+ reload(framework) {
227
+ this._framework = framework
228
+ this._store.clear()
229
+
230
+ if (this.config.type === 'json') {
231
+ this._initJsonStore()
232
+ }
233
+ }
234
+
235
+ uninstall(framework) {
236
+ this._store.clear()
237
+ this._framework = null
238
+ }
239
+ }
240
+
241
241
  module.exports = { StoragePlugin }