/** * features/chat/composables/useChatGuides.ts * Agent 学习之窗:指南列表加载与弹窗状态。 */ import { computed, ref, type ComputedRef } from 'vue'; import { listAgentGuides } from '@/features/auth/api/user.api'; export interface AgentGuide { id: number; file_name: string; file_type?: string; file_url?: string; file_path?: string; remark?: string; } export interface UseChatGuidesOptions { currentAgentId: ComputedRef; } export function useChatGuides(options: UseChatGuidesOptions) { const { currentAgentId } = options; const guides = ref([]); const showModal = ref(false); const activeGuideId = ref(null); const showSidebar = ref(true); const activeGuide = computed(() => guides.value.find((g) => g.id === activeGuideId.value)); const loadGuides = async () => { try { const res = await listAgentGuides(currentAgentId.value || 0); guides.value = Array.isArray(res) ? (res as AgentGuide[]) : []; } catch (error) { console.error('Failed to load agent guides:', error); guides.value = []; } }; const clearGuides = () => { guides.value = []; }; const openModal = () => { const first = guides.value[0]; if (!first) return; activeGuideId.value = first.id; showModal.value = true; showSidebar.value = true; }; const closeModal = () => { showModal.value = false; }; return { guides, showModal, activeGuideId, activeGuide, showSidebar, loadGuides, clearGuides, openModal, closeModal, }; } export type UseChatGuidesReturn = ReturnType;