@ahtmljs/next 0.1.0 → 0.1.1

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.
Files changed (2) hide show
  1. package/README.md +132 -0
  2. package/package.json +36 -4
package/README.md ADDED
@@ -0,0 +1,132 @@
1
+ # @ahtmljs/next
2
+
3
+ Next.js plugin for **[AHTML](https://github.com/DibbayajyotiRoy/AHTML)** —
4
+ the HTML of the agent web.
5
+
6
+ Turns your existing Next.js app into:
7
+
8
+ - An **MCP server** (`/ahtml/mcp.json` — auto-generated from your snapshots' actions)
9
+ - An **OpenAPI 3.1 provider** (`/ahtml/openapi.json`)
10
+ - A **JSON-LD source** (schema.org JSON-LD ingested + emitted)
11
+ - A **token-optimal semantic snapshot** (`/ahtml/<route>`)
12
+ - A **`llms.txt` source** (`/llms.txt` — Jeremy Howard's convention shim)
13
+ - A **discovery manifest** (`/.well-known/ahtml.json`)
14
+
15
+ All from one plugin. No parallel servers. No migration. Browsers see the
16
+ same HTML they always have.
17
+
18
+ ```bash
19
+ npm install @ahtmljs/next @ahtmljs/schema
20
+ ```
21
+
22
+ ## Quickstart — three minutes, three files
23
+
24
+ ### 1. Declare snapshots
25
+
26
+ ```ts
27
+ // lib/ahtml.ts
28
+ import { snapshot } from '@ahtmljs/schema';
29
+
30
+ export async function buildSnapshot(segments: string[], req: Request) {
31
+ if (segments[0] === 'products' && segments[1]) {
32
+ const p = await db.product.findUnique({ where: { slug: segments[1] } });
33
+ if (!p) return null;
34
+ return snapshot(req.url, 'product_detail')
35
+ .ttl(60)
36
+ .add({
37
+ id: `product:${p.slug}`,
38
+ type: 'product',
39
+ name: p.name,
40
+ price: { amount: p.price, currency: 'USD' },
41
+ stock: { status: p.qty > 0 ? 'in_stock' : 'out_of_stock', quantity: p.qty },
42
+ })
43
+ .action({
44
+ id: 'purchase',
45
+ target: `product:${p.slug}`,
46
+ category: 'transact',
47
+ execute_url: '/api/checkout',
48
+ auth: 'required',
49
+ cost: { amount: p.price, currency: 'USD', category: 'purchase' },
50
+ reversible: { reversible: true, window: 'P30D', policy: 'full_refund' },
51
+ side_effects: ['charge_card', 'email_buyer', 'decrement_stock'],
52
+ confirmation: 'required',
53
+ })
54
+ .build();
55
+ }
56
+ return null;
57
+ }
58
+ ```
59
+
60
+ ### 2. Wire the route handler
61
+
62
+ ```ts
63
+ // app/ahtml/[[...path]]/route.ts
64
+ import { createAHTMLRoute } from '@ahtmljs/next/handler';
65
+ import { buildSnapshot } from '@/lib/ahtml';
66
+ export const { GET, HEAD } = createAHTMLRoute(buildSnapshot);
67
+ ```
68
+
69
+ ### 3. Add discovery + llms.txt
70
+
71
+ ```ts
72
+ // app/.well-known/ahtml.json/route.ts
73
+ import { createWellKnownRoute } from '@ahtmljs/next/well-known';
74
+ export const { GET } = createWellKnownRoute();
75
+ ```
76
+
77
+ ```ts
78
+ // app/llms.txt/route.ts
79
+ import { createLlmsTxtRoute } from '@ahtmljs/next/llms-txt';
80
+ export const { GET } = createLlmsTxtRoute();
81
+ ```
82
+
83
+ ## What's now live on your site
84
+
85
+ | Endpoint | Format | Consumer |
86
+ |---|---|---|
87
+ | `/ahtml/<route>` | Compact text (default) | LLM agents — Claude, ChatGPT, Gemini, Cursor |
88
+ | `/ahtml/<route>?fmt=json` | Canonical JSON | Programmatic clients, signing |
89
+ | `/ahtml/<route>?since=<etag>` | Diff JSON | Incremental crawlers |
90
+ | `/ahtml/mcp.json` | MCP tool manifest | Claude Desktop, ChatGPT, Cursor, Copilot |
91
+ | `/ahtml/openapi.json` | OpenAPI 3.1 | REST clients, codegen |
92
+ | `/.well-known/ahtml.json` | Discovery manifest | Any AHTML-aware agent |
93
+ | `/llms.txt` | Markdown | IDE agents (Cursor, Continue, Cline) |
94
+
95
+ ## Honest benchmark
96
+
97
+ Measured live with `gpt-tokenizer` (OpenAI's tiktoken) and
98
+ `@anthropic-ai/tokenizer` (Anthropic's official). Same source, four
99
+ serializations:
100
+
101
+ | Archetype | Raw HTML | AHTML compact | × fewer tokens |
102
+ |---|---:|---:|---:|
103
+ | Product detail | 4,269 | 581 | **7.3×** |
104
+ | News article | 2,662 | 521 | **5.1×** |
105
+ | SaaS dashboard | 3,328 | 741 | **4.5×** |
106
+
107
+ These are on lean (~10–15 KB) HTML. Real production HTML
108
+ (200–500 KB Shopify product pages) compresses 50–100× because the
109
+ snapshot stays near-constant while HTML scales with chrome.
110
+
111
+ Reproduce: clone [the repo](https://github.com/DibbayajyotiRoy/AHTML) and
112
+ `npm run benchmark`.
113
+
114
+ ## Documentation
115
+
116
+ - **Repository:** [`DibbayajyotiRoy/AHTML`](https://github.com/DibbayajyotiRoy/AHTML)
117
+ - **Spec:** [`SPEC.md`](https://github.com/DibbayajyotiRoy/AHTML/blob/main/SPEC.md)
118
+ - **Recipes (cookbook):** [`docs/recipes.md`](https://github.com/DibbayajyotiRoy/AHTML/blob/main/docs/recipes.md)
119
+ - **For AI assistants:** [`docs/agents.md`](https://github.com/DibbayajyotiRoy/AHTML/blob/main/docs/agents.md)
120
+ - **Comparison vs MCP / llms.txt / schema.org / OpenAPI:** [`docs/compare.md`](https://github.com/DibbayajyotiRoy/AHTML/blob/main/docs/compare.md)
121
+
122
+ ## Compatibility
123
+
124
+ - Node 20+
125
+ - Next.js 14+ (App Router)
126
+ - MCP spec version 2025-11-25
127
+ - OpenAPI 3.1
128
+ - JSON Schema 2020-12
129
+
130
+ ## License
131
+
132
+ MIT
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ahtmljs/next",
3
- "version": "0.1.0",
4
- "description": "Next.js plugin for AHTML. Adds /.well-known/ahtml.json, /ahtml/[...path] route handlers, content negotiation, ETag-based incremental fetch, MCP + OpenAPI emitters, and a per-route snapshot builder.",
3
+ "version": "0.1.1",
4
+ "description": "Next.js plugin for AHTML. Turns your existing Next.js app into an MCP server, an OpenAPI provider, a JSON-LD source, and a token-optimal semantic snapshot — all from one plugin. Zero migration.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",
@@ -14,14 +14,46 @@
14
14
  "./mcp": { "types": "./dist/mcp.d.ts", "import": "./dist/mcp.js" },
15
15
  "./openapi": { "types": "./dist/openapi.d.ts", "import": "./dist/openapi.js" }
16
16
  },
17
- "files": ["dist"],
17
+ "files": ["dist", "README.md"],
18
18
  "publishConfig": { "access": "public" },
19
19
  "scripts": {
20
20
  "build": "tsc -p tsconfig.json",
21
21
  "dev": "tsc -p tsconfig.json --watch"
22
22
  },
23
+ "repository": {
24
+ "type": "git",
25
+ "url": "git+https://github.com/DibbayajyotiRoy/AHTML.git",
26
+ "directory": "packages/next"
27
+ },
28
+ "homepage": "https://github.com/DibbayajyotiRoy/AHTML#readme",
29
+ "bugs": {
30
+ "url": "https://github.com/DibbayajyotiRoy/AHTML/issues",
31
+ "email": "rdibbayajyoti@gmail.com"
32
+ },
33
+ "author": {
34
+ "name": "Dibbayajyoti Roy",
35
+ "email": "rdibbayajyoti@gmail.com",
36
+ "url": "https://github.com/DibbayajyotiRoy"
37
+ },
38
+ "keywords": [
39
+ "ahtml",
40
+ "nextjs",
41
+ "next",
42
+ "plugin",
43
+ "agent",
44
+ "agent-web",
45
+ "ai",
46
+ "llm",
47
+ "mcp",
48
+ "model-context-protocol",
49
+ "llms-txt",
50
+ "openapi",
51
+ "json-ld",
52
+ "semantic-web",
53
+ "crawler"
54
+ ],
23
55
  "dependencies": {
24
- "@ahtmljs/schema": "0.1.0"
56
+ "@ahtmljs/schema": "0.1.1"
25
57
  },
26
58
  "peerDependencies": {
27
59
  "next": ">=14"