refactor: 重构整个资源引用协议
This commit is contained in:
@ -45,6 +45,50 @@ class ProjectDiscovery extends BaseDiscovery {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 发现项目级资源注册表 (新架构方法)
|
||||
* @returns {Promise<Map>} 发现的资源注册表 Map<resourceId, reference>
|
||||
*/
|
||||
async discoverRegistry() {
|
||||
try {
|
||||
// 1. 查找项目根目录
|
||||
const projectRoot = await this._findProjectRoot()
|
||||
|
||||
// 2. 检查.promptx目录是否存在
|
||||
const hasPrompxDir = await this._checkPrompxDirectory(projectRoot)
|
||||
if (!hasPrompxDir) {
|
||||
return new Map()
|
||||
}
|
||||
|
||||
// 3. 扫描项目资源
|
||||
const resources = await this._scanProjectResources(projectRoot)
|
||||
|
||||
// 4. 构建注册表
|
||||
return this._buildRegistryFromResources(resources)
|
||||
|
||||
} catch (error) {
|
||||
console.warn(`[ProjectDiscovery] Registry discovery failed: ${error.message}`)
|
||||
return new Map()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 从资源列表构建注册表
|
||||
* @param {Array} resources - 资源列表
|
||||
* @returns {Map} 资源注册表 Map<resourceId, reference>
|
||||
*/
|
||||
_buildRegistryFromResources(resources) {
|
||||
const registry = new Map()
|
||||
|
||||
for (const resource of resources) {
|
||||
if (resource.id && resource.reference) {
|
||||
registry.set(resource.id, resource.reference)
|
||||
}
|
||||
}
|
||||
|
||||
return registry
|
||||
}
|
||||
|
||||
/**
|
||||
* 查找项目根目录
|
||||
* @returns {Promise<string>} 项目根目录路径
|
||||
@ -97,7 +141,7 @@ class ProjectDiscovery extends BaseDiscovery {
|
||||
const resources = []
|
||||
|
||||
// 定义要扫描的资源类型
|
||||
const resourceTypes = ['role', 'execution', 'thought']
|
||||
const resourceTypes = ['role', 'execution', 'thought', 'knowledge']
|
||||
|
||||
// 并行扫描所有资源类型
|
||||
for (const resourceType of resourceTypes) {
|
||||
@ -187,6 +231,10 @@ class ProjectDiscovery extends BaseDiscovery {
|
||||
return trimmedContent.includes('<execution>') && trimmedContent.includes('</execution>')
|
||||
case 'thought':
|
||||
return trimmedContent.includes('<thought>') && trimmedContent.includes('</thought>')
|
||||
case 'knowledge':
|
||||
// knowledge类型比较灵活,只要文件有内容就认为是有效的
|
||||
// 可以是纯文本、链接、图片等任何形式的知识内容
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user