feat: 更新命令名称为dpml-prompt,保持PromptX品牌名称

This commit is contained in:
sean
2025-05-31 18:59:25 +08:00
parent 0bdb5e865b
commit 0466cd3289
44 changed files with 3138 additions and 3127 deletions

View File

@ -1,47 +1,46 @@
const BasePouchCommand = require('../BasePouchCommand');
const ResourceManager = require('../../resource/resourceManager');
const { COMMANDS, buildCommand } = require('../../../../constants');
const BasePouchCommand = require('../BasePouchCommand')
const ResourceManager = require('../../resource/resourceManager')
const { COMMANDS, buildCommand } = require('../../../../constants')
/**
* 智能学习锦囊命令
* 支持加载thought、execution、memory等协议资源以及角色的personality、principle、knowledge
*/
class LearnCommand extends BasePouchCommand {
constructor() {
super();
this.resourceManager = new ResourceManager();
constructor () {
super()
this.resourceManager = new ResourceManager()
}
getPurpose() {
return '智能学习指定协议的资源内容支持thought、execution、memory等DPML协议以及角色组件';
getPurpose () {
return '智能学习指定协议的资源内容支持thought、execution、memory等DPML协议以及角色组件'
}
async getContent(args) {
const [resourceUrl] = args;
async getContent (args) {
const [resourceUrl] = args
if (!resourceUrl) {
return this.getUsageHelp();
return this.getUsageHelp()
}
try {
// 直接使用ResourceManager解析资源
const content = await this.resourceManager.resolve(resourceUrl);
const content = await this.resourceManager.resolve(resourceUrl)
// 解析协议信息
const urlMatch = resourceUrl.match(/^([a-zA-Z]+):\/\/(.+)$/);
const [, protocol, resourceId] = urlMatch;
return this.formatSuccessResponse(protocol, resourceId, content);
const urlMatch = resourceUrl.match(/^([a-zA-Z]+):\/\/(.+)$/)
const [, protocol, resourceId] = urlMatch
return this.formatSuccessResponse(protocol, resourceId, content)
} catch (error) {
return this.formatErrorResponse(resourceUrl, error.message);
return this.formatErrorResponse(resourceUrl, error.message)
}
}
/**
* 格式化成功响应
*/
formatSuccessResponse(protocol, resourceId, content) {
formatSuccessResponse (protocol, resourceId, content) {
const protocolLabels = {
thought: '🧠 思维模式',
execution: '⚡ 执行模式',
@ -49,10 +48,10 @@ class LearnCommand extends BasePouchCommand {
personality: '👤 角色人格',
principle: '⚖️ 行为原则',
knowledge: '📚 专业知识'
};
}
const label = protocolLabels[protocol] || `📄 ${protocol}`
const label = protocolLabels[protocol] || `📄 ${protocol}`;
return `✅ **成功学习${label}${resourceId}**
## 📋 学习内容
@ -72,13 +71,13 @@ ${content}
- 激活角色: 激活完整角色能力
命令: \`${buildCommand.action('<role-id>')}\`
📍 当前状态learned_${protocol}`;
📍 当前状态learned_${protocol}`
}
/**
* 格式化错误响应
*/
formatErrorResponse(resourceUrl, errorMessage) {
formatErrorResponse (resourceUrl, errorMessage) {
return `❌ 学习资源失败:${resourceUrl}
🔍 错误详情:
@ -105,13 +104,13 @@ ${buildCommand.action('<role-id>')} # 查看角色的所有依赖
- 激活角色: 激活完整角色能力
命令: ${buildCommand.action('<role-id>')}
- 查看角色列表: 选择其他角色
命令: ${COMMANDS.HELLO}`;
命令: ${COMMANDS.HELLO}`
}
/**
* 获取使用帮助
*/
getUsageHelp() {
getUsageHelp () {
return `🎓 **Learn锦囊 - 智能学习系统**
## 📖 基本用法
@ -153,15 +152,15 @@ ${COMMANDS.HELLO} # 查看可用角色列表
- 激活角色: 分析角色依赖
命令: ${buildCommand.action('<role-id>')}
- 查看角色: 选择感兴趣的角色
命令: ${COMMANDS.HELLO}`;
命令: ${COMMANDS.HELLO}`
}
/**
* 获取PATEOAS导航信息
*/
getPATEOAS(args) {
const [resourceUrl] = args;
getPATEOAS (args) {
const [resourceUrl] = args
if (!resourceUrl) {
return {
currentState: 'learn_awaiting_resource',
@ -180,27 +179,27 @@ ${COMMANDS.HELLO} # 查看可用角色列表
priority: 'high'
}
]
};
}
}
const urlMatch = resourceUrl.match(/^([a-zA-Z]+):\/\/(.+)$/);
const urlMatch = resourceUrl.match(/^([a-zA-Z]+):\/\/(.+)$/)
if (!urlMatch) {
return {
currentState: 'learn_error',
availableTransitions: ['hello', 'action'],
nextActions: [
{
name: '查看使用帮助',
description: '重新学习命令使用方法',
command: COMMANDS.LEARN,
name: '查看使用帮助',
description: '重新学习命令使用方法',
command: COMMANDS.LEARN,
priority: 'high'
}
]
};
}
}
const [, protocol, resourceId] = urlMatch;
const [, protocol, resourceId] = urlMatch
return {
currentState: `learned_${protocol}`,
availableTransitions: ['learn', 'recall', 'hello', 'action'],
@ -232,12 +231,12 @@ ${COMMANDS.HELLO} # 查看可用角色列表
],
metadata: {
learnedResource: resourceUrl,
protocol: protocol,
resourceId: resourceId,
protocol,
resourceId,
systemVersion: '锦囊串联状态机 v1.0'
}
};
}
}
}
module.exports = LearnCommand;
module.exports = LearnCommand