优化ExecutionProtocol、RoleProtocol和ThoughtProtocol中的@package://路径处理逻辑,新增PackageProtocol以解析路径,提升路径解析的准确性和灵活性。

This commit is contained in:
sean
2025-06-11 22:04:06 +08:00
parent 685cc7adaf
commit ef39222b83
3 changed files with 14 additions and 4 deletions

View File

@ -49,7 +49,10 @@ class ExecutionProtocol extends ResourceProtocol {
// 处理 @package:// 前缀 // 处理 @package:// 前缀
if (resolvedPath.startsWith('@package://')) { if (resolvedPath.startsWith('@package://')) {
resolvedPath = resolvedPath.replace('@package://', '') const PackageProtocol = require('./PackageProtocol')
const packageProtocol = new PackageProtocol()
const relativePath = resolvedPath.replace('@package://', '')
resolvedPath = await packageProtocol.resolvePath(relativePath)
} else if (resolvedPath.startsWith('@project://')) { } else if (resolvedPath.startsWith('@project://')) {
// 处理 @project:// 前缀,转换为绝对路径 // 处理 @project:// 前缀,转换为绝对路径
const relativePath = resolvedPath.replace('@project://', '') const relativePath = resolvedPath.replace('@project://', '')

View File

@ -46,11 +46,15 @@ class RoleProtocol extends ResourceProtocol {
throw new Error(`角色 "${roleId}" 未在注册表中找到。可用角色:${Object.keys(this.registry).join(', ')}`) throw new Error(`角色 "${roleId}" 未在注册表中找到。可用角色:${Object.keys(this.registry).join(', ')}`)
} }
let resolvedPath = this.registry[roleId] const roleInfo = this.registry[roleId]
let resolvedPath = typeof roleInfo === 'string' ? roleInfo : roleInfo.file
// 处理 @package:// 前缀 // 处理 @package:// 前缀
if (resolvedPath.startsWith('@package://')) { if (resolvedPath.startsWith('@package://')) {
resolvedPath = resolvedPath.replace('@package://', '') const PackageProtocol = require('./PackageProtocol')
const packageProtocol = new PackageProtocol()
const relativePath = resolvedPath.replace('@package://', '')
resolvedPath = await packageProtocol.resolvePath(relativePath)
} }
return resolvedPath return resolvedPath

View File

@ -48,7 +48,10 @@ class ThoughtProtocol extends ResourceProtocol {
// 处理 @package:// 前缀 // 处理 @package:// 前缀
if (resolvedPath.startsWith('@package://')) { if (resolvedPath.startsWith('@package://')) {
resolvedPath = resolvedPath.replace('@package://', '') const PackageProtocol = require('./PackageProtocol')
const packageProtocol = new PackageProtocol()
const relativePath = resolvedPath.replace('@package://', '')
resolvedPath = await packageProtocol.resolvePath(relativePath)
} else if (resolvedPath.startsWith('@project://')) { } else if (resolvedPath.startsWith('@project://')) {
// 处理 @project:// 前缀,转换为绝对路径 // 处理 @project:// 前缀,转换为绝对路径
const relativePath = resolvedPath.replace('@project://', '') const relativePath = resolvedPath.replace('@project://', '')