/** * Plugin to sync appState with route changes * Ensures that activeAgentId and activeTopicId stay in sync with the URL */ export default defineNuxtPlugin(() => { const route = useRoute(); const appState = useAppState(); // Sync agent ID from route params watch( () => route.params.id, (newId) => { if (newId) { const agentId = Array.isArray(newId) ? newId[0] : newId; appState.setActiveAgent(agentId); } }, { immediate: true } ); // Sync topic ID from route params watch( () => route.params.topicId, (newId) => { if (newId) { const topicId = Array.isArray(newId) ? newId[0] : newId; appState.setActiveTopic(topicId); } else { appState.setActiveTopic(null); } }, { immediate: true } ); });