fix(ai): defensive navigation — auto-resolve phantom section IDs to page routes
Deploy to VPS / deploy (push) Has been cancelled

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 <noreply@anthropic.com>
This commit is contained in:
2026-05-07 08:49:31 -05:00
parent 8941d1a2c3
commit 7278d5d00f
+23 -6
View File
@@ -78,18 +78,35 @@ export default function SilentObserver() {
}; };
handleClose(); handleClose();
if (url) { // Valid homepage DOM IDs — anything else is a page route
// Mode B: Cross-page navigation 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<string, string> = {
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(() => { setTimeout(() => {
router.push(`/${locale}${url}`); router.push(`/${locale}${resolvedUrl}`);
}, 400); }, 400);
addToolOutput({ addToolOutput({
tool: "navigate_to_section" as any, tool: "navigate_to_section" as any,
toolCallId: toolCall.toolCallId, toolCallId: toolCall.toolCallId,
output: `Navigated to page "${url}"`, output: `Navigated to page "${resolvedUrl}"`,
}); });
} else if (section) { } else if (section && HOMEPAGE_IDS.has(section)) {
// Mode A: Same-page scroll (existing behavior) // Same-page scroll — only for confirmed homepage DOM IDs
setTimeout(() => { setTimeout(() => {
const el = document.getElementById(section); const el = document.getElementById(section);
if (el) el.scrollIntoView({ behavior: "smooth", block: "start" }); if (el) el.scrollIntoView({ behavior: "smooth", block: "start" });