fix(ai): defensive navigation — auto-resolve phantom section IDs to page routes
Deploy to VPS / deploy (push) Has been cancelled
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:
@@ -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<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(() => {
|
||||
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" });
|
||||
|
||||
Reference in New Issue
Block a user