docus 5.4.4 → 5.5.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/app/app.vue +16 -6
- package/app/components/app/AppHeader.vue +5 -0
- package/app/components/docs/DocsAsideRightBottom.vue +28 -1
- package/app/pages/[[lang]]/[...slug].vue +9 -2
- package/app/plugins/i18n.ts +28 -11
- package/app/types/index.d.ts +49 -0
- package/i18n/locales/en.json +27 -0
- package/i18n/locales/fr.json +28 -1
- package/modules/assistant/README.md +213 -0
- package/modules/assistant/index.ts +100 -0
- package/modules/assistant/runtime/components/AssistantChat.vue +21 -0
- package/modules/assistant/runtime/components/AssistantChatDisabled.vue +3 -0
- package/modules/assistant/runtime/components/AssistantFloatingInput.vue +105 -0
- package/modules/assistant/runtime/components/AssistantLoading.vue +164 -0
- package/modules/assistant/runtime/components/AssistantMatrix.vue +92 -0
- package/modules/assistant/runtime/components/AssistantPanel.vue +329 -0
- package/modules/assistant/runtime/components/AssistantPreStream.vue +46 -0
- package/modules/assistant/runtime/composables/useAssistant.ts +107 -0
- package/modules/assistant/runtime/composables/useHighlighter.ts +34 -0
- package/modules/assistant/runtime/server/api/search.ts +111 -0
- package/modules/assistant/runtime/types.ts +7 -0
- package/modules/config.ts +5 -3
- package/modules/css.ts +3 -1
- package/modules/markdown-rewrite.ts +130 -0
- package/nuxt.config.ts +13 -1
- package/nuxt.schema.ts +63 -0
- package/package.json +18 -9
- package/server/routes/sitemap.xml.ts +74 -0
- package/utils/meta.ts +9 -3
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { ShikiCachedRenderer } from 'shiki-stream/vue'
|
|
3
|
+
import { useColorMode } from '#imports'
|
|
4
|
+
import { useHighlighter } from '../composables/useHighlighter'
|
|
5
|
+
|
|
6
|
+
const colorMode = useColorMode()
|
|
7
|
+
const highlighter = await useHighlighter()
|
|
8
|
+
const props = defineProps<{
|
|
9
|
+
code: string
|
|
10
|
+
language: string
|
|
11
|
+
class?: string
|
|
12
|
+
meta?: string
|
|
13
|
+
}>()
|
|
14
|
+
const trimmedCode = computed(() => {
|
|
15
|
+
return props.code.trim().replace(/`+$/, '')
|
|
16
|
+
})
|
|
17
|
+
const lang = computed(() => {
|
|
18
|
+
switch (props.language) {
|
|
19
|
+
case 'vue':
|
|
20
|
+
return 'vue'
|
|
21
|
+
case 'javascript':
|
|
22
|
+
return 'js'
|
|
23
|
+
case 'typescript':
|
|
24
|
+
return 'ts'
|
|
25
|
+
case 'css':
|
|
26
|
+
return 'css'
|
|
27
|
+
default:
|
|
28
|
+
return props.language
|
|
29
|
+
}
|
|
30
|
+
})
|
|
31
|
+
const key = computed(() => {
|
|
32
|
+
return `${lang.value}-${colorMode.value}`
|
|
33
|
+
})
|
|
34
|
+
</script>
|
|
35
|
+
|
|
36
|
+
<template>
|
|
37
|
+
<ProsePre v-bind="props">
|
|
38
|
+
<ShikiCachedRenderer
|
|
39
|
+
:key="key"
|
|
40
|
+
:highlighter="highlighter"
|
|
41
|
+
:code="trimmedCode"
|
|
42
|
+
:lang="lang"
|
|
43
|
+
:theme="colorMode.value === 'dark' ? 'material-theme-palenight' : 'material-theme-lighter'"
|
|
44
|
+
/>
|
|
45
|
+
</ProsePre>
|
|
46
|
+
</template>
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import type { UIMessage } from 'ai'
|
|
2
|
+
import { useMediaQuery } from '@vueuse/core'
|
|
3
|
+
import type { FaqCategory, FaqQuestions, LocalizedFaqQuestions } from '../types'
|
|
4
|
+
|
|
5
|
+
function normalizeFaqQuestions(questions: FaqQuestions): FaqCategory[] {
|
|
6
|
+
if (!questions || (Array.isArray(questions) && questions.length === 0)) {
|
|
7
|
+
return []
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
if (typeof questions[0] === 'string') {
|
|
11
|
+
return [{
|
|
12
|
+
category: 'Questions',
|
|
13
|
+
items: questions as string[],
|
|
14
|
+
}]
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return questions as FaqCategory[]
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const PANEL_WIDTH_COMPACT = 360
|
|
21
|
+
const PANEL_WIDTH_EXPANDED = 520
|
|
22
|
+
|
|
23
|
+
export function useAssistant() {
|
|
24
|
+
const config = useRuntimeConfig()
|
|
25
|
+
const appConfig = useAppConfig()
|
|
26
|
+
const isEnabled = computed(() => config.public.assistant?.enabled ?? false)
|
|
27
|
+
|
|
28
|
+
const isOpen = useState('assistant-open', () => false)
|
|
29
|
+
const isExpanded = useState('assistant-expanded', () => false)
|
|
30
|
+
const messages = useState<UIMessage[]>('assistant-messages', () => [])
|
|
31
|
+
const pendingMessage = useState<string | undefined>('assistant-pending', () => undefined)
|
|
32
|
+
|
|
33
|
+
const isMobile = useMediaQuery('(max-width: 767px)')
|
|
34
|
+
const panelWidth = computed(() => isExpanded.value ? PANEL_WIDTH_EXPANDED : PANEL_WIDTH_COMPACT)
|
|
35
|
+
const shouldPushContent = computed(() => !isMobile.value && isOpen.value)
|
|
36
|
+
|
|
37
|
+
const faqQuestions = computed<FaqCategory[]>(() => {
|
|
38
|
+
const assistantConfig = appConfig.assistant
|
|
39
|
+
const faqConfig = assistantConfig?.faqQuestions
|
|
40
|
+
if (!faqConfig) return []
|
|
41
|
+
|
|
42
|
+
// Check if it's a localized object (has locale keys like 'en', 'fr')
|
|
43
|
+
if (!Array.isArray(faqConfig)) {
|
|
44
|
+
const localizedConfig = faqConfig as LocalizedFaqQuestions
|
|
45
|
+
const currentLocale = appConfig.docus?.locale || 'en'
|
|
46
|
+
const defaultLocale = config.public.i18n?.defaultLocale || 'en'
|
|
47
|
+
|
|
48
|
+
// Try current locale, then default locale, then first available
|
|
49
|
+
const questions = localizedConfig[currentLocale]
|
|
50
|
+
|| localizedConfig[defaultLocale]
|
|
51
|
+
|| Object.values(localizedConfig)[0]
|
|
52
|
+
|
|
53
|
+
return normalizeFaqQuestions(questions || [])
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return normalizeFaqQuestions(faqConfig)
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
function open(initialMessage?: string, clearPrevious = false) {
|
|
60
|
+
if (clearPrevious) {
|
|
61
|
+
messages.value = []
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (initialMessage) {
|
|
65
|
+
pendingMessage.value = initialMessage
|
|
66
|
+
}
|
|
67
|
+
isOpen.value = true
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function clearPending() {
|
|
71
|
+
pendingMessage.value = undefined
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function close() {
|
|
75
|
+
isOpen.value = false
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function toggle() {
|
|
79
|
+
isOpen.value = !isOpen.value
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function clearMessages() {
|
|
83
|
+
messages.value = []
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function toggleExpanded() {
|
|
87
|
+
isExpanded.value = !isExpanded.value
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return {
|
|
91
|
+
isEnabled,
|
|
92
|
+
isOpen,
|
|
93
|
+
isExpanded,
|
|
94
|
+
isMobile,
|
|
95
|
+
panelWidth,
|
|
96
|
+
shouldPushContent,
|
|
97
|
+
messages,
|
|
98
|
+
pendingMessage,
|
|
99
|
+
faqQuestions,
|
|
100
|
+
open,
|
|
101
|
+
clearPending,
|
|
102
|
+
close,
|
|
103
|
+
toggle,
|
|
104
|
+
toggleExpanded,
|
|
105
|
+
clearMessages,
|
|
106
|
+
}
|
|
107
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { createHighlighterCore } from '@shikijs/core'
|
|
2
|
+
import type { HighlighterCore } from '@shikijs/core'
|
|
3
|
+
import { createJavaScriptRegexEngine } from '@shikijs/engine-javascript'
|
|
4
|
+
|
|
5
|
+
let highlighter: HighlighterCore | null = null
|
|
6
|
+
let promise: Promise<HighlighterCore> | null = null
|
|
7
|
+
|
|
8
|
+
export const useHighlighter = async () => {
|
|
9
|
+
if (!promise) {
|
|
10
|
+
promise = createHighlighterCore({
|
|
11
|
+
langs: [
|
|
12
|
+
import('@shikijs/langs/vue'),
|
|
13
|
+
import('@shikijs/langs/javascript'),
|
|
14
|
+
import('@shikijs/langs/typescript'),
|
|
15
|
+
import('@shikijs/langs/css'),
|
|
16
|
+
import('@shikijs/langs/html'),
|
|
17
|
+
import('@shikijs/langs/json'),
|
|
18
|
+
import('@shikijs/langs/yaml'),
|
|
19
|
+
import('@shikijs/langs/markdown'),
|
|
20
|
+
import('@shikijs/langs/bash'),
|
|
21
|
+
],
|
|
22
|
+
themes: [
|
|
23
|
+
import('@shikijs/themes/material-theme-palenight'),
|
|
24
|
+
import('@shikijs/themes/material-theme-lighter'),
|
|
25
|
+
],
|
|
26
|
+
engine: createJavaScriptRegexEngine(),
|
|
27
|
+
})
|
|
28
|
+
}
|
|
29
|
+
if (!highlighter) {
|
|
30
|
+
highlighter = await promise
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return highlighter
|
|
34
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { streamText, convertToModelMessages, createUIMessageStream, createUIMessageStreamResponse } from 'ai'
|
|
2
|
+
import type { UIMessageStreamWriter, ToolCallPart, ToolSet } from 'ai'
|
|
3
|
+
import { createMCPClient } from '@ai-sdk/mcp'
|
|
4
|
+
|
|
5
|
+
const MAX_STEPS = 10
|
|
6
|
+
|
|
7
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
8
|
+
function stopWhenResponseComplete({ steps }: { steps: any[] }): boolean {
|
|
9
|
+
const lastStep = steps.at(-1)
|
|
10
|
+
if (!lastStep) return false
|
|
11
|
+
|
|
12
|
+
// Primary condition: stop when model gives a text response without tool calls
|
|
13
|
+
const hasText = Boolean(lastStep.text && lastStep.text.trim().length > 0)
|
|
14
|
+
const hasNoToolCalls = !lastStep.toolCalls || lastStep.toolCalls.length === 0
|
|
15
|
+
|
|
16
|
+
if (hasText && hasNoToolCalls) return true
|
|
17
|
+
|
|
18
|
+
return steps.length >= MAX_STEPS
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function getSystemPrompt(siteName: string) {
|
|
22
|
+
return `You are the documentation assistant for ${siteName}. Help users navigate and understand the project documentation.
|
|
23
|
+
|
|
24
|
+
**Your identity:**
|
|
25
|
+
- You are an assistant helping users with ${siteName} documentation
|
|
26
|
+
- NEVER use first person ("I", "me", "my") - always refer to the project by name: "${siteName} provides...", "${siteName} supports...", "The project offers..."
|
|
27
|
+
- Be confident and knowledgeable about the project
|
|
28
|
+
- Speak as a helpful guide, not as the documentation itself
|
|
29
|
+
|
|
30
|
+
**Tool usage (CRITICAL):**
|
|
31
|
+
- You have tools: list-pages (discover pages) and get-page (read a page)
|
|
32
|
+
- If a page title clearly matches the question, read it directly without listing first
|
|
33
|
+
- ALWAYS respond with text after using tools - never end with just tool calls
|
|
34
|
+
|
|
35
|
+
**Guidelines:**
|
|
36
|
+
- If you can't find something, say "There is no documentation on that yet" or "${siteName} doesn't cover that topic yet"
|
|
37
|
+
- Be concise, helpful, and direct
|
|
38
|
+
- Guide users like a friendly expert would
|
|
39
|
+
|
|
40
|
+
**FORMATTING RULES (CRITICAL):**
|
|
41
|
+
- NEVER use markdown headings (#, ##, ###, etc.)
|
|
42
|
+
- Use **bold text** for emphasis and section labels
|
|
43
|
+
- Start responses with content directly, never with a heading
|
|
44
|
+
- Use bullet points for lists
|
|
45
|
+
- Keep code examples focused and minimal
|
|
46
|
+
|
|
47
|
+
**Response style:**
|
|
48
|
+
- Conversational but professional
|
|
49
|
+
- "Here's how you can do that:" instead of "The documentation shows:"
|
|
50
|
+
- "${siteName} supports TypeScript out of the box" instead of "I support TypeScript"
|
|
51
|
+
- Provide actionable guidance, not just information dumps`
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export default defineEventHandler(async (event) => {
|
|
55
|
+
const { messages } = await readBody(event)
|
|
56
|
+
const config = useRuntimeConfig()
|
|
57
|
+
const siteConfig = getSiteConfig(event)
|
|
58
|
+
|
|
59
|
+
const siteName = siteConfig.name || 'Documentation'
|
|
60
|
+
|
|
61
|
+
const mcpServer = config.assistant.mcpServer
|
|
62
|
+
const isExternalUrl = mcpServer.startsWith('http://') || mcpServer.startsWith('https://')
|
|
63
|
+
const mcpUrl = isExternalUrl
|
|
64
|
+
? mcpServer
|
|
65
|
+
: import.meta.dev
|
|
66
|
+
? `http://localhost:3000${mcpServer}`
|
|
67
|
+
: `${getRequestURL(event).origin}${mcpServer}`
|
|
68
|
+
|
|
69
|
+
const httpClient = await createMCPClient({
|
|
70
|
+
transport: { type: 'http', url: mcpUrl },
|
|
71
|
+
})
|
|
72
|
+
const mcpTools = await httpClient.tools()
|
|
73
|
+
|
|
74
|
+
const stream = createUIMessageStream({
|
|
75
|
+
execute: async ({ writer }: { writer: UIMessageStreamWriter }) => {
|
|
76
|
+
const modelMessages = await convertToModelMessages(messages)
|
|
77
|
+
const result = streamText({
|
|
78
|
+
model: config.assistant.model,
|
|
79
|
+
maxOutputTokens: 4000,
|
|
80
|
+
maxRetries: 2,
|
|
81
|
+
stopWhen: stopWhenResponseComplete,
|
|
82
|
+
system: getSystemPrompt(siteName),
|
|
83
|
+
messages: modelMessages,
|
|
84
|
+
tools: mcpTools as ToolSet,
|
|
85
|
+
onStepFinish: ({ toolCalls }: { toolCalls: ToolCallPart[] }) => {
|
|
86
|
+
if (toolCalls.length === 0) return
|
|
87
|
+
writer.write({
|
|
88
|
+
id: toolCalls[0]?.toolCallId,
|
|
89
|
+
type: 'data-tool-calls',
|
|
90
|
+
data: {
|
|
91
|
+
tools: toolCalls.map((tc: ToolCallPart) => {
|
|
92
|
+
const args = 'args' in tc ? tc.args : 'input' in tc ? tc.input : {}
|
|
93
|
+
return {
|
|
94
|
+
toolName: tc.toolName,
|
|
95
|
+
toolCallId: tc.toolCallId,
|
|
96
|
+
args,
|
|
97
|
+
}
|
|
98
|
+
}),
|
|
99
|
+
},
|
|
100
|
+
})
|
|
101
|
+
},
|
|
102
|
+
})
|
|
103
|
+
writer.merge(result.toUIMessageStream())
|
|
104
|
+
},
|
|
105
|
+
onFinish: async () => {
|
|
106
|
+
await httpClient.close()
|
|
107
|
+
},
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
return createUIMessageStreamResponse({ stream })
|
|
111
|
+
})
|
package/modules/config.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { createResolver, defineNuxtModule } from '@nuxt/kit'
|
|
1
|
+
import { createResolver, defineNuxtModule, logger } from '@nuxt/kit'
|
|
2
2
|
import { defu } from 'defu'
|
|
3
3
|
import { existsSync } from 'node:fs'
|
|
4
4
|
import { join } from 'node:path'
|
|
5
5
|
import { inferSiteURL, getPackageJsonMetadata } from '../utils/meta'
|
|
6
6
|
import { getGitBranch, getGitEnv, getLocalGitInfo } from '../utils/git'
|
|
7
7
|
|
|
8
|
+
const log = logger.withTag('Docus')
|
|
9
|
+
|
|
8
10
|
export default defineNuxtModule({
|
|
9
11
|
meta: {
|
|
10
12
|
name: 'config',
|
|
@@ -68,11 +70,11 @@ export default defineNuxtModule({
|
|
|
68
70
|
const hasContentFolder = existsSync(contentPath)
|
|
69
71
|
|
|
70
72
|
if (!hasLocaleFile) {
|
|
71
|
-
|
|
73
|
+
log.warn(`Locale file not found: ${localeCode}.json - skipping locale "${localeCode}"`)
|
|
72
74
|
}
|
|
73
75
|
|
|
74
76
|
if (!hasContentFolder) {
|
|
75
|
-
|
|
77
|
+
log.warn(`Content folder not found: content/${localeCode}/ - skipping locale "${localeCode}"`)
|
|
76
78
|
}
|
|
77
79
|
|
|
78
80
|
return hasLocaleFile && hasContentFolder
|
package/modules/css.ts
CHANGED
|
@@ -14,6 +14,7 @@ export default defineNuxtModule({
|
|
|
14
14
|
const uiPath = resolveModulePath('@nuxt/ui', { from: import.meta.url, conditions: ['style'] })
|
|
15
15
|
const tailwindPath = resolveModulePath('tailwindcss', { from: import.meta.url, conditions: ['style'] })
|
|
16
16
|
const layerDir = resolver.resolve('../app')
|
|
17
|
+
const assistantDir = resolver.resolve('../modules/assistant')
|
|
17
18
|
|
|
18
19
|
const cssTemplate = addTemplate({
|
|
19
20
|
filename: 'docus.css',
|
|
@@ -23,7 +24,8 @@ export default defineNuxtModule({
|
|
|
23
24
|
|
|
24
25
|
@source "${contentDir.replace(/\\/g, '/')}/**/*";
|
|
25
26
|
@source "${layerDir.replace(/\\/g, '/')}/**/*";
|
|
26
|
-
@source "../../app.config.ts"
|
|
27
|
+
@source "../../app.config.ts";
|
|
28
|
+
@source "${assistantDir.replace(/\\/g, '/')}/**/*";`
|
|
27
29
|
},
|
|
28
30
|
})
|
|
29
31
|
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { defineNuxtModule, logger } from '@nuxt/kit'
|
|
2
|
+
import { resolve } from 'node:path'
|
|
3
|
+
import { readFile, writeFile } from 'node:fs/promises'
|
|
4
|
+
|
|
5
|
+
const log = logger.withTag('Docus')
|
|
6
|
+
|
|
7
|
+
export default defineNuxtModule({
|
|
8
|
+
meta: {
|
|
9
|
+
name: 'markdown-rewrite',
|
|
10
|
+
},
|
|
11
|
+
setup(_options, nuxt) {
|
|
12
|
+
nuxt.hooks.hook('nitro:init', (nitro) => {
|
|
13
|
+
if (nitro.options.dev || !nitro.options.preset.includes('vercel')) {
|
|
14
|
+
return
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
nitro.hooks.hook('compiled', async () => {
|
|
18
|
+
const vcJSON = resolve(nitro.options.output.dir, 'config.json')
|
|
19
|
+
const vcConfig = JSON.parse(await readFile(vcJSON, 'utf8'))
|
|
20
|
+
|
|
21
|
+
// Check if llms.txt exists before setting up any routes
|
|
22
|
+
let llmsTxt
|
|
23
|
+
const llmsTxtPath = resolve(nitro.options.output.publicDir, 'llms.txt')
|
|
24
|
+
try {
|
|
25
|
+
llmsTxt = await readFile(llmsTxtPath, 'utf-8')
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
log.warn('llms.txt not found, skipping markdown redirect routes')
|
|
29
|
+
return
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Always redirect / to /llms.txt
|
|
33
|
+
const routes = [
|
|
34
|
+
{
|
|
35
|
+
src: '^/$',
|
|
36
|
+
dest: '/llms.txt',
|
|
37
|
+
has: [{ type: 'header', key: 'accept', value: '(.*)text/markdown(.*)' }],
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
src: '^/$',
|
|
41
|
+
dest: '/llms.txt',
|
|
42
|
+
has: [{ type: 'header', key: 'user-agent', value: 'curl/.*' }],
|
|
43
|
+
},
|
|
44
|
+
]
|
|
45
|
+
|
|
46
|
+
// Check if i18n is enabled
|
|
47
|
+
const isI18nEnabled = !!(nuxt.options.i18n && nuxt.options.i18n.locales)
|
|
48
|
+
let localeCodes: string[] = []
|
|
49
|
+
|
|
50
|
+
if (isI18nEnabled) {
|
|
51
|
+
// Get locale codes
|
|
52
|
+
const locales = nuxt.options.i18n.locales || []
|
|
53
|
+
localeCodes = locales.map((locale) => {
|
|
54
|
+
return typeof locale === 'string' ? locale : locale.code
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
// Create a regex pattern for all locales (e.g., "en|fr|es")
|
|
58
|
+
const localePattern = localeCodes.join('|')
|
|
59
|
+
|
|
60
|
+
// Add routes for each locale homepage: /{locale} → /llms.txt
|
|
61
|
+
routes.push(
|
|
62
|
+
{
|
|
63
|
+
src: `^/(${localePattern})$`,
|
|
64
|
+
dest: '/llms.txt',
|
|
65
|
+
has: [{ type: 'header', key: 'accept', value: '(.*)text/markdown(.*)' }],
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
src: `^/(${localePattern})$`,
|
|
69
|
+
dest: '/llms.txt',
|
|
70
|
+
has: [{ type: 'header', key: 'user-agent', value: 'curl/.*' }],
|
|
71
|
+
},
|
|
72
|
+
)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Parse llms.txt to get all documentation pages
|
|
76
|
+
const urlRegex = /\[([^\]]+)\]\((https?:\/\/[^)]+)\)/g
|
|
77
|
+
const matches = [...llmsTxt.matchAll(urlRegex)]
|
|
78
|
+
|
|
79
|
+
for (const match of matches) {
|
|
80
|
+
const url = match[2]
|
|
81
|
+
if (!url) continue
|
|
82
|
+
|
|
83
|
+
try {
|
|
84
|
+
// Extract path from URL
|
|
85
|
+
const urlObj = new URL(url)
|
|
86
|
+
const rawPath = urlObj.pathname
|
|
87
|
+
|
|
88
|
+
// Skip root path (already handled)
|
|
89
|
+
if (rawPath === '/') continue
|
|
90
|
+
|
|
91
|
+
// Only process raw markdown URLs from llms.txt
|
|
92
|
+
if (!rawPath.startsWith('/raw/')) continue
|
|
93
|
+
|
|
94
|
+
// Convert /raw/en/getting-started/installation.md to /en/getting-started/installation
|
|
95
|
+
const pagePath = rawPath.replace('/raw', '').replace(/\.md$/, '')
|
|
96
|
+
|
|
97
|
+
// Skip locale homepages (e.g., /en, /fr) - they already redirect to /llms.txt
|
|
98
|
+
if (isI18nEnabled) {
|
|
99
|
+
const isLocaleHomepage = localeCodes.some(code => pagePath === `/${code}`)
|
|
100
|
+
if (isLocaleHomepage) continue
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Add redirect routes: page URL → raw markdown URL
|
|
104
|
+
const docsRoutes = [
|
|
105
|
+
{
|
|
106
|
+
src: `^${pagePath}$`,
|
|
107
|
+
dest: rawPath,
|
|
108
|
+
has: [{ type: 'header', key: 'accept', value: '(.*)text/markdown(.*)' }],
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
src: `^${pagePath}$`,
|
|
112
|
+
dest: rawPath,
|
|
113
|
+
has: [{ type: 'header', key: 'user-agent', value: 'curl/.*' }],
|
|
114
|
+
},
|
|
115
|
+
]
|
|
116
|
+
routes.push(...docsRoutes)
|
|
117
|
+
}
|
|
118
|
+
catch {
|
|
119
|
+
// Skip invalid URLs
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
vcConfig.routes.unshift(...routes)
|
|
124
|
+
|
|
125
|
+
await writeFile(vcJSON, JSON.stringify(vcConfig, null, 2), 'utf8')
|
|
126
|
+
log.info(`Successfully wrote ${routes.length} routes to ${vcJSON} (serve markdown content to AI agents)`)
|
|
127
|
+
})
|
|
128
|
+
})
|
|
129
|
+
},
|
|
130
|
+
})
|
package/nuxt.config.ts
CHANGED
|
@@ -6,6 +6,7 @@ export default defineNuxtConfig({
|
|
|
6
6
|
modules: [
|
|
7
7
|
resolve('./modules/config'),
|
|
8
8
|
resolve('./modules/routing'),
|
|
9
|
+
resolve('./modules/markdown-rewrite'),
|
|
9
10
|
resolve('./modules/css'),
|
|
10
11
|
'@nuxt/ui',
|
|
11
12
|
'@nuxt/content',
|
|
@@ -19,9 +20,14 @@ export default defineNuxtConfig({
|
|
|
19
20
|
extendViteConfig((config) => {
|
|
20
21
|
config.optimizeDeps ||= {}
|
|
21
22
|
config.optimizeDeps.include ||= []
|
|
22
|
-
config.optimizeDeps.include.push(
|
|
23
|
+
config.optimizeDeps.include.push(
|
|
24
|
+
'@nuxt/content > slugify',
|
|
25
|
+
// Fix @vercel/oidc ESM export issue (transitive dep of @ai-sdk/gateway)
|
|
26
|
+
'@vercel/oidc',
|
|
27
|
+
)
|
|
23
28
|
config.optimizeDeps.include = config.optimizeDeps.include
|
|
24
29
|
.map(id => id.replace(/^@nuxt\/content > /, 'docus > @nuxt/content > '))
|
|
30
|
+
.map(id => id.replace(/^@vercel\/oidc$/, 'docus > @vercel/oidc'))
|
|
25
31
|
})
|
|
26
32
|
},
|
|
27
33
|
],
|
|
@@ -44,6 +50,11 @@ export default defineNuxtConfig({
|
|
|
44
50
|
},
|
|
45
51
|
},
|
|
46
52
|
},
|
|
53
|
+
mdc: {
|
|
54
|
+
highlight: {
|
|
55
|
+
shikiEngine: 'javascript',
|
|
56
|
+
},
|
|
57
|
+
},
|
|
47
58
|
experimental: {
|
|
48
59
|
asyncContext: true,
|
|
49
60
|
},
|
|
@@ -76,6 +87,7 @@ export default defineNuxtConfig({
|
|
|
76
87
|
nitroConfig.prerender = nitroConfig.prerender || {}
|
|
77
88
|
nitroConfig.prerender.routes = nitroConfig.prerender.routes || []
|
|
78
89
|
nitroConfig.prerender.routes.push(...(routes || []))
|
|
90
|
+
nitroConfig.prerender.routes.push('/sitemap.xml')
|
|
79
91
|
},
|
|
80
92
|
},
|
|
81
93
|
icon: {
|
package/nuxt.schema.ts
CHANGED
|
@@ -214,5 +214,68 @@ export default defineNuxtSchema({
|
|
|
214
214
|
}),
|
|
215
215
|
},
|
|
216
216
|
}),
|
|
217
|
+
assistant: group({
|
|
218
|
+
title: 'Assistant',
|
|
219
|
+
description: 'Assistant configuration.',
|
|
220
|
+
icon: 'i-lucide-sparkles',
|
|
221
|
+
fields: {
|
|
222
|
+
floatingInput: field({
|
|
223
|
+
type: 'boolean',
|
|
224
|
+
title: 'Floating Input',
|
|
225
|
+
description: 'Show the floating input at the bottom of documentation pages.',
|
|
226
|
+
icon: 'i-lucide-message-circle',
|
|
227
|
+
default: true,
|
|
228
|
+
}),
|
|
229
|
+
explainWithAi: field({
|
|
230
|
+
type: 'boolean',
|
|
231
|
+
title: 'Explain with AI',
|
|
232
|
+
description: 'Show the "Explain with AI" button in the documentation sidebar.',
|
|
233
|
+
icon: 'i-lucide-brain',
|
|
234
|
+
default: true,
|
|
235
|
+
}),
|
|
236
|
+
faqQuestions: field({
|
|
237
|
+
type: 'array',
|
|
238
|
+
title: 'FAQ Questions',
|
|
239
|
+
description: 'List of FAQ questions. Can be an array of strings or an array of categories with questions.',
|
|
240
|
+
icon: 'i-lucide-help-circle',
|
|
241
|
+
default: [],
|
|
242
|
+
}),
|
|
243
|
+
shortcuts: group({
|
|
244
|
+
title: 'Shortcuts',
|
|
245
|
+
description: 'Keyboard shortcuts configuration.',
|
|
246
|
+
icon: 'i-lucide-keyboard',
|
|
247
|
+
fields: {
|
|
248
|
+
focusInput: field({
|
|
249
|
+
type: 'string',
|
|
250
|
+
title: 'Focus Input',
|
|
251
|
+
description: 'Shortcut to focus the floating input (e.g., meta_i, ctrl_k).',
|
|
252
|
+
icon: 'i-lucide-keyboard',
|
|
253
|
+
default: 'meta_i',
|
|
254
|
+
}),
|
|
255
|
+
},
|
|
256
|
+
}),
|
|
257
|
+
icons: group({
|
|
258
|
+
title: 'Icons',
|
|
259
|
+
description: 'Icons configuration.',
|
|
260
|
+
icon: 'i-lucide-settings',
|
|
261
|
+
fields: {
|
|
262
|
+
trigger: field({
|
|
263
|
+
type: 'icon',
|
|
264
|
+
title: 'Trigger',
|
|
265
|
+
description: 'Icon for the AI chat trigger button and slideover header.',
|
|
266
|
+
icon: 'i-lucide-sparkles',
|
|
267
|
+
default: 'i-lucide-sparkles',
|
|
268
|
+
}),
|
|
269
|
+
explain: field({
|
|
270
|
+
type: 'icon',
|
|
271
|
+
title: 'Explain',
|
|
272
|
+
description: 'Icon for the "Explain with AI" button.',
|
|
273
|
+
icon: 'i-lucide-brain',
|
|
274
|
+
default: 'i-lucide-brain',
|
|
275
|
+
}),
|
|
276
|
+
},
|
|
277
|
+
}),
|
|
278
|
+
},
|
|
279
|
+
}),
|
|
217
280
|
},
|
|
218
281
|
})
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "docus",
|
|
3
3
|
"description": "Nuxt layer for Docus documentation theme",
|
|
4
|
-
"version": "5.
|
|
4
|
+
"version": "5.5.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./nuxt.config.ts",
|
|
7
7
|
"repository": {
|
|
@@ -22,30 +22,39 @@
|
|
|
22
22
|
"README.md"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@
|
|
26
|
-
"@
|
|
25
|
+
"@ai-sdk/gateway": "^3.0.32",
|
|
26
|
+
"@ai-sdk/mcp": "^1.0.18",
|
|
27
|
+
"@ai-sdk/vue": "3.0.69",
|
|
28
|
+
"@iconify-json/lucide": "^1.2.88",
|
|
29
|
+
"@iconify-json/simple-icons": "^1.2.69",
|
|
27
30
|
"@iconify-json/vscode-icons": "^1.2.40",
|
|
28
31
|
"@nuxt/content": "^3.11.0",
|
|
29
32
|
"@nuxt/image": "^2.0.0",
|
|
30
|
-
"@nuxt/kit": "^4.
|
|
31
|
-
"@nuxt/ui": "^4.
|
|
33
|
+
"@nuxt/kit": "^4.3.0",
|
|
34
|
+
"@nuxt/ui": "^4.4.0",
|
|
32
35
|
"@nuxtjs/i18n": "^10.2.1",
|
|
33
36
|
"@nuxtjs/mcp-toolkit": "^0.6.2",
|
|
34
37
|
"@nuxtjs/mdc": "^0.20.0",
|
|
35
|
-
"@nuxtjs/robots": "^5.
|
|
36
|
-
"@vueuse/core": "^14.
|
|
38
|
+
"@nuxtjs/robots": "^5.7.0",
|
|
39
|
+
"@vueuse/core": "^14.2.0",
|
|
40
|
+
"ai": "6.0.69",
|
|
37
41
|
"defu": "^6.1.4",
|
|
38
42
|
"exsolve": "^1.0.8",
|
|
39
43
|
"git-url-parse": "^16.1.0",
|
|
40
44
|
"minimark": "^0.2.0",
|
|
41
|
-
"motion-v": "^1.
|
|
45
|
+
"motion-v": "^1.10.2",
|
|
42
46
|
"nuxt-llms": "^0.2.0",
|
|
43
47
|
"nuxt-og-image": "^5.1.13",
|
|
44
48
|
"pkg-types": "^2.3.0",
|
|
45
49
|
"scule": "^1.3.0",
|
|
50
|
+
"@shikijs/core": "^3.22.0",
|
|
51
|
+
"@shikijs/engine-javascript": "^3.22.0",
|
|
52
|
+
"@shikijs/langs": "^3.22.0",
|
|
53
|
+
"@shikijs/themes": "^3.22.0",
|
|
54
|
+
"shiki-stream": "^0.1.4",
|
|
46
55
|
"tailwindcss": "^4.1.18",
|
|
47
56
|
"ufo": "^1.6.3",
|
|
48
|
-
"zod": "^4.3.
|
|
57
|
+
"zod": "^4.3.6",
|
|
49
58
|
"zod-to-json-schema": "^3.25.1"
|
|
50
59
|
},
|
|
51
60
|
"peerDependencies": {
|