Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions __tests__/search-route.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { describe, expect, it, vi } from 'vitest'

// The real fumadocs loader over a small in-memory source, so the route is exercised against the
// same createFromSource the site ships. createFromSource builds each locale's index from
// getPages(), which is what a locale filter has to wrap.
vi.mock('@/lib/source', async () => {
const { loader } = await import('fumadocs-core/source')
const { i18n } = await import('@/lib/i18n')

const page = (path: string, title: string) => ({
type: 'page' as const,
path,
data: {
title,
structuredData: {
headings: [],
contents: [{ heading: undefined, content: `${title} body` }],
},
},
})

return {
docsSource: loader({
baseUrl: '/docs',
i18n,
source: {
files: [
page('guide.mdx', 'Guide'),
page('guide.pt-BR.mdx', 'Guia'),
page('english-only.mdx', 'English only'),
],
},
}),
}
})

import { GET } from '@/app/api/search/[lang]/route'

type ExportedIndex = {
data: Record<
string,
{ docs: { docs: Record<string, { url: string; type: string; content: string }> } }
>
}

async function indexedPages(lang: string): Promise<{ url: string; title: string }[]> {
const response = await GET(new Request(`https://www.librechat.ai/api/search/${lang}`), {
params: Promise.resolve({ lang }),
})
const body = (await response.json()) as ExportedIndex
return Object.values(body.data[lang].docs.docs)
.filter((doc) => doc.type === 'page')
.map((doc) => ({ url: doc.url, title: doc.content }))
.sort((a, b) => a.url.localeCompare(b.url))
}

describe('per-locale search index', () => {
it('keeps every page, translated or not, in the default language index', async () => {
await expect(indexedPages('en')).resolves.toEqual([
{ url: '/docs/english-only', title: 'English only' },
{ url: '/docs/guide', title: 'Guide' },
])
})

it('indexes only the translated pages of a non-default locale', async () => {
await expect(indexedPages('pt-BR')).resolves.toEqual([
{ url: '/pt-BR/docs/guide', title: 'Guia' },
])
})

it('leaves a locale without translations with an empty index instead of an English copy', async () => {
await expect(indexedPages('de')).resolves.toEqual([])
})
})
30 changes: 16 additions & 14 deletions app/api/search/[lang]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,24 @@ export function generateStaticParams() {
// the documents were indexed.
//
// Restrict each non-default locale's index to pages that have a real translated
// file (path ends `.<locale>.mdx`). getLanguages() otherwise includes the English
// fallback for every untranslated page, and those hits resolve to /<locale>/docs/...
// URLs that immediately redirect to English (see the docs page route) — so
// localized search would surface results that bounce. Filtering keeps each locale's
// search consistent with what actually renders under /<locale>/docs/. The default
// language keeps every page.
// file (path ends `.<locale>.mdx`). The loader otherwise fills every locale with
// the English fallback for each untranslated page, and those hits resolve to
// /<locale>/docs/... URLs that immediately redirect to English (see the docs page
// route), so localized search would surface results that bounce. Filtering keeps
// each locale's search consistent with what actually renders under /<locale>/docs/,
// and keeps each prerendered index under Vercel's 20 MB response body limit
// (FALLBACK_BODY_TOO_LARGE). The default language keeps every page.
//
// createFromSource indexes loader.getPages() (every language, grouped by
// page.locale) and never calls getLanguages(), so the filter has to wrap getPages().
const localeFilteredSource: typeof docsSource = {
...docsSource,
getLanguages: () =>
docsSource.getLanguages().map((entry) => ({
language: entry.language,
pages:
entry.language === i18n.defaultLanguage
? entry.pages
: entry.pages.filter((page) => page.path.endsWith(`.${entry.language}.mdx`)),
})),
getPages: (language) =>
docsSource
.getPages(language)
.filter(
(page) => page.locale === i18n.defaultLanguage || page.path.endsWith(`.${page.locale}.mdx`),
),
}

const searchServer = createFromSource(localeFilteredSource, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ These are fields under `interface`:
- `landingHeading`
- `landingFooter`
- `messageAuthor`
- `conversationIcons`
- `runningChatRename`
- `historyCacheTtlMs`
- `historyCacheRecent`
Expand Down Expand Up @@ -1800,7 +1801,7 @@ interface:

## landingHeading

Chooses what heads the welcome screen when an agent, assistant, or branded model spec is selected: its name (`entity`) or the time-of-day greeting with the user's name (`greeting`). Use `greeting` when your header selector already names the entity.
Chooses what heads the welcome screen when an agent, assistant, or branded model spec is selected: its name (`entity`) or the time-of-day greeting with the user's name (`greeting`). Use `greeting` when your header selector already names the entity. In greeting mode the welcome screen also drops the entity's icon, since the selector shows it too.

**Default:** `entity`

Expand All @@ -1822,7 +1823,7 @@ interface:

## messageAuthor

Chooses which responses show the author's avatar and name above their content: all of them (`always`), or only those from an agent other than the one the header's model selector shows (`whenDifferent`). With `whenDifferent`, the selected agent's responses start directly with their content, and screen readers still announce the author. Responses keep their author when no selector is shown, such as with `modelSelect: false` and no model specs, and in read-only subagent threads.
Chooses which responses show the author's avatar and name above their content: all of them (`always`), or only those from an author other than the one the header's model selector shows (`whenDifferent`). The selected author is the saved agent, or, for a conversation without one, the model spec or endpoint and model it runs. With `whenDifferent`, the selected author's responses start directly with their content, and screen readers still announce the author. Responses keep their author when no selector is shown, such as with `modelSelect: false` and no model specs, and in read-only subagent threads.

**Default:** `always`

Expand All @@ -1831,6 +1832,17 @@ interface:
messageAuthor: whenDifferent
```

## conversationIcons

Shows the endpoint, agent, or assistant icon on each row of the sidebar chat history. Set it to `false` when every chat uses the same agent and the repeated icon adds nothing; rows then show only the title, and a running or unread chat still shows its status indicator. The welcome screen, message avatars, the project chat list, and the archived chats table keep their icons.

**Default:** `true`

```yaml filename="interface / conversationIcons"
interface:
conversationIcons: false
```

## runningChatRename

Allows renaming a conversation while it is running. Set to `false` during a rolling upgrade, until every API replica supports title ownership and old title jobs have drained.
Expand Down
Loading