@vercel/geistdocs 1.2.3-canary.48fea3c → 1.2.3-canary.53ff3db
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/icons/icon-arrow-up-right-small.d.ts +8 -0
- package/dist/assets/icons/icon-arrow-up-right-small.d.ts.map +1 -0
- package/dist/assets/icons/icon-arrow-up-right-small.js +4 -0
- package/dist/assets/icons/icon-arrow-up-right.d.ts +5 -0
- package/dist/assets/icons/icon-arrow-up-right.d.ts.map +1 -0
- package/dist/assets/icons/icon-arrow-up-right.js +4 -0
- package/dist/assets/icons/icon-check.d.ts +5 -0
- package/dist/assets/icons/icon-check.d.ts.map +1 -0
- package/dist/assets/icons/icon-check.js +4 -0
- package/dist/assets/icons/icon-chevron-down-small.d.ts +8 -0
- package/dist/assets/icons/icon-chevron-down-small.d.ts.map +1 -0
- package/dist/assets/icons/icon-chevron-down-small.js +7 -0
- package/dist/assets/icons/icon-chevron-right.d.ts +5 -0
- package/dist/assets/icons/icon-chevron-right.d.ts.map +1 -0
- package/dist/assets/icons/icon-chevron-right.js +4 -0
- package/dist/assets/icons/icon-copy.d.ts +5 -0
- package/dist/assets/icons/icon-copy.d.ts.map +1 -0
- package/dist/assets/icons/icon-copy.js +4 -0
- package/dist/assets/icons/icon-file-text.d.ts +5 -0
- package/dist/assets/icons/icon-file-text.d.ts.map +1 -0
- package/dist/assets/icons/icon-file-text.js +4 -0
- package/dist/assets/icons/icon-menu-alt.d.ts +5 -0
- package/dist/assets/icons/icon-menu-alt.d.ts.map +1 -0
- package/dist/assets/icons/icon-menu-alt.js +4 -0
- package/dist/assets/icons/icon-slash-forward.d.ts +8 -0
- package/dist/assets/icons/icon-slash-forward.d.ts.map +1 -0
- package/dist/assets/icons/icon-slash-forward.js +4 -0
- package/dist/assets/icons/index.d.ts +10 -0
- package/dist/assets/icons/index.d.ts.map +1 -0
- package/{template/components/geistcn-fallbacks/geistcn-assets/icons/index.tsx → dist/assets/icons/index.js} +0 -1
- package/dist/assets/logos/index.d.ts +15 -0
- package/dist/assets/logos/index.d.ts.map +1 -0
- package/{template/components/geistcn-fallbacks/geistcn-assets/logos/index.tsx → dist/assets/logos/index.js} +2 -1
- package/dist/assets/logos/logo-ai-elements.d.ts +8 -0
- package/dist/assets/logos/logo-ai-elements.d.ts.map +1 -0
- package/dist/assets/logos/logo-ai-elements.js +8 -0
- package/dist/assets/logos/logo-ai-sdk.d.ts +8 -0
- package/dist/assets/logos/logo-ai-sdk.d.ts.map +1 -0
- package/dist/assets/logos/logo-ai-sdk.js +8 -0
- package/dist/assets/logos/logo-chat-sdk.d.ts +8 -0
- package/dist/assets/logos/logo-chat-sdk.d.ts.map +1 -0
- package/dist/assets/logos/logo-chat-sdk.js +8 -0
- package/dist/assets/logos/logo-flags-sdk.d.ts +8 -0
- package/dist/assets/logos/logo-flags-sdk.d.ts.map +1 -0
- package/dist/assets/logos/logo-flags-sdk.js +8 -0
- package/dist/assets/logos/logo-icon-vercel.d.ts +9 -0
- package/dist/assets/logos/logo-icon-vercel.d.ts.map +1 -0
- package/dist/assets/logos/logo-icon-vercel.js +8 -0
- package/dist/assets/logos/logo-nextjs.d.ts +8 -0
- package/dist/assets/logos/logo-nextjs.d.ts.map +1 -0
- package/dist/assets/logos/logo-nextjs.js +7 -0
- package/dist/assets/logos/logo-streamdown.d.ts +8 -0
- package/dist/assets/logos/logo-streamdown.d.ts.map +1 -0
- package/dist/assets/logos/logo-streamdown.js +8 -0
- package/dist/assets/logos/logo-svelte-kit.d.ts +8 -0
- package/dist/assets/logos/logo-svelte-kit.d.ts.map +1 -0
- package/dist/assets/logos/logo-svelte-kit.js +7 -0
- package/dist/assets/logos/logo-vercel-oss.d.ts +8 -0
- package/dist/assets/logos/logo-vercel-oss.d.ts.map +1 -0
- package/dist/assets/logos/logo-vercel-oss.js +7 -0
- package/dist/assets/logos/logo-workflow-sdk.d.ts +8 -0
- package/dist/assets/logos/logo-workflow-sdk.d.ts.map +1 -0
- package/dist/assets/logos/logo-workflow-sdk.js +8 -0
- package/dist/cli/index.js +1 -1
- package/dist/components/button-group.d.ts +2 -0
- package/dist/components/button-group.d.ts.map +1 -0
- package/dist/components/button-group.js +2 -0
- package/dist/components/button.d.ts +2 -0
- package/dist/components/button.d.ts.map +1 -0
- package/dist/components/button.js +2 -0
- package/dist/components/card.d.ts +2 -0
- package/dist/components/card.d.ts.map +1 -0
- package/dist/components/card.js +2 -0
- package/dist/components/code-block-tabs.js +3 -3
- package/dist/components/code-block.js +3 -3
- package/dist/components/collapsible.d.ts +2 -0
- package/dist/components/collapsible.d.ts.map +1 -0
- package/dist/components/collapsible.js +3 -0
- package/dist/components/copy-prompt.js +3 -3
- package/dist/components/dialog.d.ts +13 -0
- package/dist/components/dialog.d.ts.map +1 -0
- package/dist/components/dialog.js +35 -0
- package/dist/components/drawer.d.ts +2 -0
- package/dist/components/drawer.d.ts.map +1 -0
- package/dist/components/drawer.js +3 -0
- package/dist/components/dropdown-menu.d.ts +2 -0
- package/dist/components/dropdown-menu.d.ts.map +1 -0
- package/dist/components/dropdown-menu.js +3 -0
- package/dist/components/input-group.d.ts +2 -0
- package/dist/components/input-group.d.ts.map +1 -0
- package/dist/components/input-group.js +3 -0
- package/dist/components/input.d.ts +2 -0
- package/dist/components/input.d.ts.map +1 -0
- package/dist/components/input.js +2 -0
- package/dist/components/kbd.d.ts +2 -0
- package/dist/components/kbd.d.ts.map +1 -0
- package/dist/components/kbd.js +2 -0
- package/dist/components/navigation-menu.d.ts +2 -0
- package/dist/components/navigation-menu.d.ts.map +1 -0
- package/dist/components/navigation-menu.js +3 -0
- package/dist/components/popover.d.ts +2 -0
- package/dist/components/popover.d.ts.map +1 -0
- package/dist/components/popover.js +3 -0
- package/dist/components/scroll-area.d.ts +2 -0
- package/dist/components/scroll-area.d.ts.map +1 -0
- package/dist/components/scroll-area.js +3 -0
- package/dist/components/separator.d.ts +2 -0
- package/dist/components/separator.d.ts.map +1 -0
- package/dist/components/separator.js +3 -0
- package/dist/components/sheet.d.ts +2 -0
- package/dist/components/sheet.d.ts.map +1 -0
- package/dist/components/sheet.js +3 -0
- package/dist/components/sonner.d.ts +2 -0
- package/dist/components/sonner.d.ts.map +1 -0
- package/dist/components/sonner.js +3 -0
- package/dist/components/spinner.d.ts +2 -0
- package/dist/components/spinner.d.ts.map +1 -0
- package/dist/components/spinner.js +2 -0
- package/dist/components/textarea.d.ts +2 -0
- package/dist/components/textarea.d.ts.map +1 -0
- package/dist/components/textarea.js +2 -0
- package/dist/components/tooltip.d.ts +2 -0
- package/dist/components/tooltip.d.ts.map +1 -0
- package/dist/components/tooltip.js +3 -0
- package/dist/config.d.ts +47 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/controls.js +4 -4
- package/dist/footer.d.ts +8 -0
- package/dist/footer.d.ts.map +1 -0
- package/dist/footer.js +6 -0
- package/dist/home-layout.d.ts +11 -0
- package/dist/home-layout.d.ts.map +1 -0
- package/dist/home-layout.js +31 -0
- package/dist/internal/chat/conversation.js +1 -1
- package/dist/internal/chat/message.js +1 -1
- package/dist/internal/chat/prompt-input.js +1 -1
- package/dist/internal/chat/shell.js +4 -4
- package/dist/internal/chat/sources.js +1 -1
- package/dist/internal/config-context.d.ts +10 -0
- package/dist/internal/config-context.d.ts.map +1 -0
- package/dist/internal/config-context.js +15 -0
- package/dist/internal/footer/github-button.d.ts +7 -0
- package/dist/internal/footer/github-button.d.ts.map +1 -0
- package/dist/internal/footer/github-button.js +10 -0
- package/dist/internal/footer/rss-button.d.ts +2 -0
- package/dist/internal/footer/rss-button.d.ts.map +1 -0
- package/dist/internal/footer/rss-button.js +4 -0
- package/dist/internal/localized-link.d.ts +8 -0
- package/dist/internal/localized-link.d.ts.map +1 -0
- package/dist/internal/localized-link.js +13 -0
- package/dist/internal/navbar/desktop-menu.d.ts +10 -0
- package/dist/internal/navbar/desktop-menu.d.ts.map +1 -0
- package/dist/internal/navbar/desktop-menu.js +11 -0
- package/dist/internal/navbar/mobile-menu.d.ts +7 -0
- package/dist/internal/navbar/mobile-menu.d.ts.map +1 -0
- package/dist/internal/navbar/mobile-menu.js +44 -0
- package/dist/internal/navbar/navbar-logo.d.ts +16 -0
- package/dist/internal/navbar/navbar-logo.d.ts.map +1 -0
- package/dist/internal/navbar/navbar-logo.js +30 -0
- package/dist/internal/page-actions-client.d.ts.map +1 -1
- package/dist/internal/page-actions-client.js +17 -6
- package/dist/internal/page-visibility.d.ts +18 -0
- package/dist/internal/page-visibility.d.ts.map +1 -0
- package/dist/internal/page-visibility.js +24 -0
- package/dist/internal/provider-client.d.ts +1 -1
- package/dist/internal/provider-client.d.ts.map +1 -1
- package/dist/internal/provider-client.js +2 -1
- package/dist/internal/sidebar.js +3 -3
- package/dist/internal/ui/button-group.js +2 -2
- package/dist/internal/ui/button.d.ts +1 -1
- package/dist/internal/ui/button.d.ts.map +1 -1
- package/dist/internal/ui/button.js +7 -7
- package/dist/internal/ui/card.js +1 -1
- package/dist/internal/ui/drawer.js +1 -1
- package/dist/internal/ui/dropdown-menu.js +7 -7
- package/dist/internal/ui/input-group.js +2 -2
- package/dist/internal/ui/input.js +1 -1
- package/dist/internal/ui/kbd.js +1 -1
- package/dist/internal/ui/navigation-menu.d.ts +17 -0
- package/dist/internal/ui/navigation-menu.d.ts.map +1 -0
- package/dist/internal/ui/navigation-menu.js +38 -0
- package/dist/internal/ui/popover.js +1 -1
- package/dist/internal/ui/scroll-area.js +2 -2
- package/dist/internal/ui/separator.js +1 -1
- package/dist/internal/ui/sheet.js +4 -4
- package/dist/internal/ui/sonner.js +3 -3
- package/dist/internal/ui/textarea.js +1 -1
- package/dist/internal/ui/tooltip.js +1 -1
- package/dist/mdx.d.ts +55 -24
- package/dist/mdx.d.ts.map +1 -1
- package/dist/mdx.js +7 -46
- package/dist/mobile-docs-bar.d.ts +7 -0
- package/dist/mobile-docs-bar.d.ts.map +1 -0
- package/dist/mobile-docs-bar.js +13 -0
- package/dist/navbar.d.ts +7 -0
- package/dist/navbar.d.ts.map +1 -0
- package/dist/navbar.js +10 -0
- package/dist/pages/docs.d.ts +8 -2
- package/dist/pages/docs.d.ts.map +1 -1
- package/dist/pages/docs.js +13 -7
- package/dist/proxy.d.ts +1 -1
- package/dist/proxy.d.ts.map +1 -1
- package/dist/proxy.js +29 -2
- package/dist/routes/agents.d.ts +21 -0
- package/dist/routes/agents.d.ts.map +1 -0
- package/dist/routes/agents.js +201 -0
- package/dist/routes/chat.d.ts +7 -2
- package/dist/routes/chat.d.ts.map +1 -1
- package/dist/routes/chat.js +357 -62
- package/dist/routes/llms.d.ts +6 -5
- package/dist/routes/llms.d.ts.map +1 -1
- package/dist/routes/llms.js +63 -12
- package/dist/routes/search.d.ts +6 -4
- package/dist/routes/search.d.ts.map +1 -1
- package/dist/routes/search.js +8 -1
- package/dist/routes/sitemap.d.ts +6 -3
- package/dist/routes/sitemap.d.ts.map +1 -1
- package/dist/routes/sitemap.js +10 -2
- package/dist/shiki-theme.d.ts +20 -0
- package/dist/shiki-theme.d.ts.map +1 -0
- package/dist/shiki-theme.js +110 -0
- package/dist/source-config.d.ts +68 -0
- package/dist/source-config.d.ts.map +1 -0
- package/dist/source-config.js +161 -0
- package/dist/source.d.ts +8 -1
- package/dist/source.d.ts.map +1 -1
- package/dist/source.js +14 -1
- package/dist/versions.d.ts +31 -1
- package/dist/versions.d.ts.map +1 -1
- package/dist/versions.js +56 -29
- package/package.json +124 -3
- package/source-config.js +174 -0
- package/styles.css +465 -102
- package/template/AGENTS.md +90 -0
- package/template/app/[lang]/(home)/components/centered-section.tsx +1 -3
- package/template/app/[lang]/(home)/components/hero.tsx +2 -2
- package/template/app/[lang]/(home)/components/one-two-section.tsx +1 -3
- package/template/app/[lang]/(home)/components/templates.tsx +3 -5
- package/template/app/[lang]/(home)/components/text-grid-section.tsx +1 -1
- package/template/app/[lang]/(home)/layout.tsx +4 -3
- package/template/app/[lang]/(home)/page.tsx +2 -2
- package/template/app/[lang]/agents.md/route.ts +6 -0
- package/template/app/[lang]/docs/[[...slug]]/page.tsx +4 -1
- package/template/app/[lang]/layout.tsx +6 -6
- package/template/app/[lang]/llms.mdx/[[...slug]]/route.ts +1 -1
- package/template/app/[lang]/sitemap.md/route.ts +2 -2
- package/template/app/api/chat/route.ts +11 -0
- package/template/app/api/search/route.ts +2 -2
- package/template/app/styles/geistdocs.css +150 -109
- package/template/components/ui/badge.tsx +5 -5
- package/template/components/ui/button.tsx +7 -7
- package/template/components/ui/command-prompt.tsx +2 -2
- package/template/content/docs/agent-readiness.mdx +103 -0
- package/template/content/docs/ask-ai.mdx +37 -3
- package/template/content/docs/configuration.mdx +77 -2
- package/template/content/docs/deployment.mdx +11 -0
- package/template/content/docs/env.mdx +36 -5
- package/template/content/docs/getting-started.mdx +2 -1
- package/template/content/docs/index.mdx +3 -0
- package/template/content/docs/llms-txt.mdx +1 -0
- package/template/content/docs/md.mdx +2 -1
- package/template/content/docs/meta.json +2 -0
- package/template/content/docs/migration.mdx +321 -0
- package/template/content/docs/proxy.cn.mdx +1 -1
- package/template/content/docs/proxy.mdx +56 -2
- package/template/content/docs/theme-aware-image.mdx +1 -1
- package/template/content/docs/versioned-docs.mdx +49 -2
- package/template/geistdocs.tsx +26 -0
- package/template/lib/geistdocs/config.tsx +3 -0
- package/template/package.json +3 -3
- package/template/proxy.ts +1 -2
- package/template/source.config.ts +8 -47
- package/template/app/actions/feedback/emotions.ts +0 -18
- package/template/app/actions/feedback/index.ts +0 -45
- package/template/components/geistcn-fallbacks/geistcn-assets/icons/icon-arrow-up-right-small.tsx +0 -35
- package/template/components/geistcn-fallbacks/geistcn-assets/icons/icon-arrow-up-right.tsx +0 -27
- package/template/components/geistcn-fallbacks/geistcn-assets/icons/icon-check.tsx +0 -27
- package/template/components/geistcn-fallbacks/geistcn-assets/icons/icon-chevron-down-small.tsx +0 -30
- package/template/components/geistcn-fallbacks/geistcn-assets/icons/icon-chevron-right.tsx +0 -27
- package/template/components/geistcn-fallbacks/geistcn-assets/icons/icon-copy.tsx +0 -27
- package/template/components/geistcn-fallbacks/geistcn-assets/icons/icon-file-text.tsx +0 -25
- package/template/components/geistcn-fallbacks/geistcn-assets/icons/icon-menu-alt.tsx +0 -27
- package/template/components/geistcn-fallbacks/geistcn-assets/icons/icon-slash-forward.tsx +0 -36
- package/template/components/geistcn-fallbacks/geistcn-assets/logos/logo-ai-elements.tsx +0 -29
- package/template/components/geistcn-fallbacks/geistcn-assets/logos/logo-ai-sdk.tsx +0 -38
- package/template/components/geistcn-fallbacks/geistcn-assets/logos/logo-chat-sdk.tsx +0 -42
- package/template/components/geistcn-fallbacks/geistcn-assets/logos/logo-flags-sdk.tsx +0 -42
- package/template/components/geistcn-fallbacks/geistcn-assets/logos/logo-icon-vercel.tsx +0 -31
- package/template/components/geistcn-fallbacks/geistcn-assets/logos/logo-streamdown.tsx +0 -29
- package/template/components/geistcn-fallbacks/geistcn-assets/logos/logo-vercel-oss.tsx +0 -24
- package/template/components/geistcn-fallbacks/geistcn-assets/logos/logo-workflow-sdk.tsx +0 -73
- package/template/components/geistdocs/callout.tsx +0 -40
- package/template/components/geistdocs/chat.tsx +0 -24
- package/template/components/geistdocs/code-block-tabs.tsx +0 -61
- package/template/components/geistdocs/code-block.tsx +0 -134
- package/template/components/geistdocs/copy-page.tsx +0 -27
- package/template/components/geistdocs/desktop-menu.tsx +0 -52
- package/template/components/geistdocs/docs-page.tsx +0 -35
- package/template/components/geistdocs/edit-source.tsx +0 -30
- package/template/components/geistdocs/feedback.tsx +0 -139
- package/template/components/geistdocs/footer.tsx +0 -30
- package/template/components/geistdocs/github-button.tsx +0 -19
- package/template/components/geistdocs/home-layout.tsx +0 -46
- package/template/components/geistdocs/icons.tsx +0 -13
- package/template/components/geistdocs/installer.tsx +0 -58
- package/template/components/geistdocs/language-selector.tsx +0 -3
- package/template/components/geistdocs/mermaid.tsx +0 -68
- package/template/components/geistdocs/mobile-docs-bar.tsx +0 -77
- package/template/components/geistdocs/mobile-menu.tsx +0 -150
- package/template/components/geistdocs/navbar-logo.tsx +0 -124
- package/template/components/geistdocs/navbar.tsx +0 -22
- package/template/components/geistdocs/rss-button.tsx +0 -10
- package/template/components/geistdocs/scroll-top.tsx +0 -21
- package/template/components/geistdocs/search.tsx +0 -17
- package/template/components/geistdocs/sidebar.tsx +0 -128
- package/template/components/geistdocs/theme-aware-image.tsx +0 -22
- package/template/components/geistdocs/theme-toggle.tsx +0 -3
- package/template/components/geistdocs/video.tsx +0 -16
- package/template/components/ui/button-group.tsx +0 -83
- package/template/components/ui/card.tsx +0 -92
- package/template/components/ui/collapsible.tsx +0 -33
- package/template/components/ui/command.tsx +0 -184
- package/template/components/ui/dialog.tsx +0 -143
- package/template/components/ui/drawer.tsx +0 -135
- package/template/components/ui/dropdown-menu.tsx +0 -257
- package/template/components/ui/hover-card.tsx +0 -44
- package/template/components/ui/input-group.tsx +0 -170
- package/template/components/ui/input.tsx +0 -21
- package/template/components/ui/kbd.tsx +0 -28
- package/template/components/ui/navigation-menu.tsx +0 -192
- package/template/components/ui/popover.tsx +0 -48
- package/template/components/ui/scroll-area.tsx +0 -58
- package/template/components/ui/select.tsx +0 -187
- package/template/components/ui/separator.tsx +0 -28
- package/template/components/ui/sheet.tsx +0 -139
- package/template/components/ui/sonner.tsx +0 -40
- package/template/components/ui/spinner.tsx +0 -16
- package/template/components/ui/textarea.tsx +0 -18
- package/template/components/ui/tooltip.tsx +0 -61
- package/template/hooks/geistdocs/use-sidebar.ts +0 -13
- package/template/hooks/use-mobile.ts +0 -19
package/dist/routes/chat.js
CHANGED
|
@@ -1,6 +1,306 @@
|
|
|
1
1
|
import { convertToModelMessages, createUIMessageStream, createUIMessageStreamResponse, stepCountIs, streamText, tool, } from "ai";
|
|
2
2
|
import { initAdvancedSearch } from "fumadocs-core/search/server";
|
|
3
3
|
import { z } from "zod";
|
|
4
|
+
import { isPageVisibleForSurface } from "../internal/page-visibility";
|
|
5
|
+
const MAX_CONTEXT_CHARS = 1500;
|
|
6
|
+
const MAX_PROXY_RELATED_PAGES = 5;
|
|
7
|
+
const MAX_TOOL_RESULTS = 8;
|
|
8
|
+
const TRAILING_SLASH_PATTERN = /\/$/;
|
|
9
|
+
const normalizePathname = (value) => {
|
|
10
|
+
if (!value) {
|
|
11
|
+
return "/";
|
|
12
|
+
}
|
|
13
|
+
let pathname = value;
|
|
14
|
+
try {
|
|
15
|
+
pathname = new URL(value, "https://geistdocs.local").pathname;
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
pathname = value.split("?")[0]?.split("#")[0] ?? value;
|
|
19
|
+
}
|
|
20
|
+
if (!pathname.startsWith("/")) {
|
|
21
|
+
pathname = `/${pathname}`;
|
|
22
|
+
}
|
|
23
|
+
return pathname.length > 1
|
|
24
|
+
? pathname.replace(TRAILING_SLASH_PATTERN, "")
|
|
25
|
+
: pathname;
|
|
26
|
+
};
|
|
27
|
+
const stripBasePath = (pathname, basePath) => {
|
|
28
|
+
const normalizedBasePath = normalizePathname(basePath);
|
|
29
|
+
if (normalizedBasePath === "/") {
|
|
30
|
+
return pathname;
|
|
31
|
+
}
|
|
32
|
+
if (pathname === normalizedBasePath) {
|
|
33
|
+
return "/";
|
|
34
|
+
}
|
|
35
|
+
if (pathname.startsWith(`${normalizedBasePath}/`)) {
|
|
36
|
+
return pathname.slice(normalizedBasePath.length) || "/";
|
|
37
|
+
}
|
|
38
|
+
return pathname;
|
|
39
|
+
};
|
|
40
|
+
const stripLanguagePrefix = (pathname, lang) => {
|
|
41
|
+
const prefix = `/${lang}`;
|
|
42
|
+
if (pathname === prefix) {
|
|
43
|
+
return "/";
|
|
44
|
+
}
|
|
45
|
+
if (pathname.startsWith(`${prefix}/`)) {
|
|
46
|
+
return pathname.slice(prefix.length) || "/";
|
|
47
|
+
}
|
|
48
|
+
return pathname;
|
|
49
|
+
};
|
|
50
|
+
const getLanguages = (config) => {
|
|
51
|
+
const defaultLanguage = config.defaultLanguage ?? "en";
|
|
52
|
+
const languages = Object.keys(config.translations ?? {});
|
|
53
|
+
return {
|
|
54
|
+
defaultLanguage,
|
|
55
|
+
languages: Array.from(new Set([defaultLanguage, ...languages])),
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
const getRequestLanguage = ({ basePath, currentRoute, defaultLanguage, languages, }) => {
|
|
59
|
+
const pathname = stripBasePath(normalizePathname(currentRoute), basePath);
|
|
60
|
+
const firstSegment = pathname.split("/").filter(Boolean)[0];
|
|
61
|
+
return firstSegment && languages.includes(firstSegment)
|
|
62
|
+
? firstSegment
|
|
63
|
+
: defaultLanguage;
|
|
64
|
+
};
|
|
65
|
+
const getMessageText = (message) => message.parts
|
|
66
|
+
.filter((part) => part.type === "text")
|
|
67
|
+
.map((part) => part.text)
|
|
68
|
+
.join("\n");
|
|
69
|
+
const isPageContextMessage = (message) => message.metadata?.isPageContext;
|
|
70
|
+
const getPageData = (page) => page.data;
|
|
71
|
+
const getStructuredContent = (page) => JSON.stringify(getPageData(page).structuredData?.contents ?? "");
|
|
72
|
+
const createSearchServer = (sources, lang) => {
|
|
73
|
+
const indexes = sources.flatMap((source) => source.source
|
|
74
|
+
.getPages(lang)
|
|
75
|
+
.filter((page) => isPageVisibleForSurface(page, "chat"))
|
|
76
|
+
.map((page) => {
|
|
77
|
+
const data = getPageData(page);
|
|
78
|
+
const structuredData = data.structuredData ??
|
|
79
|
+
{ headings: [], contents: [] };
|
|
80
|
+
return {
|
|
81
|
+
title: data.title ?? page.url,
|
|
82
|
+
description: data.description ?? "",
|
|
83
|
+
url: page.url,
|
|
84
|
+
id: page.url,
|
|
85
|
+
structuredData,
|
|
86
|
+
};
|
|
87
|
+
}));
|
|
88
|
+
return initAdvancedSearch({ indexes });
|
|
89
|
+
};
|
|
90
|
+
const resolveSearchResult = ({ lang, sources, url, }) => {
|
|
91
|
+
const result = sources
|
|
92
|
+
.map((source) => source.source.getPageByHref(url, { language: lang }))
|
|
93
|
+
.find((entry) => entry?.page);
|
|
94
|
+
if (!result?.page) {
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
const { page } = result;
|
|
98
|
+
const data = getPageData(page);
|
|
99
|
+
return {
|
|
100
|
+
title: data.title ?? page.url,
|
|
101
|
+
description: data.description ?? "",
|
|
102
|
+
content: getStructuredContent(page),
|
|
103
|
+
slug: page.url,
|
|
104
|
+
};
|
|
105
|
+
};
|
|
106
|
+
const searchDocs = async ({ lang, limit, query, sources, }) => {
|
|
107
|
+
const searchServer = createSearchServer(sources, lang);
|
|
108
|
+
const results = await searchServer.search(query);
|
|
109
|
+
const seenSlugs = new Set();
|
|
110
|
+
return results
|
|
111
|
+
.map(({ url }) => resolveSearchResult({ lang, sources, url }))
|
|
112
|
+
.filter((doc) => Boolean(doc))
|
|
113
|
+
.filter((doc) => {
|
|
114
|
+
if (seenSlugs.has(doc.slug)) {
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
seenSlugs.add(doc.slug);
|
|
118
|
+
return true;
|
|
119
|
+
})
|
|
120
|
+
.slice(0, limit);
|
|
121
|
+
};
|
|
122
|
+
const formatDocForContext = (doc) => `**${doc.title}**\nURL: ${doc.slug}\n${doc.description || ""}\n\n${doc.content.slice(0, MAX_CONTEXT_CHARS)}${doc.content.length > MAX_CONTEXT_CHARS ? "..." : ""}`;
|
|
123
|
+
const getRouteCandidates = ({ basePath, currentRoute, lang, }) => {
|
|
124
|
+
const pathname = normalizePathname(currentRoute);
|
|
125
|
+
const withoutBasePath = stripBasePath(pathname, basePath);
|
|
126
|
+
const withoutLanguage = stripLanguagePrefix(withoutBasePath, lang);
|
|
127
|
+
return Array.from(new Set([pathname, withoutBasePath, withoutLanguage]));
|
|
128
|
+
};
|
|
129
|
+
const findCurrentPage = ({ basePath, currentRoute, lang, sources, }) => {
|
|
130
|
+
const candidates = getRouteCandidates({ basePath, currentRoute, lang });
|
|
131
|
+
for (const source of sources) {
|
|
132
|
+
for (const candidate of candidates) {
|
|
133
|
+
const result = source.source.getPageByHref(candidate, { language: lang });
|
|
134
|
+
if (result?.page && isPageVisibleForSurface(result.page, "chat")) {
|
|
135
|
+
return { page: result.page, source };
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
const page = source.source
|
|
139
|
+
.getPages(lang)
|
|
140
|
+
.filter((entry) => isPageVisibleForSurface(entry, "chat"))
|
|
141
|
+
.find((entry) => candidates.includes(normalizePathname(entry.url)));
|
|
142
|
+
if (page) {
|
|
143
|
+
return { page, source };
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return null;
|
|
147
|
+
};
|
|
148
|
+
const getCurrentPageDoc = async ({ basePath, currentRoute, lang, pageContext, sources, }) => {
|
|
149
|
+
if (pageContext) {
|
|
150
|
+
return {
|
|
151
|
+
title: pageContext.title,
|
|
152
|
+
description: "",
|
|
153
|
+
content: pageContext.content,
|
|
154
|
+
slug: pageContext.url,
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
const result = findCurrentPage({ basePath, currentRoute, lang, sources });
|
|
158
|
+
if (!result) {
|
|
159
|
+
return null;
|
|
160
|
+
}
|
|
161
|
+
const data = getPageData(result.page);
|
|
162
|
+
return {
|
|
163
|
+
title: data.title ?? result.page.url,
|
|
164
|
+
description: data.description ?? "",
|
|
165
|
+
content: await result.source.getPageMarkdown(result.page),
|
|
166
|
+
slug: result.page.url,
|
|
167
|
+
};
|
|
168
|
+
};
|
|
169
|
+
const isFirstUserMessage = (messages) => messages.filter((message) => message.role === "user").length === 1;
|
|
170
|
+
const createSourceChunks = (docs) => docs.map((doc, index) => ({
|
|
171
|
+
type: "source-url",
|
|
172
|
+
sourceId: `doc-${index}-${doc.slug}`,
|
|
173
|
+
url: doc.slug,
|
|
174
|
+
title: doc.title,
|
|
175
|
+
}));
|
|
176
|
+
const buildProxyMessages = async ({ actualMessages, config, currentRoute, defaultLanguage, languages, pageContext, routeSources, }) => {
|
|
177
|
+
if (!isFirstUserMessage(actualMessages)) {
|
|
178
|
+
return { messages: actualMessages, sourceDocs: [] };
|
|
179
|
+
}
|
|
180
|
+
const lastMessage = actualMessages.at(-1);
|
|
181
|
+
if (lastMessage?.role !== "user") {
|
|
182
|
+
return { messages: actualMessages, sourceDocs: [] };
|
|
183
|
+
}
|
|
184
|
+
const userQuestion = getMessageText(lastMessage);
|
|
185
|
+
const lang = getRequestLanguage({
|
|
186
|
+
basePath: config.basePath,
|
|
187
|
+
currentRoute,
|
|
188
|
+
defaultLanguage,
|
|
189
|
+
languages,
|
|
190
|
+
});
|
|
191
|
+
const currentPageDoc = await getCurrentPageDoc({
|
|
192
|
+
basePath: config.basePath,
|
|
193
|
+
currentRoute,
|
|
194
|
+
lang,
|
|
195
|
+
pageContext,
|
|
196
|
+
sources: routeSources,
|
|
197
|
+
});
|
|
198
|
+
const relatedDocs = userQuestion.trim()
|
|
199
|
+
? await searchDocs({
|
|
200
|
+
lang,
|
|
201
|
+
limit: MAX_PROXY_RELATED_PAGES,
|
|
202
|
+
query: userQuestion,
|
|
203
|
+
sources: routeSources,
|
|
204
|
+
})
|
|
205
|
+
: [];
|
|
206
|
+
const filteredRelatedDocs = relatedDocs.filter((doc) => doc.slug !== currentPageDoc?.slug);
|
|
207
|
+
const contextParts = [];
|
|
208
|
+
if (currentPageDoc) {
|
|
209
|
+
contextParts.push(`Here's the content from the current page:\n\n**Page:** ${currentPageDoc.title}\n**URL:** ${currentPageDoc.slug}\n\n---\n\n${currentPageDoc.content.slice(0, MAX_CONTEXT_CHARS)}${currentPageDoc.content.length > MAX_CONTEXT_CHARS ? "..." : ""}`);
|
|
210
|
+
}
|
|
211
|
+
if (filteredRelatedDocs.length > 0) {
|
|
212
|
+
contextParts.push(`Related documentation pages:\n\n${filteredRelatedDocs.map(formatDocForContext).join("\n\n---\n\n")}`);
|
|
213
|
+
}
|
|
214
|
+
if (contextParts.length === 0) {
|
|
215
|
+
return { messages: actualMessages, sourceDocs: [] };
|
|
216
|
+
}
|
|
217
|
+
return {
|
|
218
|
+
messages: [
|
|
219
|
+
...actualMessages.slice(0, -1),
|
|
220
|
+
{
|
|
221
|
+
...lastMessage,
|
|
222
|
+
parts: [
|
|
223
|
+
{
|
|
224
|
+
type: "text",
|
|
225
|
+
text: `${contextParts.join("\n\n---\n\n")}\n\n---\n\nUser question: ${userQuestion}`,
|
|
226
|
+
},
|
|
227
|
+
],
|
|
228
|
+
},
|
|
229
|
+
],
|
|
230
|
+
sourceDocs: [currentPageDoc, ...filteredRelatedDocs].filter((doc) => Boolean(doc)),
|
|
231
|
+
};
|
|
232
|
+
};
|
|
233
|
+
const resolveProxyHeaders = async (headers) => typeof headers === "function" ? await headers() : headers;
|
|
234
|
+
const getProxyRequestHeaders = async ({ proxy, req, }) => {
|
|
235
|
+
const headers = new Headers(await resolveProxyHeaders(proxy.headers));
|
|
236
|
+
const clientJa4 = req.headers.get("x-vercel-ja4-digest");
|
|
237
|
+
const clientIp = req.headers.get("x-forwarded-for");
|
|
238
|
+
headers.set("Content-Type", "application/json");
|
|
239
|
+
if (clientJa4 && !headers.has("x-client-ja4")) {
|
|
240
|
+
headers.set("x-client-ja4", clientJa4);
|
|
241
|
+
}
|
|
242
|
+
if (clientIp && !headers.has("x-client-ip")) {
|
|
243
|
+
headers.set("x-client-ip", clientIp);
|
|
244
|
+
}
|
|
245
|
+
return headers;
|
|
246
|
+
};
|
|
247
|
+
const parseSseChunk = (event) => {
|
|
248
|
+
const data = event
|
|
249
|
+
.split("\n")
|
|
250
|
+
.filter((line) => line.startsWith("data:"))
|
|
251
|
+
.map((line) => line.slice(5).trimStart())
|
|
252
|
+
.join("\n");
|
|
253
|
+
if (!data || data === "[DONE]") {
|
|
254
|
+
return null;
|
|
255
|
+
}
|
|
256
|
+
return JSON.parse(data);
|
|
257
|
+
};
|
|
258
|
+
const pipeUIMessageStreamToWriter = async ({ initialChunks, stream, writer, }) => {
|
|
259
|
+
const reader = stream.getReader();
|
|
260
|
+
const decoder = new TextDecoder();
|
|
261
|
+
let buffer = "";
|
|
262
|
+
let initialChunksWritten = false;
|
|
263
|
+
const writeInitialChunks = () => {
|
|
264
|
+
if (initialChunksWritten) {
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
initialChunksWritten = true;
|
|
268
|
+
for (const chunk of initialChunks) {
|
|
269
|
+
writer.write(chunk);
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
|
+
const writeEvent = (event) => {
|
|
273
|
+
const chunk = parseSseChunk(event);
|
|
274
|
+
if (!chunk) {
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
if (chunk.type === "start") {
|
|
278
|
+
writer.write(chunk);
|
|
279
|
+
writeInitialChunks();
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
writeInitialChunks();
|
|
283
|
+
writer.write(chunk);
|
|
284
|
+
};
|
|
285
|
+
while (true) {
|
|
286
|
+
const { done, value } = await reader.read();
|
|
287
|
+
buffer += decoder.decode(value, { stream: !done }).replace(/\r\n/g, "\n");
|
|
288
|
+
let delimiterIndex = buffer.indexOf("\n\n");
|
|
289
|
+
while (delimiterIndex !== -1) {
|
|
290
|
+
const event = buffer.slice(0, delimiterIndex);
|
|
291
|
+
buffer = buffer.slice(delimiterIndex + 2);
|
|
292
|
+
writeEvent(event);
|
|
293
|
+
delimiterIndex = buffer.indexOf("\n\n");
|
|
294
|
+
}
|
|
295
|
+
if (done) {
|
|
296
|
+
break;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
if (buffer.trim()) {
|
|
300
|
+
writeEvent(buffer);
|
|
301
|
+
}
|
|
302
|
+
writeInitialChunks();
|
|
303
|
+
};
|
|
4
304
|
const createSystemPrompt = (currentRoute, config) => {
|
|
5
305
|
const basePrompt = `# Role and objective
|
|
6
306
|
You are a helpful assistant specializing in answering questions strictly. If information is unavailable, politely decline to answer. Your primary objective is to guide users through the happy path using the most relevant documentation or guides.
|
|
@@ -37,23 +337,6 @@ const createTools = (writer, sources, defaultLanguage) => {
|
|
|
37
337
|
const log = (message) => {
|
|
38
338
|
console.log(`[Geistdocs chat] ${message}`);
|
|
39
339
|
};
|
|
40
|
-
const createSearchServer = (lang) => {
|
|
41
|
-
const indexes = sources.flatMap((source) => source.source.getPages(lang).map((page) => {
|
|
42
|
-
const data = page.data;
|
|
43
|
-
const structuredData = data.structuredData ??
|
|
44
|
-
{ headings: [], contents: [] };
|
|
45
|
-
return {
|
|
46
|
-
title: data.title ?? page.url,
|
|
47
|
-
description: data.description ?? "",
|
|
48
|
-
url: page.url,
|
|
49
|
-
id: page.url,
|
|
50
|
-
structuredData,
|
|
51
|
-
};
|
|
52
|
-
}));
|
|
53
|
-
return initAdvancedSearch({
|
|
54
|
-
indexes,
|
|
55
|
-
});
|
|
56
|
-
};
|
|
57
340
|
const search_docs = tool({
|
|
58
341
|
description: "Search through documentation content by query",
|
|
59
342
|
inputSchema: z.object({
|
|
@@ -67,41 +350,15 @@ const createTools = (writer, sources, defaultLanguage) => {
|
|
|
67
350
|
execute: async ({ query, lang }) => {
|
|
68
351
|
try {
|
|
69
352
|
log(`Creating search server for language: ${lang}`);
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
|
|
353
|
+
const trimmedResults = await searchDocs({
|
|
354
|
+
lang,
|
|
355
|
+
limit: MAX_TOOL_RESULTS,
|
|
356
|
+
query,
|
|
357
|
+
sources,
|
|
358
|
+
});
|
|
359
|
+
if (trimmedResults.length === 0) {
|
|
73
360
|
return `No documentation found for query: "${query}"`;
|
|
74
361
|
}
|
|
75
|
-
const promiseResults = await Promise.all(results.map(({ url }) => {
|
|
76
|
-
const result = sources
|
|
77
|
-
.map((source) => ({
|
|
78
|
-
result: source.source.getPageByHref(url, { language: lang }),
|
|
79
|
-
source,
|
|
80
|
-
}))
|
|
81
|
-
.find(({ result }) => result?.page);
|
|
82
|
-
if (!result?.result?.page) {
|
|
83
|
-
return null;
|
|
84
|
-
}
|
|
85
|
-
const { page } = result.result;
|
|
86
|
-
const data = page.data;
|
|
87
|
-
return {
|
|
88
|
-
title: data.title ?? page.url,
|
|
89
|
-
description: data.description ?? "",
|
|
90
|
-
content: JSON.stringify(data.structuredData?.contents ?? ""),
|
|
91
|
-
slug: page.url,
|
|
92
|
-
};
|
|
93
|
-
}));
|
|
94
|
-
const seenSlugs = new Set();
|
|
95
|
-
const trimmedResults = promiseResults
|
|
96
|
-
.filter((doc) => Boolean(doc))
|
|
97
|
-
.filter((doc) => {
|
|
98
|
-
if (!doc || seenSlugs.has(doc.slug)) {
|
|
99
|
-
return false;
|
|
100
|
-
}
|
|
101
|
-
seenSlugs.add(doc.slug);
|
|
102
|
-
return true;
|
|
103
|
-
})
|
|
104
|
-
.slice(0, 8);
|
|
105
362
|
for (const [index, doc] of trimmedResults.entries()) {
|
|
106
363
|
writer.write({
|
|
107
364
|
type: "source-url",
|
|
@@ -111,7 +368,7 @@ const createTools = (writer, sources, defaultLanguage) => {
|
|
|
111
368
|
});
|
|
112
369
|
}
|
|
113
370
|
const formattedResultsString = trimmedResults
|
|
114
|
-
.map((doc) =>
|
|
371
|
+
.map((doc) => `${formatDocForContext(doc)}\n\n---\n`)
|
|
115
372
|
.join("\n");
|
|
116
373
|
return `Found ${trimmedResults.length} documentation pages for "${query}":\n\n${formattedResultsString}`;
|
|
117
374
|
}
|
|
@@ -135,7 +392,10 @@ const createTools = (writer, sources, defaultLanguage) => {
|
|
|
135
392
|
}),
|
|
136
393
|
execute: async ({ slug, lang }) => {
|
|
137
394
|
const doc = sources
|
|
138
|
-
.flatMap((source) => source.source
|
|
395
|
+
.flatMap((source) => source.source
|
|
396
|
+
.getPages(lang)
|
|
397
|
+
.filter((page) => isPageVisibleForSurface(page, "chat"))
|
|
398
|
+
.map((page) => ({ page, source })))
|
|
139
399
|
.find(({ page }) => page.url === slug || page.url.endsWith(slug));
|
|
140
400
|
if (!doc) {
|
|
141
401
|
return `Documentation page not found: "${slug}"`;
|
|
@@ -153,7 +413,9 @@ const createTools = (writer, sources, defaultLanguage) => {
|
|
|
153
413
|
.default(defaultLanguage),
|
|
154
414
|
}),
|
|
155
415
|
execute: ({ lang }) => {
|
|
156
|
-
const pages = sources.flatMap((source) => source.source
|
|
416
|
+
const pages = sources.flatMap((source) => source.source
|
|
417
|
+
.getPages(lang)
|
|
418
|
+
.filter((page) => isPageVisibleForSurface(page, "chat")));
|
|
157
419
|
const docsList = pages
|
|
158
420
|
.map((doc) => `- **${doc.data.title}** (${doc.url}): ${doc.data.description}`)
|
|
159
421
|
.join("\n");
|
|
@@ -173,22 +435,55 @@ const resolveSources = (source, sources) => {
|
|
|
173
435
|
}
|
|
174
436
|
return resolvedSources;
|
|
175
437
|
};
|
|
176
|
-
export const createChatRoute = ({ config, source, sources, }) => {
|
|
177
|
-
const defaultLanguage = config
|
|
438
|
+
export const createChatRoute = ({ config, proxy, source, sources, }) => {
|
|
439
|
+
const { defaultLanguage, languages } = getLanguages(config);
|
|
178
440
|
const routeSources = resolveSources(source, sources);
|
|
179
441
|
const POST = async (req) => {
|
|
180
442
|
try {
|
|
181
443
|
const { messages, currentRoute, pageContext } = await req.json();
|
|
182
|
-
const actualMessages = messages.filter((message) => !message
|
|
183
|
-
|
|
444
|
+
const actualMessages = messages.filter((message) => !isPageContextMessage(message));
|
|
445
|
+
if (proxy) {
|
|
446
|
+
const { messages: proxyMessages, sourceDocs } = await buildProxyMessages({
|
|
447
|
+
actualMessages,
|
|
448
|
+
config,
|
|
449
|
+
currentRoute,
|
|
450
|
+
defaultLanguage,
|
|
451
|
+
languages,
|
|
452
|
+
pageContext,
|
|
453
|
+
routeSources,
|
|
454
|
+
});
|
|
455
|
+
const stream = createUIMessageStream({
|
|
456
|
+
originalMessages: messages,
|
|
457
|
+
onError: () => "Something went wrong with your query.",
|
|
458
|
+
execute: async ({ writer }) => {
|
|
459
|
+
const response = await fetch(proxy.url, {
|
|
460
|
+
method: "POST",
|
|
461
|
+
body: JSON.stringify({
|
|
462
|
+
messages: proxyMessages,
|
|
463
|
+
platform: "vercel",
|
|
464
|
+
}),
|
|
465
|
+
headers: await getProxyRequestHeaders({ proxy, req }),
|
|
466
|
+
});
|
|
467
|
+
if (!response.ok) {
|
|
468
|
+
throw new Error(`Chat proxy returned ${response.status}: ${response.statusText}`);
|
|
469
|
+
}
|
|
470
|
+
if (!response.body) {
|
|
471
|
+
throw new Error("Chat proxy returned an empty response body");
|
|
472
|
+
}
|
|
473
|
+
await pipeUIMessageStreamToWriter({
|
|
474
|
+
initialChunks: createSourceChunks(sourceDocs),
|
|
475
|
+
stream: response.body,
|
|
476
|
+
writer,
|
|
477
|
+
});
|
|
478
|
+
},
|
|
479
|
+
});
|
|
480
|
+
return createUIMessageStreamResponse({ stream });
|
|
481
|
+
}
|
|
184
482
|
let processedMessages = actualMessages;
|
|
185
483
|
if (pageContext && actualMessages.length > 0) {
|
|
186
484
|
const lastMessage = actualMessages.at(-1);
|
|
187
485
|
if (lastMessage?.role === "user") {
|
|
188
|
-
const userQuestion = lastMessage
|
|
189
|
-
.filter((part) => part.type === "text")
|
|
190
|
-
.map((part) => part.text)
|
|
191
|
-
.join("\n");
|
|
486
|
+
const userQuestion = getMessageText(lastMessage);
|
|
192
487
|
processedMessages = [
|
|
193
488
|
...actualMessages.slice(0, -1),
|
|
194
489
|
{
|
|
@@ -211,7 +506,7 @@ export const createChatRoute = ({ config, source, sources, }) => {
|
|
|
211
506
|
messages: convertToModelMessages(processedMessages),
|
|
212
507
|
stopWhen: stepCountIs(10),
|
|
213
508
|
tools: createTools(writer, routeSources, defaultLanguage),
|
|
214
|
-
system: createSystemPrompt(currentRoute, config),
|
|
509
|
+
system: createSystemPrompt(currentRoute ?? "/", config),
|
|
215
510
|
prepareStep: ({ stepNumber }) => {
|
|
216
511
|
if (stepNumber === 0) {
|
|
217
512
|
return {
|
package/dist/routes/llms.d.ts
CHANGED
|
@@ -30,19 +30,20 @@ export declare const createLlmsRoute: ({ filterPage, source, sources, transform,
|
|
|
30
30
|
};
|
|
31
31
|
interface CreateDocsMarkdownRouteOptions {
|
|
32
32
|
filterStaticParams?: (params: DocsMarkdownParams) => boolean;
|
|
33
|
-
source
|
|
33
|
+
source?: SourceBundle;
|
|
34
|
+
sources?: SourceBundle[];
|
|
34
35
|
transform?: MarkdownTransform;
|
|
35
36
|
}
|
|
36
|
-
export declare const createDocsMarkdownRoute: ({ filterStaticParams, source, transform, }: CreateDocsMarkdownRouteOptions) => {
|
|
37
|
+
export declare const createDocsMarkdownRoute: ({ filterStaticParams, source, sources, transform, }: CreateDocsMarkdownRouteOptions) => {
|
|
37
38
|
GET: (_req: Request, { params }: {
|
|
38
39
|
params: Promise<{
|
|
39
40
|
lang: string;
|
|
40
41
|
slug?: string[];
|
|
41
42
|
}>;
|
|
42
43
|
}) => Promise<Response>;
|
|
43
|
-
generateStaticParams: ({ params, }
|
|
44
|
-
params
|
|
45
|
-
lang
|
|
44
|
+
generateStaticParams: ({ params, }?: {
|
|
45
|
+
params?: Promise<{
|
|
46
|
+
lang?: string;
|
|
46
47
|
}>;
|
|
47
48
|
}) => Promise<DocsMarkdownParams[]>;
|
|
48
49
|
revalidate: false;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"llms.d.ts","sourceRoot":"","sources":["../../src/routes/llms.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"llms.d.ts","sourceRoot":"","sources":["../../src/routes/llms.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAEvD,KAAK,YAAY,GAAG,qBAAqB,CAAC;AAC1C,KAAK,aAAa,GAAG,WAAW,CAAC,UAAU,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;AAChF,UAAU,kBAAkB;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;CACjB;AAED,UAAU,wBAAwB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,aAAa,CAAC;IACpB,MAAM,EAAE,YAAY,CAAC;CACtB;AAED,KAAK,iBAAiB,GAAG,CACvB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,wBAAwB,KAC9B,OAAO,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC;AAE9B,UAAU,sBAAsB;IAC9B,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,aAAa,EAAE,OAAO,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,KAAK,OAAO,CAAC;IACzE,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB,OAAO,CAAC,EAAE,YAAY,EAAE,CAAC;IACzB,SAAS,CAAC,EAAE,iBAAiB,CAAC;CAC/B;AAkGD,eAAO,MAAM,eAAe,GAAI,6CAK7B,sBAAsB;gBAIf,WAAW,cACL;QAAE,MAAM,EAAE,OAAO,CAAC;YAAE,IAAI,EAAE,MAAM,CAAA;SAAE,CAAC,CAAA;KAAE;;CAgCpD,CAAC;AAEF,UAAU,8BAA8B;IACtC,kBAAkB,CAAC,EAAE,CAAC,MAAM,EAAE,kBAAkB,KAAK,OAAO,CAAC;IAC7D,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB,OAAO,CAAC,EAAE,YAAY,EAAE,CAAC;IACzB,SAAS,CAAC,EAAE,iBAAiB,CAAC;CAC/B;AAED,eAAO,MAAM,uBAAuB,GAAI,qDAKrC,8BAA8B;gBAQvB,OAAO,cACD;QAAE,MAAM,EAAE,OAAO,CAAC;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,IAAI,CAAC,EAAE,MAAM,EAAE,CAAA;SAAE,CAAC,CAAA;KAAE;yCA0BjE;QACD,MAAM,CAAC,EAAE,OAAO,CAAC;YAAE,IAAI,CAAC,EAAE,MAAM,CAAA;SAAE,CAAC,CAAC;KACrC;;CAgBF,CAAC"}
|
package/dist/routes/llms.js
CHANGED
|
@@ -1,18 +1,62 @@
|
|
|
1
1
|
import { notFound } from "next/navigation";
|
|
2
|
-
|
|
2
|
+
import { isPageVisibleForSurface } from "../internal/page-visibility";
|
|
3
|
+
const resolveSources = (source, sources, caller) => {
|
|
3
4
|
const resolvedSources = sources ?? (source ? [source] : []);
|
|
4
5
|
if (resolvedSources.length === 0) {
|
|
5
|
-
throw new Error(
|
|
6
|
+
throw new Error(`${caller} requires source or sources.`);
|
|
6
7
|
}
|
|
7
8
|
return resolvedSources;
|
|
8
9
|
};
|
|
10
|
+
const pageUrlToSlug = (url) => url.split("/").filter(Boolean);
|
|
11
|
+
const getPathnameFromSlug = (slug) => {
|
|
12
|
+
const segments = slug ?? [];
|
|
13
|
+
return segments.length === 0 ? "/" : `/${segments.join("/")}`;
|
|
14
|
+
};
|
|
15
|
+
const findPageBySlug = ({ lang, slug, sources, }) => {
|
|
16
|
+
for (const source of sources) {
|
|
17
|
+
const page = source.source.getPage(slug, lang);
|
|
18
|
+
if (page) {
|
|
19
|
+
return { page, source };
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
const pathname = getPathnameFromSlug(slug);
|
|
23
|
+
for (const source of sources) {
|
|
24
|
+
const page = source.source
|
|
25
|
+
.getPages(lang)
|
|
26
|
+
.find((entry) => entry.url === pathname);
|
|
27
|
+
if (page) {
|
|
28
|
+
return { page, source };
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return null;
|
|
32
|
+
};
|
|
33
|
+
const getMarkdownStaticParams = ({ lang, sources, }) => {
|
|
34
|
+
if (sources.length === 1) {
|
|
35
|
+
return sources[0].source.generateParams(lang);
|
|
36
|
+
}
|
|
37
|
+
const sourceLanguages = Array.from(new Set(sources.flatMap((source) => source.source.generateParams()
|
|
38
|
+
.map((param) => param.lang)
|
|
39
|
+
.filter((value) => typeof value === "string"))));
|
|
40
|
+
let languages = sourceLanguages.length > 0 ? sourceLanguages : ["en"];
|
|
41
|
+
if (lang) {
|
|
42
|
+
languages = [lang];
|
|
43
|
+
}
|
|
44
|
+
return languages.flatMap((language) => sources.flatMap((source) => source.source.getPages(language).map((page) => {
|
|
45
|
+
const params = { slug: pageUrlToSlug(page.url) };
|
|
46
|
+
if (!lang) {
|
|
47
|
+
params.lang = language;
|
|
48
|
+
}
|
|
49
|
+
return params;
|
|
50
|
+
})));
|
|
51
|
+
};
|
|
9
52
|
export const createLlmsRoute = ({ filterPage, source, sources, transform, }) => {
|
|
10
|
-
const routeSources = resolveSources(source, sources);
|
|
53
|
+
const routeSources = resolveSources(source, sources, "createLlmsRoute");
|
|
11
54
|
const GET = async (_req, { params }) => {
|
|
12
55
|
const { lang } = await params;
|
|
13
56
|
const scanned = await Promise.all(routeSources.flatMap((entry) => entry.source
|
|
14
57
|
.getPages(lang)
|
|
15
|
-
.filter((page) =>
|
|
58
|
+
.filter((page) => isPageVisibleForSurface(page, "llms") &&
|
|
59
|
+
(filterPage?.(page, { lang }) ?? true))
|
|
16
60
|
.map(async (page) => {
|
|
17
61
|
const rendered = await entry.getPageMarkdown(page);
|
|
18
62
|
return transform
|
|
@@ -30,23 +74,30 @@ export const createLlmsRoute = ({ filterPage, source, sources, transform, }) =>
|
|
|
30
74
|
revalidate: false,
|
|
31
75
|
};
|
|
32
76
|
};
|
|
33
|
-
export const createDocsMarkdownRoute = ({ filterStaticParams, source, transform, }) => {
|
|
77
|
+
export const createDocsMarkdownRoute = ({ filterStaticParams, source, sources, transform, }) => {
|
|
78
|
+
const routeSources = resolveSources(source, sources, "createDocsMarkdownRoute");
|
|
34
79
|
const GET = async (_req, { params }) => {
|
|
35
80
|
const { slug, lang } = await params;
|
|
36
|
-
const
|
|
37
|
-
if (!
|
|
81
|
+
const result = findPageBySlug({ lang, slug, sources: routeSources });
|
|
82
|
+
if (!result) {
|
|
38
83
|
notFound();
|
|
39
84
|
}
|
|
40
|
-
const
|
|
41
|
-
|
|
85
|
+
const { page, source: pageSource } = result;
|
|
86
|
+
const rendered = await pageSource.getPageMarkdown(page);
|
|
87
|
+
return new Response(transform
|
|
88
|
+
? await transform(rendered, { lang, page, source: pageSource })
|
|
89
|
+
: rendered, {
|
|
42
90
|
headers: {
|
|
43
91
|
"Content-Type": "text/markdown",
|
|
44
92
|
},
|
|
45
93
|
});
|
|
46
94
|
};
|
|
47
|
-
const generateStaticParams = async ({ params, }) => {
|
|
48
|
-
const { lang } = await params;
|
|
49
|
-
const staticParams =
|
|
95
|
+
const generateStaticParams = async ({ params, } = {}) => {
|
|
96
|
+
const { lang } = (await params) ?? {};
|
|
97
|
+
const staticParams = getMarkdownStaticParams({
|
|
98
|
+
lang,
|
|
99
|
+
sources: routeSources,
|
|
100
|
+
});
|
|
50
101
|
return filterStaticParams
|
|
51
102
|
? staticParams.filter(filterStaticParams)
|
|
52
103
|
: staticParams;
|
package/dist/routes/search.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import type { GeistdocsConfig } from "../config";
|
|
2
|
-
import type
|
|
3
|
-
type
|
|
2
|
+
import { type GeistdocsSourceBundle } from "../source";
|
|
3
|
+
type SourceBundle = GeistdocsSourceBundle;
|
|
4
|
+
type SearchSource = SourceBundle["source"];
|
|
5
|
+
type SearchSourceInput = SearchSource | SourceBundle;
|
|
4
6
|
interface CreateSearchRouteOptions {
|
|
5
7
|
config: Pick<GeistdocsConfig, "defaultLanguage" | "translations">;
|
|
6
|
-
source?:
|
|
7
|
-
sources?:
|
|
8
|
+
source?: SearchSourceInput;
|
|
9
|
+
sources?: SearchSourceInput[];
|
|
8
10
|
}
|
|
9
11
|
export declare const createSearchRoute: ({ config, source, sources, }: CreateSearchRouteOptions) => (request: Request) => Promise<Response>;
|
|
10
12
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../../src/routes/search.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../../src/routes/search.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAEjD,OAAO,EAAE,KAAK,qBAAqB,EAA2B,MAAM,WAAW,CAAC;AAEhF,KAAK,YAAY,GAAG,qBAAqB,CAAC;AAC1C,KAAK,YAAY,GAAG,YAAY,CAAC,QAAQ,CAAC,CAAC;AAC3C,KAAK,iBAAiB,GAAG,YAAY,GAAG,YAAY,CAAC;AAIrD,UAAU,wBAAwB;IAChC,MAAM,EAAE,IAAI,CAAC,eAAe,EAAE,iBAAiB,GAAG,cAAc,CAAC,CAAC;IAClE,MAAM,CAAC,EAAE,iBAAiB,CAAC;IAC3B,OAAO,CAAC,EAAE,iBAAiB,EAAE,CAAC;CAC/B;AAsCD,eAAO,MAAM,iBAAiB,GAAI,8BAI/B,wBAAwB,4CAqE1B,CAAC"}
|
package/dist/routes/search.js
CHANGED
|
@@ -2,6 +2,8 @@ import { createTokenizer as createTokenizerJapanese } from "@orama/tokenizers/ja
|
|
|
2
2
|
import { createTokenizer as createTokenizerMandarin } from "@orama/tokenizers/mandarin";
|
|
3
3
|
import { defineI18n } from "fumadocs-core/i18n";
|
|
4
4
|
import { createI18nSearchAPI, } from "fumadocs-core/search/server";
|
|
5
|
+
import { isPageVisibleForSurface } from "../internal/page-visibility";
|
|
6
|
+
import { isGeistdocsSourceBundle } from "../source";
|
|
5
7
|
const getLanguages = (config) => {
|
|
6
8
|
const defaultLanguage = config.defaultLanguage ?? "en";
|
|
7
9
|
const languages = Object.keys(config.translations ?? {});
|
|
@@ -17,6 +19,9 @@ const resolveSources = (source, sources) => {
|
|
|
17
19
|
}
|
|
18
20
|
return resolvedSources;
|
|
19
21
|
};
|
|
22
|
+
const getPages = (source, locale) => isGeistdocsSourceBundle(source)
|
|
23
|
+
? source.source.getPages(locale)
|
|
24
|
+
: source.getPages(locale);
|
|
20
25
|
export const createSearchRoute = ({ config, source, sources, }) => {
|
|
21
26
|
const translations = config.translations ?? {};
|
|
22
27
|
const routeSources = resolveSources(source, sources);
|
|
@@ -52,7 +57,9 @@ export const createSearchRoute = ({ config, source, sources, }) => {
|
|
|
52
57
|
},
|
|
53
58
|
};
|
|
54
59
|
}
|
|
55
|
-
const getIndexes = () => languages.flatMap((locale) => routeSources.flatMap((source) =>
|
|
60
|
+
const getIndexes = () => languages.flatMap((locale) => routeSources.flatMap((source) => getPages(source, locale)
|
|
61
|
+
.filter((page) => isPageVisibleForSurface(page, "search"))
|
|
62
|
+
.map((page) => {
|
|
56
63
|
const data = page.data;
|
|
57
64
|
return {
|
|
58
65
|
id: page.url,
|