foliko 1.0.29 → 1.0.30

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.
@@ -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)
@@ -1,49 +1,49 @@
1
- /**
2
- * Skill 管理器示例
3
- * 展示如何加载和使用 Skill
4
- */
5
-
6
- const { Framework } = require('../src')
7
- const { SkillManagerPlugin } = require('../src/capabilities/skill-manager')
8
-
9
- async function main() {
10
- console.log('=== Skill Manager Example ===\n')
11
-
12
- // 创建框架
13
- const framework = new Framework({ debug: true })
14
-
15
- // 创建 skills 目录(如果没有)
16
- const fs = require('fs')
17
- const skillsDir = './skills'
18
- if (!fs.existsSync(skillsDir)) {
19
- fs.mkdirSync(skillsDir, { recursive: true })
20
- }
21
-
22
- // 加载 Skill 管理器插件
23
- const skillPlugin = new SkillManagerPlugin({
24
- skillsDir: skillsDir
25
- })
26
-
27
- await framework.loadPlugin(skillPlugin)
28
-
29
- // 列出所有加载的 skills
30
- console.log('\n--- Loaded Skills ---')
31
- const skills = skillPlugin.getAllSkills()
32
- console.log(`Found ${skills.length} skills:`)
33
- for (const skill of skills) {
34
- console.log(` - ${skill.name}: ${skill.metadata.description}`)
35
- }
36
-
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
- // 清理
45
- await framework.destroy()
46
- console.log('\n[Done]')
47
- }
48
-
49
- main().catch(console.error)
1
+ /**
2
+ * Skill 管理器示例
3
+ * 展示如何加载和使用 Skill
4
+ */
5
+
6
+ const { Framework } = require('../src')
7
+ const { SkillManagerPlugin } = require('../src/capabilities/skill-manager')
8
+
9
+ async function main() {
10
+ console.log('=== Skill Manager Example ===\n')
11
+
12
+ // 创建框架
13
+ const framework = new Framework({ debug: true })
14
+
15
+ // 创建 skills 目录(如果没有)
16
+ const fs = require('fs')
17
+ const skillsDir = './skills'
18
+ if (!fs.existsSync(skillsDir)) {
19
+ fs.mkdirSync(skillsDir, { recursive: true })
20
+ }
21
+
22
+ // 加载 Skill 管理器插件
23
+ const skillPlugin = new SkillManagerPlugin({
24
+ skillsDir: skillsDir
25
+ })
26
+
27
+ await framework.loadPlugin(skillPlugin)
28
+
29
+ // 列出所有加载的 skills
30
+ console.log('\n--- Loaded Skills ---')
31
+ const skills = skillPlugin.getAllSkills()
32
+ console.log(`Found ${skills.length} skills:`)
33
+ for (const skill of skills) {
34
+ console.log(` - ${skill.name}: ${skill.metadata.description}`)
35
+ }
36
+
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
+ // 清理
45
+ await framework.destroy()
46
+ console.log('\n[Done]')
47
+ }
48
+
49
+ main().catch(console.error)
@@ -9,7 +9,7 @@ const readline = require('readline')
9
9
  require('dotenv').config()
10
10
 
11
11
  async function main() {
12
- console.log('=== VB-Agent 持续聊天测试 ===\n')
12
+ console.log('=== Foliko 持续聊天测试 ===\n')
13
13
  console.log('输入消息与 Agent 对话,输入 exit 或 quit 退出')
14
14
  console.log('多行输入:按两次回车结束,或输入 !! 立即结束\n')
15
15
 
@@ -35,7 +35,7 @@ async function main() {
35
35
  systemPrompt: '你是一个有帮助的助手,擅长回答问题和执行任务。',
36
36
  sharedPrompt: '工作目录: {{WORK_DIR}}',
37
37
  metadata: {
38
- projectName: 'VB-Agent',
38
+ projectName: 'Foliko',
39
39
  version: '1.0.0'
40
40
  }
41
41
  })
@@ -1,79 +1,79 @@
1
- /**
2
- * MCP 插件测试脚本
3
- */
4
-
5
- const { Framework } = require('../src')
6
- const { MCPExecutorPlugin } = require('../src/executors/mcp-executor')
7
-
8
- async function test() {
9
- console.log('=== MCP Plugin Test ===\n')
10
-
11
- console.log('1. Creating framework...')
12
- const framework = new Framework({ debug: true })
13
-
14
- console.log('2. Creating MCP plugin with fetch server...')
15
- const mcpPlugin = new MCPExecutorPlugin({
16
- servers: [
17
- {
18
- name: 'fetch',
19
- command: 'uvx',
20
- args: ['mcp-server-fetch']
21
- }
22
- ]
23
- })
24
-
25
- console.log('3. Loading MCP plugin...')
26
- await framework.loadPlugin(mcpPlugin)
27
-
28
- console.log('4. Starting framework...')
29
- await framework.pluginManager.startAll()
30
-
31
- // 等待 MCP 服务器连接
32
- console.log('\n5. Waiting for MCP connection...')
33
- await new Promise(resolve => setTimeout(resolve, 2000))
34
-
35
- console.log('\n6. Listing MCP servers...')
36
- const servers = mcpPlugin.getServers()
37
- console.log('Servers:', JSON.stringify(servers, null, 2))
38
-
39
- console.log('\n7. Listing MCP tools...')
40
- const mcpTools = framework.getTools().filter(t => t.name.startsWith('mcp_'))
41
- console.log('MCP Tools:', mcpTools.map(t => t.name))
42
-
43
- if (mcpTools.length > 0) {
44
- console.log('\n8. Testing mcp_list_servers...')
45
- const listResult = await framework.executeTool('mcp_list_servers', {})
46
- console.log('List Servers Result:', JSON.stringify(listResult, null, 2))
47
-
48
- console.log('\n9. Testing mcp_tool_schema...')
49
- const schemaResult = await framework.executeTool('mcp_tool_schema', {
50
- server: 'fetch',
51
- tool: 'fetch'
52
- })
53
- console.log('Tool Schema:', JSON.stringify(schemaResult, null, 2))
54
-
55
- console.log('\n10. Testing mcp_call (fetch a webpage)...')
56
- const callResult = await framework.executeTool('mcp_call', {
57
- server: 'fetch',
58
- tool: 'fetch',
59
- args_json: JSON.stringify({ url: 'https://httpbin.org/get' })
60
- })
61
- console.log('Fetch Result (truncated):', JSON.stringify(callResult, null, 2).substring(0, 500) + '...')
62
- }
63
-
64
- console.log('\n11. Destroying framework...')
65
- await framework.destroy()
66
-
67
- console.log('\n=== Test Complete ===')
68
- }
69
-
70
- test()
71
- .then(() => {
72
- console.log('\n✓ Test completed successfully')
73
- process.exit(0)
74
- })
75
- .catch(err => {
76
- console.error('\n✗ Test failed:', err.message)
77
- console.error(err.stack)
78
- process.exit(1)
79
- })
1
+ /**
2
+ * MCP 插件测试脚本
3
+ */
4
+
5
+ const { Framework } = require('../src')
6
+ const { MCPExecutorPlugin } = require('../src/executors/mcp-executor')
7
+
8
+ async function test() {
9
+ console.log('=== MCP Plugin Test ===\n')
10
+
11
+ console.log('1. Creating framework...')
12
+ const framework = new Framework({ debug: true })
13
+
14
+ console.log('2. Creating MCP plugin with fetch server...')
15
+ const mcpPlugin = new MCPExecutorPlugin({
16
+ servers: [
17
+ {
18
+ name: 'fetch',
19
+ command: 'uvx',
20
+ args: ['mcp-server-fetch']
21
+ }
22
+ ]
23
+ })
24
+
25
+ console.log('3. Loading MCP plugin...')
26
+ await framework.loadPlugin(mcpPlugin)
27
+
28
+ console.log('4. Starting framework...')
29
+ await framework.pluginManager.startAll()
30
+
31
+ // 等待 MCP 服务器连接
32
+ console.log('\n5. Waiting for MCP connection...')
33
+ await new Promise(resolve => setTimeout(resolve, 2000))
34
+
35
+ console.log('\n6. Listing MCP servers...')
36
+ const servers = mcpPlugin.getServers()
37
+ console.log('Servers:', JSON.stringify(servers, null, 2))
38
+
39
+ console.log('\n7. Listing MCP tools...')
40
+ const mcpTools = framework.getTools().filter(t => t.name.startsWith('mcp_'))
41
+ console.log('MCP Tools:', mcpTools.map(t => t.name))
42
+
43
+ if (mcpTools.length > 0) {
44
+ console.log('\n8. Testing mcp_list_servers...')
45
+ const listResult = await framework.executeTool('mcp_list_servers', {})
46
+ console.log('List Servers Result:', JSON.stringify(listResult, null, 2))
47
+
48
+ console.log('\n9. Testing mcp_tool_schema...')
49
+ const schemaResult = await framework.executeTool('mcp_tool_schema', {
50
+ server: 'fetch',
51
+ tool: 'fetch'
52
+ })
53
+ console.log('Tool Schema:', JSON.stringify(schemaResult, null, 2))
54
+
55
+ console.log('\n10. Testing mcp_call (fetch a webpage)...')
56
+ const callResult = await framework.executeTool('mcp_call', {
57
+ server: 'fetch',
58
+ tool: 'fetch',
59
+ args_json: JSON.stringify({ url: 'https://httpbin.org/get' })
60
+ })
61
+ console.log('Fetch Result (truncated):', JSON.stringify(callResult, null, 2).substring(0, 500) + '...')
62
+ }
63
+
64
+ console.log('\n11. Destroying framework...')
65
+ await framework.destroy()
66
+
67
+ console.log('\n=== Test Complete ===')
68
+ }
69
+
70
+ test()
71
+ .then(() => {
72
+ console.log('\n✓ Test completed successfully')
73
+ process.exit(0)
74
+ })
75
+ .catch(err => {
76
+ console.error('\n✗ Test failed:', err.message)
77
+ console.error(err.stack)
78
+ process.exit(1)
79
+ })