From 31097d5bcfc5e51ffce6346e315f908a3c35c2d6 Mon Sep 17 00:00:00 2001 From: Lesnak1 Date: Sat, 15 Aug 2026 13:30:12 +0300 Subject: [PATCH] fix(tools): fetch documentation from base/docs with candidate path resolution --- sidebar.ts | 11 +++-------- tools.ts | 39 ++++++++++++++++++++++++++++++--------- utils.ts | 4 ++-- 3 files changed, 35 insertions(+), 19 deletions(-) diff --git a/sidebar.ts b/sidebar.ts index f367b95..4ef98fa 100644 --- a/sidebar.ts +++ b/sidebar.ts @@ -1788,16 +1788,11 @@ export const sidebar: Sidebar = [ export async function fetchAndUpdateSidebar() { try { - const response = await fetch('https://raw.githubusercontent.com/base/web/refs/heads/master/apps/base-docs/sidebar.ts'); - if (!response.ok) { - throw new Error(`Failed to fetch sidebar: ${response.statusText}`); - } - sidebarContent = await response.text(); - console.log('Successfully fetched and updated sidebar content'); - console.log(sidebarContent); + // The upstream repository structure now lives under base/docs. + // Use fallback sidebarContent when remote sidebar asset is not available. + return; } catch (error) { console.error('Error fetching sidebar:', error); - // We'll keep using the fallback content if fetch fails } } diff --git a/tools.ts b/tools.ts index c83fa47..45c878f 100644 --- a/tools.ts +++ b/tools.ts @@ -7,17 +7,38 @@ export const getGuide = async ({ }: z.infer) => { console.log("Received request for guide:", guideLink); try { - // Remove the base URL prefix and ensure the path starts correctly - const guidePath = guideLink.replace("https://docs.base.org", ""); - const githubRawUrl = `https://raw.githubusercontent.com/base/web/refs/heads/master/apps/base-docs/docs/pages${guidePath}.mdx`; - console.log("Fetching from URL:", githubRawUrl); + // Normalize path by stripping base URL if provided + let guidePath = guideLink.replace(/^https?:\/\/docs\.base\.org/, ""); + if (!guidePath.startsWith("/")) { + guidePath = `/${guidePath}`; + } + // Strip trailing slash if any + guidePath = guidePath.replace(/\/$/, ""); + // Strip existing .mdx or .md extension if passed + guidePath = guidePath.replace(/\.(mdx|md)$/, ""); + + const baseRawDocsUrl = "https://raw.githubusercontent.com/base/docs/master/docs"; + const candidates = [ + `${baseRawDocsUrl}${guidePath}.mdx`, + `${baseRawDocsUrl}${guidePath}.md`, + `${baseRawDocsUrl}${guidePath}/index.mdx`, + `${baseRawDocsUrl}${guidePath}/index.md`, + ]; + + let guide: string | null = null; + for (const url of candidates) { + console.log("Fetching from URL:", url); + const response = await fetch(url); + if (response.ok) { + guide = await response.text(); + console.log("Successfully fetched guide content from:", url); + break; + } + } - const response = await fetch(githubRawUrl); - if (!response.ok) { - throw new Error(`Failed to fetch guide: ${response.statusText}`); + if (!guide) { + throw new Error(`Failed to fetch guide for path: ${guidePath}`); } - const guide = await response.text(); - console.log("Successfully fetched guide content"); let finalResult = guide; diff --git a/utils.ts b/utils.ts index 1932f1e..b7e6d8a 100644 --- a/utils.ts +++ b/utils.ts @@ -17,9 +17,9 @@ export const findGuideParamsPrompt = ` ${getFormattedSidebar()} Find the path of the guide in the sidebar and pass it as guideLink by adding https://docs.base.org to the getStepsList tool. - For example, if the user wants to create a sign and verify component, the guideLink should be https://docs.base.org/identity/smart-wallet/guides/signing-and-verifying-messages + For example, if the user wants to create a sign and verify component, the guideLink should be https://docs.base.org/base-account/guides/sign-and-verify-typed-data - You will find that in the sidebar list, the guide is under the "Smart Wallet" section. + You will find that in the sidebar list, the guide is under the "Base Account" section. `; export const testingPrompt = (code: string) => {