@seoengine.ai/next-llm-ready 1.0.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.
@@ -0,0 +1,295 @@
1
+ import { NextRequest, NextResponse } from 'next/server';
2
+
3
+ /**
4
+ * next-llm-ready - TypeScript Type Definitions
5
+ * Make your Next.js content AI-ready
6
+ */
7
+ /**
8
+ * Content metadata for LLM-ready output
9
+ */
10
+ interface LLMContent {
11
+ /** Page/post title */
12
+ title: string;
13
+ /** Main content (HTML or Markdown) */
14
+ content: string;
15
+ /** Short description/excerpt */
16
+ excerpt?: string;
17
+ /** Canonical URL */
18
+ url: string;
19
+ /** Publication date (ISO 8601) */
20
+ date?: string;
21
+ /** Last modified date (ISO 8601) */
22
+ modifiedDate?: string;
23
+ /** Author name */
24
+ author?: string;
25
+ /** Categories/sections */
26
+ categories?: string[];
27
+ /** Tags/keywords */
28
+ tags?: string[];
29
+ /** Custom prompt prefix for AI context */
30
+ promptPrefix?: string;
31
+ /** Featured image URL */
32
+ image?: string;
33
+ /** Reading time in minutes */
34
+ readingTime?: number;
35
+ }
36
+ /**
37
+ * Copy action types for analytics
38
+ */
39
+ type CopyAction = 'copy' | 'view' | 'download';
40
+ /**
41
+ * Analytics event
42
+ */
43
+ interface AnalyticsEvent {
44
+ /** Event type */
45
+ action: CopyAction;
46
+ /** Page/content identifier */
47
+ contentId?: string;
48
+ /** Page URL */
49
+ url?: string;
50
+ /** Timestamp */
51
+ timestamp?: string;
52
+ /** Additional metadata */
53
+ metadata?: Record<string, unknown>;
54
+ }
55
+ /**
56
+ * Custom analytics storage adapter
57
+ */
58
+ interface AnalyticsStorageAdapter {
59
+ /** Save event */
60
+ save: (event: AnalyticsEvent) => Promise<void>;
61
+ /** Get all events */
62
+ getAll: () => Promise<AnalyticsEvent[]>;
63
+ /** Clear events */
64
+ clear: () => Promise<void>;
65
+ }
66
+ /**
67
+ * Single item in LLMs.txt listing
68
+ */
69
+ interface LLMsTxtItem {
70
+ /** Content title */
71
+ title: string;
72
+ /** Page URL */
73
+ url: string;
74
+ /** Content type (post, page, etc.) */
75
+ type?: string;
76
+ /** Publication date */
77
+ date?: string;
78
+ /** Short description */
79
+ description?: string;
80
+ }
81
+ /**
82
+ * Markdown API handler options
83
+ */
84
+ interface MarkdownHandlerOptions {
85
+ /** Function to fetch content by slug/id */
86
+ getContent: (slug: string) => Promise<LLMContent | null>;
87
+ /** Cache control header value */
88
+ cacheControl?: string;
89
+ /** Enable CORS */
90
+ cors?: boolean;
91
+ }
92
+ /**
93
+ * Analytics API handler options
94
+ */
95
+ interface AnalyticsHandlerOptions {
96
+ /** Storage adapter */
97
+ storage: AnalyticsStorageAdapter;
98
+ /** Rate limiting (requests per minute) */
99
+ rateLimit?: number;
100
+ /** Enable CORS */
101
+ cors?: boolean;
102
+ }
103
+
104
+ /**
105
+ * LLMs.txt API Route Handler
106
+ * Creates an API route handler for serving /llms.txt
107
+ */
108
+
109
+ interface LLMsTxtHandlerOptions {
110
+ /** Function to get site configuration */
111
+ getSiteConfig: () => Promise<{
112
+ siteName: string;
113
+ siteDescription?: string;
114
+ siteUrl: string;
115
+ }>;
116
+ /** Function to get all content items */
117
+ getContent: () => Promise<LLMsTxtItem[]>;
118
+ /** Cache control header (default: 1 hour) */
119
+ cacheControl?: string;
120
+ /** Custom header text */
121
+ headerText?: string;
122
+ /** Custom footer text */
123
+ footerText?: string;
124
+ }
125
+ /**
126
+ * Create an API route handler for /llms.txt
127
+ *
128
+ * @example
129
+ * ```ts
130
+ * // app/llms.txt/route.ts
131
+ * import { createLLMsTxtHandler } from 'next-llm-ready/api';
132
+ *
133
+ * export const GET = createLLMsTxtHandler({
134
+ * getSiteConfig: async () => ({
135
+ * siteName: 'My Site',
136
+ * siteDescription: 'A great website',
137
+ * siteUrl: 'https://example.com',
138
+ * }),
139
+ * getContent: async () => {
140
+ * const posts = await getAllPosts();
141
+ * return posts.map(post => ({
142
+ * title: post.title,
143
+ * url: `https://example.com/blog/${post.slug}`,
144
+ * type: 'post',
145
+ * date: post.date,
146
+ * }));
147
+ * },
148
+ * });
149
+ * ```
150
+ */
151
+ declare function createLLMsTxtHandler(options: LLMsTxtHandlerOptions): (request: NextRequest) => Promise<NextResponse>;
152
+ /**
153
+ * Create a Pages Router API handler for /api/llms.txt
154
+ *
155
+ * @example
156
+ * ```ts
157
+ * // pages/api/llms.txt.ts
158
+ * import { createLLMsTxtPageHandler } from 'next-llm-ready/api';
159
+ *
160
+ * export default createLLMsTxtPageHandler({
161
+ * getSiteConfig: async () => ({ ... }),
162
+ * getContent: async () => { ... },
163
+ * });
164
+ * ```
165
+ */
166
+ declare function createLLMsTxtPageHandler(options: LLMsTxtHandlerOptions): (req: {
167
+ method?: string;
168
+ }, res: {
169
+ status: (code: number) => {
170
+ end: (body?: string) => void;
171
+ json: (body: unknown) => void;
172
+ };
173
+ setHeader: (name: string, value: string) => void;
174
+ }) => Promise<void>;
175
+
176
+ /**
177
+ * Markdown API Route Handler
178
+ * Serves markdown content for ?llm=1 requests
179
+ */
180
+
181
+ /**
182
+ * Create middleware to handle ?llm=1 query parameter
183
+ *
184
+ * @example
185
+ * ```ts
186
+ * // middleware.ts
187
+ * import { withLLMParam } from 'next-llm-ready/api';
188
+ *
189
+ * export default withLLMParam({
190
+ * getContent: async (pathname) => {
191
+ * // Extract slug and fetch content
192
+ * const slug = pathname.split('/').pop();
193
+ * const post = await getPostBySlug(slug);
194
+ * if (!post) return null;
195
+ * return {
196
+ * title: post.title,
197
+ * content: post.content,
198
+ * url: `https://example.com${pathname}`,
199
+ * date: post.date,
200
+ * };
201
+ * },
202
+ * });
203
+ * ```
204
+ */
205
+ declare function withLLMParam(options: MarkdownHandlerOptions): (request: NextRequest) => Promise<NextResponse | undefined>;
206
+ /**
207
+ * Create an API route handler for markdown endpoints
208
+ *
209
+ * @example
210
+ * ```ts
211
+ * // app/api/content/[slug]/route.ts
212
+ * import { createMarkdownHandler } from 'next-llm-ready/api';
213
+ *
214
+ * export const GET = createMarkdownHandler({
215
+ * getContent: async (slug) => {
216
+ * const post = await getPostBySlug(slug);
217
+ * if (!post) return null;
218
+ * return {
219
+ * title: post.title,
220
+ * content: post.content,
221
+ * url: `https://example.com/blog/${slug}`,
222
+ * };
223
+ * },
224
+ * });
225
+ * ```
226
+ */
227
+ declare function createMarkdownHandler(options: Omit<MarkdownHandlerOptions, 'getContent'> & {
228
+ getContent: (slug: string) => Promise<LLMContent | null>;
229
+ }): (request: NextRequest, { params }: {
230
+ params: {
231
+ slug?: string;
232
+ };
233
+ }) => Promise<NextResponse>;
234
+ /**
235
+ * Helper to check if request has ?llm=1 parameter
236
+ */
237
+ declare function hasLLMParam(request: NextRequest): boolean;
238
+
239
+ /**
240
+ * Analytics API Route Handler
241
+ * Tracks copy/view/download events
242
+ */
243
+
244
+ /**
245
+ * In-memory analytics storage (for development/testing)
246
+ */
247
+ declare function createInMemoryStorage(): AnalyticsStorageAdapter;
248
+ /**
249
+ * Create an API route handler for analytics tracking
250
+ *
251
+ * @example
252
+ * ```ts
253
+ * // app/api/analytics/route.ts
254
+ * import { createAnalyticsHandler, createInMemoryStorage } from 'next-llm-ready/api';
255
+ *
256
+ * const storage = createInMemoryStorage();
257
+ *
258
+ * export const POST = createAnalyticsHandler({
259
+ * storage,
260
+ * rateLimit: 100,
261
+ * });
262
+ *
263
+ * export const GET = async () => {
264
+ * const events = await storage.getAll();
265
+ * return NextResponse.json({ events });
266
+ * };
267
+ * ```
268
+ */
269
+ declare function createAnalyticsHandler(options: AnalyticsHandlerOptions): (request: NextRequest) => Promise<NextResponse>;
270
+ /**
271
+ * Create a Pages Router API handler for analytics
272
+ */
273
+ declare function createAnalyticsPageHandler(options: AnalyticsHandlerOptions): (req: {
274
+ method?: string;
275
+ body?: unknown;
276
+ headers?: {
277
+ [key: string]: string | string[] | undefined;
278
+ };
279
+ }, res: {
280
+ status: (code: number) => {
281
+ end: (body?: string) => void;
282
+ json: (body: unknown) => void;
283
+ };
284
+ setHeader: (name: string, value: string) => void;
285
+ }) => Promise<void>;
286
+ /**
287
+ * Aggregate analytics events by action type
288
+ */
289
+ declare function aggregateEvents(storage: AnalyticsStorageAdapter): Promise<Record<string, number>>;
290
+ /**
291
+ * Get events for a specific content ID
292
+ */
293
+ declare function getEventsForContent(storage: AnalyticsStorageAdapter, contentId: string): Promise<AnalyticsEvent[]>;
294
+
295
+ export { type AnalyticsEvent, type AnalyticsHandlerOptions, type AnalyticsStorageAdapter, type LLMsTxtHandlerOptions, type MarkdownHandlerOptions, aggregateEvents, createAnalyticsHandler, createAnalyticsPageHandler, createInMemoryStorage, createLLMsTxtHandler, createLLMsTxtPageHandler, createMarkdownHandler, getEventsForContent, hasLLMParam, withLLMParam };