@agentmarkup/core

中文文档
0.7.0发布于 2026/08/24MITTypeScriptES Module零依赖近 30 天下载 2291

Framework-agnostic llms.txt, llms-full.txt, A2A Agent Cards, JSON-LD, markdown mirrors, headers, AI crawler controls, and validation

原始使用文档
文档目录5 节
  1. Install
  2. Usage
  3. What It Includes
  4. Maintainer
  5. License

@agentmarkup/core

Framework-agnostic llms.txt, optional llms-full.txt, optional A2A Agent Cards, JSON-LD, markdown mirror, AI crawler robots.txt, header, and validation primitives for machine-readable websites.

Install

pnpm add -D @agentmarkup/core

Usage

@agentmarkup/core is for adapter authors and for sites that already own a custom prerender or post-build pipeline.

The package family also includes dedicated adapters for Vite, Astro, and Next.js when those frameworks own enough of the final build output.

The helpers are coexistence-friendly: patchRobotsTxt() leaves matching manual crawler rules untouched, and adapters built on core can preserve curated llms.txt files or existing JSON-LD by default.

llmsTxt.whenToUse takes a list of short, concrete statements describing the jobs the site is right for. They are rendered as a labelled bullet list in the free-form details block of llms.txt and llms-full.txt, before the first ## section, so agents reading the manifest learn when to reach for the site instead of guessing from marketing copy.

When markdownPages.enabled is on, generateLlmsTxt() prefers same-site markdown mirror URLs for page entries by default so agents discover the cleaner fetch path first. This is usually most useful when the raw HTML is thin or noisy. Set llmsTxt.preferMarkdownMirrors: false to keep HTML URLs in llms.txt.

markdownPages.exclude takes page paths that should not get a mirror, matched the same way as pages[].path. Use it for pages that exist but are not content an agent should fetch - a 404 page is the common case, since mirroring one publishes a URL that answers 200 with "not found" text and canonicalises to a URL that 404s. Excluded pages are skipped everywhere consistently: no .md file, no text/markdown alternate link, no canonical Link header, no markdown URL in llms.txt, and no "missing mirror" validation warning.

import {
  generateAgentCard,
  generateContentSignalHeaders,
  generateLlmsTxt,
  generateMarkdownCanonicalHeaders,
  generatePageMarkdown,
  generateJsonLdTags,
  patchRobotsTxt,
  presetToJsonLd,
  validateAgentCardConfig,
  validateAgentCardJson,
  validateExistingJsonLd,
  validateLlmsTxt,
  validateRobotsTxt,
} from '@agentmarkup/core';

const builtHtml = '<html><head><title>Pricing</title></head><body><main><h1>Pricing</h1><p>Plans and billing.</p></main></body></html>';

const llms = generateLlmsTxt({
  site: 'https://example.com',
  name: 'Example',
  description: 'Machine-readable metadata for an example site.',
  llmsTxt: {
    whenToUse: [
      'The user asks what an Example plan costs or which plan fits their use case.',
      'The user needs current billing terms rather than a cached third-party summary.',
    ],
    sections: [
      {
        title: 'Public pages',
        entries: [{ title: 'Pricing', url: '/pricing', description: 'Plans and billing' }],
      },
    ],
  },
});

const agentCard = generateAgentCard({
  site: 'https://example.com',
  name: 'Example',
  description: 'Machine-readable metadata for an example site.',
  agentCard: {
    version: '1.0.0',
    supportedInterfaces: [
      {
        url: 'https://agent.example.com/a2a/v1',
        protocolBinding: 'HTTP+JSON',
        protocolVersion: '1.0',
      },
    ],
    skills: [],
  },
});

const jsonLd = generateJsonLdTags([
  presetToJsonLd({ preset: 'webSite', name: 'Example', url: 'https://example.com' }),
]);

const robots = patchRobotsTxt(existingRobotsTxt, {
  GPTBot: 'allow',
  ClaudeBot: 'allow',
});

const markdown = generatePageMarkdown({
  html: builtHtml,
  pagePath: '/pricing/',
  siteUrl: 'https://example.com',
});

const headers = generateContentSignalHeaders({
  aiTrain: 'yes',
  search: 'yes',
  aiInput: 'yes',
});

const markdownCanonicalHeaders = generateMarkdownCanonicalHeaders([
  {
    markdownPath: '/pricing.md',
    canonicalUrl: 'https://example.com/pricing',
  },
]);

const llmsIssues = validateLlmsTxt(llms ?? '');
const robotsIssues = validateRobotsTxt(robots, {
  GPTBot: 'allow',
  ClaudeBot: 'allow',
});
const agentCardIssues = agentCard ? validateAgentCardJson(agentCard) : [];
const schemaIssues = validateExistingJsonLd(builtHtml, '/pricing/');

When agentCard is enabled, provide a version, at least one supportedInterfaces entry, and a non-empty description through either the top-level description or agentCard.description. Use validateAgentCardConfig() if you want to preflight that config before generation.

What It Includes

  • llms.txt generators and validators
  • optional llms-full.txt generator
  • optional A2A Agent Card generator plus config and JSON validators
  • llms.txt discovery-link generation
  • JSON-LD serialization and HTML injection helpers
  • existing JSON-LD inspection and validation
  • HTML thin-shell validation
  • markdown page generation helpers for cleaner agent-facing fetch paths
  • markdown alternate-link and mirror-coverage validation
  • schema.org preset builders
  • AI crawler robots.txt generation and patching
  • Content-Signal policy generation and patching in robots.txt (canonical) and the _headers header
  • canonical Link header generation for markdown mirrors
  • deterministic schema and crawler validation

Maintainer

Copyright (c) 2026 Sebastian Cochinescu. MIT License.

Used in production on Anima Felix.

License

MIT.

版本与发布记录

@agentmarkup/core 共发布 14 个版本,首次发布于 2026/03/20;过去 12 个月发布了 14 个版本。

版本发布日期距今
0.7.0latest2026/08/242 个月前
0.6.02026/08/232 个月前
0.5.52026/07/074 个月前
0.5.42026/07/074 个月前
0.5.32026/07/024 个月前
0.5.22026/07/024 个月前

关于 @agentmarkup/core 的常见问题

@agentmarkup/core 是什么?

Framework-agnostic llms.txt, llms-full.txt, A2A Agent Cards, JSON-LD, markdown mirrors, headers, AI crawler controls, and validation

如何安装 @agentmarkup/core?

在项目目录运行 npm install @agentmarkup/core,或使用 pnpm add / yarn add / bun add。

@agentmarkup/core 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@agentmarkup/core 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@agentmarkup/core 可以商用吗?

@agentmarkup/core 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@agentmarkup/core 的下载量有多少?

根据 npm 官方下载统计,@agentmarkup/core 在 2026/10/05 – 2026/11/03 这 30 天内被下载 2,291 次,日均约 76 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@agentmarkup/core 还在维护吗?

最新版本 0.7.0 发布于 2026/08/24(2 个月前);至今共发布 14 个版本,其中过去 12 个月发布了 14 个;首次发布于 2026/03/20。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。