Update pnpm-lock.yaml and refactor LLM route handling

### Summary of Changes
- Added 'rolldown' as a new optional dependency in `pnpm-lock.yaml`.
- Simplified middleware logic to handle redirects for `/skill.md` and `/skills.md` in a case-insensitive manner.
- Refactored the `resolvePage` function in `route.ts` to accept only defined slugs, improving clarity.
- Enhanced URL collection logic in `llms.txt` to streamline the extraction of relative URLs for documentation and API pages.

These updates improve dependency management and enhance the routing logic for better URL handling.
This commit is contained in:
mantrakp04 2026-03-23 11:51:51 -07:00
parent cf657cc2ec
commit adbbe44dbf
5 changed files with 34 additions and 58 deletions

View File

@ -10,10 +10,7 @@ export async function GET(
) {
const { slug } = await params;
// Try to find the page in either source
let page = source.getPage(slug);
// If not found in main docs, try API docs
if (!page) {
page = apiSource.getPage(slug);
}
@ -23,7 +20,11 @@ export async function GET(
}
try {
return new NextResponse(await getLLMText(page));
return new NextResponse(await getLLMText(page), {
headers: {
'Content-Type': 'text/plain; charset=utf-8',
},
});
} catch (error) {
console.error('Error generating LLM text:', error);
return new NextResponse('Error generating content', { status: 500 });
@ -31,15 +32,5 @@ export async function GET(
}
export function generateStaticParams() {
try {
// Generate static params for both main docs and API docs
const docsParams = source.generateParams();
const apiParams = apiSource.generateParams();
return [...docsParams, ...apiParams];
} catch (error) {
console.error('Error generating static params:', error);
// Return empty array to prevent build failure
return [];
}
return [...source.generateParams(), ...apiSource.generateParams()];
}

View File

@ -4,42 +4,40 @@ import { apiSource, source } from 'lib/source';
// cached forever
export const revalidate = false;
function collectRelativeUrls(
pages: ReturnType<typeof source.getPages>,
prefix: string,
label: string,
): string[] {
const urls: string[] = [];
for (const page of pages) {
if (page.url !== `/${prefix}` && !page.url.startsWith(`/${prefix}/`)) {
throw new Error(`Unexpected page URL "${page.url}" in ${label} source — expected "/${prefix}" or "/${prefix}/..." prefix`);
}
const relativeUrl = page.url === `/${prefix}` ? '' : page.url.slice(`/${prefix}/`.length);
if (relativeUrl !== '') {
urls.push(relativeUrl);
}
}
return urls;
}
export async function GET(request: Request) {
const docsUrls = new Set<string>();
const apiUrls = new Set<string>();
const origin = new URL(request.url).origin;
const docsBaseUrl = `${origin}/llms/docs/`;
const apiBaseUrl = `${origin}/llms/api/`;
for (const page of source.getPages()) {
if (page.url !== '/docs' && !page.url.startsWith('/docs/')) {
throw new Error(`Unexpected page URL "${page.url}" in docs source — expected "/docs" or "/docs/..." prefix`);
}
const relativeUrl = page.url === '/docs' ? '' : page.url.slice('/docs/'.length);
if (relativeUrl !== '') {
docsUrls.add(relativeUrl);
}
}
for (const page of apiSource.getPages()) {
if (page.url !== '/api' && !page.url.startsWith('/api/')) {
throw new Error(`Unexpected page URL "${page.url}" in API source — expected "/api" or "/api/..." prefix`);
}
const relativeUrl = page.url === '/api' ? '' : page.url.slice('/api/'.length);
if (relativeUrl !== '') {
apiUrls.add(relativeUrl);
}
}
const docsUrls = collectRelativeUrls(source.getPages(), 'docs', 'docs');
const apiUrls = collectRelativeUrls(apiSource.getPages(), 'api', 'API');
const body = [
'# Stack Auth Docs',
`docs base url: ${docsBaseUrl}`,
'',
...[...docsUrls].sort((left, right) => stringCompare(left, right)),
...docsUrls.sort((left, right) => stringCompare(left, right)),
'',
`api base url: ${apiBaseUrl}`,
'',
...[...apiUrls].sort((left, right) => stringCompare(left, right)),
...apiUrls.sort((left, right) => stringCompare(left, right)),
'',
].join('\n');

View File

@ -6,11 +6,7 @@ import { apiSource, source } from '../../../../lib/source';
// (those emitted by generateStaticParams). The empty-slug redirect is always dynamic.
export const revalidate = false;
function resolvePage(slug: string[] | undefined) {
if (slug == null || slug.length === 0) {
return null;
}
function resolvePage(slug: string[]) {
const [prefix, ...rest] = slug;
if (prefix === 'docs') {

View File

@ -16,12 +16,8 @@ export default function middleware(request: NextRequest, event: NextFetchEvent)
runAsynchronously(trackPromise);
event.waitUntil(trackPromise);
if (
pathname === '/SKILL.md' ||
pathname === '/SKILLS.md' ||
pathname === '/skill.md' ||
pathname === '/skills.md'
) {
const lowerPathname = pathname.toLowerCase();
if (lowerPathname === '/skill.md' || lowerPathname === '/skills.md') {
const url = request.nextUrl.clone();
url.pathname = '/llms.txt';
return NextResponse.redirect(url, 307);

View File

@ -737,7 +737,7 @@ importers:
version: 1.166.6(crossws@0.4.4(srvx@0.8.16))
nitro:
specifier: ^3.0.0
version: 3.0.0(@electric-sql/pglite@0.3.2)(chokidar@4.0.3)(lru-cache@11.2.2)(mysql2@3.15.3)(vite@7.3.1(@types/node@22.19.0)(jiti@2.6.1)(lightningcss@1.30.1)(terser@5.44.0)(tsx@4.21.0)(yaml@2.8.0))
version: 3.0.0(@electric-sql/pglite@0.3.2)(chokidar@4.0.3)(lru-cache@11.2.2)(mysql2@3.15.3)(rolldown@1.0.0-rc.3)(vite@7.3.1(@types/node@22.19.0)(jiti@2.6.1)(lightningcss@1.30.1)(terser@5.44.0)(tsx@4.21.0)(yaml@2.8.0))
react:
specifier: 19.2.1
version: 19.2.1
@ -1699,12 +1699,6 @@ importers:
specifier: ^0.20.3
version: 0.20.3(typescript@5.9.3)
packages/private:
devDependencies:
rimraf:
specifier: ^6.1.2
version: 6.1.2
packages/react:
dependencies:
'@hookform/resolvers':
@ -31942,7 +31936,7 @@ snapshots:
nice-try@1.0.5: {}
nitro@3.0.0(@electric-sql/pglite@0.3.2)(chokidar@4.0.3)(lru-cache@11.2.2)(mysql2@3.15.3)(vite@7.3.1(@types/node@22.19.0)(jiti@2.6.1)(lightningcss@1.30.1)(terser@5.44.0)(tsx@4.21.0)(yaml@2.8.0)):
nitro@3.0.0(@electric-sql/pglite@0.3.2)(chokidar@4.0.3)(lru-cache@11.2.2)(mysql2@3.15.3)(rolldown@1.0.0-rc.3)(vite@7.3.1(@types/node@22.19.0)(jiti@2.6.1)(lightningcss@1.30.1)(terser@5.44.0)(tsx@4.21.0)(yaml@2.8.0)):
dependencies:
consola: 3.4.2
cookie-es: 2.0.0
@ -31962,6 +31956,7 @@ snapshots:
unenv: 2.0.0-rc.21
unstorage: 2.0.0-alpha.3(chokidar@4.0.3)(db0@0.3.4(@electric-sql/pglite@0.3.2)(mysql2@3.15.3))(lru-cache@11.2.2)(ofetch@1.5.1)
optionalDependencies:
rolldown: 1.0.0-rc.3
vite: 7.3.1(@types/node@22.19.0)(jiti@2.6.1)(lightningcss@1.30.1)(terser@5.44.0)(tsx@4.21.0)(yaml@2.8.0)
transitivePeerDependencies:
- '@azure/app-configuration'