Package Exports
- @ahtmljs/schema
- @ahtmljs/schema/schema.json
Readme
@ahtmljs/schema
Types, runtime validator, JSON + token-optimal compact text formatters, structural diff, and snapshot builder DSL for AHTML โ the HTML of the agent web.
npm install @ahtmljs/schema๐ How well does an AI read it?
We asked an AI 20 questions about the same page โ given in 4 different formats:
| Format you give the AI | Tokens used | Right answers |
|---|---|---|
| Plain HTML | 684 | 91% |
| llms.txt | 227 | 89% |
| AHTML compact | 338 | 95% |
| AHTML JSON | 365 | 100% โ |
AHTML JSON: every answer right. AHTML compact: ~50% fewer tokens than HTML โ and still more accurate.
How we measured this โ open for details
- Real API calls to gpt-4o-mini, claude-haiku-4.5, gemini-2.5-flash, llama-3.3-70b at temperature=0.
- 20 hand-graded questions an AI agent actually wants to know: price, in stock?, SKU, return window, confirmation needed?, author, publication date, etc.
- Tokens counted with the official OpenAI + Anthropic tokenizers (
gpt-tokenizer,@anthropic-ai/tokenizer). Notext.length/4guessing. - Cost from real provider usage ร public prices.
- Reproduce:
git clone https://github.com/DibbayajyotiRoy/AHTML && cp .env.example .env && bash scripts/run-llm-benchmark.sh
What this package gives you
- TypeScript types for
Snapshot, six entity primitives (Product,Document,Task,Profile,Dataset,Conversation),Action,Policy,Provenance,Links,SnapshotDiff. snapshot()builder DSL โ fluent API to compose a typed snapshot.- Zero-dependency runtime validator (
validate) that returns a list of structured issues withpath+severity. lint(s)snapshot quality linter โ best-practice checks beyond validity: a priced product with no stock, a product-detail page with no actions, an action withcharge_cardside effects but no required confirmation, a truncated dataset with nonextlink, a dangling action target. Every finding has a stableruleid you can suppress in CI.- Two serializations:
toJson(s)/fromJson(text)โ canonical JSON, deterministic, signable.toCompact(s)/fromCompact(text)โ token-optimal text, round-trips losslessly.
diff(prev, next)/applyDiff(prev, d)โ structural snapshot diffing.computeEtag(s)โ content-addressed weak ETag.- JSON Schema 2020-12 spec at
./src/schema.json.
Quickstart
import { snapshot, toCompact, toJson, validate, lint } from '@ahtmljs/schema';
const snap = snapshot('https://shop.com/products/mbp-14', 'product_detail')
.ttl(60)
.policy({ agents_welcome: true, license: 'MIT', rate_limit: '100/min' })
.add({
id: 'product:mbp-14',
type: 'product',
name: 'MacBook Pro 14"',
price: { amount: 1999, currency: 'USD' },
stock: { status: 'in_stock', quantity: 42 },
})
.action({
id: 'purchase',
target: 'product:mbp-14',
category: 'transact',
execute_url: '/api/checkout',
auth: 'required',
cost: { amount: 1999, currency: 'USD', category: 'purchase' },
reversible: { reversible: true, window: 'P30D', policy: 'full_refund' },
side_effects: ['charge_card', 'email_buyer', 'decrement_stock'],
confirmation: 'required',
})
.build();
console.log(toCompact(snap)); // token-optimal text โ default for LLM agents
console.log(toJson(snap)); // canonical JSON โ sign-able
const issues = validate(snap);
if (issues.some((i) => i.severity === 'error')) throw new Error('invalid');
// validate() = "is it legal?" โ lint() = "is it actually useful to an agent?"
for (const w of lint(snap)) {
console.warn(`[${w.rule}] ${w.path}: ${w.message}`);
}What is AHTML?
AHTML turns any website into an MCP server, an OpenAPI provider, a
JSON-LD source, and a token-optimal semantic snapshot โ from one plugin.
This package is the schema underneath. Most users want
@ahtmljs/next (the
Next.js plugin) or @ahtmljs/agent
(the client SDK).
Documentation
- Repository:
DibbayajyotiRoy/AHTML - Spec:
SPEC.md - Plan / roadmap:
PLAN.md - For AI assistants:
docs/agents.md - Comparison vs MCP / llms.txt / schema.org / OpenAPI:
docs/compare.md
License
MIT