refactor(agent-tools): 移除已弃用的工具获取接口及相关代码

This commit is contained in:
Wenjie Zhang 2025-12-21 20:58:40 +08:00
parent 3b03a91e39
commit 1d04842f02
4 changed files with 10 additions and 56 deletions

View File

@ -718,6 +718,7 @@ async def update_chat_models(model_provider: str, model_names: list[str], curren
@chat.get("/tools") @chat.get("/tools")
async def get_tools(agent_id: str, current_user: User = Depends(get_required_user)): async def get_tools(agent_id: str, current_user: User = Depends(get_required_user)):
"""获取所有可用工具(需要登录)""" """获取所有可用工具(需要登录)"""
logger.error("[DEPRECATED] 该接口已被弃用,将在未来版本中移除")
# 获取Agent实例和配置类 # 获取Agent实例和配置类
if not (agent := agent_manager.get_agent(agent_id)): if not (agent := agent_manager.get_agent(agent_id)):
raise HTTPException(status_code=404, detail=f"智能体 {agent_id} 不存在") raise HTTPException(status_code=404, detail=f"智能体 {agent_id} 不存在")

View File

@ -141,12 +141,6 @@ export const agentApi = {
return apiAdminPost('/api/chat/set_default_agent', { agent_id: agentId }) 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 * @param {string} agentId - 智能体ID

View File

@ -421,21 +421,9 @@ const getToolNameById = (toolId) => {
return tool ? tool.name : 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 () => { const openToolsModal = async () => {
console.log("availableTools.value", availableTools.value)
try { try {
await loadAvailableTools();
selectedTools.value = [...(agentConfig.value?.tools || [])]; selectedTools.value = [...(agentConfig.value?.tools || [])];
toolsModalOpen.value = true; toolsModalOpen.value = true;
} catch (error) { } catch (error) {
@ -563,13 +551,6 @@ const resetConfig = async () => {
message.error('重置配置失败'); message.error('重置配置失败');
} }
}; };
//
watch(() => props.isOpen, (newVal) => {
if (newVal && (!availableTools.value || Object.keys(availableTools.value).length === 0)) {
loadAvailableTools();
}
});
</script> </script>
<style lang="less" scoped> <style lang="less" scoped>

View File

@ -19,13 +19,9 @@ export const useAgentStore = defineStore('agent', () => {
// 智能体详情相关状态 // 智能体详情相关状态
const agentDetails = ref({}) // 存储每个智能体的详细信息(含 configurable_items const agentDetails = ref({}) // 存储每个智能体的详细信息(含 configurable_items
// 工具相关状态
const availableTools = ref([])
// 加载状态 // 加载状态
const isLoadingAgents = ref(false) const isLoadingAgents = ref(false)
const isLoadingConfig = ref(false) const isLoadingConfig = ref(false)
const isLoadingTools = ref(false)
const isLoadingAgentDetail = ref(false) const isLoadingAgentDetail = ref(false)
// 错误状态 // 错误状态
@ -66,6 +62,12 @@ export const useAgentStore = defineStore('agent', () => {
return items return items
}) })
// 工具相关状态
const availableTools = computed(() => {
return configurableItems.value.tools?.options || []
})
const hasConfigChanges = computed(() => const hasConfigChanges = computed(() =>
JSON.stringify(agentConfig.value) !== JSON.stringify(originalAgentConfig.value) JSON.stringify(agentConfig.value) !== JSON.stringify(originalAgentConfig.value)
) )
@ -108,7 +110,6 @@ export const useAgentStore = defineStore('agent', () => {
if (userStore.isAdmin) { if (userStore.isAdmin) {
await loadAgentConfig() await loadAgentConfig()
} }
await fetchTools()
} }
isInitialized.value = true isInitialized.value = true
@ -284,25 +285,6 @@ export const useAgentStore = defineStore('agent', () => {
Object.assign(agentConfig.value, updates) Object.assign(agentConfig.value, updates)
} }
/**
* 获取工具列表
*/
async function fetchTools() {
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
}
}
/** /**
* 清除错误状态 * 清除错误状态
@ -321,10 +303,8 @@ export const useAgentStore = defineStore('agent', () => {
agentConfig.value = {} agentConfig.value = {}
originalAgentConfig.value = {} originalAgentConfig.value = {}
agentDetails.value = {} agentDetails.value = {}
availableTools.value = []
isLoadingAgents.value = false isLoadingAgents.value = false
isLoadingConfig.value = false isLoadingConfig.value = false
isLoadingTools.value = false
isLoadingAgentDetail.value = false isLoadingAgentDetail.value = false
error.value = null error.value = null
isInitialized.value = false isInitialized.value = false
@ -339,10 +319,8 @@ export const useAgentStore = defineStore('agent', () => {
agentConfig, agentConfig,
originalAgentConfig, originalAgentConfig,
agentDetails, agentDetails,
availableTools,
isLoadingAgents, isLoadingAgents,
isLoadingConfig, isLoadingConfig,
isLoadingTools,
isLoadingAgentDetail, isLoadingAgentDetail,
error, error,
isInitialized, isInitialized,
@ -353,6 +331,7 @@ export const useAgentStore = defineStore('agent', () => {
agentsList, agentsList,
isDefaultAgent, isDefaultAgent,
configurableItems, configurableItems,
availableTools,
hasConfigChanges, hasConfigChanges,
// 方法 // 方法
@ -367,7 +346,6 @@ export const useAgentStore = defineStore('agent', () => {
resetAgentConfig, resetAgentConfig,
updateConfigItem, updateConfigItem,
updateAgentConfig, updateAgentConfig,
fetchTools,
clearError, clearError,
reset reset
} }