import { defineStore } from 'pinia' import { ref } from 'vue' import { getAgentDetail, updateAgentApi, type AIAgent } from '../api/agents' export const useAgentStore = defineStore('agent', () => { const currentAgent = ref(null) // 获取单个AI Agent const fetchAgent = async (name: string) => { try { const agentData = await getAgentDetail(name) currentAgent.value = agentData } catch (err: any) { console.error('获取AI Agent详情失败:', err) throw err } } // 更新AI Agent const updateAgent = async (name: string, data: Partial) => { try { await updateAgentApi(name, data) // 更新成功后,手动更新本地状态 if (currentAgent.value && currentAgent.value.name === name) { currentAgent.value = { ...currentAgent.value, ...data } } return { success: true } } catch (err: any) { console.error('更新AI Agent失败:', err) throw err } } return { // 状态 currentAgent, // 方法 fetchAgent, updateAgent } })