更新资源管理器和协议处理逻辑:优化角色资源的合并方式,支持直接处理thought和execution的路径字符串,同时增强对@project://前缀的处理,提升路径解析的灵活性和准确性。
This commit is contained in:
@ -50,6 +50,10 @@ class ExecutionProtocol extends ResourceProtocol {
|
|||||||
// 处理 @package:// 前缀
|
// 处理 @package:// 前缀
|
||||||
if (resolvedPath.startsWith('@package://')) {
|
if (resolvedPath.startsWith('@package://')) {
|
||||||
resolvedPath = resolvedPath.replace('@package://', '')
|
resolvedPath = resolvedPath.replace('@package://', '')
|
||||||
|
} else if (resolvedPath.startsWith('@project://')) {
|
||||||
|
// 处理 @project:// 前缀,转换为绝对路径
|
||||||
|
const relativePath = resolvedPath.replace('@project://', '')
|
||||||
|
resolvedPath = path.join(process.cwd(), relativePath)
|
||||||
}
|
}
|
||||||
|
|
||||||
return resolvedPath
|
return resolvedPath
|
||||||
|
|||||||
@ -49,6 +49,10 @@ class ThoughtProtocol extends ResourceProtocol {
|
|||||||
// 处理 @package:// 前缀
|
// 处理 @package:// 前缀
|
||||||
if (resolvedPath.startsWith('@package://')) {
|
if (resolvedPath.startsWith('@package://')) {
|
||||||
resolvedPath = resolvedPath.replace('@package://', '')
|
resolvedPath = resolvedPath.replace('@package://', '')
|
||||||
|
} else if (resolvedPath.startsWith('@project://')) {
|
||||||
|
// 处理 @project:// 前缀,转换为绝对路径
|
||||||
|
const relativePath = resolvedPath.replace('@project://', '')
|
||||||
|
resolvedPath = path.join(process.cwd(), relativePath)
|
||||||
}
|
}
|
||||||
|
|
||||||
return resolvedPath
|
return resolvedPath
|
||||||
|
|||||||
@ -90,10 +90,16 @@ class ResourceManager {
|
|||||||
if (extractedSystemResources[resourceType]) {
|
if (extractedSystemResources[resourceType]) {
|
||||||
if (!mergedRegistry[resourceType]) mergedRegistry[resourceType] = {}
|
if (!mergedRegistry[resourceType]) mergedRegistry[resourceType] = {}
|
||||||
for (const [id, resourceInfo] of Object.entries(extractedSystemResources[resourceType])) {
|
for (const [id, resourceInfo] of Object.entries(extractedSystemResources[resourceType])) {
|
||||||
|
// 对于role资源,resourceInfo是对象;对于thought/execution,resourceInfo是字符串
|
||||||
|
if (resourceType === 'role') {
|
||||||
mergedRegistry[resourceType][id] = {
|
mergedRegistry[resourceType][id] = {
|
||||||
...resourceInfo,
|
...resourceInfo,
|
||||||
source: 'system'
|
source: 'system'
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// 对于thought和execution,resourceInfo直接是路径字符串
|
||||||
|
mergedRegistry[resourceType][id] = resourceInfo
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -161,10 +167,17 @@ class ResourceManager {
|
|||||||
const protocolHandler = new ProtocolClass()
|
const protocolHandler = new ProtocolClass()
|
||||||
|
|
||||||
// 从统一注册表获取协议配置
|
// 从统一注册表获取协议配置
|
||||||
const protocolConfig = this.registry.protocols[protocolName]
|
// 对于基础协议(thought, execution等),直接从registry中获取
|
||||||
|
const protocolRegistry = this.registry[protocolName]
|
||||||
|
if (protocolRegistry) {
|
||||||
|
protocolHandler.setRegistry(protocolRegistry)
|
||||||
|
} else {
|
||||||
|
// 对于复杂协议配置,从protocols配置中获取
|
||||||
|
const protocolConfig = this.registry.protocols && this.registry.protocols[protocolName]
|
||||||
if (protocolConfig && protocolConfig.registry) {
|
if (protocolConfig && protocolConfig.registry) {
|
||||||
protocolHandler.setRegistry(protocolConfig.registry)
|
protocolHandler.setRegistry(protocolConfig.registry)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
handlers.set(protocolName, protocolHandler)
|
handlers.set(protocolName, protocolHandler)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user