refactor(agent-tools): 移除已弃用的工具获取接口及相关代码
This commit is contained in:
parent
3b03a91e39
commit
643f49e218
@ -718,6 +718,7 @@ async def update_chat_models(model_provider: str, model_names: list[str], curren
|
||||
@chat.get("/tools")
|
||||
async def get_tools(agent_id: str, current_user: User = Depends(get_required_user)):
|
||||
"""获取所有可用工具(需要登录)"""
|
||||
logger.error("[DEPRECATED] 该接口已被弃用,将在未来版本中移除")
|
||||
# 获取Agent实例和配置类
|
||||
if not (agent := agent_manager.get_agent(agent_id)):
|
||||
raise HTTPException(status_code=404, detail=f"智能体 {agent_id} 不存在")
|
||||
|
||||
@ -141,12 +141,6 @@ export const agentApi = {
|
||||
return apiAdminPost('/api/chat/set_default_agent', { agent_id: agentId })
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取所有可用工具的信息
|
||||
* @returns {Promise} - 工具信息列表
|
||||
*/
|
||||
getTools: (agentId) => apiGet(`/api/chat/tools?agent_id=${agentId}`),
|
||||
|
||||
/**
|
||||
* 恢复被人工审批中断的对话(流式响应)
|
||||
* @param {string} agentId - 智能体ID
|
||||
|
||||
@ -421,21 +421,9 @@ const getToolNameById = (toolId) => {
|
||||
return tool ? tool.name : toolId;
|
||||
};
|
||||
|
||||
const loadAvailableTools = async () => {
|
||||
try {
|
||||
// 避免重复加载,如果已经有工具就直接返回
|
||||
if (availableTools.value && Object.keys(availableTools.value).length > 0) {
|
||||
return;
|
||||
}
|
||||
await agentStore.fetchTools();
|
||||
} catch (error) {
|
||||
console.error('加载工具列表失败:', error);
|
||||
}
|
||||
};
|
||||
|
||||
const openToolsModal = async () => {
|
||||
console.log("availableTools.value", availableTools.value)
|
||||
try {
|
||||
await loadAvailableTools();
|
||||
selectedTools.value = [...(agentConfig.value?.tools || [])];
|
||||
toolsModalOpen.value = true;
|
||||
} catch (error) {
|
||||
@ -563,13 +551,6 @@ const resetConfig = async () => {
|
||||
message.error('重置配置失败');
|
||||
}
|
||||
};
|
||||
|
||||
// 监听器
|
||||
watch(() => props.isOpen, (newVal) => {
|
||||
if (newVal && (!availableTools.value || Object.keys(availableTools.value).length === 0)) {
|
||||
loadAvailableTools();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
|
||||
@ -19,9 +19,6 @@ export const useAgentStore = defineStore('agent', () => {
|
||||
// 智能体详情相关状态
|
||||
const agentDetails = ref({}) // 存储每个智能体的详细信息(含 configurable_items)
|
||||
|
||||
// 工具相关状态
|
||||
const availableTools = ref([])
|
||||
|
||||
// 加载状态
|
||||
const isLoadingAgents = ref(false)
|
||||
const isLoadingConfig = ref(false)
|
||||
@ -66,6 +63,12 @@ export const useAgentStore = defineStore('agent', () => {
|
||||
return items
|
||||
})
|
||||
|
||||
|
||||
// 工具相关状态
|
||||
const availableTools = computed(() => {
|
||||
return configurableItems.value.tools?.options || []
|
||||
})
|
||||
|
||||
const hasConfigChanges = computed(() =>
|
||||
JSON.stringify(agentConfig.value) !== JSON.stringify(originalAgentConfig.value)
|
||||
)
|
||||
@ -108,7 +111,6 @@ export const useAgentStore = defineStore('agent', () => {
|
||||
if (userStore.isAdmin) {
|
||||
await loadAgentConfig()
|
||||
}
|
||||
await fetchTools()
|
||||
}
|
||||
|
||||
isInitialized.value = true
|
||||
@ -159,6 +161,7 @@ export const useAgentStore = defineStore('agent', () => {
|
||||
try {
|
||||
const response = await agentApi.getAgentDetail(agentId)
|
||||
agentDetails.value[agentId] = response
|
||||
// availableTools.value[agentId] = response.available_tools || []
|
||||
return response
|
||||
} catch (err) {
|
||||
console.error(`Failed to fetch agent detail for ${agentId}:`, err)
|
||||
@ -291,17 +294,8 @@ export const useAgentStore = defineStore('agent', () => {
|
||||
isLoadingTools.value = true
|
||||
error.value = null
|
||||
|
||||
try {
|
||||
const response = await agentApi.getTools(selectedAgentId.value)
|
||||
availableTools.value = response.tools
|
||||
} catch (err) {
|
||||
console.error('Failed to fetch tools:', err)
|
||||
handleChatError(err, 'fetch')
|
||||
error.value = err.message
|
||||
throw err
|
||||
} finally {
|
||||
isLoadingTools.value = false
|
||||
}
|
||||
console.error('[DEPRECATED] THIS METHOD IS DEPRECATED. USE fetchAgentDetail INSTEAD.')
|
||||
console.error('[DEPRECATED] fetchTools: selectedAgentId.value =', selectedAgentId.value)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
Reference in New Issue
Block a user