npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

payload-plugin-llms

v0.9.2

Published

Payload global for llms.txt / llms-full.txt, Lexical → Markdown, and Next.js markdown helpers.

Readme

payload-plugin-llms

Helpers for llms.txt / llms-full.txt content stored in a Payload global, Lexical → Markdown conversion, and Next.js utilities for markdown responses and Accept-based rewrites.

Install

pnpm add payload-plugin-llms
npm install payload-plugin-llms

Peer dependencies

  • payload ^3.80.0
  • @payloadcms/richtext-lexical ^3.80.0
  • next ^15.0.0 || ^16.0.0 — optional; required for payload-plugin-llms/next

payload.config.ts

import { buildConfig } from "payload"
import { llmsPlugin } from "payload-plugin-llms"

export default buildConfig({
  plugins: [
    llmsPlugin({
      enabled: true,
      routes: {
        llmsTxt: "/llms.txt",
        markdownSegment: "md",
      },
      global: {
        slug: "llms",
        label: "LLMs",
        localized: false,
      },
    }),
  ],
})

normalizeOptions(options) returns defaults including global:

import { normalizeOptions } from "payload-plugin-llms"

const normalized = normalizeOptions({})

Options (PayloadPluginLlmsOptions)

| Option | Default | Purpose | | ------------------------ | ------------- | -------------------------------------------------------- | | enabled | true | Toggle plugin | | routes.llmsTxt | "/llms.txt" | Documented path for llms.txt in your app | | routes.markdownSegment | "md" | Segment name for markdown URLs (rewrites) | | global.slug | "llms" | Global slug | | global.label | "LLMs" | Admin label | | global.localized | false | Localize tab fields | | global.overrides | — | Partial<GlobalConfig> merged into the generated global |

If a global with the same slug already exists in config, the plugin does not add another.

Core helpers (payload-plugin-llms)

  • buildLlmsTxt({ payload, locale?, draft?, depth?, globalSlug?, lexical? }) — reads the llms.txt tab and returns markdown text (lexical.resolveLexicalBlock handles top-level serialized block nodes)
  • buildLlmsFullTxt({ … }) — same for the llms-full.txt tab
  • buildLlmsTxtFromStructured(content) — legacy structured LlmsTxtContentllms.txt lines (no Lexical)
  • formatLlmsTxtLink(link)
  • lexicalToMarkdown(root, options?) — sync Lexical JSON → Markdown (block nodes are omitted)
  • lexicalToMarkdownAsync(root, options?) — async; optional resolveLexicalBlock for custom Lexical blocks
  • createLlmsGlobal(normalizeOptions()) — use the generated global config directly if you are not using the plugin
  • createLlmsLexicalEditor() — Lexical adapter for custom fields that should match the llms editor

Example: Next.js llms.txt route

import { cacheLife } from "next/cache"
import { getPayload } from "payload"
import { buildLlmsTxt } from "payload-plugin-llms"
import { LlmsResponse } from "payload-plugin-llms/next"
import config from "@payload-config"

export async function GET() {
  "use cache"
  cacheLife("days")

  const payload = await getPayload({ config })

  const body = await buildLlmsTxt({
    payload,
    locale: "en",
    depth: 2,
    lexical: {
      resolveInternalLink: ({ relationTo, value }) =>
        relationTo && value && typeof value === "object" && value !== null && "slug" in value
          ? `/${String((value as { slug?: string }).slug)}`
          : null,
      resolveLexicalBlock: async (fields) => {
        if (fields.blockType === "my-custom-block") {
          // Load data, format markdown, etc.
          return "\n---\n\n"
        }
        return ""
      },
    },
  })

  return new LlmsResponse(body)
}

lexical.resolveLexicalBlock runs only for Lexical nodes with type: "block" that are direct children of the field’s root; omit it if you do not use custom blocks in llms rich text.

Lexical → Markdown

import { lexicalToMarkdown, lexicalToMarkdownAsync } from "payload-plugin-llms"

lexicalToMarkdown(payloadLexicalRoot, {
  resolveInternalLink: (reference) =>
    reference.relationTo && reference.value
      ? `/${reference.relationTo}/${String(reference.value)}`
      : (reference.url ?? null),
})

await lexicalToMarkdownAsync(payloadLexicalRoot, {
  resolveInternalLink: (reference) => reference.url ?? null,
  resolveLexicalBlock: async (fields) => (fields.blockType === "my-block" ? "custom output\n" : ""),
})

Types include LlmsTxtContent, LlmsTxtSection, LlmsTxtLink, BuildLlmsTxtFromGlobalOptions, LexicalToMarkdownOptions, LexicalToMarkdownAsyncOptions, SerializedLexicalNode.

Next.js (payload-plugin-llms/next)

Use your own App Router handlers and choose caching (dynamic, revalidate, unstable_cache, etc.). This entry exports small helpers only:

  • LlmsResponse — subclass of Response; constructor merges DEFAULT_LLMS_TXT_HEADERS with optional init.headers and forwards other ResponseInit fields
  • createMarkdownResponse(markdown, { headers? })
  • createMarkdownRewrites(...) — Accept: text/markdown rewrites
  • DEFAULT_LLMS_TXT_HEADERS, DEFAULT_MARKDOWN_HEADERS, mergeHeaders, isMarkdownAccepted

Rewrites for clients that prefer Markdown

CreateMarkdownRewritesOptions: either { locales, localizedRoutes?: true, ... } for /:locale/... routes, or { localizedRoutes: false, ... } when there is no locale prefix. Optional fields: markdownSegment, acceptHeaderPattern, includeIndexRewrite, has.

import type { NextConfig } from "next"
import { createMarkdownRewrites } from "payload-plugin-llms/next"

const nextConfig: NextConfig = {
  async rewrites() {
    return createMarkdownRewrites({
      locales: ["en", "de"],
      markdownSegment: "md",
    })
  },
}

export default nextConfig

License

Apache-2.0 (see repository root).