diff --git a/src/components/ai/SilentObserver.tsx b/src/components/ai/SilentObserver.tsx index c41e71f..62195f1 100644 --- a/src/components/ai/SilentObserver.tsx +++ b/src/components/ai/SilentObserver.tsx @@ -78,18 +78,35 @@ export default function SilentObserver() { }; handleClose(); - if (url) { - // Mode B: Cross-page navigation + // Valid homepage DOM IDs — anything else is a page route + const HOMEPAGE_IDS = new Set([ + "technology", "applications-dashboard", "applications-deep", + "global", "our-story", "legacy", + ]); + + // Fallback map: if the AI sends a section name that's actually a page + const SECTION_TO_PAGE: Record = { + news: "/news", heritage: "/heritage", parts: "/parts", + "parts-catalog": "/parts", contact: "/parts", + "inside-flux": "/news", "spare-parts": "/parts", + }; + + // Resolve: explicit url > section-to-page fallback > homepage scroll + const resolvedUrl = url + || (section && !HOMEPAGE_IDS.has(section) ? SECTION_TO_PAGE[section] || null : null); + + if (resolvedUrl) { + // Cross-page navigation setTimeout(() => { - router.push(`/${locale}${url}`); + router.push(`/${locale}${resolvedUrl}`); }, 400); addToolOutput({ tool: "navigate_to_section" as any, toolCallId: toolCall.toolCallId, - output: `Navigated to page "${url}"`, + output: `Navigated to page "${resolvedUrl}"`, }); - } else if (section) { - // Mode A: Same-page scroll (existing behavior) + } else if (section && HOMEPAGE_IDS.has(section)) { + // Same-page scroll — only for confirmed homepage DOM IDs setTimeout(() => { const el = document.getElementById(section); if (el) el.scrollIntoView({ behavior: "smooth", block: "start" });