diff --git a/prompt/core/dacp-email-sending.execution.md b/prompt/core/dacp-email-sending.execution.md
new file mode 100644
index 0000000..85157d8
--- /dev/null
+++ b/prompt/core/dacp-email-sending.execution.md
@@ -0,0 +1,156 @@
+
+
+ ## 技术和环境限制
+ - **配置依赖性**:真实发送需要用户在~/.promptx/dacp/send_email.json配置邮箱信息
+ - **服务可用性**:需要DACP服务运行在localhost:3002或指定端口
+ - **网络连接要求**:发送真实邮件需要稳定的网络连接和SMTP服务可达性
+ - **邮件服务商限制**:不同服务商有发送频率和内容限制
+ - **协议格式约束**:必须符合DACP协议标准的请求格式
+
+
+
+ ## 强制执行规则
+ - **服务ID固定**:必须使用"dacp-promptx-service"作为service_id
+ - **action名称固定**:必须使用"send_email"作为action
+ - **必需参数验证**:user_request是必需参数,不能为空
+ - **配置错误处理**:配置缺失或无效时必须向用户说明具体解决方案
+ - **安全信息保护**:不得在日志或响应中暴露用户的邮箱密码
+
+
+
+ ## 使用指导原则
+ - **智能需求解析**:从用户自然语言中提取收件人、主题、内容等信息
+ - **上下文感知**:根据urgency、recipient_type等上下文调整邮件语气
+ - **友好降级**:无配置时自动使用Demo模式,同时提供配置指导
+ - **错误信息友好化**:将技术错误转化为用户可理解的解决建议
+
+
+
+ ## 邮件发送执行流程
+
+ ### Step 1: 需求分析和参数准备
+ ```
+ 1. 解析用户输入,提取邮件要素(收件人、主题、内容)
+ 2. 确定邮件类型和紧急程度
+ 3. 构造user_request自然语言描述
+ 4. 准备context上下文信息
+ 5. 验证所有必需参数完整性
+ ```
+
+ ### Step 2: DACP服务调用
+ ```json
+ // 标准DACP邮件请求格式
+ {
+ "service_id": "dacp-promptx-service",
+ "action": "send_email",
+ "parameters": {
+ "user_request": "用户的自然语言邮件描述",
+ "context": {
+ "urgency": "high|medium|low",
+ "recipient_type": "colleague|superior|client"
+ }
+ }
+ }
+ ```
+
+ ### Step 3: 配置文件格式要求
+ ```json
+ // ~/.promptx/dacp/send_email.json 配置文件格式
+ {
+ "provider": "gmail|outlook|qq|163|126",
+ "smtp": {
+ "user": "your-email@gmail.com",
+ "password": "your-app-password"
+ },
+ "sender": {
+ "name": "Your Name",
+ "email": "your-email@gmail.com"
+ }
+ }
+ ```
+
+ ### Step 4: 结果处理和用户反馈
+ ```
+ 1. 检查响应状态和demo_mode字段
+ 2. Demo模式:提供配置指导和创建配置文件的详细说明
+ 3. 真实发送:确认发送成功并显示message_id
+ 4. 错误处理:解析错误原因并提供具体解决方案
+ 5. 向用户反馈执行结果和后续建议
+ ```
+
+ ### 配置错误处理流程
+ ```
+ 配置缺失 → 显示配置文件路径和格式 → 指导创建配置
+ 配置无效 → 指出具体错误字段 → 提供修复建议
+ 认证失败 → 检查密码和服务器设置 → 应用专用密码指导
+ 发送失败 → 网络和SMTP检查 → 故障排除建议
+ ```
+
+ ### 邮件服务商配置指导
+ ```
+ Gmail: 需要启用两步验证并生成应用专用密码
+ Outlook: 使用账户密码,确保SMTP已启用
+ QQ/163/126: 需要开启SMTP服务并使用授权码
+ ```
+
+ ### 配置指导详细说明
+ ```
+ 📧 DACP邮件服务配置说明
+
+ 📍 配置文件位置:~/.promptx/dacp/send_email.json
+
+ 📝 完整配置示例:
+ {
+ "provider": "gmail",
+ "smtp": {
+ "user": "your-email@gmail.com",
+ "password": "your-app-password"
+ },
+ "sender": {
+ "name": "Your Name",
+ "email": "your-email@gmail.com"
+ }
+ }
+
+ 💡 支持的邮件服务商:gmail, outlook, qq, 163, 126
+
+ 🔐 Gmail用户专用设置:
+ 1. 进入 Google 账户设置
+ 2. 启用两步验证
+ 3. 生成应用专用密码
+ 4. 使用生成的密码替换 "your-app-password"
+
+ 📞 其他服务商设置:
+ - Outlook: 直接使用账户密码
+ - QQ/163/126: 需要开启SMTP服务并使用授权码
+ ```
+
+
+
+ ## 邮件发送质量评价标准
+
+ ### 功能完整性
+ - ✅ 正确调用DACP邮件服务
+ - ✅ 准确解析用户邮件需求
+ - ✅ 妥善处理配置和发送异常
+ - ✅ 提供完整的配置指导
+
+ ### 用户体验质量
+ - ✅ 自然语言交互流畅
+ - ✅ 错误提示友好明确
+ - ✅ 配置指导详细实用
+ - ✅ Demo模式平滑降级
+
+ ### 安全合规性
+ - ✅ 不暴露敏感配置信息
+ - ✅ 遵循邮件发送最佳实践
+ - ✅ 用户级配置安全存储
+ - ✅ 符合反垃圾邮件规范
+
+ ### 系统稳定性
+ - ✅ 配置缺失时不影响系统运行
+ - ✅ 合理的错误处理和重试机制
+ - ✅ 完整的执行反馈和日志记录
+ - ✅ 多邮件服务商兼容支持
+
+
\ No newline at end of file
diff --git a/prompt/domain/assistant/assistant.role.md b/prompt/domain/assistant/assistant.role.md
index e4715f6..c0b059c 100644
--- a/prompt/domain/assistant/assistant.role.md
+++ b/prompt/domain/assistant/assistant.role.md
@@ -9,5 +9,6 @@
@!execution://assistant
@!execution://dacp-service-calling
+ @!execution://dacp-email-sending
\ No newline at end of file
diff --git a/src/dacp/dacp-promptx-service/actions/email.js b/src/dacp/dacp-promptx-service/actions/email.js
index 1937b5d..3df22af 100644
--- a/src/dacp/dacp-promptx-service/actions/email.js
+++ b/src/dacp/dacp-promptx-service/actions/email.js
@@ -1,8 +1,11 @@
/**
* Email Action Module for DACP PromptX Service
- * 提供邮件发送功能
+ * 提供邮件发送功能 - 支持Demo模式和真实发送
*/
+const nodemailer = require('nodemailer')
+const DACPConfigManager = require('../../../lib/utils/DACPConfigManager')
+
// Email action handler
async function send_email(parameters) {
const { user_request, context = {} } = parameters;
@@ -124,7 +127,39 @@ function validateEmailData(emailData) {
// 执行邮件发送
async function executeSendEmail(emailData, context) {
- // Demo模式:模拟发送
+ const configManager = new DACPConfigManager()
+
+ // 检查是否有用户配置
+ const hasConfig = await configManager.hasActionConfig('send_email')
+
+ if (!hasConfig) {
+ // 无配置,回退到Demo模式
+ return await executeDemoSendEmail(emailData, context)
+ }
+
+ // 读取配置
+ const config = await configManager.readActionConfig('send_email')
+
+ // 验证配置
+ const validation = configManager.validateEmailConfig(config)
+ if (!validation.valid) {
+ // 配置无效,抛出友好错误
+ const errorMessage = configManager.generateConfigErrorMessage('send_email', validation)
+ throw new Error(errorMessage)
+ }
+
+ try {
+ // 真实邮件发送
+ return await executeRealSendEmail(emailData, config, context)
+ } catch (error) {
+ // 发送失败,提供友好提示
+ console.error('邮件发送失败:', error.message)
+ throw new Error(`\n📧 邮件发送失败\n\n❌ 错误信息: ${error.message}\n\n💡 可能的解决方案:\n • 检查邮箱密码是否正确\n • 确认已启用SMTP服务\n • 验证网络连接状态\n • Gmail用户确保使用应用专用密码\n`)
+ }
+}
+
+// Demo模式发送
+async function executeDemoSendEmail(emailData, context) {
console.log('📧 [DACP Demo] Simulating email send:');
console.log(` To: ${emailData.to}`);
console.log(` Subject: ${emailData.subject}`);
@@ -133,15 +168,19 @@ async function executeSendEmail(emailData, context) {
// 模拟网络延迟
await new Promise(resolve => setTimeout(resolve, 100));
+ const configManager = new DACPConfigManager()
+ const configHint = configManager.generateConfigErrorMessage('send_email')
+
return {
- message_id: `msg_${Date.now()}`,
- status: 'sent',
+ message_id: `demo_msg_${Date.now()}`,
+ status: 'demo_sent',
recipient: emailData.to,
subject: emailData.subject,
body: emailData.body,
sent_at: emailData.timestamp,
urgency: emailData.urgency,
demo_mode: true,
+ config_hint: configHint,
execution_metrics: {
parsing_time: '10ms',
validation_time: '5ms',
@@ -150,6 +189,61 @@ async function executeSendEmail(emailData, context) {
};
}
+// 真实邮件发送
+async function executeRealSendEmail(emailData, config, context) {
+ const startTime = Date.now()
+
+ // 获取提供商配置
+ const configManager = new DACPConfigManager()
+ const providerConfig = configManager.getProviderConfig(config.provider)
+
+ if (!providerConfig) {
+ throw new Error(`不支持的邮件服务提供商: ${config.provider}`)
+ }
+
+ // 创建邮件传输器
+ const transporter = nodemailer.createTransport({
+ host: providerConfig.smtp,
+ port: providerConfig.port,
+ secure: providerConfig.secure,
+ auth: {
+ user: config.smtp.user,
+ pass: config.smtp.password
+ }
+ })
+
+ // 构建邮件选项
+ const mailOptions = {
+ from: `"${config.sender.name}" <${config.sender.email}>`,
+ to: emailData.to,
+ subject: emailData.subject,
+ html: emailData.body.replace(/\n/g, '
'),
+ text: emailData.body
+ }
+
+ // 发送邮件
+ const info = await transporter.sendMail(mailOptions)
+ const endTime = Date.now()
+
+ return {
+ message_id: info.messageId,
+ status: 'sent',
+ recipient: emailData.to,
+ subject: emailData.subject,
+ body: emailData.body,
+ sent_at: new Date().toISOString(),
+ urgency: emailData.urgency,
+ demo_mode: false,
+ provider: config.provider,
+ smtp_response: info.response,
+ execution_metrics: {
+ parsing_time: '10ms',
+ validation_time: '5ms',
+ sending_time: `${endTime - startTime}ms`
+ }
+ }
+}
+
// 导出所有email相关的actions
module.exports = {
send_email
diff --git a/src/dacp/dacp-promptx-service/package.json b/src/dacp/dacp-promptx-service/package.json
index 9aa5bb1..fc6ae3b 100644
--- a/src/dacp/dacp-promptx-service/package.json
+++ b/src/dacp/dacp-promptx-service/package.json
@@ -9,13 +9,14 @@
"test": "jest"
},
"dependencies": {
- "express": "^4.18.2",
"body-parser": "^1.20.2",
"cors": "^2.8.5",
- "joi": "^17.11.0"
+ "express": "^4.18.2",
+ "joi": "^17.11.0",
+ "nodemailer": "^7.0.3"
},
"devDependencies": {
"jest": "^29.7.0",
"supertest": "^6.3.3"
}
-}
\ No newline at end of file
+}
diff --git a/src/lib/utils/DACPConfigManager.js b/src/lib/utils/DACPConfigManager.js
new file mode 100644
index 0000000..9a5cc31
--- /dev/null
+++ b/src/lib/utils/DACPConfigManager.js
@@ -0,0 +1,207 @@
+const fs = require('fs-extra')
+const path = require('path')
+const os = require('os')
+
+/**
+ * DACP用户级配置管理器
+ * 管理 ~/.promptx/dacp/ 下的配置文件
+ */
+class DACPConfigManager {
+ constructor() {
+ this.userHome = os.homedir()
+ this.dacpConfigDir = path.join(this.userHome, '.promptx', 'dacp')
+ }
+
+ /**
+ * 确保DACP配置目录存在
+ */
+ async ensureConfigDir() {
+ await fs.ensureDir(this.dacpConfigDir)
+ }
+
+ /**
+ * 获取指定action的配置文件路径
+ * @param {string} action - action名称,如 'send_email'
+ * @returns {string} 配置文件完整路径
+ */
+ getConfigPath(action) {
+ return path.join(this.dacpConfigDir, `${action}.json`)
+ }
+
+ /**
+ * 读取action配置
+ * @param {string} action - action名称
+ * @returns {Promise