foliko 1.0.50 → 1.0.52
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 +9 -1
- package/Dockerfile +30 -2
- package/examples/basic.js +110 -110
- package/examples/mcp-example.js +53 -53
- package/examples/skill-example.js +49 -49
- package/examples/test-mcp.js +79 -79
- package/examples/test-reload.js +61 -61
- package/package.json +1 -1
- package/plugins/ai-plugin.js +1 -0
- package/plugins/audit-plugin.js +1 -0
- package/plugins/default-plugins.js +16 -12
- package/plugins/file-system-plugin.js +1 -0
- package/plugins/install-plugin.js +1 -0
- package/plugins/python-executor-plugin.js +2 -0
- package/plugins/python-plugin-loader.js +1 -0
- package/plugins/rules-plugin.js +2 -1
- package/plugins/scheduler-plugin.js +1 -1
- package/plugins/session-plugin.js +2 -0
- package/plugins/shell-executor-plugin.js +2 -0
- package/plugins/storage-plugin.js +2 -0
- package/plugins/subagent-plugin.js +2 -0
- package/plugins/tools-plugin.js +4 -1
- package/plugins/web-plugin.js +26 -5
- package/src/capabilities/skill-manager.js +1 -0
- package/src/capabilities/workflow-engine.js +1 -0
- package/src/core/agent-chat.js +5 -11
- package/src/core/agent.js +33 -1
- package/src/core/plugin-base.js +7 -0
- package/src/core/plugin-manager.js +58 -11
- package/src/executors/executor-base.js +58 -58
- package/src/executors/mcp-executor.js +1 -0
- package/test-server.js +25 -25
- package/test.txt +3 -3
|
@@ -117,7 +117,15 @@
|
|
|
117
117
|
"Bash(curl -s -X POST \"http://localhost:3000/webhook/075s5s2umn4smn4f\" \\\\\n -H \"Content-Type: application/json\" \\\\\n -d '{\"test\":\"data\"}' 2>&1)",
|
|
118
118
|
"Bash(curl -s http://localhost:3000/api/hello 2>&1)",
|
|
119
119
|
"Bash(curl -v -X POST \"http://localhost:3000/webhook/075s5s2umn4smn4f\" \\\\\n -H \"Content-Type: application/json\" \\\\\n -d '{\"test\":\"data\"}' 2>&1 | head -30)",
|
|
120
|
-
"Bash(cd D:/code/vb-agent && timeout 30 node test-compression.js 2>&1)"
|
|
120
|
+
"Bash(cd D:/code/vb-agent && timeout 30 node test-compression.js 2>&1)",
|
|
121
|
+
"Bash(cd D:/code/vb-agent && node -c src/core/agent-chat.js 2>&1)",
|
|
122
|
+
"Bash(cd D:/code/vb-agent && node -e \"require\\('./src/core/agent-chat.js'\\); console.log\\('模块加载成功'\\)\" 2>&1)",
|
|
123
|
+
"Bash(cd D:/code/vb-agent && node -e \"require\\('./src/core/agent.js'\\); console.log\\('Agent 加载成功'\\)\" 2>&1)",
|
|
124
|
+
"Bash(node -c src/capabilities/skill-manager.js && node -c src/executors/mcp-executor.js && node -c src/capabilities/workflow-engine.js && node -c src/core/plugin-manager.js 2>&1)",
|
|
125
|
+
"Bash(node -c src/core/plugin-manager.js && node -c plugins/tools-plugin.js 2>&1)",
|
|
126
|
+
"Bash(node -c plugins/default-plugins.js && node -c cli/src/commands/chat.js 2>&1)",
|
|
127
|
+
"Bash(node -c plugins/telegram-plugin.js && node -c plugins/feishu-plugin.js && node -c plugins/weixin-plugin.js 2>&1)",
|
|
128
|
+
"Bash(node -c src/core/agent.js 2>&1)"
|
|
121
129
|
]
|
|
122
130
|
}
|
|
123
131
|
}
|
package/Dockerfile
CHANGED
|
@@ -3,15 +3,43 @@
|
|
|
3
3
|
|
|
4
4
|
FROM node:25-slim
|
|
5
5
|
|
|
6
|
-
#
|
|
6
|
+
# 安装无头浏览器(Chromium)和构建工具
|
|
7
7
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
8
8
|
build-essential \
|
|
9
9
|
python3 \
|
|
10
10
|
python3-pip \
|
|
11
11
|
curl \
|
|
12
12
|
git \
|
|
13
|
+
wget \
|
|
14
|
+
gnupg \
|
|
15
|
+
# Chromium 及依赖
|
|
16
|
+
chromium \
|
|
17
|
+
chromium-sandbox \
|
|
18
|
+
libnss3 \
|
|
19
|
+
libatk1.0-0 \
|
|
20
|
+
libatk-bridge2.0-0 \
|
|
21
|
+
libcups2 \
|
|
22
|
+
libdrm2 \
|
|
23
|
+
libxkbcommon0 \
|
|
24
|
+
libxcomposite1 \
|
|
25
|
+
libxdamage1 \
|
|
26
|
+
libxfixes3 \
|
|
27
|
+
libxrandr2 \
|
|
28
|
+
libgbm1 \
|
|
29
|
+
libasound2 \
|
|
30
|
+
libpango-1.0-0 \
|
|
31
|
+
libpangocairo-1.0-0 \
|
|
32
|
+
libgtk-3-0 \
|
|
33
|
+
fonts-liberation \
|
|
34
|
+
xdg-utils \
|
|
13
35
|
&& rm -rf /var/lib/apt/lists/* \
|
|
14
|
-
&& ln -sf /usr/bin/python3 /usr/bin/python
|
|
36
|
+
&& ln -sf /usr/bin/python3 /usr/bin/python \
|
|
37
|
+
&& ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
|
|
38
|
+
|
|
39
|
+
# 设置 Chromium 环境变量(无头模式运行)
|
|
40
|
+
ENV PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium
|
|
41
|
+
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
|
|
42
|
+
ENV CHROME_BIN=/usr/bin/chromium
|
|
15
43
|
|
|
16
44
|
# 安装 uv(快速的 Python 包管理器)
|
|
17
45
|
RUN curl -LsSf https://astral.sh/uv/install.sh | sh
|
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)
|
package/examples/mcp-example.js
CHANGED
|
@@ -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)
|
package/examples/test-mcp.js
CHANGED
|
@@ -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
|
+
})
|