foliko 1.0.29 → 1.0.31

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.
@@ -72,7 +72,8 @@
72
72
  "Bash(node -c plugins/email.js && node -c plugins/default-plugins.js 2>&1)",
73
73
  "Bash(node -c plugins/email.js 2>&1)",
74
74
  "Bash(npm list:*)",
75
- "Bash(node -e \"const {EmailPlugin} = require\\('./plugins/email'\\); const p = new EmailPlugin\\(\\); console.log\\('email plugin loaded ok'\\); console.log\\('enabled:', p.enabled\\); console.log\\('version:', p.version\\);\" 2>&1)"
75
+ "Bash(node -e \"const {EmailPlugin} = require\\('./plugins/email'\\); const p = new EmailPlugin\\(\\); console.log\\('email plugin loaded ok'\\); console.log\\('enabled:', p.enabled\\); console.log\\('version:', p.version\\);\" 2>&1)",
76
+ "Bash(cd D:/Code/vb-agent && node -e \"console.log\\('IMAP_HOST:', process.env.IMAP_HOST\\); console.log\\('IMAP_USER:', process.env.IMAP_USER\\); console.log\\('IMAP_PORT:', process.env.IMAP_PORT\\);\")"
76
77
  ]
77
78
  }
78
79
  }
package/SPEC.md CHANGED
@@ -1,4 +1,4 @@
1
- # VB-Agent Framework 规划文档
1
+ # Foliko Framework 规划文档
2
2
 
3
3
  ## 一、设计目标
4
4
 
@@ -11,7 +11,7 @@
11
11
 
12
12
  ```
13
13
  ┌─────────────────────────────────────────────────┐
14
- VB-Agent Framework
14
+ Foliko Framework
15
15
  ├─────────────────────────────────────────────────┤
16
16
  │ Framework (容器层) │
17
17
  │ ├── pluginManager - 插件加载/卸载/重载 │
package/cli/bin/foliko.js CHANGED
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env node
1
+ #!/usr/bin/env node
2
2
  /**
3
3
  * Foliko CLI 入口
4
4
  * Usage: foliko <command> [options]
@@ -1,4 +1,4 @@
1
- # VB-Agent 快速参考
1
+ # Foliko 快速参考
2
2
 
3
3
  ## 启动框架
4
4
  ```javascript
@@ -1,4 +1,4 @@
1
- # VB-Agent Framework 用户手册
1
+ # Foliko Framework 用户手册
2
2
 
3
3
  > 简约的插件化 Agent 框架
4
4
 
@@ -20,7 +20,7 @@
20
20
 
21
21
  ## 1. 项目概述
22
22
 
23
- VB-Agent 是一个基于插件的 Agent 框架,具有以下特性:
23
+ Foliko 是一个基于插件的 Agent 框架,具有以下特性:
24
24
 
25
25
  - **纯 JS 实现** - 无 TypeScript,简单易懂
26
26
  - **插件化架构** - 通过插件扩展功能
@@ -759,7 +759,7 @@ Agent: [获取插件开发指南后,按照指南创建插件]
759
759
 
760
760
  ### 6.4 内置技能
761
761
 
762
- - **foliko-dev** - VB-Agent 插件开发指南
762
+ - **foliko-dev** - Foliko 插件开发指南
763
763
  - **api-patterns** - API 设计模式
764
764
  - **app-builder** - 应用程序构建
765
765
  - **architecture** - 架构设计
@@ -906,7 +906,7 @@ const agent = framework.createAgent({
906
906
 
907
907
  ## 10. 事件系统
908
908
 
909
- VB-Agent 基于 EventEmitter,提供完整的事件系统。
909
+ Foliko 基于 EventEmitter,提供完整的事件系统。
910
910
 
911
911
  ### 10.1 事件基础
912
912
 
package/examples/basic.js CHANGED
@@ -1,110 +1,110 @@
1
- /**
2
- * 基础示例
3
- * 展示如何使用 Framework 和 Agent
4
- */
5
-
6
- const { Framework } = require('../src')
7
- const { AIPlugin } = require('../plugins/ai-plugin')
8
- const { z } = require('zod')
9
-
10
- async function main() {
11
- // 创建框架实例
12
- const framework = new Framework({ debug: true })
13
-
14
- // 加载 AI 插件
15
- await framework.loadPlugin(new AIPlugin({
16
- provider: 'deepseek',
17
- model: 'deepseek-chat',
18
- apiKey: process.env.DEEPSEEK_API_KEY || 'your-api-key'
19
- }))
20
-
21
- // 注册自定义工具(使用 inputSchema 格式)
22
- framework.registerTool({
23
- name: 'hello',
24
- description: '打招呼工具',
25
- inputSchema: z.object({
26
- name: z.string().optional().describe('姓名')
27
- }),
28
- execute: async (args) => {
29
- return `Hello, ${args.name || 'World'}!`
30
- }
31
- })
32
-
33
- // 注册计算器工具
34
- framework.registerTool({
35
- name: 'calculate',
36
- description: '简单的计算器',
37
- inputSchema: z.object({
38
- expression: z.string().describe('数学表达式,如 2+3*4')
39
- }),
40
- execute: async (args) => {
41
- try {
42
- // 安全计算(仅支持基本运算)
43
- const result = Function(`"use strict"; return (${args.expression})`)()
44
- return { result }
45
- } catch (e) {
46
- return { error: e.message }
47
- }
48
- }
49
- })
50
-
51
- console.log('[Framework] Ready!')
52
- console.log('[Tools]', framework.getTools().map(t => t.name))
53
-
54
- // 创建 Agent
55
- const agent = framework.createAgent({
56
- name: 'MyAgent',
57
- systemPrompt: '你是一个有帮助的助手。当需要计算时,使用 calculate 工具。'
58
- })
59
-
60
- // 监听事件
61
- agent.on('tool-call', (tool) => {
62
- console.log('[Agent] Tool call:', tool.name, tool.args)
63
- })
64
-
65
- agent.on('tool-result', (result) => {
66
- console.log('[Agent] Tool result:', result.name, result.result)
67
- })
68
-
69
- // AI 对话示例
70
- console.log('\n=== AI Chat Example ===')
71
- try {
72
- const response = await agent.chat('你好!')
73
- console.log('[Agent] Response:', response.message)
74
- } catch (err) {
75
- console.error('[Agent] Error:', err.message)
76
- }
77
-
78
- // 使用工具的对话示例
79
- console.log('\n=== AI Chat with Tool Call ===')
80
- try {
81
- const response = await agent.chat('请帮我计算 (15 + 25) * 2 等于多少?')
82
- console.log('[Agent] Response:', response.message)
83
- } catch (err) {
84
- console.error('[Agent] Error:', err.message)
85
- }
86
-
87
- // 流式对话示例
88
- console.log('\n=== Streaming Chat ===')
89
- try {
90
- for await (const chunk of agent.chatStream('请用中文介绍一下你自己')) {
91
- if (chunk.type === 'text') {
92
- process.stdout.write(chunk.text)
93
- }
94
- }
95
- console.log('\n')
96
- } catch (err) {
97
- console.error('[Agent] Stream Error:', err.message)
98
- }
99
-
100
- // 热重载示例
101
- console.log('\n=== Hot Reload ===')
102
- await framework.reloadPlugin('ai')
103
- console.log('AI plugin reloaded!')
104
-
105
- // 清理
106
- await framework.destroy()
107
- console.log('\n[Done]')
108
- }
109
-
110
- main().catch(console.error)
1
+ /**
2
+ * 基础示例
3
+ * 展示如何使用 Framework 和 Agent
4
+ */
5
+
6
+ const { Framework } = require('../src')
7
+ const { AIPlugin } = require('../plugins/ai-plugin')
8
+ const { z } = require('zod')
9
+
10
+ async function main() {
11
+ // 创建框架实例
12
+ const framework = new Framework({ debug: true })
13
+
14
+ // 加载 AI 插件
15
+ await framework.loadPlugin(new AIPlugin({
16
+ provider: 'deepseek',
17
+ model: 'deepseek-chat',
18
+ apiKey: process.env.DEEPSEEK_API_KEY || 'your-api-key'
19
+ }))
20
+
21
+ // 注册自定义工具(使用 inputSchema 格式)
22
+ framework.registerTool({
23
+ name: 'hello',
24
+ description: '打招呼工具',
25
+ inputSchema: z.object({
26
+ name: z.string().optional().describe('姓名')
27
+ }),
28
+ execute: async (args) => {
29
+ return `Hello, ${args.name || 'World'}!`
30
+ }
31
+ })
32
+
33
+ // 注册计算器工具
34
+ framework.registerTool({
35
+ name: 'calculate',
36
+ description: '简单的计算器',
37
+ inputSchema: z.object({
38
+ expression: z.string().describe('数学表达式,如 2+3*4')
39
+ }),
40
+ execute: async (args) => {
41
+ try {
42
+ // 安全计算(仅支持基本运算)
43
+ const result = Function(`"use strict"; return (${args.expression})`)()
44
+ return { result }
45
+ } catch (e) {
46
+ return { error: e.message }
47
+ }
48
+ }
49
+ })
50
+
51
+ console.log('[Framework] Ready!')
52
+ console.log('[Tools]', framework.getTools().map(t => t.name))
53
+
54
+ // 创建 Agent
55
+ const agent = framework.createAgent({
56
+ name: 'MyAgent',
57
+ systemPrompt: '你是一个有帮助的助手。当需要计算时,使用 calculate 工具。'
58
+ })
59
+
60
+ // 监听事件
61
+ agent.on('tool-call', (tool) => {
62
+ console.log('[Agent] Tool call:', tool.name, tool.args)
63
+ })
64
+
65
+ agent.on('tool-result', (result) => {
66
+ console.log('[Agent] Tool result:', result.name, result.result)
67
+ })
68
+
69
+ // AI 对话示例
70
+ console.log('\n=== AI Chat Example ===')
71
+ try {
72
+ const response = await agent.chat('你好!')
73
+ console.log('[Agent] Response:', response.message)
74
+ } catch (err) {
75
+ console.error('[Agent] Error:', err.message)
76
+ }
77
+
78
+ // 使用工具的对话示例
79
+ console.log('\n=== AI Chat with Tool Call ===')
80
+ try {
81
+ const response = await agent.chat('请帮我计算 (15 + 25) * 2 等于多少?')
82
+ console.log('[Agent] Response:', response.message)
83
+ } catch (err) {
84
+ console.error('[Agent] Error:', err.message)
85
+ }
86
+
87
+ // 流式对话示例
88
+ console.log('\n=== Streaming Chat ===')
89
+ try {
90
+ for await (const chunk of agent.chatStream('请用中文介绍一下你自己')) {
91
+ if (chunk.type === 'text') {
92
+ process.stdout.write(chunk.text)
93
+ }
94
+ }
95
+ console.log('\n')
96
+ } catch (err) {
97
+ console.error('[Agent] Stream Error:', err.message)
98
+ }
99
+
100
+ // 热重载示例
101
+ console.log('\n=== Hot Reload ===')
102
+ await framework.reloadPlugin('ai')
103
+ console.log('AI plugin reloaded!')
104
+
105
+ // 清理
106
+ await framework.destroy()
107
+ console.log('\n[Done]')
108
+ }
109
+
110
+ main().catch(console.error)
@@ -1,93 +1,93 @@
1
- /**
2
- * Bootstrap 示例
3
- * 使用 framework.bootstrap() 自动加载 .agent/ 目录配置
4
- */
5
-
6
- const { Framework } = require('../src')
7
- const { z } = require('zod')
8
-
9
- async function main() {
10
- console.log('=== Bootstrap Example ===\n')
11
-
12
- // 创建框架
13
- const framework = new Framework({ debug: true })
14
-
15
- // 使用 bootstrap 自动加载所有默认插件
16
- // 会自动检测 .agent/ 目录下的配置
17
- await framework.bootstrap({
18
- agentDir: './.agent', // 配置目录
19
- aiConfig: { // 可选:覆盖 AI 配置
20
- provider: 'deepseek',
21
- model: 'deepseek-chat',
22
- apiKey: process.env.DEEPSEEK_API_KEY || 'your-api-key'
23
- }
24
- })
25
-
26
- // 注册 hello 工具(演示用)
27
- framework.registerTool({
28
- name: 'hello',
29
- description: '打招呼',
30
- inputSchema: z.object({
31
- name: z.string().optional().describe('姓名')
32
- }),
33
- execute: async (args) => `Hello, ${args.name || 'World'}!`
34
- })
35
-
36
- console.log('\n--- Framework Ready ---')
37
- console.log('Plugins:', framework.pluginManager.getAll().map(p => p.name))
38
- console.log('Tools:', framework.getTools().map(t => t.name))
39
-
40
- // 创建 Agent (支持 sharedPrompt 和 metadata)
41
- const agent = framework.createAgent({
42
- name: 'MyAgent',
43
- systemPrompt: '你是一个有帮助的助手。',
44
- sharedPrompt: '工作目录: {{WORK_DIR}}\n用户名: {{USER_NAME}}\n当前时间: {{TIME}}',
45
- metadata: {
46
- projectName: 'VB-Agent',
47
- version: '1.0.0'
48
- }
49
- })
50
-
51
- console.log('\n--- Agent Context ---')
52
- console.log(agent.systemPrompt)
53
-
54
- // 测试对话
55
- console.log('\n--- AI Chat Test ---')
56
- // try {
57
- // const response = await agent.chat('帮我开发一个获取系统信息的插件')
58
- // console.log('Agent:', response.message)
59
- // } catch (err) {
60
- // console.error('Chat error:', err.message)
61
- // }
62
-
63
- try {
64
- for await (const chunk of agent.chatStream('帮我开发一个获取系统信息的插件')) {
65
- if (chunk.type === 'text') {
66
- process.stdout.write(chunk.text)
67
- }else if (chunk?.type === 'tool-call') {
68
- console.log(`\n[工具调用: ${chunk.toolName}]`);
69
- } else if (chunk?.type === 'tool-result') {
70
- console.log(`\n[工具结果: ${chunk.toolName}]`);
71
- }
72
- }
73
- console.log('\n')
74
- } catch (err) {
75
- console.error('[Agent] Stream Error:', err.message)
76
- }
77
-
78
- // 测试工具调用
79
- console.log('\n--- Tool Call Test ---')
80
- const result = await framework.executeTool('hello', { name: 'Bootstrap' })
81
- console.log('Tool result:', result)
82
-
83
- // 测试内置工具
84
- console.log('\n--- Built-in Tools Test ---')
85
- const listResult = await framework.executeTool('list_plugins', {})
86
- console.log('list_plugins:', listResult)
87
-
88
- // 清理
89
- await framework.destroy()
90
- console.log('\n[Done]')
91
- }
92
-
93
- main().catch(console.error)
1
+ /**
2
+ * Bootstrap 示例
3
+ * 使用 framework.bootstrap() 自动加载 .agent/ 目录配置
4
+ */
5
+
6
+ const { Framework } = require('../src')
7
+ const { z } = require('zod')
8
+
9
+ async function main() {
10
+ console.log('=== Bootstrap Example ===\n')
11
+
12
+ // 创建框架
13
+ const framework = new Framework({ debug: true })
14
+
15
+ // 使用 bootstrap 自动加载所有默认插件
16
+ // 会自动检测 .agent/ 目录下的配置
17
+ await framework.bootstrap({
18
+ agentDir: './.agent', // 配置目录
19
+ aiConfig: { // 可选:覆盖 AI 配置
20
+ provider: 'deepseek',
21
+ model: 'deepseek-chat',
22
+ apiKey: process.env.DEEPSEEK_API_KEY || 'your-api-key'
23
+ }
24
+ })
25
+
26
+ // 注册 hello 工具(演示用)
27
+ framework.registerTool({
28
+ name: 'hello',
29
+ description: '打招呼',
30
+ inputSchema: z.object({
31
+ name: z.string().optional().describe('姓名')
32
+ }),
33
+ execute: async (args) => `Hello, ${args.name || 'World'}!`
34
+ })
35
+
36
+ console.log('\n--- Framework Ready ---')
37
+ console.log('Plugins:', framework.pluginManager.getAll().map(p => p.name))
38
+ console.log('Tools:', framework.getTools().map(t => t.name))
39
+
40
+ // 创建 Agent (支持 sharedPrompt 和 metadata)
41
+ const agent = framework.createAgent({
42
+ name: 'MyAgent',
43
+ systemPrompt: '你是一个有帮助的助手。',
44
+ sharedPrompt: '工作目录: {{WORK_DIR}}\n用户名: {{USER_NAME}}\n当前时间: {{TIME}}',
45
+ metadata: {
46
+ projectName: 'Foliko',
47
+ version: '1.0.0'
48
+ }
49
+ })
50
+
51
+ console.log('\n--- Agent Context ---')
52
+ console.log(agent.systemPrompt)
53
+
54
+ // 测试对话
55
+ console.log('\n--- AI Chat Test ---')
56
+ // try {
57
+ // const response = await agent.chat('帮我开发一个获取系统信息的插件')
58
+ // console.log('Agent:', response.message)
59
+ // } catch (err) {
60
+ // console.error('Chat error:', err.message)
61
+ // }
62
+
63
+ try {
64
+ for await (const chunk of agent.chatStream('帮我开发一个获取系统信息的插件')) {
65
+ if (chunk.type === 'text') {
66
+ process.stdout.write(chunk.text)
67
+ }else if (chunk?.type === 'tool-call') {
68
+ console.log(`\n[工具调用: ${chunk.toolName}]`);
69
+ } else if (chunk?.type === 'tool-result') {
70
+ console.log(`\n[工具结果: ${chunk.toolName}]`);
71
+ }
72
+ }
73
+ console.log('\n')
74
+ } catch (err) {
75
+ console.error('[Agent] Stream Error:', err.message)
76
+ }
77
+
78
+ // 测试工具调用
79
+ console.log('\n--- Tool Call Test ---')
80
+ const result = await framework.executeTool('hello', { name: 'Bootstrap' })
81
+ console.log('Tool result:', result)
82
+
83
+ // 测试内置工具
84
+ console.log('\n--- Built-in Tools Test ---')
85
+ const listResult = await framework.executeTool('list_plugins', {})
86
+ console.log('list_plugins:', listResult)
87
+
88
+ // 清理
89
+ await framework.destroy()
90
+ console.log('\n[Done]')
91
+ }
92
+
93
+ main().catch(console.error)
@@ -1,53 +1,53 @@
1
- /**
2
- * MCP 执行器示例
3
- * 展示如何连接 MCP 服务器
4
- */
5
-
6
- const { Framework } = require('../src')
7
- const { MCPExecutorPlugin } = require('../src/executors/mcp-executor')
8
-
9
- async function main() {
10
- console.log('=== MCP Executor Example ===\n')
11
-
12
- // 创建框架
13
- const framework = new Framework({ debug: true })
14
-
15
- // 创建 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
- })
27
-
28
- // 加载插件
29
- await framework.loadPlugin(mcpPlugin)
30
-
31
- // 列出服务器
32
- console.log('\n--- MCP Servers ---')
33
- const servers = mcpPlugin.getServers()
34
- console.log('Servers:', servers)
35
-
36
- // 列出所有 MCP 工具
37
- console.log('\n--- MCP Tools ---')
38
- const tools = framework.getTools().filter(t => t.name.startsWith('mcp_'))
39
- console.log('MCP tools:', tools.map(t => t.name))
40
-
41
- // 如果有配置的服务器,可以这样调用:
42
- // const result = await framework.executeTool('mcp_call', {
43
- // server: 'example',
44
- // tool: 'tool_name',
45
- // args: { /* tool arguments */ }
46
- // })
47
-
48
- // 清理
49
- await framework.destroy()
50
- console.log('\n[Done]')
51
- }
52
-
53
- main().catch(console.error)
1
+ /**
2
+ * MCP 执行器示例
3
+ * 展示如何连接 MCP 服务器
4
+ */
5
+
6
+ const { Framework } = require('../src')
7
+ const { MCPExecutorPlugin } = require('../src/executors/mcp-executor')
8
+
9
+ async function main() {
10
+ console.log('=== MCP Executor Example ===\n')
11
+
12
+ // 创建框架
13
+ const framework = new Framework({ debug: true })
14
+
15
+ // 创建 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
+ })
27
+
28
+ // 加载插件
29
+ await framework.loadPlugin(mcpPlugin)
30
+
31
+ // 列出服务器
32
+ console.log('\n--- MCP Servers ---')
33
+ const servers = mcpPlugin.getServers()
34
+ console.log('Servers:', servers)
35
+
36
+ // 列出所有 MCP 工具
37
+ console.log('\n--- MCP Tools ---')
38
+ const tools = framework.getTools().filter(t => t.name.startsWith('mcp_'))
39
+ console.log('MCP tools:', tools.map(t => t.name))
40
+
41
+ // 如果有配置的服务器,可以这样调用:
42
+ // const result = await framework.executeTool('mcp_call', {
43
+ // server: 'example',
44
+ // tool: 'tool_name',
45
+ // args: { /* tool arguments */ }
46
+ // })
47
+
48
+ // 清理
49
+ await framework.destroy()
50
+ console.log('\n[Done]')
51
+ }
52
+
53
+ main().catch(console.error)