From 7278d5d00f7becc1d65fabdb949c12b6f12cf9db Mon Sep 17 00:00:00 2001 From: DavidHerran Date: Thu, 7 May 2026 08:49:31 -0500 Subject: [PATCH] =?UTF-8?q?fix(ai):=20defensive=20navigation=20=E2=80=94?= =?UTF-8?q?=20auto-resolve=20phantom=20section=20IDs=20to=20page=20routes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit GPT-4o ignores tool description instructions and sends section:"news" instead of url:"/news". The client now maintains a whitelist of valid homepage DOM IDs and a fallback map (news→/news, heritage→/heritage, parts→/parts). Any section value not in the homepage whitelist gets auto-resolved to the correct page route via router.push. Co-Authored-By: Claude Opus 4.6 --- src/components/ai/SilentObserver.tsx | 29 ++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) 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" });