@vercel/geistdocs 1.2.3-canary.48fea3c → 1.2.3-canary.73598cf
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.d.ts.map +1 -1
- package/dist/internal/chat/shell.js +6 -5
- 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 +373 -65
- 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 +126 -5
- package/source-config.js +174 -0
- package/styles.css +465 -102
- package/template/AGENTS.md +95 -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 +55 -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 +8 -1
- package/template/content/docs/index.mdx +5 -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 +364 -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 +5 -5
- 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,309 @@
|
|
|
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 isChatRequestBody = (value) => typeof value === "object" &&
|
|
71
|
+
value !== null &&
|
|
72
|
+
Array.isArray(value.messages);
|
|
73
|
+
const getPageData = (page) => page.data;
|
|
74
|
+
const getStructuredContent = (page) => JSON.stringify(getPageData(page).structuredData?.contents ?? "");
|
|
75
|
+
const createSearchServer = (sources, lang) => {
|
|
76
|
+
const indexes = sources.flatMap((source) => source.source
|
|
77
|
+
.getPages(lang)
|
|
78
|
+
.filter((page) => isPageVisibleForSurface(page, "chat"))
|
|
79
|
+
.map((page) => {
|
|
80
|
+
const data = getPageData(page);
|
|
81
|
+
const structuredData = data.structuredData ??
|
|
82
|
+
{ headings: [], contents: [] };
|
|
83
|
+
return {
|
|
84
|
+
title: data.title ?? page.url,
|
|
85
|
+
description: data.description ?? "",
|
|
86
|
+
url: page.url,
|
|
87
|
+
id: page.url,
|
|
88
|
+
structuredData,
|
|
89
|
+
};
|
|
90
|
+
}));
|
|
91
|
+
return initAdvancedSearch({ indexes });
|
|
92
|
+
};
|
|
93
|
+
const resolveSearchResult = ({ lang, sources, url, }) => {
|
|
94
|
+
const result = sources
|
|
95
|
+
.map((source) => source.source.getPageByHref(url, { language: lang }))
|
|
96
|
+
.find((entry) => entry?.page);
|
|
97
|
+
if (!result?.page) {
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
const { page } = result;
|
|
101
|
+
const data = getPageData(page);
|
|
102
|
+
return {
|
|
103
|
+
title: data.title ?? page.url,
|
|
104
|
+
description: data.description ?? "",
|
|
105
|
+
content: getStructuredContent(page),
|
|
106
|
+
slug: page.url,
|
|
107
|
+
};
|
|
108
|
+
};
|
|
109
|
+
const searchDocs = async ({ lang, limit, query, sources, }) => {
|
|
110
|
+
const searchServer = createSearchServer(sources, lang);
|
|
111
|
+
const results = await searchServer.search(query);
|
|
112
|
+
const seenSlugs = new Set();
|
|
113
|
+
return results
|
|
114
|
+
.map(({ url }) => resolveSearchResult({ lang, sources, url }))
|
|
115
|
+
.filter((doc) => Boolean(doc))
|
|
116
|
+
.filter((doc) => {
|
|
117
|
+
if (seenSlugs.has(doc.slug)) {
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
seenSlugs.add(doc.slug);
|
|
121
|
+
return true;
|
|
122
|
+
})
|
|
123
|
+
.slice(0, limit);
|
|
124
|
+
};
|
|
125
|
+
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 ? "..." : ""}`;
|
|
126
|
+
const getRouteCandidates = ({ basePath, currentRoute, lang, }) => {
|
|
127
|
+
const pathname = normalizePathname(currentRoute);
|
|
128
|
+
const withoutBasePath = stripBasePath(pathname, basePath);
|
|
129
|
+
const withoutLanguage = stripLanguagePrefix(withoutBasePath, lang);
|
|
130
|
+
return Array.from(new Set([pathname, withoutBasePath, withoutLanguage]));
|
|
131
|
+
};
|
|
132
|
+
const findCurrentPage = ({ basePath, currentRoute, lang, sources, }) => {
|
|
133
|
+
const candidates = getRouteCandidates({ basePath, currentRoute, lang });
|
|
134
|
+
for (const source of sources) {
|
|
135
|
+
for (const candidate of candidates) {
|
|
136
|
+
const result = source.source.getPageByHref(candidate, { language: lang });
|
|
137
|
+
if (result?.page && isPageVisibleForSurface(result.page, "chat")) {
|
|
138
|
+
return { page: result.page, source };
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
const page = source.source
|
|
142
|
+
.getPages(lang)
|
|
143
|
+
.filter((entry) => isPageVisibleForSurface(entry, "chat"))
|
|
144
|
+
.find((entry) => candidates.includes(normalizePathname(entry.url)));
|
|
145
|
+
if (page) {
|
|
146
|
+
return { page, source };
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return null;
|
|
150
|
+
};
|
|
151
|
+
const getCurrentPageDoc = async ({ basePath, currentRoute, lang, pageContext, sources, }) => {
|
|
152
|
+
if (pageContext) {
|
|
153
|
+
return {
|
|
154
|
+
title: pageContext.title,
|
|
155
|
+
description: "",
|
|
156
|
+
content: pageContext.content,
|
|
157
|
+
slug: pageContext.url,
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
const result = findCurrentPage({ basePath, currentRoute, lang, sources });
|
|
161
|
+
if (!result) {
|
|
162
|
+
return null;
|
|
163
|
+
}
|
|
164
|
+
const data = getPageData(result.page);
|
|
165
|
+
return {
|
|
166
|
+
title: data.title ?? result.page.url,
|
|
167
|
+
description: data.description ?? "",
|
|
168
|
+
content: await result.source.getPageMarkdown(result.page),
|
|
169
|
+
slug: result.page.url,
|
|
170
|
+
};
|
|
171
|
+
};
|
|
172
|
+
const isFirstUserMessage = (messages) => messages.filter((message) => message.role === "user").length === 1;
|
|
173
|
+
const createSourceChunks = (docs) => docs.map((doc, index) => ({
|
|
174
|
+
type: "source-url",
|
|
175
|
+
sourceId: `doc-${index}-${doc.slug}`,
|
|
176
|
+
url: doc.slug,
|
|
177
|
+
title: doc.title,
|
|
178
|
+
}));
|
|
179
|
+
const buildProxyMessages = async ({ actualMessages, config, currentRoute, defaultLanguage, languages, pageContext, routeSources, }) => {
|
|
180
|
+
if (!isFirstUserMessage(actualMessages)) {
|
|
181
|
+
return { messages: actualMessages, sourceDocs: [] };
|
|
182
|
+
}
|
|
183
|
+
const lastMessage = actualMessages.at(-1);
|
|
184
|
+
if (lastMessage?.role !== "user") {
|
|
185
|
+
return { messages: actualMessages, sourceDocs: [] };
|
|
186
|
+
}
|
|
187
|
+
const userQuestion = getMessageText(lastMessage);
|
|
188
|
+
const lang = getRequestLanguage({
|
|
189
|
+
basePath: config.basePath,
|
|
190
|
+
currentRoute,
|
|
191
|
+
defaultLanguage,
|
|
192
|
+
languages,
|
|
193
|
+
});
|
|
194
|
+
const currentPageDoc = await getCurrentPageDoc({
|
|
195
|
+
basePath: config.basePath,
|
|
196
|
+
currentRoute,
|
|
197
|
+
lang,
|
|
198
|
+
pageContext,
|
|
199
|
+
sources: routeSources,
|
|
200
|
+
});
|
|
201
|
+
const relatedDocs = userQuestion.trim()
|
|
202
|
+
? await searchDocs({
|
|
203
|
+
lang,
|
|
204
|
+
limit: MAX_PROXY_RELATED_PAGES,
|
|
205
|
+
query: userQuestion,
|
|
206
|
+
sources: routeSources,
|
|
207
|
+
})
|
|
208
|
+
: [];
|
|
209
|
+
const filteredRelatedDocs = relatedDocs.filter((doc) => doc.slug !== currentPageDoc?.slug);
|
|
210
|
+
const contextParts = [];
|
|
211
|
+
if (currentPageDoc) {
|
|
212
|
+
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 ? "..." : ""}`);
|
|
213
|
+
}
|
|
214
|
+
if (filteredRelatedDocs.length > 0) {
|
|
215
|
+
contextParts.push(`Related documentation pages:\n\n${filteredRelatedDocs.map(formatDocForContext).join("\n\n---\n\n")}`);
|
|
216
|
+
}
|
|
217
|
+
if (contextParts.length === 0) {
|
|
218
|
+
return { messages: actualMessages, sourceDocs: [] };
|
|
219
|
+
}
|
|
220
|
+
return {
|
|
221
|
+
messages: [
|
|
222
|
+
...actualMessages.slice(0, -1),
|
|
223
|
+
{
|
|
224
|
+
...lastMessage,
|
|
225
|
+
parts: [
|
|
226
|
+
{
|
|
227
|
+
type: "text",
|
|
228
|
+
text: `${contextParts.join("\n\n---\n\n")}\n\n---\n\nUser question: ${userQuestion}`,
|
|
229
|
+
},
|
|
230
|
+
],
|
|
231
|
+
},
|
|
232
|
+
],
|
|
233
|
+
sourceDocs: [currentPageDoc, ...filteredRelatedDocs].filter((doc) => Boolean(doc)),
|
|
234
|
+
};
|
|
235
|
+
};
|
|
236
|
+
const resolveProxyHeaders = async (headers) => typeof headers === "function" ? await headers() : headers;
|
|
237
|
+
const getProxyRequestHeaders = async ({ proxy, req, }) => {
|
|
238
|
+
const headers = new Headers(await resolveProxyHeaders(proxy.headers));
|
|
239
|
+
const clientJa4 = req.headers.get("x-vercel-ja4-digest");
|
|
240
|
+
const clientIp = req.headers.get("x-forwarded-for");
|
|
241
|
+
headers.set("Content-Type", "application/json");
|
|
242
|
+
if (clientJa4 && !headers.has("x-client-ja4")) {
|
|
243
|
+
headers.set("x-client-ja4", clientJa4);
|
|
244
|
+
}
|
|
245
|
+
if (clientIp && !headers.has("x-client-ip")) {
|
|
246
|
+
headers.set("x-client-ip", clientIp);
|
|
247
|
+
}
|
|
248
|
+
return headers;
|
|
249
|
+
};
|
|
250
|
+
const parseSseChunk = (event) => {
|
|
251
|
+
const data = event
|
|
252
|
+
.split("\n")
|
|
253
|
+
.filter((line) => line.startsWith("data:"))
|
|
254
|
+
.map((line) => line.slice(5).trimStart())
|
|
255
|
+
.join("\n");
|
|
256
|
+
if (!data || data === "[DONE]") {
|
|
257
|
+
return null;
|
|
258
|
+
}
|
|
259
|
+
return JSON.parse(data);
|
|
260
|
+
};
|
|
261
|
+
const pipeUIMessageStreamToWriter = async ({ initialChunks, stream, writer, }) => {
|
|
262
|
+
const reader = stream.getReader();
|
|
263
|
+
const decoder = new TextDecoder();
|
|
264
|
+
let buffer = "";
|
|
265
|
+
let initialChunksWritten = false;
|
|
266
|
+
const writeInitialChunks = () => {
|
|
267
|
+
if (initialChunksWritten) {
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
initialChunksWritten = true;
|
|
271
|
+
for (const chunk of initialChunks) {
|
|
272
|
+
writer.write(chunk);
|
|
273
|
+
}
|
|
274
|
+
};
|
|
275
|
+
const writeEvent = (event) => {
|
|
276
|
+
const chunk = parseSseChunk(event);
|
|
277
|
+
if (!chunk) {
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
if (chunk.type === "start") {
|
|
281
|
+
writer.write(chunk);
|
|
282
|
+
writeInitialChunks();
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
writeInitialChunks();
|
|
286
|
+
writer.write(chunk);
|
|
287
|
+
};
|
|
288
|
+
while (true) {
|
|
289
|
+
const { done, value } = await reader.read();
|
|
290
|
+
buffer += decoder.decode(value, { stream: !done }).replace(/\r\n/g, "\n");
|
|
291
|
+
let delimiterIndex = buffer.indexOf("\n\n");
|
|
292
|
+
while (delimiterIndex !== -1) {
|
|
293
|
+
const event = buffer.slice(0, delimiterIndex);
|
|
294
|
+
buffer = buffer.slice(delimiterIndex + 2);
|
|
295
|
+
writeEvent(event);
|
|
296
|
+
delimiterIndex = buffer.indexOf("\n\n");
|
|
297
|
+
}
|
|
298
|
+
if (done) {
|
|
299
|
+
break;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
if (buffer.trim()) {
|
|
303
|
+
writeEvent(buffer);
|
|
304
|
+
}
|
|
305
|
+
writeInitialChunks();
|
|
306
|
+
};
|
|
4
307
|
const createSystemPrompt = (currentRoute, config) => {
|
|
5
308
|
const basePrompt = `# Role and objective
|
|
6
309
|
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 +340,6 @@ const createTools = (writer, sources, defaultLanguage) => {
|
|
|
37
340
|
const log = (message) => {
|
|
38
341
|
console.log(`[Geistdocs chat] ${message}`);
|
|
39
342
|
};
|
|
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
343
|
const search_docs = tool({
|
|
58
344
|
description: "Search through documentation content by query",
|
|
59
345
|
inputSchema: z.object({
|
|
@@ -67,41 +353,15 @@ const createTools = (writer, sources, defaultLanguage) => {
|
|
|
67
353
|
execute: async ({ query, lang }) => {
|
|
68
354
|
try {
|
|
69
355
|
log(`Creating search server for language: ${lang}`);
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
|
|
356
|
+
const trimmedResults = await searchDocs({
|
|
357
|
+
lang,
|
|
358
|
+
limit: MAX_TOOL_RESULTS,
|
|
359
|
+
query,
|
|
360
|
+
sources,
|
|
361
|
+
});
|
|
362
|
+
if (trimmedResults.length === 0) {
|
|
73
363
|
return `No documentation found for query: "${query}"`;
|
|
74
364
|
}
|
|
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
365
|
for (const [index, doc] of trimmedResults.entries()) {
|
|
106
366
|
writer.write({
|
|
107
367
|
type: "source-url",
|
|
@@ -111,7 +371,7 @@ const createTools = (writer, sources, defaultLanguage) => {
|
|
|
111
371
|
});
|
|
112
372
|
}
|
|
113
373
|
const formattedResultsString = trimmedResults
|
|
114
|
-
.map((doc) =>
|
|
374
|
+
.map((doc) => `${formatDocForContext(doc)}\n\n---\n`)
|
|
115
375
|
.join("\n");
|
|
116
376
|
return `Found ${trimmedResults.length} documentation pages for "${query}":\n\n${formattedResultsString}`;
|
|
117
377
|
}
|
|
@@ -135,7 +395,10 @@ const createTools = (writer, sources, defaultLanguage) => {
|
|
|
135
395
|
}),
|
|
136
396
|
execute: async ({ slug, lang }) => {
|
|
137
397
|
const doc = sources
|
|
138
|
-
.flatMap((source) => source.source
|
|
398
|
+
.flatMap((source) => source.source
|
|
399
|
+
.getPages(lang)
|
|
400
|
+
.filter((page) => isPageVisibleForSurface(page, "chat"))
|
|
401
|
+
.map((page) => ({ page, source })))
|
|
139
402
|
.find(({ page }) => page.url === slug || page.url.endsWith(slug));
|
|
140
403
|
if (!doc) {
|
|
141
404
|
return `Documentation page not found: "${slug}"`;
|
|
@@ -153,7 +416,9 @@ const createTools = (writer, sources, defaultLanguage) => {
|
|
|
153
416
|
.default(defaultLanguage),
|
|
154
417
|
}),
|
|
155
418
|
execute: ({ lang }) => {
|
|
156
|
-
const pages = sources.flatMap((source) => source.source
|
|
419
|
+
const pages = sources.flatMap((source) => source.source
|
|
420
|
+
.getPages(lang)
|
|
421
|
+
.filter((page) => isPageVisibleForSurface(page, "chat")));
|
|
157
422
|
const docsList = pages
|
|
158
423
|
.map((doc) => `- **${doc.data.title}** (${doc.url}): ${doc.data.description}`)
|
|
159
424
|
.join("\n");
|
|
@@ -173,22 +438,64 @@ const resolveSources = (source, sources) => {
|
|
|
173
438
|
}
|
|
174
439
|
return resolvedSources;
|
|
175
440
|
};
|
|
176
|
-
export const createChatRoute = ({ config, source, sources, }) => {
|
|
177
|
-
const defaultLanguage = config
|
|
441
|
+
export const createChatRoute = ({ config, proxy, source, sources, }) => {
|
|
442
|
+
const { defaultLanguage, languages } = getLanguages(config);
|
|
178
443
|
const routeSources = resolveSources(source, sources);
|
|
179
444
|
const POST = async (req) => {
|
|
180
445
|
try {
|
|
181
|
-
const
|
|
182
|
-
|
|
183
|
-
|
|
446
|
+
const requestBody = await req.json();
|
|
447
|
+
if (!isChatRequestBody(requestBody)) {
|
|
448
|
+
return new Response(JSON.stringify({
|
|
449
|
+
error: "Invalid chat request: messages must be an array.",
|
|
450
|
+
}), {
|
|
451
|
+
status: 400,
|
|
452
|
+
headers: { "Content-Type": "application/json" },
|
|
453
|
+
});
|
|
454
|
+
}
|
|
455
|
+
const { messages, currentRoute, pageContext } = requestBody;
|
|
456
|
+
const actualMessages = messages.filter((message) => !isPageContextMessage(message));
|
|
457
|
+
if (proxy) {
|
|
458
|
+
const { messages: proxyMessages, sourceDocs } = await buildProxyMessages({
|
|
459
|
+
actualMessages,
|
|
460
|
+
config,
|
|
461
|
+
currentRoute,
|
|
462
|
+
defaultLanguage,
|
|
463
|
+
languages,
|
|
464
|
+
pageContext,
|
|
465
|
+
routeSources,
|
|
466
|
+
});
|
|
467
|
+
const stream = createUIMessageStream({
|
|
468
|
+
originalMessages: messages,
|
|
469
|
+
onError: () => "Something went wrong with your query.",
|
|
470
|
+
execute: async ({ writer }) => {
|
|
471
|
+
const response = await fetch(proxy.url, {
|
|
472
|
+
method: "POST",
|
|
473
|
+
body: JSON.stringify({
|
|
474
|
+
messages: proxyMessages,
|
|
475
|
+
platform: "vercel",
|
|
476
|
+
}),
|
|
477
|
+
headers: await getProxyRequestHeaders({ proxy, req }),
|
|
478
|
+
});
|
|
479
|
+
if (!response.ok) {
|
|
480
|
+
throw new Error(`Chat proxy returned ${response.status}: ${response.statusText}`);
|
|
481
|
+
}
|
|
482
|
+
if (!response.body) {
|
|
483
|
+
throw new Error("Chat proxy returned an empty response body");
|
|
484
|
+
}
|
|
485
|
+
await pipeUIMessageStreamToWriter({
|
|
486
|
+
initialChunks: createSourceChunks(sourceDocs),
|
|
487
|
+
stream: response.body,
|
|
488
|
+
writer,
|
|
489
|
+
});
|
|
490
|
+
},
|
|
491
|
+
});
|
|
492
|
+
return createUIMessageStreamResponse({ stream });
|
|
493
|
+
}
|
|
184
494
|
let processedMessages = actualMessages;
|
|
185
495
|
if (pageContext && actualMessages.length > 0) {
|
|
186
496
|
const lastMessage = actualMessages.at(-1);
|
|
187
497
|
if (lastMessage?.role === "user") {
|
|
188
|
-
const userQuestion = lastMessage
|
|
189
|
-
.filter((part) => part.type === "text")
|
|
190
|
-
.map((part) => part.text)
|
|
191
|
-
.join("\n");
|
|
498
|
+
const userQuestion = getMessageText(lastMessage);
|
|
192
499
|
processedMessages = [
|
|
193
500
|
...actualMessages.slice(0, -1),
|
|
194
501
|
{
|
|
@@ -205,13 +512,14 @@ export const createChatRoute = ({ config, source, sources, }) => {
|
|
|
205
512
|
}
|
|
206
513
|
const stream = createUIMessageStream({
|
|
207
514
|
originalMessages: messages,
|
|
208
|
-
execute: ({ writer }) => {
|
|
515
|
+
execute: async ({ writer }) => {
|
|
516
|
+
const modelMessages = await convertToModelMessages(processedMessages);
|
|
209
517
|
const result = streamText({
|
|
210
518
|
model: "openai/gpt-4.1-mini",
|
|
211
|
-
messages:
|
|
519
|
+
messages: modelMessages,
|
|
212
520
|
stopWhen: stepCountIs(10),
|
|
213
521
|
tools: createTools(writer, routeSources, defaultLanguage),
|
|
214
|
-
system: createSystemPrompt(currentRoute, config),
|
|
522
|
+
system: createSystemPrompt(currentRoute ?? "/", config),
|
|
215
523
|
prepareStep: ({ stepNumber }) => {
|
|
216
524
|
if (stepNumber === 0) {
|
|
217
525
|
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"}
|