@markdown-for-agents/hono 1.2.0 → 1.3.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/dist/index.mjs +7 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -18,12 +18,13 @@ import { buildContentSignalHeader, convert } from "markdown-for-agents";
|
|
|
18
18
|
*/
|
|
19
19
|
function markdown(options) {
|
|
20
20
|
const tokenHeader = options?.tokenHeader ?? "x-markdown-tokens";
|
|
21
|
+
const timingHeader = options?.timingHeader ?? "x-markdown-timing";
|
|
21
22
|
return async (c, next) => {
|
|
22
23
|
await next();
|
|
23
24
|
c.res.headers.append("vary", "Accept");
|
|
24
25
|
if (!(c.req.header("accept") ?? "").includes("text/markdown")) return;
|
|
25
26
|
if (!(c.res.headers.get("content-type") ?? "").includes("text/html")) return;
|
|
26
|
-
const { markdown: md, tokenEstimate, contentHash } = convert(await c.res.text(), options);
|
|
27
|
+
const { markdown: md, tokenEstimate, contentHash, convertDuration } = convert(await c.res.text(), options);
|
|
27
28
|
c.res = new Response(md, {
|
|
28
29
|
status: c.res.status,
|
|
29
30
|
headers: c.res.headers
|
|
@@ -31,6 +32,11 @@ function markdown(options) {
|
|
|
31
32
|
c.res.headers.set("content-type", "text/markdown; charset=utf-8");
|
|
32
33
|
c.res.headers.set(tokenHeader, String(tokenEstimate.tokens));
|
|
33
34
|
c.res.headers.set("etag", `"${contentHash}"`);
|
|
35
|
+
if (convertDuration !== void 0) {
|
|
36
|
+
const timingValue = `mfa.convert;dur=${convertDuration.toFixed(1)};desc="HTML to Markdown"`;
|
|
37
|
+
c.res.headers.set("server-timing", timingValue);
|
|
38
|
+
c.res.headers.set(timingHeader, timingValue);
|
|
39
|
+
}
|
|
34
40
|
if (options?.contentSignal) {
|
|
35
41
|
const signalValue = buildContentSignalHeader(options.contentSignal);
|
|
36
42
|
if (signalValue) c.res.headers.set("content-signal", signalValue);
|
package/dist/index.mjs.map
CHANGED
|
@@ -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;
|
|
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 const timingHeader = options?.timingHeader ?? 'x-markdown-timing';\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\n const { markdown: md, tokenEstimate, contentHash, convertDuration } = 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 (convertDuration !== undefined) {\n const timingValue = `mfa.convert;dur=${convertDuration.toFixed(1)};desc=\"HTML to Markdown\"`;\n c.res.headers.set('server-timing', timingValue);\n c.res.headers.set(timingHeader, timingValue);\n }\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;CAC5C,MAAM,eAAe,SAAS,gBAAgB;AAE9C,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;EAIxC,MAAM,EAAE,UAAU,IAAI,eAAe,aAAa,oBAAoB,QAFzD,MAAM,EAAE,IAAI,MAAM,EAEqD,QAAQ;AAE5F,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,oBAAoB,KAAA,GAAW;GAC/B,MAAM,cAAc,mBAAmB,gBAAgB,QAAQ,EAAE,CAAC;AAClE,KAAE,IAAI,QAAQ,IAAI,iBAAiB,YAAY;AAC/C,KAAE,IAAI,QAAQ,IAAI,cAAc,YAAY;;AAEhD,MAAI,SAAS,eAAe;GACxB,MAAM,cAAc,yBAAyB,QAAQ,cAAc;AACnE,OAAI,YAAa,GAAE,IAAI,QAAQ,IAAI,kBAAkB,YAAY"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@markdown-for-agents/hono",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"description": "Hono middleware — serve Markdown to AI agents via content negotiation",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"main": "./dist/index.mjs",
|
|
21
21
|
"types": "./dist/index.d.mts",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"markdown-for-agents": "1.
|
|
23
|
+
"markdown-for-agents": "1.3.1"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
26
26
|
"hono": ">=4.0.0"
|