From 05945f4b5336b39bcf87617a06f042c8c1243812 Mon Sep 17 00:00:00 2001 From: Steven H Date: Thu, 1 Oct 2026 08:54:22 +0100 Subject: [PATCH] lint --- packages/gitbook/src/lib/ask-prompt.ts | 17 +++++++++++ packages/gitbook/src/routes/markdownPage.ts | 31 ++++++--------------- 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/packages/gitbook/src/lib/ask-prompt.ts b/packages/gitbook/src/lib/ask-prompt.ts index 6e2307f03..f6c2aebe9 100644 --- a/packages/gitbook/src/lib/ask-prompt.ts +++ b/packages/gitbook/src/lib/ask-prompt.ts @@ -5,3 +5,20 @@ export function renderAskParametersDescription(): string { return `\`ask\` is the immediate question: it should be specific, self-contained, and written in natural language. \`goal\` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with \`ask=how do I create an API token\`, a goal like \`build a script that syncs our docs to a CMS\` lets GitBook tailor the answer to that use case.`; } + +/** + * Render the "Querying This Documentation" section of the agent instructions. + * `pageUrl` is the URL of the current page, which the `ask` and `goal` parameters are appended to. + */ +export function renderQueryingDocumentation(options: { pageUrl: string }): string { + const { pageUrl } = options; + return `Perform an HTTP GET request on the following URL with the \`ask\` and \`goal\` query parameters: + +\`\`\` +GET ${pageUrl}?ask=&goal= +\`\`\` + +${renderAskParametersDescription()} + +The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.`; +} diff --git a/packages/gitbook/src/routes/markdownPage.ts b/packages/gitbook/src/routes/markdownPage.ts index 5bfe7c375..7fb8138ee 100644 --- a/packages/gitbook/src/routes/markdownPage.ts +++ b/packages/gitbook/src/routes/markdownPage.ts @@ -1,7 +1,7 @@ import type { RevisionPageDocument, RevisionPageGroup } from '@gitbook/api'; import { isAIEnabled } from '@/components/utils/isAIChatEnabled'; -import { renderAskParametersDescription } from '@/lib/ask-prompt'; +import { renderQueryingDocumentation } from '@/lib/ask-prompt'; import type { GitBookSiteContext } from '@/lib/context'; import { getExposableError } from '@/lib/data'; import { linkerWithMarkdownPages } from '@/lib/links'; @@ -70,6 +70,11 @@ function renderNotFoundMarkdown(context: GitBookSiteContext, pagePath: string) { const fullContentUrl = context.linker.toAbsoluteURL( context.linker.toPathInSite('llms-full.txt') ); + const askPageUrl = context.linker.toAbsoluteURL( + context.linker.toPathForPagePath({ + path: similarPages[0]?.path ?? 'docs/example', + }) + ); return `# Page Not Found @@ -86,19 +91,7 @@ If the exact page cannot be found, you can still retrieve the information using ### Option 1 — Ask a question (recommended) -Perform an HTTP GET request on the documentation index with the \`ask\` and \`goal\` parameters: - -\`\`\` -GET ${context.linker.toAbsoluteURL( - context.linker.toPathForPagePath({ - path: similarPages[0]?.path ?? 'docs/example', - }) - )}?ask=&goal= -\`\`\` - -${renderAskParametersDescription()} - -The response will contain a direct answer to the question and relevant excerpts and sources from the documentation. +${renderQueryingDocumentation({ pageUrl: askPageUrl })} ### Option 2 — Browse the documentation index @@ -145,15 +138,7 @@ This documentation is published with GitBook. GitBook is the documentation platf ## Querying This Documentation If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question. -Perform an HTTP GET request on the current page URL with the \`ask\` and \`goal\` query parameters: - -\`\`\` -GET ${pageUrl}?ask=&goal= -\`\`\` - -${renderAskParametersDescription()} - -The response will contain a direct answer to the question and relevant excerpts and sources from the documentation. +${renderQueryingDocumentation({ pageUrl })} Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections. `;