nuxt-llms 0.0.1 → 0.1.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/README.md +164 -2
- package/dist/module.d.mts +3 -28
- package/dist/module.d.ts +3 -28
- package/dist/module.json +1 -1
- package/dist/module.mjs +3 -3
- package/dist/runtime/server/routes/llms.txt.get.js +2 -1
- package/dist/runtime/server/routes/llms_full.txt.get.js +2 -10
- package/dist/runtime/server/utils/hooks.d.ts +13 -2
- package/dist/runtime/server/utils/hooks.js +6 -2
- package/dist/runtime/types.d.ts +33 -0
- package/dist/runtime/types.js +0 -0
- package/dist/types.d.mts +7 -1
- package/dist/types.d.ts +7 -1
- package/package.json +3 -3
- package/dist/runtime/server/tsconfig.json +0 -3
package/README.md
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+

|
|
2
|
+
|
|
1
3
|
# Nuxt LLMs
|
|
2
4
|
|
|
3
5
|
[![npm version][npm-version-src]][npm-version-href]
|
|
@@ -13,7 +15,8 @@ Nuxt LLMs automatically generates [`llms.txt` markdown documentation](https://ll
|
|
|
13
15
|
|
|
14
16
|
## Features
|
|
15
17
|
|
|
16
|
-
- Generates & prerenders `/llms.txt`
|
|
18
|
+
- Generates & prerenders `/llms.txt` automatically
|
|
19
|
+
- Generate & prerenders `/llms_full.txt` when enabled
|
|
17
20
|
- Customizable sections directly from your `nuxt.config.ts`
|
|
18
21
|
- Integrates with Nuxt modules and your application via the runtime hooks system
|
|
19
22
|
|
|
@@ -80,7 +83,166 @@ That's it! You can visit `/llms.txt` to see the generated documentation ✨
|
|
|
80
83
|
- `title`(required): The title of the link
|
|
81
84
|
- `description`: The description of the link
|
|
82
85
|
- `href`(required): The href of the link
|
|
83
|
-
- `notes`: The notes of the documentation. Notes are a special section which always appears at the end of the documentation. Notes are
|
|
86
|
+
- `notes`: The notes of the documentation. Notes are a special section which always appears at the end of the documentation. Notes are useful to add any information about the application or documentation itself.
|
|
87
|
+
- `full`: The `llms_full.txt` configuration. Setting this option will enable the `llms_full.txt` route.
|
|
88
|
+
- `title`: The title of the llms_full documentation
|
|
89
|
+
- `description`: The description of the llms_full documentation
|
|
90
|
+
|
|
91
|
+
## Documentation Formats
|
|
92
|
+
|
|
93
|
+
The module generates two different documentation formats:
|
|
94
|
+
|
|
95
|
+
### llms.txt
|
|
96
|
+
|
|
97
|
+
The `/llms.txt` route generates a concise, structured documentation that follows the [llms.txt specification](https://llmstxt.org/). This format is optimized for both human readability and AI consumption. It includes:
|
|
98
|
+
|
|
99
|
+
- Application title and description
|
|
100
|
+
- Organized sections with titles and descriptions
|
|
101
|
+
- Links with titles, descriptions, and URLs
|
|
102
|
+
- Optional notes section
|
|
103
|
+
|
|
104
|
+
### llms_full.txt
|
|
105
|
+
|
|
106
|
+
The `/llms_full.txt` route provides a more detailed, free-form documentation format. This is useful to reduce crawler traffic on your application and provide a more detailed documentation to your users and LLMs.
|
|
107
|
+
|
|
108
|
+
By default module does not generate the `llms_full.txt` route, you need to enable it by setting `full.title` and `full.description` in your `nuxt.config.ts`.
|
|
109
|
+
|
|
110
|
+
```ts
|
|
111
|
+
export default defineNuxtConfig({
|
|
112
|
+
llms: {
|
|
113
|
+
domain: 'https://example.com',
|
|
114
|
+
title: 'My Application',
|
|
115
|
+
full: {
|
|
116
|
+
title: 'Full Documentation',
|
|
117
|
+
description: 'Full documentation of the application',
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
})
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## Extending the documentation using hooks
|
|
124
|
+
|
|
125
|
+
The module provides a hooks system that allows you to dynamically extend both documentation formats. There are two main hooks:
|
|
126
|
+
|
|
127
|
+
### Available Hooks
|
|
128
|
+
|
|
129
|
+
#### `llms:generate(event, options)`
|
|
130
|
+
|
|
131
|
+
This hook is called for every request to `/llms.txt`. Use this hook to modify the structured documentation, It allows you to add sections, links, and metadata.
|
|
132
|
+
|
|
133
|
+
**Parameters:**
|
|
134
|
+
- `event`: H3Event - The current request event
|
|
135
|
+
- `options`: ModuleOptions - The module options that you can modify to add sections, links, etc.
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
#### `llms:generate:llms_full(event, options, contents)`
|
|
139
|
+
|
|
140
|
+
This hook is called for every request to `/llms_full.txt`. It allows you to add custom content sections in any format.
|
|
141
|
+
|
|
142
|
+
**Parameters:**
|
|
143
|
+
- `event`: H3Event - The current request event
|
|
144
|
+
- `options`: ModuleOptions - The module options that you can modify to add sections, links, etc.
|
|
145
|
+
- `contents`: string[] - Array of content sections you can add to or modify
|
|
146
|
+
|
|
147
|
+
### Using Hooks in Your Application
|
|
148
|
+
|
|
149
|
+
Create a server plugin in your `server/plugins` directory:
|
|
150
|
+
|
|
151
|
+
```ts
|
|
152
|
+
// server/plugins/llms.ts
|
|
153
|
+
export default defineNitroPlugin((nitroApp) => {
|
|
154
|
+
// Method 1: Using the hooks directly
|
|
155
|
+
nitroApp.hooks.hook('llms:generate', (event, options) => {
|
|
156
|
+
// Add a new section to llms.txt
|
|
157
|
+
options.sections.push({
|
|
158
|
+
title: 'API Documentation',
|
|
159
|
+
description: 'REST API endpoints and usage',
|
|
160
|
+
links: [
|
|
161
|
+
{
|
|
162
|
+
title: 'Authentication',
|
|
163
|
+
description: 'API authentication methods',
|
|
164
|
+
href: `${options.domain}/api/auth`
|
|
165
|
+
}
|
|
166
|
+
]
|
|
167
|
+
})
|
|
168
|
+
})
|
|
169
|
+
|
|
170
|
+
// Method 2: Using the helper function
|
|
171
|
+
nitroApp.hooks.hook('llms:generate:full', (event, options, contents) => {
|
|
172
|
+
// Add detailed documentation to llms_full.txt
|
|
173
|
+
contents.push(`## API Authentication
|
|
174
|
+
|
|
175
|
+
### Bearer Token
|
|
176
|
+
To authenticate API requests, include a Bearer token in the Authorization header:
|
|
177
|
+
|
|
178
|
+
\`\`\`
|
|
179
|
+
Authorization: Bearer <your-token>
|
|
180
|
+
\`\`\`
|
|
181
|
+
|
|
182
|
+
### API Keys
|
|
183
|
+
For server-to-server communication, use API keys:
|
|
184
|
+
|
|
185
|
+
\`\`\`
|
|
186
|
+
X-API-Key: <your-api-key>
|
|
187
|
+
\`\`\`
|
|
188
|
+
`)
|
|
189
|
+
})
|
|
190
|
+
})
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
### Using Hooks in Nuxt Modules
|
|
194
|
+
|
|
195
|
+
If you're developing a Nuxt module that needs to extend the LLMs documentation:
|
|
196
|
+
|
|
197
|
+
1. Create a server plugin in your module:
|
|
198
|
+
```ts
|
|
199
|
+
// module/runtime/server/plugins/my-module-llms.ts
|
|
200
|
+
export default defineNitroPlugin((nitroApp) => {
|
|
201
|
+
nitroApp.hooks.hook('llms:generate', (event, options) => {
|
|
202
|
+
options.sections.push({
|
|
203
|
+
title: 'My Module',
|
|
204
|
+
description: 'Documentation for my module features',
|
|
205
|
+
links: [/* ... */]
|
|
206
|
+
})
|
|
207
|
+
})
|
|
208
|
+
})
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
2. Register the plugin in your module setup:
|
|
212
|
+
```ts
|
|
213
|
+
import { defineNuxtModule, addServerPlugin } from '@nuxt/kit'
|
|
214
|
+
import { fileURLToPath } from 'url'
|
|
215
|
+
|
|
216
|
+
export default defineNuxtModule({
|
|
217
|
+
setup(options, nuxt) {
|
|
218
|
+
const runtimeDir = fileURLToPath(new URL('./runtime', import.meta.url))
|
|
219
|
+
addServerPlugin(resolve(runtimeDir, 'server/plugins/my-module-llms'))
|
|
220
|
+
}
|
|
221
|
+
})
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
## Integrations
|
|
225
|
+
|
|
226
|
+
### Nuxt Content
|
|
227
|
+
|
|
228
|
+
Nuxt Content ^3.2.0 comes with built-in support for LLMs documentation. You can use `nuxt-llms` with `@nuxt/content` to efficiently write content and documentation for your website and generate LLM-friendly documentation without extra effort. Content module uses `nuxt-llms` hooks and automatically adds all your contents into `llms.txt` and `llms_full.txt` documentation.
|
|
229
|
+
|
|
230
|
+
All you need is to install both modules and write your content files in the `content` directory.
|
|
231
|
+
|
|
232
|
+
```ts
|
|
233
|
+
export default defineNuxtConfig({
|
|
234
|
+
modules: ['nuxt-llms', '@nuxt/content'],
|
|
235
|
+
llms: {
|
|
236
|
+
domain: 'https://example.com',
|
|
237
|
+
title: 'My Application',
|
|
238
|
+
description: 'My Application Description',
|
|
239
|
+
},
|
|
240
|
+
})
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
Checkout the [Nuxt Content documentation](https://content.nuxt.com/docs/usage/content-pages) for more information on how to write your content files.
|
|
244
|
+
|
|
245
|
+
And checkout the [Nuxt Content llms documentation](https://content.nuxt.com/docs/advanced/llms) for more information on how to customize LLMs contents with `nuxt-llms` and `@nuxt/content`.
|
|
84
246
|
|
|
85
247
|
## 💻 Development
|
|
86
248
|
|
package/dist/module.d.mts
CHANGED
|
@@ -1,32 +1,7 @@
|
|
|
1
1
|
import * as _nuxt_schema from '@nuxt/schema';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
title: string;
|
|
5
|
-
description?: string;
|
|
6
|
-
links?: Array<{
|
|
7
|
-
title: string;
|
|
8
|
-
description?: string;
|
|
9
|
-
href: string;
|
|
10
|
-
}>;
|
|
11
|
-
}
|
|
12
|
-
interface ModuleOptions {
|
|
13
|
-
/**
|
|
14
|
-
* Domain of the documentation
|
|
15
|
-
*/
|
|
16
|
-
domain: string;
|
|
17
|
-
/**
|
|
18
|
-
* Enable the full documentation
|
|
19
|
-
*/
|
|
20
|
-
llmsFull?: {
|
|
21
|
-
title: string;
|
|
22
|
-
description: string;
|
|
23
|
-
};
|
|
24
|
-
sections: Array<LLMsSection>;
|
|
25
|
-
title?: string;
|
|
26
|
-
description?: string;
|
|
27
|
-
notes?: string[];
|
|
28
|
-
}
|
|
2
|
+
import { ModuleOptions } from '../dist/runtime/types.js';
|
|
3
|
+
export * from '../dist/runtime/types.js';
|
|
29
4
|
|
|
30
5
|
declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
|
|
31
6
|
|
|
32
|
-
export {
|
|
7
|
+
export { _default as default };
|
package/dist/module.d.ts
CHANGED
|
@@ -1,32 +1,7 @@
|
|
|
1
1
|
import * as _nuxt_schema from '@nuxt/schema';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
title: string;
|
|
5
|
-
description?: string;
|
|
6
|
-
links?: Array<{
|
|
7
|
-
title: string;
|
|
8
|
-
description?: string;
|
|
9
|
-
href: string;
|
|
10
|
-
}>;
|
|
11
|
-
}
|
|
12
|
-
interface ModuleOptions {
|
|
13
|
-
/**
|
|
14
|
-
* Domain of the documentation
|
|
15
|
-
*/
|
|
16
|
-
domain: string;
|
|
17
|
-
/**
|
|
18
|
-
* Enable the full documentation
|
|
19
|
-
*/
|
|
20
|
-
llmsFull?: {
|
|
21
|
-
title: string;
|
|
22
|
-
description: string;
|
|
23
|
-
};
|
|
24
|
-
sections: Array<LLMsSection>;
|
|
25
|
-
title?: string;
|
|
26
|
-
description?: string;
|
|
27
|
-
notes?: string[];
|
|
28
|
-
}
|
|
2
|
+
import { ModuleOptions } from '../dist/runtime/types.js';
|
|
3
|
+
export * from '../dist/runtime/types.js';
|
|
29
4
|
|
|
30
5
|
declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
|
|
31
6
|
|
|
32
|
-
export {
|
|
7
|
+
export { _default as default };
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -23,13 +23,13 @@ const module = defineNuxtModule({
|
|
|
23
23
|
addServerImports([{ name: "llmsHooks", from: resolve("./runtime/server/utils/hooks") }]);
|
|
24
24
|
addServerHandler({ route: "/llms.txt", handler: resolve("./runtime/server/routes/llms.txt.get") });
|
|
25
25
|
addPrerenderRoutes("/llms.txt");
|
|
26
|
-
if (options.
|
|
26
|
+
if (options.full) {
|
|
27
27
|
llmsConfig.sections.unshift({
|
|
28
28
|
title: "Documentation Sets",
|
|
29
29
|
links: [
|
|
30
30
|
{
|
|
31
|
-
title: options.
|
|
32
|
-
description: options.
|
|
31
|
+
title: options.full.title,
|
|
32
|
+
description: options.full.description,
|
|
33
33
|
href: `${options.domain}/llms_full.txt`
|
|
34
34
|
}
|
|
35
35
|
]
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { eventHandler, setHeader } from "h3";
|
|
2
2
|
import { llmsHooks } from "nuxt-llms/runtime";
|
|
3
|
-
import { useRuntimeConfig } from "#imports";
|
|
3
|
+
import { useRuntimeConfig, useNitroApp } from "#imports";
|
|
4
4
|
export default eventHandler(async (event) => {
|
|
5
5
|
const options = useRuntimeConfig(event).llms;
|
|
6
6
|
const llms = JSON.parse(JSON.stringify(options));
|
|
7
|
+
await useNitroApp().hooks.callHook("llms:generate", event, llms);
|
|
7
8
|
await llmsHooks.callHook("generate", event, llms);
|
|
8
9
|
const document = [
|
|
9
10
|
`# ${llms.title || "Documentation"}`
|
|
@@ -1,20 +1,12 @@
|
|
|
1
1
|
import { eventHandler, setHeader } from "h3";
|
|
2
2
|
import { llmsHooks } from "nuxt-llms/runtime";
|
|
3
|
-
import { useRuntimeConfig } from "#imports";
|
|
3
|
+
import { useRuntimeConfig, useNitroApp } from "#imports";
|
|
4
4
|
export default eventHandler(async (event) => {
|
|
5
5
|
const options = useRuntimeConfig(event).llms;
|
|
6
6
|
const contents = [];
|
|
7
7
|
const llms = JSON.parse(JSON.stringify(options));
|
|
8
|
+
await useNitroApp().hooks.callHook("llms:generate:full", event, llms, contents);
|
|
8
9
|
await llmsHooks.callHook("generate:full", event, llms, contents);
|
|
9
|
-
const document = [
|
|
10
|
-
`# ${llms.llmsFull?.title || "Documentation"}`
|
|
11
|
-
];
|
|
12
|
-
if (llms.description) {
|
|
13
|
-
document.push(`> ${llms.llmsFull?.description}`);
|
|
14
|
-
}
|
|
15
|
-
for (const content of contents) {
|
|
16
|
-
document.push(content);
|
|
17
|
-
}
|
|
18
10
|
setHeader(event, "Content-Type", "text/plain");
|
|
19
11
|
return contents.join("\n\n");
|
|
20
12
|
});
|
|
@@ -1,15 +1,26 @@
|
|
|
1
1
|
import type { H3Event } from 'h3';
|
|
2
2
|
import type { ModuleOptions } from 'nuxt-llms';
|
|
3
|
+
import type { NitroRuntimeHooks } from 'nitropack/types';
|
|
4
|
+
/**
|
|
5
|
+
* @deprecated Custom hooks are deprecated in favor of NitroRuntimeHooks.
|
|
6
|
+
*/
|
|
3
7
|
export interface LLMSHooks {
|
|
4
8
|
'generate': (event: H3Event, options: ModuleOptions) => void;
|
|
5
9
|
'generate:full': (event: H3Event, options: ModuleOptions, contents: string[]) => void;
|
|
6
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* @deprecated Custom hooks are deprecated in favor of NitroRuntimeHooks.
|
|
13
|
+
*/
|
|
7
14
|
export declare const llmsHooks: import("hookable").Hookable<LLMSHooks, import("hookable").HookKeys<LLMSHooks>>;
|
|
8
15
|
/**
|
|
9
16
|
* Run a callback when LLMs is being generated.
|
|
17
|
+
*
|
|
18
|
+
* @deprecated Use `useNitroApp().hooks.hook('llms:generate', (event, options) => {})` instead
|
|
10
19
|
*/
|
|
11
|
-
export declare function onLLMsGenerate(cb:
|
|
20
|
+
export declare function onLLMsGenerate(cb: NitroRuntimeHooks['llms:generate']): any;
|
|
12
21
|
/**
|
|
13
22
|
* Run a callback when Full LLMs is being generated.
|
|
23
|
+
*
|
|
24
|
+
* @deprecated Use `useNitroApp().hooks.hook('llms:generate:full', (event, options, contents) => {})` instead
|
|
14
25
|
*/
|
|
15
|
-
export declare function onLLMsGenerateFull(cb:
|
|
26
|
+
export declare function onLLMsGenerateFull(cb: NitroRuntimeHooks['llms:generate:full']): any;
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import { createHooks } from "hookable";
|
|
2
|
+
import { useNitroApp } from "#imports";
|
|
2
3
|
export const llmsHooks = createHooks();
|
|
4
|
+
llmsHooks.beforeEach(() => {
|
|
5
|
+
console.warn("[nuxt-llms] `llmsHooks` are deprecated and will be removed in future versions. Use `useNitroApp().hooks.hook('llms:generate', (event, options) => {})` instead");
|
|
6
|
+
});
|
|
3
7
|
export function onLLMsGenerate(cb) {
|
|
4
|
-
return
|
|
8
|
+
return useNitroApp().hooks.hook("llms:generate", cb);
|
|
5
9
|
}
|
|
6
10
|
export function onLLMsGenerateFull(cb) {
|
|
7
|
-
return
|
|
11
|
+
return useNitroApp().hooks.hook("llms:generate:full", cb);
|
|
8
12
|
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { H3Event } from 'h3';
|
|
2
|
+
declare module 'nitropack/types' {
|
|
3
|
+
interface NitroRuntimeHooks {
|
|
4
|
+
'llms:generate': (event: H3Event, options: ModuleOptions) => void;
|
|
5
|
+
'llms:generate:full': (event: H3Event, options: ModuleOptions, contents: string[]) => void;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
export interface LLMsSection {
|
|
9
|
+
title: string;
|
|
10
|
+
description?: string;
|
|
11
|
+
links?: Array<{
|
|
12
|
+
title: string;
|
|
13
|
+
description?: string;
|
|
14
|
+
href: string;
|
|
15
|
+
}>;
|
|
16
|
+
}
|
|
17
|
+
export interface ModuleOptions {
|
|
18
|
+
/**
|
|
19
|
+
* Domain of the documentation
|
|
20
|
+
*/
|
|
21
|
+
domain: string;
|
|
22
|
+
/**
|
|
23
|
+
* Enable the full documentation
|
|
24
|
+
*/
|
|
25
|
+
full?: {
|
|
26
|
+
title: string;
|
|
27
|
+
description: string;
|
|
28
|
+
};
|
|
29
|
+
sections: Array<LLMsSection>;
|
|
30
|
+
title?: string;
|
|
31
|
+
description?: string;
|
|
32
|
+
notes?: string[];
|
|
33
|
+
}
|
|
File without changes
|
package/dist/types.d.mts
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import type { NuxtModule } from '@nuxt/schema'
|
|
2
|
+
|
|
3
|
+
import type { default as Module } from './module.js'
|
|
4
|
+
|
|
5
|
+
export type ModuleOptions = typeof Module extends NuxtModule<infer O> ? Partial<O> : Record<string, any>
|
|
6
|
+
|
|
7
|
+
export { default } from './module.js'
|
package/dist/types.d.ts
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import type { NuxtModule } from '@nuxt/schema'
|
|
2
|
+
|
|
3
|
+
import type { default as Module } from './module'
|
|
4
|
+
|
|
5
|
+
export type ModuleOptions = typeof Module extends NuxtModule<infer O> ? Partial<O> : Record<string, any>
|
|
6
|
+
|
|
7
|
+
export { default } from './module'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-llms",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "Generate llms.txt documentation for your Nuxt application",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"type": "module",
|
|
11
11
|
"exports": {
|
|
12
12
|
".": {
|
|
13
|
-
"types": "./dist/
|
|
13
|
+
"types": "./dist/module.d.ts",
|
|
14
14
|
"import": "./dist/module.mjs",
|
|
15
15
|
"require": "./dist/module.cjs"
|
|
16
16
|
},
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
}
|
|
22
22
|
},
|
|
23
23
|
"main": "./dist/module.cjs",
|
|
24
|
-
"types": "./dist/
|
|
24
|
+
"types": "./dist/module.d.ts",
|
|
25
25
|
"files": [
|
|
26
26
|
"dist"
|
|
27
27
|
],
|