@markdown-for-agents/hono 0.3.3 → 1.0.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.
package/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # @markdown-for-agents/hono
2
2
 
3
+ [![npm version](https://img.shields.io/npm/v/@markdown-for-agents/hono)](https://www.npmjs.com/package/@markdown-for-agents/hono) [![npm downloads](https://img.shields.io/npm/dm/@markdown-for-agents/hono)](https://www.npmjs.com/package/@markdown-for-agents/hono)
4
+ [![types](https://img.shields.io/npm/types/@markdown-for-agents/hono)](https://www.npmjs.com/package/@markdown-for-agents/hono) [![license](https://img.shields.io/npm/l/@markdown-for-agents/hono)](https://github.com/KKonstantinov/markdown-for-agents/blob/main/LICENSE)
5
+
3
6
  Hono middleware for [markdown-for-agents](https://www.npmjs.com/package/markdown-for-agents) — a runtime-agnostic HTML to Markdown converter built for AI agents.
4
7
 
5
8
  Add one line to your Hono app and AI agents get clean, token-efficient Markdown instead of HTML. Normal browser requests pass through untouched.
package/dist/index.mjs CHANGED
@@ -1,5 +1,4 @@
1
1
  import { buildContentSignalHeader, convert } from "markdown-for-agents";
2
-
3
2
  //#region src/index.ts
4
3
  /**
5
4
  * Hono middleware that converts HTML responses to markdown
@@ -38,7 +37,7 @@ function markdown(options) {
38
37
  }
39
38
  };
40
39
  }
41
-
42
40
  //#endregion
43
41
  export { markdown };
42
+
44
43
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["/**\n * Hono middleware that converts HTML responses to Markdown\n * when the client sends an `Accept: text/markdown` header.\n *\n * ```ts\n * import { Hono } from \"hono\";\n * import { markdown } from \"@markdown-for-agents/hono\";\n *\n * const app = new Hono();\n * app.use(\"*\", markdown());\n * ```\n * @module\n */\n\nimport type { MiddlewareHandler } from 'hono';\nimport { convert, buildContentSignalHeader } from 'markdown-for-agents';\nimport type { MiddlewareOptions } from 'markdown-for-agents';\n\nexport type { MiddlewareOptions } from 'markdown-for-agents';\n\n/**\n * Hono middleware that converts HTML responses to markdown\n * when the client sends an `Accept: text/markdown` header.\n *\n * @param options - Conversion and middleware options.\n * @returns A Hono middleware handler.\n *\n * @example\n * ```ts\n * import { Hono } from \"hono\";\n * import { markdown } from \"@markdown-for-agents/hono\";\n *\n * const app = new Hono();\n * app.use(\"*\", markdown());\n * ```\n */\nexport function markdown(options?: MiddlewareOptions): MiddlewareHandler {\n const tokenHeader = options?.tokenHeader ?? 'x-markdown-tokens';\n\n return async (c, next) => {\n await next();\n\n // Always signal that responses vary by Accept so caches store\n // separate entries for HTML and Markdown representations.\n c.res.headers.append('vary', 'Accept');\n\n const accept = c.req.header('accept') ?? '';\n if (!accept.includes('text/markdown')) return;\n\n const contentType = c.res.headers.get('content-type') ?? '';\n if (!contentType.includes('text/html')) return;\n\n const html = await c.res.text();\n const { markdown: md, tokenEstimate, contentHash } = convert(html, options);\n\n c.res = new Response(md, {\n status: c.res.status,\n headers: c.res.headers\n });\n c.res.headers.set('content-type', 'text/markdown; charset=utf-8');\n c.res.headers.set(tokenHeader, String(tokenEstimate.tokens));\n c.res.headers.set('etag', `\"${contentHash}\"`);\n if (options?.contentSignal) {\n const signalValue = buildContentSignalHeader(options.contentSignal);\n if (signalValue) c.res.headers.set('content-signal', signalValue);\n }\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAoCA,SAAgB,SAAS,SAAgD;CACrE,MAAM,cAAc,SAAS,eAAe;AAE5C,QAAO,OAAO,GAAG,SAAS;AACtB,QAAM,MAAM;AAIZ,IAAE,IAAI,QAAQ,OAAO,QAAQ,SAAS;AAGtC,MAAI,EADW,EAAE,IAAI,OAAO,SAAS,IAAI,IAC7B,SAAS,gBAAgB,CAAE;AAGvC,MAAI,EADgB,EAAE,IAAI,QAAQ,IAAI,eAAe,IAAI,IACxC,SAAS,YAAY,CAAE;EAGxC,MAAM,EAAE,UAAU,IAAI,eAAe,gBAAgB,QADxC,MAAM,EAAE,IAAI,MAAM,EACoC,QAAQ;AAE3E,IAAE,MAAM,IAAI,SAAS,IAAI;GACrB,QAAQ,EAAE,IAAI;GACd,SAAS,EAAE,IAAI;GAClB,CAAC;AACF,IAAE,IAAI,QAAQ,IAAI,gBAAgB,+BAA+B;AACjE,IAAE,IAAI,QAAQ,IAAI,aAAa,OAAO,cAAc,OAAO,CAAC;AAC5D,IAAE,IAAI,QAAQ,IAAI,QAAQ,IAAI,YAAY,GAAG;AAC7C,MAAI,SAAS,eAAe;GACxB,MAAM,cAAc,yBAAyB,QAAQ,cAAc;AACnE,OAAI,YAAa,GAAE,IAAI,QAAQ,IAAI,kBAAkB,YAAY"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["/**\n * Hono middleware that converts HTML responses to Markdown\n * when the client sends an `Accept: text/markdown` header.\n *\n * ```ts\n * import { Hono } from \"hono\";\n * import { markdown } from \"@markdown-for-agents/hono\";\n *\n * const app = new Hono();\n * app.use(\"*\", markdown());\n * ```\n * @module\n */\n\nimport type { MiddlewareHandler } from 'hono';\nimport { convert, buildContentSignalHeader } from 'markdown-for-agents';\nimport type { MiddlewareOptions } from 'markdown-for-agents';\n\nexport type { MiddlewareOptions } from 'markdown-for-agents';\n\n/**\n * Hono middleware that converts HTML responses to markdown\n * when the client sends an `Accept: text/markdown` header.\n *\n * @param options - Conversion and middleware options.\n * @returns A Hono middleware handler.\n *\n * @example\n * ```ts\n * import { Hono } from \"hono\";\n * import { markdown } from \"@markdown-for-agents/hono\";\n *\n * const app = new Hono();\n * app.use(\"*\", markdown());\n * ```\n */\nexport function markdown(options?: MiddlewareOptions): MiddlewareHandler {\n const tokenHeader = options?.tokenHeader ?? 'x-markdown-tokens';\n\n return async (c, next) => {\n await next();\n\n // Always signal that responses vary by Accept so caches store\n // separate entries for HTML and Markdown representations.\n c.res.headers.append('vary', 'Accept');\n\n const accept = c.req.header('accept') ?? '';\n if (!accept.includes('text/markdown')) return;\n\n const contentType = c.res.headers.get('content-type') ?? '';\n if (!contentType.includes('text/html')) return;\n\n const html = await c.res.text();\n const { markdown: md, tokenEstimate, contentHash } = convert(html, options);\n\n c.res = new Response(md, {\n status: c.res.status,\n headers: c.res.headers\n });\n c.res.headers.set('content-type', 'text/markdown; charset=utf-8');\n c.res.headers.set(tokenHeader, String(tokenEstimate.tokens));\n c.res.headers.set('etag', `\"${contentHash}\"`);\n if (options?.contentSignal) {\n const signalValue = buildContentSignalHeader(options.contentSignal);\n if (signalValue) c.res.headers.set('content-signal', signalValue);\n }\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAoCA,SAAgB,SAAS,SAAgD;CACrE,MAAM,cAAc,SAAS,eAAe;AAE5C,QAAO,OAAO,GAAG,SAAS;AACtB,QAAM,MAAM;AAIZ,IAAE,IAAI,QAAQ,OAAO,QAAQ,SAAS;AAGtC,MAAI,EADW,EAAE,IAAI,OAAO,SAAS,IAAI,IAC7B,SAAS,gBAAgB,CAAE;AAGvC,MAAI,EADgB,EAAE,IAAI,QAAQ,IAAI,eAAe,IAAI,IACxC,SAAS,YAAY,CAAE;EAGxC,MAAM,EAAE,UAAU,IAAI,eAAe,gBAAgB,QADxC,MAAM,EAAE,IAAI,MAAM,EACoC,QAAQ;AAE3E,IAAE,MAAM,IAAI,SAAS,IAAI;GACrB,QAAQ,EAAE,IAAI;GACd,SAAS,EAAE,IAAI;GAClB,CAAC;AACF,IAAE,IAAI,QAAQ,IAAI,gBAAgB,+BAA+B;AACjE,IAAE,IAAI,QAAQ,IAAI,aAAa,OAAO,cAAc,OAAO,CAAC;AAC5D,IAAE,IAAI,QAAQ,IAAI,QAAQ,IAAI,YAAY,GAAG;AAC7C,MAAI,SAAS,eAAe;GACxB,MAAM,cAAc,yBAAyB,QAAQ,cAAc;AACnE,OAAI,YAAa,GAAE,IAAI,QAAQ,IAAI,kBAAkB,YAAY"}
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@markdown-for-agents/hono",
3
- "version": "0.3.3",
3
+ "version": "1.0.1",
4
4
  "description": "Hono middleware for markdown-for-agents",
5
5
  "type": "module",
6
6
  "sideEffects": false,
7
7
  "engines": {
8
- "node": ">=20"
8
+ "node": ">=24"
9
9
  },
10
10
  "files": [
11
11
  "dist",
@@ -20,13 +20,13 @@
20
20
  "main": "./dist/index.mjs",
21
21
  "types": "./dist/index.d.mts",
22
22
  "dependencies": {
23
- "markdown-for-agents": "0.3.3"
23
+ "markdown-for-agents": "1.0.1"
24
24
  },
25
25
  "peerDependencies": {
26
26
  "hono": ">=4.0.0"
27
27
  },
28
28
  "devDependencies": {
29
- "hono": "^4.7.0"
29
+ "hono": "^4.12.5"
30
30
  },
31
31
  "keywords": [
32
32
  "html",