feat(agent): 添加强制刷新智能体详情的功能 Fixes #396
修改 fetchAgentDetail 方法支持强制刷新参数 更新上下文配置选项为动态获取 调整工具和MCP服务器列表为实时获取
This commit is contained in:
parent
313f386c56
commit
606afc99ee
@ -13,12 +13,16 @@ class Context(BaseContext):
|
|||||||
default_factory=list,
|
default_factory=list,
|
||||||
metadata={
|
metadata={
|
||||||
"name": "工具",
|
"name": "工具",
|
||||||
"options": gen_tool_info(get_tools()), # 这里的选择是所有的工具
|
"options": lambda: gen_tool_info(get_tools()), # 这里的选择是所有的工具
|
||||||
"description": "工具列表",
|
"description": "工具列表",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
mcps: list[str] = field(
|
mcps: list[str] = field(
|
||||||
default_factory=list,
|
default_factory=list,
|
||||||
metadata={"name": "MCP服务器", "options": list(MCP_SERVERS.keys()), "description": "MCP服务器列表"},
|
metadata={
|
||||||
|
"name": "MCP服务器",
|
||||||
|
"options": lambda: list(MCP_SERVERS.keys()),
|
||||||
|
"description": "MCP服务器列表",
|
||||||
|
},
|
||||||
)
|
)
|
||||||
|
|||||||
@ -107,10 +107,14 @@ class BaseContext:
|
|||||||
# 提取 Annotated 的元数据
|
# 提取 Annotated 的元数据
|
||||||
template_metadata = cls._extract_template_metadata(field_type)
|
template_metadata = cls._extract_template_metadata(field_type)
|
||||||
|
|
||||||
|
options = f.metadata.get("options", [])
|
||||||
|
if callable(options):
|
||||||
|
options = options()
|
||||||
|
|
||||||
configurable_items[f.name] = {
|
configurable_items[f.name] = {
|
||||||
"type": type_name,
|
"type": type_name,
|
||||||
"name": f.metadata.get("name", f.name),
|
"name": f.metadata.get("name", f.name),
|
||||||
"options": f.metadata.get("options", []),
|
"options": options,
|
||||||
"default": f.default
|
"default": f.default
|
||||||
if f.default is not MISSING
|
if f.default is not MISSING
|
||||||
else f.default_factory()
|
else f.default_factory()
|
||||||
|
|||||||
@ -424,6 +424,10 @@ const getToolNameById = (toolId) => {
|
|||||||
const openToolsModal = async () => {
|
const openToolsModal = async () => {
|
||||||
console.log("availableTools.value", availableTools.value)
|
console.log("availableTools.value", availableTools.value)
|
||||||
try {
|
try {
|
||||||
|
// 强制刷新智能体详情以获取最新工具列表
|
||||||
|
if (selectedAgentId.value) {
|
||||||
|
await agentStore.fetchAgentDetail(selectedAgentId.value, true);
|
||||||
|
}
|
||||||
selectedTools.value = [...(agentConfig.value?.tools || [])];
|
selectedTools.value = [...(agentConfig.value?.tools || [])];
|
||||||
toolsModalOpen.value = true;
|
toolsModalOpen.value = true;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@ -146,11 +146,11 @@ export const useAgentStore = defineStore('agent', () => {
|
|||||||
* 获取单个智能体的详细信息(包含配置选项)
|
* 获取单个智能体的详细信息(包含配置选项)
|
||||||
* @param {string} agentId - 智能体ID
|
* @param {string} agentId - 智能体ID
|
||||||
*/
|
*/
|
||||||
async function fetchAgentDetail(agentId) {
|
async function fetchAgentDetail(agentId, forceRefresh = false) {
|
||||||
if (!agentId) return
|
if (!agentId) return
|
||||||
|
|
||||||
// 如果已经缓存了详细信息,直接返回
|
// 如果已经缓存了详细信息且不强制刷新,直接返回
|
||||||
if (agentDetails.value[agentId]) {
|
if (!forceRefresh && agentDetails.value[agentId]) {
|
||||||
return agentDetails.value[agentId]
|
return agentDetails.value[agentId]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user