feat: 添加DACP服务支持,允许通过命令行调用DACP专业服务,增强AI角色的执行能力,同时更新相关依赖和工具定义。

This commit is contained in:
sean
2025-06-18 15:42:49 +08:00
parent 15b5e607dd
commit 47582c56c9
25 changed files with 3511 additions and 10 deletions

View File

@ -29,4 +29,14 @@ fi
# 切换到项目根目录并执行命令
echo -e "${GREEN}✅ 正在启动 MCP Server...${NC}"
cd "$PROJECT_ROOT" && pnpm start mcp-server
# 设置环境变量
export PROMPTX_ENV=development
# 检查是否传入了 --with-dacp 参数
if [[ "$1" == "--with-dacp" ]]; then
echo -e "${YELLOW}🔌 将同时启动 DACP 服务...${NC}"
cd "$PROJECT_ROOT" && node src/bin/promptx.js mcp-server --with-dacp
else
cd "$PROJECT_ROOT" && node src/bin/promptx.js mcp-server
fi

52
scripts/test-dacp-calculator.js Executable file
View File

@ -0,0 +1,52 @@
#!/usr/bin/env node
const { spawn } = require('child_process');
const path = require('path');
// 测试计算器功能
async function testCalculator() {
console.log('🧪 测试DACP计算器服务...\n');
const promptxPath = path.join(__dirname, '..', 'src', 'bin', 'promptx.js');
// 测试案例
const testCases = [
{
name: '简单加法',
command: ['node', promptxPath, 'dacp', 'dacp-promptx-service', 'calculate', '{"user_request": "2加3等于多少"}']
},
{
name: '复杂计算',
command: ['node', promptxPath, 'dacp', 'dacp-promptx-service', 'calculate', '{"user_request": "(10 + 5) * 2 - 8 / 4"}']
},
{
name: '中文运算符',
command: ['node', promptxPath, 'dacp', 'dacp-promptx-service', 'calculate', '{"user_request": "100减去25"}']
}
];
for (const testCase of testCases) {
console.log(`📝 测试: ${testCase.name}`);
console.log(`命令: ${testCase.command.join(' ')}`);
await new Promise((resolve) => {
const child = spawn(testCase.command[0], testCase.command.slice(1), {
stdio: 'inherit'
});
child.on('close', (code) => {
console.log(`\n✅ 测试完成 (退出码: ${code})\n`);
console.log('-'.repeat(60) + '\n');
resolve();
});
});
}
}
// 运行测试
testCalculator().then(() => {
console.log('🎉 所有测试完成!');
}).catch(error => {
console.error('❌ 测试失败:', error);
process.exit(1);
});

74
scripts/test-dacp.sh Executable file
View File

@ -0,0 +1,74 @@
#!/bin/bash
# 颜色定义
GREEN='\033[0;32m'
RED='\033[0;31m'
YELLOW='\033[1;33m'
NC='\033[0m'
echo -e "${YELLOW}🧪 DACP 集成测试${NC}"
echo "================================="
# 检查 DACP 服务是否运行
echo -e "\n${YELLOW}1. 检查 DACP 服务状态${NC}"
if curl -s http://localhost:3002/health > /dev/null; then
echo -e "${GREEN}✅ DACP 服务运行正常${NC}"
curl -s http://localhost:3002/health | jq .
else
echo -e "${RED}❌ DACP 服务未运行请先启动sh scripts/start-mcp.sh --with-dacp${NC}"
exit 1
fi
# 测试计算器
echo -e "\n${YELLOW}2. 测试计算器 Action${NC}"
echo "请求: 100 + 200"
curl -s -X POST http://localhost:3002/dacp \
-H "Content-Type: application/json" \
-d '{
"service_id": "dacp-promptx-service",
"action": "calculate",
"parameters": {
"user_request": "100 + 200"
}
}' | jq '.data.execution_result'
# 测试邮件
echo -e "\n${YELLOW}3. 测试邮件 Action${NC}"
echo "请求: 发送会议提醒邮件"
curl -s -X POST http://localhost:3002/dacp \
-H "Content-Type: application/json" \
-d '{
"service_id": "dacp-promptx-service",
"action": "send_email",
"parameters": {
"user_request": "给 team@example.com 发个明天下午3点的会议提醒"
}
}' | jq '.data.execution_result | {recipient, subject, status}'
# 测试日历
echo -e "\n${YELLOW}4. 测试日历 Action${NC}"
echo "请求: 安排会议"
curl -s -X POST http://localhost:3002/dacp \
-H "Content-Type: application/json" \
-d '{
"service_id": "dacp-promptx-service",
"action": "schedule_meeting",
"parameters": {
"user_request": "安排明天和张三讨论项目进展"
}
}' | jq '.data.execution_result | {title, time, attendees}'
# 测试文档
echo -e "\n${YELLOW}5. 测试文档 Action${NC}"
echo "请求: 创建工作报告"
curl -s -X POST http://localhost:3002/dacp \
-H "Content-Type: application/json" \
-d '{
"service_id": "dacp-promptx-service",
"action": "create_document",
"parameters": {
"user_request": "创建一份本周工作报告"
}
}' | jq '.data.execution_result | {title, type, format}'
echo -e "\n${GREEN}✅ 测试完成!${NC}"

79
scripts/test-mcp-dacp.js Executable file
View File

@ -0,0 +1,79 @@
#!/usr/bin/env node
/**
* 测试 MCP → PromptX → DACP 完整链路
*/
const { cli } = require('../src/lib/core/pouch');
async function testDACPIntegration() {
console.log('🧪 测试 MCP → PromptX → DACP 集成\n');
const tests = [
{
name: '计算器测试',
args: {
service_id: 'dacp-promptx-service',
action: 'calculate',
parameters: {
user_request: '(100 + 200) * 3'
}
}
},
{
name: '邮件测试',
args: {
service_id: 'dacp-promptx-service',
action: 'send_email',
parameters: {
user_request: '给 boss@company.com 发个项目进展汇报邮件',
context: {
urgency: 'normal',
recipient_type: 'superior'
}
}
}
},
{
name: '日历测试',
args: {
service_id: 'dacp-promptx-service',
action: 'schedule_meeting',
parameters: {
user_request: '下周一安排团队周会',
context: {
location: '会议室A'
}
}
}
}
];
for (const test of tests) {
console.log(`\n📍 ${test.name}`);
console.log('请求:', JSON.stringify(test.args, null, 2));
try {
// 调用 DACP 命令
const result = await cli.execute('dacp', [test.args], true);
if (result.success) {
console.log('✅ 成功!');
console.log('结果:', JSON.stringify(result.data.execution_result, null, 2));
} else {
console.log('❌ 失败:', result.error);
}
} catch (error) {
console.log('❌ 错误:', error.message);
}
}
}
// 运行测试
testDACPIntegration().then(() => {
console.log('\n✅ 所有测试完成!');
process.exit(0);
}).catch(error => {
console.error('测试失败:', error);
process.exit(1);
});