Skip to content

Self-evolving Context Database for AI Agents. Unify Agent Memory, Knowledge RAG and Skills.

feat(docs): add OpenViking-powered search (#2664)

Hao Zheef0cbfcdef80
diff --git a/docs/.vitepress/config.ts b/docs/.vitepress/config.ts
index 7f9d62564..25221b83c 100644
--- a/docs/.vitepress/config.ts
+++ b/docs/.vitepress/config.ts
@@ -133,9 +133,13 @@ const zhNav: DefaultTheme.NavItem[] = [
{ text: navLabels.zh.about, link: '/zh/about/01-about-us', activeMatch: '/zh/about/' }
]
-function collectAllMdFiles(srcDir: string): { relativePath: string; absPath: string }[] {
+function collectAllMdFiles(
+ srcDir: string,
+ options: { includeIndex?: boolean } = {}
+): { relativePath: string; absPath: string }[] {
const results: { relativePath: string; absPath: string }[] = []
const ignored = new Set(['node_modules', '.vitepress'])
+ const includeIndex = options.includeIndex ?? false
function walk(dir: string) {
for (const entry of fs.readdirSync(dir)) {
@@ -144,7 +148,7 @@ function collectAllMdFiles(srcDir: string): { relativePath: string; absPath: str
const stat = fs.statSync(abs)
if (stat.isDirectory()) {
walk(abs)
- } else if (entry.endsWith('.md') && entry !== 'index.md') {
+ } else if (entry.endsWith('.md') && (includeIndex || entry !== 'index.md')) {
results.push({ relativePath: path.relative(srcDir, abs), absPath: abs })
}
}
@@ -154,6 +158,61 @@ function collectAllMdFiles(srcDir: string): { relativePath: string; absPath: str
return results.sort((a, b) => a.relativePath.localeCompare(b.relativePath))
}
+function markdownToSearchText(content: string): string {
+ return content
+ .replace(/^---[\s\S]*?---\s*/m, '')
+ .replace(/```[\s\S]*?```/g, ' ')
+ .replace(/`([^`]+)`/g, '$1')
+ .replace(/!\[[^\]]*\]\([^)]+\)/g, ' ')
+ .replace(/\[([^\]]+)\]\([^)]+\)/g, '$1')
+ .replace(/^\s{0,3}#{1,6}\s+/gm, ' ')
+ .replace(/^\s{0,3}>\s?/gm, ' ')
+ .replace(/^\s*[-*+]\s+/gm, ' ')
+ .replace(/^\s*\|?[\s:-]+\|[\s|:-]*$/gm, ' ')
+ .replace(/\*\*([^*\n]+)\*\*/g, '$1')
+ .replace(/__([^_\n]+)__/g, '$1')
+ .replace(/~~([^~\n]+)~~/g, '$1')
+ .replace(/(^|[\s([{"'(【])\*([^*\n]+)\*(?=$|[\s.,;:!?,。;:!?、)】\])}"'])/g, '$1$2')
+ .replace(/(^|[\s([{"'(【])_([^_\n]+)_(?=$|[\s.,;:!?,。;:!?、)】\])}"'])/g, '$1$2')
+ .replace(/\s+/g, ' ')
+ .trim()
+}
+
+function docsSearchLocale(relativePath: string): 'en' | 'zh' | null {
+ if (relativePath.startsWith('en/')) return 'en'
+ if (relativePath.startsWith('zh/')) return 'zh'
+ return null
+}
+
+function buildDocsSearchRecords(srcDir: string) {
+ return collectAllMdFiles(srcDir, { includeIndex: true })
+ .map(({ relativePath, absPath }) => {
+ const normalizedPath = relativePath.replace(/\\/g, '/')
+ const locale = docsSearchLocale(normalizedPath)
+ if (!locale) return null
+
+ const content = fs.readFileSync(absPath, 'utf-8')
+ const url = `/${normalizedPath.replace(/\.md$/, '')}`.replace(/\/index$/, '')
+ return {
+ locale,
+ path: normalizedPath,
+ text: markdownToSearchText(content),
+ title: titleFromMarkdown(absPath),
+ url
+ }
+ })
+ .filter((record): record is NonNullable<typeof record> => record !== null)
+}
+
+// eslint-disable-next-line @typescript-eslint/no-explicit-any
+function buildDocsSearchIndex(siteConfig: any) {
+ fs.writeFileSync(
+ path.join(siteConfig.outDir, 'docs-search-index.json'),
+ JSON.stringify(buildDocsSearchRecords(siteConfig.srcDir)),
+ 'utf-8'
+ )
+}
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function buildLlmsTxt(siteConfig: any) {
const siteUrl = (process.env.DOCS_SITE_URL || '').replace(/\/$/, '')
@@ -242,6 +301,7 @@ export default defineConfig({
},
buildEnd(siteConfig) {
buildLlmsTxt(siteConfig)
+ buildDocsSearchIndex(siteConfig)
},
vite: {
publicDir: 'images',
@@ -260,6 +320,13 @@ export default defineConfig({
next()
}
})
+ server.middlewares.use((req, res, next) => {
+ const pathname = req.url?.split('?')[0]
+ if (pathname !== '/docs-search-index.json') return next()
+
+ res.setHeader('Content-Type', 'application/json; charset=utf-8')
+ res.end(JSON.stringify(buildDocsSearchRecords(docsRoot)))
+ })
}
}
]
@@ -267,9 +334,6 @@ export default defineConfig({
themeConfig: {
logo: '/ov-logo.png',
logoLink: mainSiteBase,
- search: {
- provider: 'local'
- },
socialLinks: [
{ icon: 'github', link: `https://github.com/${repo}` }
],
diff --git a/docs/.vitepress/theme/OpenVikingSearch.vue b/docs/.vitepress/theme/OpenVikingSearch.vue
new file mode 100644
index 000000000..131d033a5
--- /dev/null
+++ b/docs/.vitepress/theme/OpenVikingSearch.vue
@@ -0,0 +1,586 @@
+<script setup lang="ts">
+import { computed, nextTick, onMounted, onUnmounted, ref, watch } from 'vue'
+import { withBase } from 'vitepress'
+
+type SearchMode = 'semantic' | 'keyword' | 'file'
+type SearchLocale = 'en' | 'zh'
+
+type DocsIndexRecord = {
+ locale: SearchLocale
+ path: string
+ text: string
+ title: string
+ url: string
+}
+
+type DocsSearchResult = {
+ line?: number | null
+ mode?: SearchMode
+ relativePath?: string
+ score?: number | null
+ snippet?: string
+ title?: string
+ uri?: string
+ url?: string
+}
+
+type ResolvedDocsSearchResult = DocsSearchResult & {
+ cleanedSnippet: string
+ resolvedUrl: string
+}
+
+type RemoteSearchFailureReason = 'rate_limited' | 'timeout' | 'unavailable'
+
+type RemoteSearchResponse =
+ | { ok: true; results: DocsSearchResult[] }
+ | { ok: false; reason: RemoteSearchFailureReason }
+
+const PRODUCTION_SEARCH_URL = 'https://openviking.ai/studio/gateway/docs/search'
+const SEARCH_LIMIT = 8
+const REMOTE_SEARCH_DEBOUNCE_MS = 1000
+const REMOTE_SEARCH_TIMEOUT_MS = 10000
+
+const modes: { command: string; label: string; placeholder: string; value: SearchMode }[] = [
+ {
+ command: '/find',
+ label: 'Semantic',
+ placeholder: 'Ask a question about the docs',
+ value: 'semantic'
+ },
+ {
+ command: '/grep',
+ label: 'Keyword',
+ placeholder: 'Search exact words in the docs',
+ value: 'keyword'
+ },
+ {
+ command: '/glob',
+ label: 'File',
+ placeholder: 'Find docs by path or filename',
+ value: 'file'
+ }
+]
+
+const inputRef = ref<HTMLInputElement | null>(null)
+const triggerRef = ref<HTMLButtonElement | null>(null)
+const dialogRef = ref<HTMLElement | null>(null)
+const isOpen = ref(false)
+const isMounted = ref(false)
+const isLoading = ref(false)
+const isModeMenuOpen = ref(false)
+const mode = ref<SearchMode>('semantic')
+const query = ref('')
+const results = ref<DocsSearchResult[]>([])
+const notice = ref('')
+
+let debounceTimer: ReturnType<typeof window.setTimeout> | null = null
+let searchSequence = 0
+let localIndexPromise: Promise<DocsIndexRecord[]> | null = null
+let activeSearchController: AbortController | null = null
+
+const trimmedQuery = computed(() => query.value.trim())
+const activeMode = computed(() => modes.find((item) => item.value === mode.value) ?? modes[0])
+const resolvedResults = computed<ResolvedDocsSearchResult[]>(() =>
+ results.value.flatMap((result) => {
+ const resolvedUrl = resultUrl(result)
+ return resolvedUrl ? [{ ...result, cleanedSnippet: cleanSearchSnippet(result.snippet), resolvedUrl }] : []
+ })
+)
+
+function docsLocale(): SearchLocale {
+ const basePath = normalizeBasePath(import.meta.env.BASE_URL)
+ const pathname = window.location.pathname
+ const localizedPath = pathname.startsWith(basePath)
+ ? pathname.slice(basePath.length - 1)
+ : pathname
+
+ return localizedPath.startsWith('/zh/') ? 'zh' : 'en'
+}
+
+function normalizeBasePath(basePath: string) {
+ if (!basePath || basePath === '/') return '/'
+ return `/${basePath.replace(/^\/+|\/+$/g, '')}/`
+}
+
+function openSearch() {
+ isOpen.value = true
+ void nextTick(() => inputRef.value?.focus())
+ scheduleSearch()
+}
+
+function closeSearch() {
+ const shouldRestoreFocus = isOpen.value
+ isOpen.value = false
+ isModeMenuOpen.value = false
+ clearPendingSearch()
+ cancelActiveSearch()
+ if (shouldRestoreFocus) {
+ void nextTick(() => triggerRef.value?.focus())
+ }
+}
+
+function toggleModeMenu() {
+ isModeMenuOpen.value = !isModeMenuOpen.value
+}
+
+function selectMode(value: SearchMode) {
+ mode.value = value
+ isModeMenuOpen.value = false
+ void nextTick(() => inputRef.value?.focus())
+}
+
+function shouldIgnoreShortcut(event: KeyboardEvent) {
+ const target = event.target
+ if (!(target instanceof HTMLElement)) return false
+
+ const tagName = target.tagName.toLowerCase()
+ return target.isContentEditable || ['input', 'textarea', 'select'].includes(tagName)
+}
+
+function handleKeydown(event: KeyboardEvent) {
+ if (event.key === 'Escape' && isModeMenuOpen.value) {
+ isModeMenuOpen.value = false
+ return
+ }
+
+ if (event.key === 'Escape' && isOpen.value) {
+ closeSearch()
+ return
+ }
+
+ const opensWithSlash = event.key === '/' && !shouldIgnoreShortcut(event)
+ const opensWithK = event.key.toLowerCase() === 'k' && (event.metaKey || event.ctrlKey)
+ if (!opensWithSlash && !opensWithK) return
+
+ event.preventDefault()
+ openSearch()
+}
+
+function handleDialogKeydown(event: KeyboardEvent) {
+ if (event.key !== 'Tab') return
+
+ const focusable = dialogFocusableElements()
+ if (focusable.length === 0) {
+ event.preventDefault()
+ return
+ }
+
+ const first = focusable[0]
+ const last = focusable[focusable.length - 1]
+ const activeElement = document.activeElement
+
+ if (event.shiftKey && activeElement === first) {
+ event.preventDefault()
+ last.focus()
+ return
+ }
+
+ if (!event.shiftKey && activeElement === last) {
+ event.preventDefault()
+ first.focus()
+ }
+}
+
+function dialogFocusableElements() {
+ const elements = dialogRef.value?.querySelectorAll<HTMLElement>(
+ [
+ 'a[href]',
+ 'button:not([disabled])',
+ 'input:not([disabled])',
+ 'select:not([disabled])',
+ 'textarea:not([disabled])',
+ '[tabindex]:not([tabindex="-1"])'
+ ].join(',')
+ )
+
+ return Array.from(elements ?? []).filter((element) => element.tabIndex >= 0)
+}
+
+function scheduleSearch() {
+ clearPendingSearch()
+
+ debounceTimer = window.setTimeout(() => {
+ void runSearch()
+ }, REMOTE_SEARCH_DEBOUNCE_MS)
+}
+
+async function runSearch() {
+ cancelActiveSearch()
+ const currentQuery = trimmedQuery.value
+ const currentSequence = ++searchSequence
+ notice.value = ''
+
+ if (!currentQuery) {
+ results.value = []
+ isLoading.value = false
+ return
+ }
+
+ isLoading.value = true
+ const controller = new AbortController()
+ activeSearchController = controller
+
+ try {
+ const remoteResponse = await fetchRemoteResults(
+ PRODUCTION_SEARCH_URL,
+ currentQuery,
+ mode.value,
+ docsLocale(),
+ controller
+ )
+
+ if (currentSequence !== searchSequence) return
+
+ if (remoteResponse?.ok) {
+ results.value = remoteResponse.results
+ return
+ }
+
+ const localResults = await searchLocalIndex(currentQuery, mode.value, docsLocale())
+ if (currentSequence !== searchSequence) return
+
+ results.value = localResults
+ if (remoteResponse && !remoteResponse.ok) {
+ notice.value = fallbackNotice(remoteResponse.reason, localResults.length)
+ }
+ } finally {
+ if (activeSearchController === controller) {
+ activeSearchController = null
+ }
+ if (currentSequence === searchSequence) {
+ isLoading.value = false
+ }
+ }
+}
+
+async function fetchRemoteResults(
+ endpoint: string,
+ searchQuery: string,
+ searchMode: SearchMode,
+ locale: SearchLocale,
+ controller: AbortController
+) {
+ const timeout = window.setTimeout(() => {
+ controller.abort('timeout')
+ }, REMOTE_SEARCH_TIMEOUT_MS)
+
+ try {
+ const response = await fetch(endpoint, {
+ body: JSON.stringify({
+ limit: SEARCH_LIMIT,
+ locale,
+ mode: searchMode,
+ query: searchQuery
+ }),
+ headers: {
+ Accept: 'application/json',
+ 'Content-Type': 'application/json'
+ },
+ method: 'POST',
+ signal: controller.signal
+ })
+
+ if (response.status === 429) {
+ return { ok: false, reason: 'rate_limited' } satisfies RemoteSearchResponse
+ }
+ if (!response.ok) {
+ return { ok: false, reason: 'unavailable' } satisfies RemoteSearchResponse
+ }
+
+ const payload = (await response.json()) as { results?: DocsSearchResult[] }
+ return {
+ ok: true,
+ results: Array.isArray(payload.results) ? payload.results : []
+ } satisfies RemoteSearchResponse
+ } catch (error) {
+ const isTimeout =
+ controller.signal.reason === 'timeout' ||
+ (error instanceof DOMException && error.name === 'TimeoutError')
+ return {
+ ok: false,
+ reason: isTimeout ? 'timeout' : 'unavailable'
+ } satisfies RemoteSearchResponse
+ } finally {
+ window.clearTimeout(timeout)
+ }
+}
+
+function cancelActiveSearch() {
+ if (activeSearchController && !activeSearchController.signal.aborted) {
+ activeSearchController.abort('superseded')
+ }
+ activeSearchController = null
+ searchSequence += 1
+}
+
+function clearPendingSearch() {
+ if (debounceTimer) {
+ window.clearTimeout(debounceTimer)
+ debounceTimer = null
+ }
+}
+
+function fallbackNotice(reason: RemoteSearchFailureReason, localResultCount: number) {
+ const prefix =
+ reason === 'rate_limited'
+ ? 'OpenViking search is rate limited.'
+ : reason === 'timeout'
+ ? 'OpenViking search timed out.'
+ : 'OpenViking search is unavailable.'
+
+ return localResultCount > 0
+ ? `${prefix} Showing local docs results.`
+ : `${prefix} No local results found.`
+}
+
+async function loadLocalIndex() {
+ localIndexPromise ??= fetch(withBase('/docs-search-index.json'))
+ .then((response) => {
+ if (!response.ok) {
+ localIndexPromise = null
+ return []
+ }
+
+ return response.json()
+ })
+ .then((payload) => (Array.isArray(payload) ? (payload as DocsIndexRecord[]) : []))
+ .catch((error) => {
+ localIndexPromise = null
+ console.warn('Failed to load local docs search index.', error)
+ return []
+ })
+
+ return localIndexPromise
+}
+
+async function searchLocalIndex(
+ searchQuery: string,
+ searchMode: SearchMode,
+ locale: SearchLocale
+) {
+ const index = await loadLocalIndex()
+ const normalizedQuery = searchQuery.toLowerCase()
+
+ return index
+ .filter((item) => item.locale === locale)
+ .map((item) => localScore(item, normalizedQuery, searchMode))
+ .filter((item): item is DocsSearchResult & { score: number } => item.score > 0)
+ .sort((a, b) => b.score - a.score || String(a.title).localeCompare(String(b.title)))
+ .slice(0, SEARCH_LIMIT)
+}
+
+function localScore(record: DocsIndexRecord, normalizedQuery: string, searchMode: SearchMode) {
+ const title = record.title.toLowerCase()
+ const path = record.path.toLowerCase()
+ const text = record.text.toLowerCase()
+ const fileMode = searchMode === 'file'
+ const titleMatch = title.includes(normalizedQuery)
+ const pathMatch = path.includes(normalizedQuery)
+ const textMatch = !fileMode && text.includes(normalizedQuery)
+ const score = (titleMatch ? 5 : 0) + (pathMatch ? 3 : 0) + (textMatch ? 1 : 0)
+
+ return {
+ mode: searchMode,
+ relativePath: record.path,
+ score,
+ snippet: fileMode
+ ? record.path
+ : localSnippet(record.text, normalizedQuery),
+ title: record.title,
+ url: record.url
+ }
+}
+
+function localSnippet(text: string, normalizedQuery: string) {
+ const normalizedText = text.toLowerCase()
+ const index = normalizedText.indexOf(normalizedQuery)
+ if (index < 0) return text.slice(0, 180)
+
+ const start = Math.max(0, index - 70)
+ const end = Math.min(text.length, index + normalizedQuery.length + 110)
+ const prefix = start > 0 ? '...' : ''
+ const suffix = end < text.length ? '...' : ''
+ return `${prefix}${text.slice(start, end)}${suffix}`
+}
+
+function cleanSearchSnippet(value: string | undefined) {
+ if (!value) return ''
+
+ return value
+ .replace(/!\[([^\]]*)\]\([^)]+\)/g, '$1')
+ .replace(/\[([^\]]+)\]\([^)]+\)/g, '$1')
+ .replace(/`([^`]+)`/g, '$1')
+ .replace(/\*\*([^*]+)\*\*/g, '$1')
+ .replace(/__([^_]+)__/g, '$1')
+ .replace(/(^|[\s([{"'(【])\*([^*\n]+)\*(?=$|[\s.,;:!?,。;:!?、)】\])}"'])/g, '$1$2')
+ .replace(/(^|[\s([{"'(【])_([^_\n]+)_(?=$|[\s.,;:!?,。;:!?、)】\])}"'])/g, '$1$2')
+ .replace(/^\s{0,3}#{1,6}\s+/gm, '')
+ .replace(/^\s*[-*+]\s+/gm, '')
+ .replace(/^\s*\|?[\s:-]+\|[\s|:-]*$/gm, '')
+ .split('\n')
+ .map((line) => line
+ .replace(/^\s*\|\s*/, '')
+ .replace(/\s*\|\s*$/, '')
+ .replace(/\s*\|\s*/g, ' - ')
+ .trim())
+ .filter(Boolean)
+ .join(' ')
+ .replace(/\s+/g, ' ')
+ .trim()
+}
+
+function resultUrl(result: DocsSearchResult) {
+ const url =
+ result.url ||
+ routeFromRelativePath(result.relativePath, docsLocale()) ||
+ routeFromVikingUri(result.uri)
+
+ if (!url) return ''
+
+ if (/^https?:\/\//.test(url)) return url
+ return withBase(url)
+}
+
+function routeFromRelativePath(path: string | undefined, locale: SearchLocale) {
+ if (!path) return ''
+
+ const normalizedPath = path.replace(/^\/+/, '').replace(/^docs\//, '')
+ const localeMatch = normalizedPath.match(/^(en|zh)\/(.+)$/)
+ if (localeMatch) {
+ return `/${localeMatch[1]}/${stripMarkdownExtension(localeMatch[2])}`
+ }
+
+ return `/${locale}/${stripMarkdownExtension(normalizedPath)}`
+}
+
+function routeFromVikingUri(uri: string | undefined) {
+ if (!uri) return ''
+
+ const match = uri.match(/\/docs\/(en|zh)\/(.+)$/)
+ if (!match) return ''
+
+ return `/${match[1]}/${stripMarkdownExtension(match[2])}`
+}
+
+function stripMarkdownExtension(path: string) {
+ return path.replace(/(?:\/index)?\.mdx?$/, '')
+}
+
+watch([query, mode], scheduleSearch)
+
+onMounted(() => {
+ isMounted.value = true
+ window.addEventListener('keydown', handleKeydown)
+})
+
+onUnmounted(() => {
+ window.removeEventListener('keydown', handleKeydown)
+ clearPendingSearch()
+ cancelActiveSearch()
+})
+</script>
+
+<template>
+ <div class="ov-docs-search">
+ <button
+ ref="triggerRef"
+ aria-label="Search docs"
+ class="ov-docs-search-trigger"
+ type="button"
+ @click="openSearch"
+ >
+ <span class="ov-docs-search-trigger-label">Search docs</span>
+ <span aria-hidden="true" class="ov-docs-search-trigger-compact">Search</span>
+ <kbd>Ctrl K</kbd>
+ </button>
+
+ <Teleport v-if="isMounted && isOpen" to="body">
+ <div class="ov-docs-search-backdrop" @click.self="closeSearch">
+ <section
+ ref="dialogRef"
+ aria-label="OpenViking docs search"
+ aria-modal="true"
+ class="ov-docs-search-dialog"
+ role="dialog"
+ @keydown="handleDialogKeydown"
+ >
+ <div class="ov-docs-search-bar">
+ <div class="ov-docs-search-mode-picker">
+ <button
+ aria-controls="ov-docs-search-mode-menu"
+ :aria-expanded="isModeMenuOpen"
+ aria-haspopup="listbox"
+ aria-label="Search mode"
+ class="ov-docs-search-mode-button"
+ type="button"
+ @click="toggleModeMenu"
+ >
+ <span>{{ activeMode.label }}</span>
+ <span aria-hidden="true" class="ov-docs-search-mode-caret"></span>
+ </button>
+
+ <div
+ v-if="isModeMenuOpen"
+ id="ov-docs-search-mode-menu"
+ aria-label="Search mode options"
+ class="ov-docs-search-mode-menu"
+ role="listbox"
+ >
+ <button
+ v-for="item in modes"
+ :key="item.value"
+ :aria-selected="item.value === mode"
+ class="ov-docs-search-mode-option"
+ :class="{ 'is-selected': item.value === mode }"
+ role="option"
+ type="button"
+ @click="selectMode(item.value)"
+ >
+ <span>{{ item.label }}</span>
+ <code>{{ item.command }}</code>
+ </button>
+ </div>
+ </div>
+
+ <input
+ ref="inputRef"
+ v-model="query"
+ aria-label="Search OpenViking docs"
+ class="ov-docs-search-input"
+ :placeholder="activeMode.placeholder"
+ type="search"
+ @focus="isModeMenuOpen = false"
+ >
+ </div>
+
+ <p v-if="notice" class="ov-docs-search-notice">{{ notice }}</p>
+
+ <div class="ov-docs-search-results">
+ <p v-if="isLoading" class="ov-docs-search-empty">Searching...</p>
+ <p v-else-if="trimmedQuery && resolvedResults.length === 0" class="ov-docs-search-empty">
+ No results found.
+ </p>
+ <p v-else-if="!trimmedQuery" class="ov-docs-search-empty">
+ Type a query to search the current language docs.
+ </p>
+ <template v-else>
+ <a
+ v-for="result in resolvedResults"
+ :key="`${result.resolvedUrl}-${result.line ?? ''}-${result.snippet ?? ''}`"
+ class="ov-docs-search-result"
+ :href="result.resolvedUrl"
+ @click="closeSearch"
+ >
+ <span class="ov-docs-search-result-title">{{ result.title }}</span>
+ <span v-if="result.cleanedSnippet" class="ov-docs-search-result-snippet">
+ {{ result.cleanedSnippet }}
+ </span>
+ <span class="ov-docs-search-result-path">{{ result.relativePath }}</span>
+ </a>
+ </template>
+ </div>
+ </section>
+ </div>
+ </Teleport>
+ </div>
+</template>
diff --git a/docs/.vitepress/theme/custom.css b/docs/.vitepress/theme/custom.css
index 2c3162c36..c7f38c8a4 100644
--- a/docs/.vitepress/theme/custom.css
+++ b/docs/.vitepress/theme/custom.css
@@ -63,3 +63,269 @@
display: none !important;
}
}
+
+.VPNavBarSearch {
+ display: none !important;
+}
+
+.ov-docs-search {
+ display: flex;
+ align-items: center;
+ margin-right: 12px;
+}
+
+.ov-docs-search-trigger {
+ display: inline-flex;
+ align-items: center;
+ gap: 10px;
+ height: 40px;
+ min-width: 190px;
+ max-width: 260px;
+ padding: 0 10px 0 14px;
+ border: 1px solid var(--vp-c-divider);
+ border-radius: 8px;
+ background: var(--vp-c-bg-alt);
+ color: var(--vp-c-text-2);
+ font-size: 14px;
+ line-height: 1;
+ cursor: pointer;
+}
+
+.ov-docs-search-trigger:hover {
+ border-color: var(--vp-c-brand-1);
+ color: var(--vp-c-text-1);
+}
+
+.ov-docs-search-trigger-label {
+ flex: 1;
+ overflow: hidden;
+ text-align: left;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+}
+
+.ov-docs-search-trigger-compact {
+ display: none;
+}
+
+.ov-docs-search-trigger kbd {
+ flex: 0 0 auto;
+ min-width: 46px;
+ padding: 4px 6px;
+ border: 1px solid var(--vp-c-divider);
+ border-radius: 6px;
+ background: var(--vp-c-bg);
+ color: var(--vp-c-text-3);
+ font-family: var(--vp-font-family-mono);
+ font-size: 11px;
+ font-weight: 600;
+ text-align: center;
+}
+
+.ov-docs-search-backdrop {
+ position: fixed;
+ inset: 0;
+ z-index: 100;
+ display: flex;
+ align-items: flex-start;
+ justify-content: center;
+ padding: 84px 20px 24px;
+ background: rgba(0, 0, 0, 0.36);
+}
+
+.ov-docs-search-dialog {
+ width: min(720px, 100%);
+ max-height: min(720px, calc(100vh - 108px));
+ overflow: visible;
+ border: 1px solid var(--vp-c-divider);
+ border-radius: 8px;
+ background: var(--vp-c-bg);
+ box-shadow: 0 22px 70px rgba(0, 0, 0, 0.28);
+}
+
+.ov-docs-search-bar {
+ display: grid;
+ grid-template-columns: 150px minmax(0, 1fr);
+ gap: 10px;
+ padding: 14px;
+ border-bottom: 1px solid var(--vp-c-divider);
+}
+
+.ov-docs-search-mode-button,
+.ov-docs-search-input {
+ height: 42px;
+ border: 1px solid var(--vp-c-divider);
+ border-radius: 8px;
+ background: var(--vp-c-bg-soft);
+ color: var(--vp-c-text-1);
+ font: inherit;
+}
+
+.ov-docs-search-mode-picker {
+ position: relative;
+}
+
+.ov-docs-search-mode-button {
+ display: flex;
+ width: 100%;
+ align-items: center;
+ justify-content: space-between;
+ gap: 10px;
+ padding: 0 12px;
+ cursor: pointer;
+ text-align: left;
+}
+
+.ov-docs-search-mode-button span:first-child {
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+}
+
+.ov-docs-search-mode-caret {
+ width: 7px;
+ height: 7px;
+ flex: 0 0 auto;
+ border-right: 1.5px solid currentColor;
+ border-bottom: 1.5px solid currentColor;
+ opacity: 0.7;
+ transform: translateY(-2px) rotate(45deg);
+}
+
+.ov-docs-search-mode-menu {
+ position: absolute;
+ top: calc(100% + 8px);
+ left: 0;
+ z-index: 2;
+ width: 210px;
+ overflow: hidden;
+ border: 1px solid var(--vp-c-divider);
+ border-radius: 8px;
+ background: var(--vp-c-bg-elv);
+ box-shadow: 0 18px 48px rgba(0, 0, 0, 0.24);
+}
+
+.ov-docs-search-mode-option {
+ display: flex;
+ width: 100%;
+ align-items: center;
+ justify-content: space-between;
+ gap: 16px;
+ padding: 11px 12px;
+ border: 0;
+ background: transparent;
+ color: var(--vp-c-text-1);
+ cursor: pointer;
+ font: inherit;
+ text-align: left;
+}
+
+.ov-docs-search-mode-option:hover,
+.ov-docs-search-mode-option.is-selected {
+ background: var(--vp-c-bg-soft);
+}
+
+.ov-docs-search-mode-option code {
+ color: var(--vp-c-text-3);
+ font-family: var(--vp-font-family-mono);
+ font-size: 12px;
+}
+
+.ov-docs-search-input {
+ min-width: 0;
+ padding: 0 13px;
+}
+
+.ov-docs-search-input:focus,
+.ov-docs-search-mode-button:focus {
+ border-color: var(--vp-c-brand-1);
+ outline: 2px solid var(--vp-c-brand-soft);
+}
+
+.ov-docs-search-notice {
+ margin: 0;
+ padding: 9px 14px;
+ border-bottom: 1px solid var(--vp-c-divider);
+ color: var(--vp-c-text-2);
+ font-size: 13px;
+}
+
+.ov-docs-search-results {
+ max-height: min(560px, calc(100vh - 218px));
+ overflow: auto;
+ padding: 8px;
+}
+
+.ov-docs-search-empty {
+ margin: 0;
+ padding: 34px 18px;
+ color: var(--vp-c-text-2);
+ text-align: center;
+}
+
+.ov-docs-search-result {
+ display: grid;
+ gap: 6px;
+ padding: 12px;
+ border-radius: 8px;
+ color: inherit;
+ text-decoration: none;
+}
+
+.ov-docs-search-result:hover {
+ background: var(--vp-c-bg-soft);
+}
+
+.ov-docs-search-result-title {
+ color: var(--vp-c-text-1);
+ font-size: 15px;
+ font-weight: 700;
+}
+
+.ov-docs-search-result-snippet {
+ display: -webkit-box;
+ overflow: hidden;
+ color: var(--vp-c-text-2);
+ font-size: 13px;
+ line-height: 1.55;
+ -webkit-box-orient: vertical;
+ -webkit-line-clamp: 2;
+}
+
+.ov-docs-search-result-path {
+ overflow: hidden;
+ color: var(--vp-c-text-3);
+ font-family: var(--vp-font-family-mono);
+ font-size: 12px;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+}
+
+@media (max-width: 767px) {
+ .ov-docs-search-trigger {
+ min-width: 72px;
+ width: 72px;
+ padding: 0 12px;
+ justify-content: center;
+ }
+
+ .ov-docs-search-trigger-label,
+ .ov-docs-search-trigger kbd {
+ display: none;
+ }
+
+ .ov-docs-search-trigger-compact {
+ display: inline;
+ color: var(--vp-c-text-2);
+ font-size: 13px;
+ font-weight: 600;
+ }
+
+ .ov-docs-search-backdrop {
+ padding: 58px 12px 16px;
+ }
+
+ .ov-docs-search-bar {
+ grid-template-columns: 1fr;
+ }
+}
diff --git a/docs/.vitepress/theme/index.ts b/docs/.vitepress/theme/index.ts
index e1329c920..4499da9bb 100644
--- a/docs/.vitepress/theme/index.ts
+++ b/docs/.vitepress/theme/index.ts
@@ -2,6 +2,7 @@ import { h } from 'vue'
import DefaultTheme from 'vitepress/theme'
import CopyMarkdownButton from './CopyMarkdownButton.vue'
import LlmsTxtLink from './LlmsTxtLink.vue'
+import OpenVikingSearch from './OpenVikingSearch.vue'
import './custom.css'
type OpenVikingPreference = {
@@ -300,7 +301,8 @@ export default {
Layout() {
return h(DefaultTheme.Layout, null, {
'doc-before': () => h(CopyMarkdownButton),
- 'doc-footer-before': () => h(LlmsTxtLink)
+ 'doc-footer-before': () => h(LlmsTxtLink),
+ 'nav-bar-content-before': () => h(OpenVikingSearch)
})
}
}