foliko 1.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.
- package/.claude/settings.local.json +30 -0
- package/22.txt +10 -0
- package/README.md +218 -0
- package/SPEC.md +452 -0
- package/cli/bin/foliko.js +12 -0
- package/cli/src/commands/chat.js +75 -0
- package/cli/src/index.js +64 -0
- package/cli/src/ui/chat-ui.js +272 -0
- package/cli/src/utils/ansi.js +40 -0
- package/cli/src/utils/markdown.js +296 -0
- package/docs/quick-reference.md +131 -0
- package/docs/user-manual.md +1205 -0
- package/examples/basic.js +110 -0
- package/examples/bootstrap.js +93 -0
- package/examples/mcp-example.js +53 -0
- package/examples/skill-example.js +49 -0
- package/examples/workflow.js +158 -0
- package/package.json +36 -0
- package/plugins/ai-plugin.js +89 -0
- package/plugins/audit-plugin.js +187 -0
- package/plugins/default-plugins.js +412 -0
- package/plugins/file-system-plugin.js +344 -0
- package/plugins/install-plugin.js +93 -0
- package/plugins/python-executor-plugin.js +331 -0
- package/plugins/rules-plugin.js +292 -0
- package/plugins/scheduler-plugin.js +426 -0
- package/plugins/session-plugin.js +343 -0
- package/plugins/shell-executor-plugin.js +196 -0
- package/plugins/storage-plugin.js +237 -0
- package/plugins/subagent-plugin.js +395 -0
- package/plugins/think-plugin.js +329 -0
- package/plugins/tools-plugin.js +114 -0
- package/skills/mcp-usage/SKILL.md +198 -0
- package/skills/vb-agent-dev/AGENTS.md +162 -0
- package/skills/vb-agent-dev/SKILL.md +370 -0
- package/src/capabilities/index.js +11 -0
- package/src/capabilities/skill-manager.js +319 -0
- package/src/capabilities/workflow-engine.js +401 -0
- package/src/core/agent-chat.js +311 -0
- package/src/core/agent.js +573 -0
- package/src/core/framework.js +255 -0
- package/src/core/index.js +19 -0
- package/src/core/plugin-base.js +205 -0
- package/src/core/plugin-manager.js +392 -0
- package/src/core/provider.js +108 -0
- package/src/core/tool-registry.js +134 -0
- package/src/core/tool-router.js +216 -0
- package/src/executors/executor-base.js +58 -0
- package/src/executors/mcp-executor.js +728 -0
- package/src/index.js +37 -0
- package/src/utils/event-emitter.js +97 -0
- package/test-chat.js +129 -0
- package/test-mcp.js +79 -0
- package/test-reload.js +61 -0
package/SPEC.md
ADDED
|
@@ -0,0 +1,452 @@
|
|
|
1
|
+
# VB-Agent Framework 规划文档
|
|
2
|
+
|
|
3
|
+
## 一、设计目标
|
|
4
|
+
|
|
5
|
+
1. **纯 JS 实现** - 无 TypeScript,简明易懂
|
|
6
|
+
2. **架构简约** - 核心仅包含必要组件,通过插件扩展功能
|
|
7
|
+
3. **插件系统与 Agent 分离** - Agent 专注于对话推理,插件提供扩展能力
|
|
8
|
+
4. **手动热重载** - 不监测文件变化,通过 API 手动调用重载
|
|
9
|
+
|
|
10
|
+
## 二、核心架构
|
|
11
|
+
|
|
12
|
+
```
|
|
13
|
+
┌─────────────────────────────────────────────────┐
|
|
14
|
+
│ VB-Agent Framework │
|
|
15
|
+
├─────────────────────────────────────────────────┤
|
|
16
|
+
│ Framework (容器层) │
|
|
17
|
+
│ ├── pluginManager - 插件加载/卸载/重载 │
|
|
18
|
+
│ ├── toolRegistry - 工具注册表 │
|
|
19
|
+
│ ├── skillManager - Skill管理 (可选) │
|
|
20
|
+
│ └── eventEmitter - 事件总线 │
|
|
21
|
+
├─────────────────────────────────────────────────┤
|
|
22
|
+
│ Agent (对话层) │
|
|
23
|
+
│ ├── chat() - 对话接口 │
|
|
24
|
+
│ ├── tools - 从 Framework 获取 │
|
|
25
|
+
│ └── events - 事件监听 │
|
|
26
|
+
└─────────────────────────────────────────────────┘
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### 2.1 Framework 类
|
|
30
|
+
|
|
31
|
+
```javascript
|
|
32
|
+
class Framework {
|
|
33
|
+
constructor(config = {})
|
|
34
|
+
registerPlugin(plugin) // 注册插件
|
|
35
|
+
loadPlugin(pluginDef) // 加载插件
|
|
36
|
+
unloadPlugin(name) // 卸载插件
|
|
37
|
+
reloadPlugin(name) // 重载单个插件
|
|
38
|
+
reloadAllPlugins() // 重载所有插件
|
|
39
|
+
registerTool(tool) // 注册工具
|
|
40
|
+
getTools() // 获取所有工具
|
|
41
|
+
on(event, handler) // 监听事件
|
|
42
|
+
emit(event, data) // 触发事件
|
|
43
|
+
ready() // 等待初始化完成
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### 2.2 Agent 类
|
|
48
|
+
|
|
49
|
+
```javascript
|
|
50
|
+
// 创建 Agent
|
|
51
|
+
const agent = framework.createAgent({
|
|
52
|
+
name: 'MyAgent', // Agent 名称
|
|
53
|
+
systemPrompt: '你是一个助手', // 系统提示
|
|
54
|
+
|
|
55
|
+
// 共享提示模板 (支持 {{VAR}} 占位符)
|
|
56
|
+
sharedPrompt: `工作目录: {{WORK_DIR}}`,
|
|
57
|
+
|
|
58
|
+
// 元数据 (供 sharedPrompt 和自身使用)
|
|
59
|
+
metadata: {
|
|
60
|
+
projectName: 'MyProject',
|
|
61
|
+
version: '1.0.0'
|
|
62
|
+
}
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
// 运行时元数据操作
|
|
66
|
+
agent.setMetadata('task', '数据分析') // 设置单个
|
|
67
|
+
agent.setMetadata({ key: 'value' }) // 批量设置
|
|
68
|
+
agent.getMetadata('task') // 获取
|
|
69
|
+
agent.deleteMetadata('task') // 删除
|
|
70
|
+
agent.clearMetadata() // 清空
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
**内置占位符:**
|
|
74
|
+
| 占位符 | 说明 |
|
|
75
|
+
|--------|------|
|
|
76
|
+
| `{{WORK_DIR}}` | 工作目录 |
|
|
77
|
+
| `{{HOME_DIR}}` | 主目录 |
|
|
78
|
+
| `{{HOST_NAME}}` | 主机名 |
|
|
79
|
+
| `{{PLATFORM}}` | 平台 |
|
|
80
|
+
| `{{TIME}}` | 当前时间 |
|
|
81
|
+
| `{{DATE}}` | 当前日期 |
|
|
82
|
+
|
|
83
|
+
**Agent 方法:**
|
|
84
|
+
```javascript
|
|
85
|
+
class Agent {
|
|
86
|
+
constructor(framework, config) // 创建 Agent
|
|
87
|
+
chat(message, options) // 发送消息
|
|
88
|
+
chatStream(message, options) // 流式发送消息
|
|
89
|
+
setSystemPrompt(prompt) // 设置系统提示
|
|
90
|
+
registerTool(tool) // 注册工具
|
|
91
|
+
getTools() // 获取工具列表
|
|
92
|
+
clearHistory() // 清空对话历史
|
|
93
|
+
getStatus() // 获取状态
|
|
94
|
+
destroy() // 销毁 Agent
|
|
95
|
+
|
|
96
|
+
// 元数据管理
|
|
97
|
+
setMetadata(key, value) // 设置元数据
|
|
98
|
+
getMetadata(key) // 获取元数据
|
|
99
|
+
deleteMetadata(key) // 删除元数据
|
|
100
|
+
clearMetadata() // 清空元数据
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
**生成的 System Prompt 示例:**
|
|
105
|
+
```
|
|
106
|
+
你是一个助手。
|
|
107
|
+
|
|
108
|
+
工作目录: D:\project
|
|
109
|
+
|
|
110
|
+
【元数据】
|
|
111
|
+
- projectName: MyProject
|
|
112
|
+
- version: 1.0.0
|
|
113
|
+
|
|
114
|
+
【可用工具】
|
|
115
|
+
- shell: 执行命令
|
|
116
|
+
- python: 执行Python代码
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### 2.3 插件基类
|
|
120
|
+
|
|
121
|
+
```javascript
|
|
122
|
+
class Plugin {
|
|
123
|
+
name // 插件名称 (必填)
|
|
124
|
+
version = '1.0.0'
|
|
125
|
+
description // 插件描述
|
|
126
|
+
|
|
127
|
+
install(framework) { } // 安装时调用
|
|
128
|
+
start(framework) { } // 启动时调用
|
|
129
|
+
reload(framework) { } // 热重载时调用
|
|
130
|
+
uninstall(framework) { } // 卸载时调用
|
|
131
|
+
}
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
## 三、目录结构
|
|
135
|
+
|
|
136
|
+
```
|
|
137
|
+
D:\code\vb-agent\
|
|
138
|
+
├── src/
|
|
139
|
+
│ ├── core/
|
|
140
|
+
│ │ ├── framework.js # 核心容器
|
|
141
|
+
│ │ ├── agent.js # Agent类
|
|
142
|
+
│ │ ├── agent-chat.js # 聊天处理器
|
|
143
|
+
│ │ ├── plugin-manager.js# 插件管理器
|
|
144
|
+
│ │ ├── plugin-base.js # 插件基类
|
|
145
|
+
│ │ ├── tool-registry.js # 工具注册表
|
|
146
|
+
│ │ ├── provider.js # AI Provider 工厂
|
|
147
|
+
│ │ └── index.js # 统一导出
|
|
148
|
+
│ ├── capabilities/
|
|
149
|
+
│ │ ├── skill-manager.js # Skill 管理器
|
|
150
|
+
│ │ └── workflow-engine.js # 工作流引擎
|
|
151
|
+
│ ├── executors/
|
|
152
|
+
│ │ ├── executor-base.js # 执行器基类
|
|
153
|
+
│ │ └── mcp-executor.js # MCP 执行器
|
|
154
|
+
│ ├── utils/
|
|
155
|
+
│ │ └── event-emitter.js # 事件发射器
|
|
156
|
+
│ └── index.js
|
|
157
|
+
├── plugins/ # 内置插件
|
|
158
|
+
│ ├── ai-plugin.js # AI对话插件
|
|
159
|
+
│ ├── tools-plugin.js # 内置工具插件
|
|
160
|
+
│ ├── default-plugins.js # 默认插件加载器
|
|
161
|
+
│ ├── shell-executor-plugin.js # Shell执行器插件
|
|
162
|
+
│ ├── python-executor-plugin.js # Python执行器插件
|
|
163
|
+
│ ├── session-plugin.js # Session会话管理插件
|
|
164
|
+
│ ├── audit-plugin.js # Audit审计日志插件
|
|
165
|
+
│ ├── rules-plugin.js # Rules规则引擎插件
|
|
166
|
+
│ ├── scheduler-plugin.js # Scheduler定时任务插件
|
|
167
|
+
│ ├── storage-plugin.js # Storage存储插件
|
|
168
|
+
│ └── subagent-plugin.js # SubAgent子代理插件
|
|
169
|
+
├── examples/
|
|
170
|
+
│ ├── basic.js # 基础示例
|
|
171
|
+
│ ├── bootstrap.js # Bootstrap示例
|
|
172
|
+
│ └── workflow.js # 工作流示例
|
|
173
|
+
├── .agent/ # Agent 配置目录
|
|
174
|
+
│ ├── config # 配置文件
|
|
175
|
+
│ ├── ai.json # AI 配置
|
|
176
|
+
│ ├── plugins.json # 插件列表
|
|
177
|
+
│ ├── mcp_config.json # MCP 服务器配置
|
|
178
|
+
│ └── skills/ # Skill 目录
|
|
179
|
+
├── package.json
|
|
180
|
+
└── SPEC.md
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
## 四、核心模块
|
|
184
|
+
|
|
185
|
+
### 4.1 Framework (src/core/framework.js)
|
|
186
|
+
|
|
187
|
+
**职责**:
|
|
188
|
+
- 管理插件生命周期
|
|
189
|
+
- 提供工具注册表
|
|
190
|
+
- 事件总线
|
|
191
|
+
- 初始化协调
|
|
192
|
+
|
|
193
|
+
**API**:
|
|
194
|
+
```javascript
|
|
195
|
+
const framework = new Framework({
|
|
196
|
+
debug: false
|
|
197
|
+
})
|
|
198
|
+
|
|
199
|
+
// 插件操作
|
|
200
|
+
framework.registerPlugin(myPlugin)
|
|
201
|
+
await framework.loadPlugin({ type: 'ai-plugin', config: {...} })
|
|
202
|
+
await framework.unloadPlugin('my-plugin')
|
|
203
|
+
await framework.reloadPlugin('my-plugin') // 手动热重载
|
|
204
|
+
await framework.reloadAllPlugins()
|
|
205
|
+
|
|
206
|
+
// 工具操作
|
|
207
|
+
framework.registerTool({
|
|
208
|
+
name: 'my_tool',
|
|
209
|
+
description: '...',
|
|
210
|
+
execute: async (args) => { ... }
|
|
211
|
+
})
|
|
212
|
+
|
|
213
|
+
// 事件
|
|
214
|
+
framework.on('plugin:loaded', (plugin) => { ... })
|
|
215
|
+
framework.emit('agent:message', { content: '...' })
|
|
216
|
+
|
|
217
|
+
// 就绪
|
|
218
|
+
await framework.ready()
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
### 4.2 Agent (src/core/agent.js)
|
|
222
|
+
|
|
223
|
+
**职责**:
|
|
224
|
+
- 维护对话上下文
|
|
225
|
+
- 调用 AI 进行对话
|
|
226
|
+
- 管理工具调用循环
|
|
227
|
+
|
|
228
|
+
**API**:
|
|
229
|
+
```javascript
|
|
230
|
+
const agent = framework.createAgent({
|
|
231
|
+
systemPrompt: '你是一个有帮助的助手',
|
|
232
|
+
model: 'deepseek-chat',
|
|
233
|
+
apiKey: '...'
|
|
234
|
+
})
|
|
235
|
+
|
|
236
|
+
agent.on('message', (msg) => { ... })
|
|
237
|
+
agent.on('tool-call', (tool) => { ... })
|
|
238
|
+
|
|
239
|
+
const response = await agent.chat('你好')
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
### 4.3 PluginManager (src/core/plugin-manager.js)
|
|
243
|
+
|
|
244
|
+
**职责**:
|
|
245
|
+
- 维护已加载插件列表
|
|
246
|
+
- 按优先级排序加载
|
|
247
|
+
- 协调插件生命周期
|
|
248
|
+
|
|
249
|
+
**生命周期**:
|
|
250
|
+
1. `install()` - 注册工具/事件
|
|
251
|
+
2. `start()` - 初始化完成,开始工作
|
|
252
|
+
3. `reload()` - 热重载
|
|
253
|
+
4. `uninstall()` - 清理
|
|
254
|
+
|
|
255
|
+
### 4.4 ToolRegistry (src/core/tool-registry.js)
|
|
256
|
+
|
|
257
|
+
**职责**:
|
|
258
|
+
- 注册工具
|
|
259
|
+
- 调用工具
|
|
260
|
+
- 工具描述管理
|
|
261
|
+
|
|
262
|
+
**工具格式**:
|
|
263
|
+
```javascript
|
|
264
|
+
{
|
|
265
|
+
name: 'tool_name',
|
|
266
|
+
description: '工具描述',
|
|
267
|
+
parameters: { ... }, // Zod schema 或 JSON schema
|
|
268
|
+
execute: async (args, framework) => { ... }
|
|
269
|
+
}
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
## 五、事件系统
|
|
273
|
+
|
|
274
|
+
```javascript
|
|
275
|
+
// 事件列表
|
|
276
|
+
'framework:ready' // 框架就绪
|
|
277
|
+
'plugin:install' // 插件安装
|
|
278
|
+
'plugin:start' // 插件启动
|
|
279
|
+
'plugin:reload' // 插件重载
|
|
280
|
+
'plugin:uninstall' // 插件卸载
|
|
281
|
+
'agent:message' // Agent消息
|
|
282
|
+
'agent:tool-call' // Agent调用工具
|
|
283
|
+
'agent:tool-result' // 工具执行结果
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
## 六、热重载机制
|
|
287
|
+
|
|
288
|
+
### 设计原则
|
|
289
|
+
- **不监测文件变化** - 避免复杂性和性能开销
|
|
290
|
+
- **手动调用重载** - 通过 API 触发
|
|
291
|
+
- **插件自管理** - 插件提供 reload() 方法
|
|
292
|
+
|
|
293
|
+
### API
|
|
294
|
+
```javascript
|
|
295
|
+
// 重载单个插件
|
|
296
|
+
await framework.reloadPlugin('my-plugin')
|
|
297
|
+
|
|
298
|
+
// 重载所有插件
|
|
299
|
+
await framework.reloadAllPlugins()
|
|
300
|
+
|
|
301
|
+
// 在 Agent 中调用
|
|
302
|
+
agent.chat('请重载 my-plugin 插件')
|
|
303
|
+
// 需要插件提供 reload_plugins 工具
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
### 重载流程
|
|
307
|
+
1. 调用 `plugin.reload(framework)`
|
|
308
|
+
2. 插件清理旧资源
|
|
309
|
+
3. 插件重新初始化
|
|
310
|
+
4. 更新工具注册表
|
|
311
|
+
|
|
312
|
+
## 七、内置插件
|
|
313
|
+
|
|
314
|
+
### 7.1 AI Plugin (plugins/ai-plugin.js)
|
|
315
|
+
|
|
316
|
+
**功能**:
|
|
317
|
+
- AI 对话能力
|
|
318
|
+
- 工具调用循环
|
|
319
|
+
|
|
320
|
+
**配置**:
|
|
321
|
+
```javascript
|
|
322
|
+
{
|
|
323
|
+
type: 'ai-plugin',
|
|
324
|
+
provider: 'deepseek', // deepseek / openai / anthropic
|
|
325
|
+
model: 'deepseek-chat',
|
|
326
|
+
apiKey: '...',
|
|
327
|
+
baseURL: '...' // 可选,自定义端点
|
|
328
|
+
}
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
### 7.2 Tools Plugin (plugins/tools-plugin.js)
|
|
332
|
+
|
|
333
|
+
**功能**:
|
|
334
|
+
- 内置工具注册
|
|
335
|
+
- 工具调用执行
|
|
336
|
+
|
|
337
|
+
**内置工具**:
|
|
338
|
+
- `reload_plugins` - 热重载插件
|
|
339
|
+
- `list_plugins` - 列出已加载插件
|
|
340
|
+
|
|
341
|
+
## 八、使用示例
|
|
342
|
+
|
|
343
|
+
### 8.1 基础用法
|
|
344
|
+
|
|
345
|
+
```javascript
|
|
346
|
+
const { Framework } = require('./src')
|
|
347
|
+
|
|
348
|
+
const framework = new Framework({ debug: true })
|
|
349
|
+
|
|
350
|
+
// 注册插件
|
|
351
|
+
framework.registerPlugin({
|
|
352
|
+
name: 'my-plugin',
|
|
353
|
+
install(f) {
|
|
354
|
+
f.registerTool({
|
|
355
|
+
name: 'greet',
|
|
356
|
+
description: '打招呼',
|
|
357
|
+
execute: async (args) => `Hello, ${args.name}!`
|
|
358
|
+
})
|
|
359
|
+
}
|
|
360
|
+
})
|
|
361
|
+
|
|
362
|
+
await framework.ready()
|
|
363
|
+
|
|
364
|
+
const agent = framework.createAgent({
|
|
365
|
+
systemPrompt: '你是一个助手',
|
|
366
|
+
model: 'deepseek-chat',
|
|
367
|
+
apiKey: process.env.API_KEY
|
|
368
|
+
})
|
|
369
|
+
|
|
370
|
+
const response = await agent.chat('你好')
|
|
371
|
+
console.log(response)
|
|
372
|
+
```
|
|
373
|
+
|
|
374
|
+
### 8.2 热重载
|
|
375
|
+
|
|
376
|
+
```javascript
|
|
377
|
+
// 重载单个插件
|
|
378
|
+
await framework.reloadPlugin('my-plugin')
|
|
379
|
+
|
|
380
|
+
// 重载所有插件
|
|
381
|
+
await framework.reloadAllPlugins()
|
|
382
|
+
```
|
|
383
|
+
|
|
384
|
+
## 九、代码规范
|
|
385
|
+
|
|
386
|
+
### 9.1 文件命名
|
|
387
|
+
- 类文件:`小写-连字符.js`,如 `plugin-base.js`
|
|
388
|
+
- 目录:`小写-连字符`,如 `src/core`
|
|
389
|
+
|
|
390
|
+
### 9.2 类命名
|
|
391
|
+
- 类名:`大写驼峰`,如 `Framework`, `Agent`
|
|
392
|
+
- 方法名:`小写驼峰`,如 `registerTool`, `loadPlugin`
|
|
393
|
+
|
|
394
|
+
### 9.3 变量命名
|
|
395
|
+
- 类属性:`小写驼峰`
|
|
396
|
+
- 常量:`全大写+下划线`,如 `DEFAULT_PRIORITY`
|
|
397
|
+
- 私有属性:`_下划线前缀`
|
|
398
|
+
|
|
399
|
+
### 9.4 注释
|
|
400
|
+
```javascript
|
|
401
|
+
/**
|
|
402
|
+
* 类描述
|
|
403
|
+
*/
|
|
404
|
+
class Framework {
|
|
405
|
+
/**
|
|
406
|
+
* 方法描述
|
|
407
|
+
* @param {string} name - 参数描述
|
|
408
|
+
* @returns {Promise<void>}
|
|
409
|
+
*/
|
|
410
|
+
async loadPlugin(name) { }
|
|
411
|
+
}
|
|
412
|
+
```
|
|
413
|
+
|
|
414
|
+
## 十、已实现功能
|
|
415
|
+
|
|
416
|
+
### Phase 1 - 核心框架 ✓
|
|
417
|
+
- [x] Framework 核心类 (`src/core/framework.js`)
|
|
418
|
+
- [x] Agent 基础类 (`src/core/agent.js`)
|
|
419
|
+
- [x] 插件系统 (`src/core/plugin-manager.js`, `src/core/plugin-base.js`)
|
|
420
|
+
- [x] 工具注册表 (`src/core/tool-registry.js`)
|
|
421
|
+
- [x] 事件系统 (`src/utils/event-emitter.js`)
|
|
422
|
+
- [x] 热重载 API (`reloadPlugin()`, `reloadAllPlugins()`)
|
|
423
|
+
|
|
424
|
+
### Phase 2 - 内置插件 ✓
|
|
425
|
+
- [x] AI Plugin (`plugins/ai-plugin.js`) - 对接 Vercel AI SDK
|
|
426
|
+
- [x] 内置工具插件 (`plugins/tools-plugin.js`) - 热重载、列表工具
|
|
427
|
+
|
|
428
|
+
### Phase 3 - 高级功能 ✓
|
|
429
|
+
- [x] Skill 管理 (`src/capabilities/skill-manager.js`) - 加载和管理 Skill
|
|
430
|
+
- [x] 工作流引擎 (`src/capabilities/workflow-engine.js`) - 支持脚本、条件、循环等
|
|
431
|
+
- [x] MCP 执行器 (`src/executors/mcp-executor.js`) - 连接 MCP 服务器
|
|
432
|
+
- [x] Shell 执行器 (`plugins/shell-executor-plugin.js`) - 执行终端命令
|
|
433
|
+
- [x] Python 执行器 (`plugins/python-executor-plugin.js`) - 执行 Python 代码和脚本
|
|
434
|
+
- [x] Session 管理 (`plugins/session-plugin.js`) - 多会话支持、历史记录
|
|
435
|
+
- [x] Audit 审计日志 (`plugins/audit-plugin.js`) - 操作日志记录和查询
|
|
436
|
+
- [x] Rules 规则引擎 (`plugins/rules-plugin.js`) - 权限控制、内容过滤
|
|
437
|
+
- [x] Scheduler 定时任务 (`plugins/scheduler-plugin.js`) - Cron 调度
|
|
438
|
+
- [x] Storage 存储 (`plugins/storage-plugin.js`) - 键值对持久化存储
|
|
439
|
+
- [x] SubAgent 子Agent (`plugins/subagent-plugin.js`) - 子Agent隔离工具集
|
|
440
|
+
|
|
441
|
+
## 十一、依赖
|
|
442
|
+
|
|
443
|
+
```json
|
|
444
|
+
{
|
|
445
|
+
"dependencies": {
|
|
446
|
+
"@ai-sdk/openai": "^3.0.41",
|
|
447
|
+
"@ai-sdk/openai-compatible": "^2.0.35",
|
|
448
|
+
"ai": "^6.0.116",
|
|
449
|
+
"zod": "^4.3.6"
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
```
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Chat 命令实现
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
const readline = require('readline')
|
|
6
|
+
const { Framework } = require('../../../src')
|
|
7
|
+
const { ChatUI } = require('../ui/chat-ui')
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* 解析命令行参数
|
|
11
|
+
*/
|
|
12
|
+
function parseArgs(args) {
|
|
13
|
+
const options = {
|
|
14
|
+
model: process.env.FOLIKO_MODEL || 'MiniMax-M2.7',
|
|
15
|
+
provider: process.env.FOLIKO_PROVIDER || 'minimax',
|
|
16
|
+
baseURL: process.env.FOLIKO_BASE_URL || 'https://api.minimaxi.com/v1',
|
|
17
|
+
apiKey: process.env.MINIMAX_API_KEY || process.env.DEEPSEEK_API_KEY
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
for (let i = 0; i < args.length; i++) {
|
|
21
|
+
const arg = args[i]
|
|
22
|
+
if (arg === '--model' && args[i + 1]) {
|
|
23
|
+
options.model = args[++i]
|
|
24
|
+
} else if (arg === '--provider' && args[i + 1]) {
|
|
25
|
+
options.provider = args[++i]
|
|
26
|
+
} else if (arg === '--base-url' && args[i + 1]) {
|
|
27
|
+
options.baseURL = args[++i]
|
|
28
|
+
} else if (arg === '--api-key' && args[i + 1]) {
|
|
29
|
+
options.apiKey = args[++i]
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return options
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Chat 命令入口
|
|
38
|
+
*/
|
|
39
|
+
async function chatCommand(args) {
|
|
40
|
+
const options = parseArgs(args)
|
|
41
|
+
|
|
42
|
+
console.log('=== Foliko 持续对话 ===\n')
|
|
43
|
+
console.log('输入 exit 或 quit 退出\n')
|
|
44
|
+
|
|
45
|
+
// 初始化框架
|
|
46
|
+
const framework = new Framework({ debug: false })
|
|
47
|
+
await framework.bootstrap({
|
|
48
|
+
agentDir: process.cwd() + '/.agent',
|
|
49
|
+
aiConfig: {
|
|
50
|
+
provider: options.provider,
|
|
51
|
+
model: options.model,
|
|
52
|
+
baseURL: options.baseURL,
|
|
53
|
+
apiKey: options.apiKey
|
|
54
|
+
}
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
// 创建 Agent
|
|
58
|
+
const agent = framework.createAgent({
|
|
59
|
+
name: 'FolikoAgent',
|
|
60
|
+
systemPrompt: '你是一个有帮助的助手,擅长回答问题和执行任务。',
|
|
61
|
+
sharedPrompt: '工作目录: {{WORK_DIR}}',
|
|
62
|
+
sharedPrompt: '工作目录: {{WORK_DIR}}',
|
|
63
|
+
metadata: {
|
|
64
|
+
WORK_DIR: process.cwd() // 覆盖内置的 WORK_DIR
|
|
65
|
+
}
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
// 初始化 UI
|
|
69
|
+
const ui = new ChatUI(agent)
|
|
70
|
+
|
|
71
|
+
// 启动聊天
|
|
72
|
+
ui.start()
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
module.exports = { chatCommand }
|
package/cli/src/index.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Foliko CLI 主逻辑
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
const { chatCommand } = require('./commands/chat')
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* CLI 主入口
|
|
9
|
+
*/
|
|
10
|
+
function cli() {
|
|
11
|
+
const args = process.argv.slice(2)
|
|
12
|
+
const command = args[0] || 'chat'
|
|
13
|
+
|
|
14
|
+
switch (command) {
|
|
15
|
+
case 'chat':
|
|
16
|
+
chatCommand(args.slice(1))
|
|
17
|
+
break
|
|
18
|
+
|
|
19
|
+
case 'help':
|
|
20
|
+
case '--help':
|
|
21
|
+
case '-h':
|
|
22
|
+
printHelp()
|
|
23
|
+
break
|
|
24
|
+
|
|
25
|
+
case 'version':
|
|
26
|
+
case '--version':
|
|
27
|
+
case '-v':
|
|
28
|
+
console.log('foliko v1.0.0')
|
|
29
|
+
break
|
|
30
|
+
|
|
31
|
+
default:
|
|
32
|
+
console.error(`Unknown command: ${command}`)
|
|
33
|
+
console.error('Run "foliko help" for usage information')
|
|
34
|
+
process.exit(1)
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* 打印帮助信息
|
|
40
|
+
*/
|
|
41
|
+
function printHelp() {
|
|
42
|
+
console.log(`
|
|
43
|
+
Foliko CLI - Agent 框架的命令行工具
|
|
44
|
+
|
|
45
|
+
Usage: foliko <command> [options]
|
|
46
|
+
|
|
47
|
+
Commands:
|
|
48
|
+
chat 启动持续对话聊天
|
|
49
|
+
help 显示帮助信息
|
|
50
|
+
version 显示版本号
|
|
51
|
+
|
|
52
|
+
Chat Options:
|
|
53
|
+
--model <name> 指定 AI 模型
|
|
54
|
+
--provider <name> 指定 AI 提供商
|
|
55
|
+
--base-url <url> 指定 API 基础地址
|
|
56
|
+
|
|
57
|
+
Examples:
|
|
58
|
+
foliko chat
|
|
59
|
+
foliko chat --model MiniMax-M2.7
|
|
60
|
+
foliko chat --provider minimax --base-url https://api.minimaxi.com/v1
|
|
61
|
+
`)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
module.exports = { cli }
|