@vercel/geistdocs 1.3.0-canary.5af98bc → 1.3.0
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 +66 -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.d.ts +4 -1
- package/dist/internal/sidebar.d.ts.map +1 -1
- package/dist/internal/sidebar.js +4 -4
- 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/layout.d.ts +2 -1
- package/dist/layout.d.ts.map +1 -1
- package/dist/layout.js +2 -2
- 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 +33 -5
- package/dist/pages/docs.d.ts.map +1 -1
- package/dist/pages/docs.js +46 -17
- package/dist/proxy.d.ts +24 -8
- package/dist/proxy.d.ts.map +1 -1
- package/dist/proxy.js +116 -36
- 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 +11 -5
- package/dist/routes/chat.d.ts.map +1 -1
- package/dist/routes/chat.js +386 -65
- package/dist/routes/llms.d.ts +29 -10
- package/dist/routes/llms.d.ts.map +1 -1
- package/dist/routes/llms.js +80 -9
- package/dist/routes/search.d.ts +8 -5
- package/dist/routes/search.d.ts.map +1 -1
- package/dist/routes/search.js +52 -4
- package/dist/routes/sitemap.d.ts +15 -3
- package/dist/routes/sitemap.d.ts.map +1 -1
- package/dist/routes/sitemap.js +32 -6
- 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 +155 -4
- package/dist/source.d.ts.map +1 -1
- package/dist/source.js +73 -3
- package/dist/versions.d.ts +45 -0
- package/dist/versions.d.ts.map +1 -0
- package/dist/versions.js +79 -0
- package/package.json +134 -9
- 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]/llms.txt/route.ts +1 -1
- package/template/app/[lang]/sitemap.md/route.ts +2 -2
- package/template/app/api/chat/route.ts +12 -1
- 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 +57 -5
- package/template/content/docs/configuration.cn.mdx +47 -7
- package/template/content/docs/configuration.mdx +158 -1
- package/template/content/docs/deployment.mdx +11 -0
- package/template/content/docs/edit-on-github.mdx +2 -2
- package/template/content/docs/env.mdx +36 -5
- package/template/content/docs/feedback.mdx +2 -2
- package/template/content/docs/getting-started.cn.mdx +2 -2
- package/template/content/docs/getting-started.mdx +8 -1
- package/template/content/docs/index.cn.mdx +36 -33
- package/template/content/docs/index.mdx +12 -0
- package/template/content/docs/internationalization.mdx +1 -1
- package/template/content/docs/llms-txt.cn.mdx +24 -2
- package/template/content/docs/llms-txt.mdx +44 -12
- package/template/content/docs/md.cn.mdx +12 -15
- package/template/content/docs/md.mdx +26 -16
- package/template/content/docs/meta.json +4 -0
- package/template/content/docs/migration.mdx +364 -0
- package/template/content/docs/open-in-chat.mdx +8 -10
- package/template/content/docs/provider.cn.mdx +6 -5
- package/template/content/docs/provider.mdx +9 -8
- package/template/content/docs/proxy.cn.mdx +96 -0
- package/template/content/docs/proxy.mdx +178 -0
- package/template/content/docs/rss.mdx +2 -2
- package/template/content/docs/syntax.mdx +1 -1
- package/template/content/docs/theme-aware-image.mdx +1 -1
- package/template/content/docs/versioned-docs.cn.mdx +117 -0
- package/template/content/docs/versioned-docs.mdx +228 -0
- package/template/geistdocs.tsx +26 -0
- package/template/lib/geistdocs/config.tsx +3 -0
- package/template/package.json +5 -5
- package/template/proxy.ts +2 -1
- 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.
|
|
@@ -33,28 +336,10 @@ You are a helpful assistant specializing in answering questions strictly. If inf
|
|
|
33
336
|
- Be friendly, clear, and specific.`;
|
|
34
337
|
return [basePrompt, config.ai?.prompt].filter(Boolean).join("\n\n");
|
|
35
338
|
};
|
|
36
|
-
const createTools = (writer,
|
|
339
|
+
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 pages = source.source.getPages(lang);
|
|
42
|
-
const indexes = pages.map((page) => {
|
|
43
|
-
const data = page.data;
|
|
44
|
-
const structuredData = data.structuredData ??
|
|
45
|
-
{ headings: [], contents: [] };
|
|
46
|
-
return {
|
|
47
|
-
title: data.title ?? page.url,
|
|
48
|
-
description: data.description ?? "",
|
|
49
|
-
url: page.url,
|
|
50
|
-
id: page.url,
|
|
51
|
-
structuredData,
|
|
52
|
-
};
|
|
53
|
-
});
|
|
54
|
-
return initAdvancedSearch({
|
|
55
|
-
indexes,
|
|
56
|
-
});
|
|
57
|
-
};
|
|
58
343
|
const search_docs = tool({
|
|
59
344
|
description: "Search through documentation content by query",
|
|
60
345
|
inputSchema: z.object({
|
|
@@ -68,36 +353,15 @@ const createTools = (writer, source, defaultLanguage) => {
|
|
|
68
353
|
execute: async ({ query, lang }) => {
|
|
69
354
|
try {
|
|
70
355
|
log(`Creating search server for language: ${lang}`);
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
|
|
356
|
+
const trimmedResults = await searchDocs({
|
|
357
|
+
lang,
|
|
358
|
+
limit: MAX_TOOL_RESULTS,
|
|
359
|
+
query,
|
|
360
|
+
sources,
|
|
361
|
+
});
|
|
362
|
+
if (trimmedResults.length === 0) {
|
|
74
363
|
return `No documentation found for query: "${query}"`;
|
|
75
364
|
}
|
|
76
|
-
const promiseResults = await Promise.all(results.map(({ url }) => {
|
|
77
|
-
const result = source.source.getPageByHref(url, { language: lang });
|
|
78
|
-
if (!result?.page) {
|
|
79
|
-
return null;
|
|
80
|
-
}
|
|
81
|
-
const { page } = result;
|
|
82
|
-
const data = page.data;
|
|
83
|
-
return {
|
|
84
|
-
title: data.title ?? page.url,
|
|
85
|
-
description: data.description ?? "",
|
|
86
|
-
content: JSON.stringify(data.structuredData?.contents ?? ""),
|
|
87
|
-
slug: page.url,
|
|
88
|
-
};
|
|
89
|
-
}));
|
|
90
|
-
const seenSlugs = new Set();
|
|
91
|
-
const trimmedResults = promiseResults
|
|
92
|
-
.filter((doc) => Boolean(doc))
|
|
93
|
-
.filter((doc) => {
|
|
94
|
-
if (!doc || seenSlugs.has(doc.slug)) {
|
|
95
|
-
return false;
|
|
96
|
-
}
|
|
97
|
-
seenSlugs.add(doc.slug);
|
|
98
|
-
return true;
|
|
99
|
-
})
|
|
100
|
-
.slice(0, 8);
|
|
101
365
|
for (const [index, doc] of trimmedResults.entries()) {
|
|
102
366
|
writer.write({
|
|
103
367
|
type: "source-url",
|
|
@@ -107,7 +371,7 @@ const createTools = (writer, source, defaultLanguage) => {
|
|
|
107
371
|
});
|
|
108
372
|
}
|
|
109
373
|
const formattedResultsString = trimmedResults
|
|
110
|
-
.map((doc) =>
|
|
374
|
+
.map((doc) => `${formatDocForContext(doc)}\n\n---\n`)
|
|
111
375
|
.join("\n");
|
|
112
376
|
return `Found ${trimmedResults.length} documentation pages for "${query}":\n\n${formattedResultsString}`;
|
|
113
377
|
}
|
|
@@ -130,12 +394,16 @@ const createTools = (writer, source, defaultLanguage) => {
|
|
|
130
394
|
.default(defaultLanguage),
|
|
131
395
|
}),
|
|
132
396
|
execute: async ({ slug, lang }) => {
|
|
133
|
-
const
|
|
134
|
-
|
|
397
|
+
const doc = sources
|
|
398
|
+
.flatMap((source) => source.source
|
|
399
|
+
.getPages(lang)
|
|
400
|
+
.filter((page) => isPageVisibleForSurface(page, "chat"))
|
|
401
|
+
.map((page) => ({ page, source })))
|
|
402
|
+
.find(({ page }) => page.url === slug || page.url.endsWith(slug));
|
|
135
403
|
if (!doc) {
|
|
136
404
|
return `Documentation page not found: "${slug}"`;
|
|
137
405
|
}
|
|
138
|
-
return await source.getPageMarkdown(doc);
|
|
406
|
+
return await doc.source.getPageMarkdown(doc.page);
|
|
139
407
|
},
|
|
140
408
|
});
|
|
141
409
|
const list_docs = tool({
|
|
@@ -148,7 +416,9 @@ const createTools = (writer, source, defaultLanguage) => {
|
|
|
148
416
|
.default(defaultLanguage),
|
|
149
417
|
}),
|
|
150
418
|
execute: ({ lang }) => {
|
|
151
|
-
const pages = source.source
|
|
419
|
+
const pages = sources.flatMap((source) => source.source
|
|
420
|
+
.getPages(lang)
|
|
421
|
+
.filter((page) => isPageVisibleForSurface(page, "chat")));
|
|
152
422
|
const docsList = pages
|
|
153
423
|
.map((doc) => `- **${doc.data.title}** (${doc.url}): ${doc.data.description}`)
|
|
154
424
|
.join("\n");
|
|
@@ -161,21 +431,71 @@ const createTools = (writer, source, defaultLanguage) => {
|
|
|
161
431
|
search_docs,
|
|
162
432
|
};
|
|
163
433
|
};
|
|
164
|
-
|
|
165
|
-
const
|
|
434
|
+
const resolveSources = (source, sources) => {
|
|
435
|
+
const resolvedSources = sources ?? (source ? [source] : []);
|
|
436
|
+
if (resolvedSources.length === 0) {
|
|
437
|
+
throw new Error("createChatRoute requires source or sources.");
|
|
438
|
+
}
|
|
439
|
+
return resolvedSources;
|
|
440
|
+
};
|
|
441
|
+
export const createChatRoute = ({ config, proxy, source, sources, }) => {
|
|
442
|
+
const { defaultLanguage, languages } = getLanguages(config);
|
|
443
|
+
const routeSources = resolveSources(source, sources);
|
|
166
444
|
const POST = async (req) => {
|
|
167
445
|
try {
|
|
168
|
-
const
|
|
169
|
-
|
|
170
|
-
|
|
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
|
+
}
|
|
171
494
|
let processedMessages = actualMessages;
|
|
172
495
|
if (pageContext && actualMessages.length > 0) {
|
|
173
496
|
const lastMessage = actualMessages.at(-1);
|
|
174
497
|
if (lastMessage?.role === "user") {
|
|
175
|
-
const userQuestion = lastMessage
|
|
176
|
-
.filter((part) => part.type === "text")
|
|
177
|
-
.map((part) => part.text)
|
|
178
|
-
.join("\n");
|
|
498
|
+
const userQuestion = getMessageText(lastMessage);
|
|
179
499
|
processedMessages = [
|
|
180
500
|
...actualMessages.slice(0, -1),
|
|
181
501
|
{
|
|
@@ -192,13 +512,14 @@ export const createChatRoute = ({ config, source }) => {
|
|
|
192
512
|
}
|
|
193
513
|
const stream = createUIMessageStream({
|
|
194
514
|
originalMessages: messages,
|
|
195
|
-
execute: ({ writer }) => {
|
|
515
|
+
execute: async ({ writer }) => {
|
|
516
|
+
const modelMessages = await convertToModelMessages(processedMessages);
|
|
196
517
|
const result = streamText({
|
|
197
518
|
model: "openai/gpt-4.1-mini",
|
|
198
|
-
messages:
|
|
519
|
+
messages: modelMessages,
|
|
199
520
|
stopWhen: stepCountIs(10),
|
|
200
|
-
tools: createTools(writer,
|
|
201
|
-
system: createSystemPrompt(currentRoute, config),
|
|
521
|
+
tools: createTools(writer, routeSources, defaultLanguage),
|
|
522
|
+
system: createSystemPrompt(currentRoute ?? "/", config),
|
|
202
523
|
prepareStep: ({ stepNumber }) => {
|
|
203
524
|
if (stepNumber === 0) {
|
|
204
525
|
return {
|
package/dist/routes/llms.d.ts
CHANGED
|
@@ -1,10 +1,26 @@
|
|
|
1
1
|
import type { NextRequest } from "next/server";
|
|
2
|
-
import type {
|
|
3
|
-
type SourceBundle =
|
|
4
|
-
|
|
2
|
+
import type { GeistdocsSourceBundle } from "../source";
|
|
3
|
+
type SourceBundle = GeistdocsSourceBundle;
|
|
4
|
+
type GeistdocsPage = NonNullable<ReturnType<SourceBundle["source"]["getPage"]>>;
|
|
5
|
+
interface DocsMarkdownParams {
|
|
6
|
+
lang: string;
|
|
7
|
+
slug?: string[];
|
|
8
|
+
}
|
|
9
|
+
interface MarkdownTransformContext {
|
|
10
|
+
lang: string;
|
|
11
|
+
page: GeistdocsPage;
|
|
5
12
|
source: SourceBundle;
|
|
6
13
|
}
|
|
7
|
-
|
|
14
|
+
type MarkdownTransform = (markdown: string, context: MarkdownTransformContext) => Promise<string> | string;
|
|
15
|
+
interface CreateLlmsRouteOptions {
|
|
16
|
+
filterPage?: (page: GeistdocsPage, context: {
|
|
17
|
+
lang: string;
|
|
18
|
+
}) => boolean;
|
|
19
|
+
source?: SourceBundle;
|
|
20
|
+
sources?: SourceBundle[];
|
|
21
|
+
transform?: MarkdownTransform;
|
|
22
|
+
}
|
|
23
|
+
export declare const createLlmsRoute: ({ filterPage, source, sources, transform, }: CreateLlmsRouteOptions) => {
|
|
8
24
|
GET: (_req: NextRequest, { params }: {
|
|
9
25
|
params: Promise<{
|
|
10
26
|
lang: string;
|
|
@@ -13,20 +29,23 @@ export declare const createLlmsRoute: ({ source }: CreateLlmsRouteOptions) => {
|
|
|
13
29
|
revalidate: false;
|
|
14
30
|
};
|
|
15
31
|
interface CreateDocsMarkdownRouteOptions {
|
|
16
|
-
|
|
32
|
+
filterStaticParams?: (params: DocsMarkdownParams) => boolean;
|
|
33
|
+
source?: SourceBundle;
|
|
34
|
+
sources?: SourceBundle[];
|
|
35
|
+
transform?: MarkdownTransform;
|
|
17
36
|
}
|
|
18
|
-
export declare const createDocsMarkdownRoute: ({ source, }: CreateDocsMarkdownRouteOptions) => {
|
|
37
|
+
export declare const createDocsMarkdownRoute: ({ filterStaticParams, source, sources, transform, }: CreateDocsMarkdownRouteOptions) => {
|
|
19
38
|
GET: (_req: Request, { params }: {
|
|
20
39
|
params: Promise<{
|
|
21
40
|
lang: string;
|
|
22
41
|
slug?: string[];
|
|
23
42
|
}>;
|
|
24
43
|
}) => Promise<Response>;
|
|
25
|
-
generateStaticParams: ({ params, }
|
|
26
|
-
params
|
|
27
|
-
lang
|
|
44
|
+
generateStaticParams: ({ params, }?: {
|
|
45
|
+
params?: Promise<{
|
|
46
|
+
lang?: string;
|
|
28
47
|
}>;
|
|
29
|
-
}) => Promise<
|
|
48
|
+
}) => Promise<DocsMarkdownParams[]>;
|
|
30
49
|
revalidate: false;
|
|
31
50
|
};
|
|
32
51
|
export {};
|
|
@@ -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"}
|