From 2afdf4f276060eb8c26f6dab98a100854ffaa021 Mon Sep 17 00:00:00 2001 From: Britton Hayes Date: Fri, 20 Mar 2026 23:11:25 -0700 Subject: [PATCH] Fix Open with AI button to include current URL in prompt The AI prompt now embeds the current page URL so the agent can fetch the page content directly (either the .md file for doc pages or the page itself for API pages). Also references llms.txt for API pages so agents have a site overview fallback. Markdown is always copied to clipboard as a convenience backup. Co-Authored-By: Claude Opus 4.6 (1M context) --- src/components/AiContextMenu/index.tsx | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/components/AiContextMenu/index.tsx b/src/components/AiContextMenu/index.tsx index 9929e72..32ac821 100644 --- a/src/components/AiContextMenu/index.tsx +++ b/src/components/AiContextMenu/index.tsx @@ -204,23 +204,17 @@ export default function AiContextMenu(): JSX.Element { function buildAiUrl(baseUrl: string, queryParam: string): string { const mdUrl = getMarkdownUrl(); - const pageTitle = document.querySelector("h1")?.textContent || document.title; - if (mdUrl) { - const prompt = `Read from ${mdUrl} so I can ask questions about it.`; - return `${baseUrl}?${queryParam}=${encodeURIComponent(prompt)}`; - } - // For API pages without .md files, copy content and prompt to paste - const prompt = `I have a page from the D&D 5e SRD API documentation: "${pageTitle}". The content is in my clipboard. I'll paste it so you can help me with questions about it.`; + const pageUrl = window.location.href; + const prompt = mdUrl + ? `Fetch ${mdUrl} and read the documentation so I can ask questions about it. The page is located at ${pageUrl}` + : `Fetch ${pageUrl} and read the page content so I can ask questions about this D&D 5e SRD API documentation. You can also fetch https://5e-bits.github.io/docs/llms.txt for a site overview.`; return `${baseUrl}?${queryParam}=${encodeURIComponent(prompt)}`; } async function handleOpenInAi(item: { id: string; url: string }) { - const mdUrl = getMarkdownUrl(); - // Copy markdown to clipboard for API pages (no .md file) or as fallback - if (!mdUrl) { - const md = getPageMarkdown(); - await navigator.clipboard.writeText(md); - } + // Always copy markdown to clipboard as a fallback + const md = getPageMarkdown(); + await navigator.clipboard.writeText(md); let finalUrl: string; if (item.id === "claude") {