nuxt-llms 0.0.2 → 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 CHANGED
@@ -1,3 +1,5 @@
1
+ ![nuxt-llms-social-card](https://github.com/user-attachments/assets/4570398c-0e49-4199-bc30-ab72f6680f4b)
2
+
1
3
  # Nuxt LLMs
2
4
 
3
5
  [![npm version][npm-version-src]][npm-version-href]
@@ -81,7 +83,7 @@ That's it! You can visit `/llms.txt` to see the generated documentation ✨
81
83
  - `title`(required): The title of the link
82
84
  - `description`: The description of the link
83
85
  - `href`(required): The href of the link
84
- - `notes`: The notes of the documentation. Notes are a special section which always appears at the end of the documentation. Notes are usefull to add any information about the application or documentation itself.
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.
85
87
  - `full`: The `llms_full.txt` configuration. Setting this option will enable the `llms_full.txt` route.
86
88
  - `title`: The title of the llms_full documentation
87
89
  - `description`: The description of the llms_full documentation
@@ -124,7 +126,7 @@ The module provides a hooks system that allows you to dynamically extend both do
124
126
 
125
127
  ### Available Hooks
126
128
 
127
- #### `generate:llms(event, options)`
129
+ #### `llms:generate(event, options)`
128
130
 
129
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.
130
132
 
@@ -133,7 +135,7 @@ This hook is called for every request to `/llms.txt`. Use this hook to modify th
133
135
  - `options`: ModuleOptions - The module options that you can modify to add sections, links, etc.
134
136
 
135
137
 
136
- #### `generate:llms_full(event, options, contents)`
138
+ #### `llms:generate:llms_full(event, options, contents)`
137
139
 
138
140
  This hook is called for every request to `/llms_full.txt`. It allows you to add custom content sections in any format.
139
141
 
@@ -148,11 +150,9 @@ Create a server plugin in your `server/plugins` directory:
148
150
 
149
151
  ```ts
150
152
  // server/plugins/llms.ts
151
- import { onLLMsGenerate, onLLMsGenerateFull, llmsHooks } from 'nuxt-llms/runtime'
152
-
153
- export default defineNitroPlugin(() => {
153
+ export default defineNitroPlugin((nitroApp) => {
154
154
  // Method 1: Using the hooks directly
155
- llmsHooks.hook('generate', (event, options) => {
155
+ nitroApp.hooks.hook('llms:generate', (event, options) => {
156
156
  // Add a new section to llms.txt
157
157
  options.sections.push({
158
158
  title: 'API Documentation',
@@ -168,7 +168,7 @@ export default defineNitroPlugin(() => {
168
168
  })
169
169
 
170
170
  // Method 2: Using the helper function
171
- onLLMsGenerateFull((event, options, contents) => {
171
+ nitroApp.hooks.hook('llms:generate:full', (event, options, contents) => {
172
172
  // Add detailed documentation to llms_full.txt
173
173
  contents.push(`## API Authentication
174
174
 
@@ -197,8 +197,8 @@ If you're developing a Nuxt module that needs to extend the LLMs documentation:
197
197
  1. Create a server plugin in your module:
198
198
  ```ts
199
199
  // module/runtime/server/plugins/my-module-llms.ts
200
- export default defineNitroPlugin(() => {
201
- onLLMsGenerate((event, options) => {
200
+ export default defineNitroPlugin((nitroApp) => {
201
+ nitroApp.hooks.hook('llms:generate', (event, options) => {
202
202
  options.sections.push({
203
203
  title: 'My Module',
204
204
  description: 'Documentation for my module features',
@@ -221,6 +221,29 @@ export default defineNuxtModule({
221
221
  })
222
222
  ```
223
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`.
246
+
224
247
  ## 💻 Development
225
248
 
226
249
  - Clone repository
package/dist/module.d.mts CHANGED
@@ -1,32 +1,7 @@
1
1
  import * as _nuxt_schema from '@nuxt/schema';
2
-
3
- interface LLMsSection {
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
- full?: {
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 { type LLMsSection, type ModuleOptions, _default as default };
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
- interface LLMsSection {
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
- full?: {
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 { type LLMsSection, type ModuleOptions, _default as default };
7
+ export { _default as default };
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "Nuxt LLMS",
3
3
  "configKey": "llms",
4
- "version": "0.0.2",
4
+ "version": "0.1.0",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "0.8.4",
7
7
  "unbuild": "2.0.0"
@@ -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.full?.title || "Documentation"}`
11
- ];
12
- if (llms.description) {
13
- document.push(`> ${llms.full?.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: LLMSHooks['generate']): () => void;
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: LLMSHooks['generate:full']): () => void;
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 llmsHooks.hook("generate", cb);
8
+ return useNitroApp().hooks.hook("llms:generate", cb);
5
9
  }
6
10
  export function onLLMsGenerateFull(cb) {
7
- return llmsHooks.hook("generate:full", cb);
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
- export { type LLMsSection, type ModuleOptions, default } from './module.js'
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
- export { type LLMsSection, type ModuleOptions, default } from './module'
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.2",
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/types.d.ts",
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/types.d.ts",
24
+ "types": "./dist/module.d.ts",
25
25
  "files": [
26
26
  "dist"
27
27
  ],
@@ -1,3 +0,0 @@
1
- {
2
- "extends": "../../../.nuxt/tsconfig.server.json",
3
- }