Skip to content

Commit 1039817

Browse files
brittonhayesclaude
andauthored
Fix Open with AI button to include current URL in prompt (#189)
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: Britton Hayes <brittonhayes@users.noreply.github.com> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 2059845 commit 1039817

1 file changed

Lines changed: 7 additions & 13 deletions

File tree

src/components/AiContextMenu/index.tsx

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -204,23 +204,17 @@ export default function AiContextMenu(): JSX.Element {
204204

205205
function buildAiUrl(baseUrl: string, queryParam: string): string {
206206
const mdUrl = getMarkdownUrl();
207-
const pageTitle = document.querySelector("h1")?.textContent || document.title;
208-
if (mdUrl) {
209-
const prompt = `Read from ${mdUrl} so I can ask questions about it.`;
210-
return `${baseUrl}?${queryParam}=${encodeURIComponent(prompt)}`;
211-
}
212-
// For API pages without .md files, copy content and prompt to paste
213-
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.`;
207+
const pageUrl = window.location.href;
208+
const prompt = mdUrl
209+
? `Fetch ${mdUrl} and read the documentation so I can ask questions about it. The page is located at ${pageUrl}`
210+
: `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.`;
214211
return `${baseUrl}?${queryParam}=${encodeURIComponent(prompt)}`;
215212
}
216213

217214
async function handleOpenInAi(item: { id: string; url: string }) {
218-
const mdUrl = getMarkdownUrl();
219-
// Copy markdown to clipboard for API pages (no .md file) or as fallback
220-
if (!mdUrl) {
221-
const md = getPageMarkdown();
222-
await navigator.clipboard.writeText(md);
223-
}
215+
// Always copy markdown to clipboard as a fallback
216+
const md = getPageMarkdown();
217+
await navigator.clipboard.writeText(md);
224218

225219
let finalUrl: string;
226220
if (item.id === "claude") {

0 commit comments

Comments
 (0)