agent-reader 1.1.0 → 1.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.
@@ -4,6 +4,7 @@ import {
4
4
  cleanCommand,
5
5
  doctorCommand,
6
6
  exportCommand,
7
+ mcpStubCommand,
7
8
  openCommand,
8
9
  renderCommand,
9
10
  runCommandSafely,
@@ -16,7 +17,7 @@ const program = new Command();
16
17
  program
17
18
  .name('agent-reader')
18
19
  .description('AI Agent output beautifier and slideshow generator')
19
- .version('1.1.0');
20
+ .version('1.1.1');
20
21
 
21
22
  setupCommonCommandOptions(
22
23
  program
@@ -80,4 +81,9 @@ program
80
81
  .option('--days <days>', 'max age in days', '7')
81
82
  .action((options) => runCommandSafely(() => cleanCommand(options)));
82
83
 
84
+ program
85
+ .command('mcp')
86
+ .description('Start MCP server on stdio')
87
+ .action(() => runCommandSafely(() => mcpStubCommand()));
88
+
83
89
  await program.parseAsync(process.argv);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-reader",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "AI Agent 的文档美化引擎 — 一键把 Markdown 变成漂亮网页、Word、PDF 和幻灯片",
5
5
  "main": "index.js",
6
6
  "directories": {
@@ -1,5 +1,6 @@
1
1
  import { promises as fs } from 'node:fs';
2
2
  import path from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
3
4
  import open from 'open';
4
5
  import { execa } from 'execa';
5
6
  import { renderMarkdown } from '../core/renderer.js';
@@ -49,6 +50,9 @@ function normalizeMode(options) {
49
50
  }
50
51
 
51
52
  async function readAllFromStdin() {
53
+ if (process.stdin.isTTY) {
54
+ throw new Error('stdin is a terminal — pipe content or use a file path instead (e.g. echo "# hi" | agent-reader render --stdin)');
55
+ }
52
56
  const chunks = [];
53
57
  for await (const chunk of process.stdin) {
54
58
  chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
@@ -591,7 +595,9 @@ export async function cleanCommand(options) {
591
595
  }
592
596
 
593
597
  export async function mcpStubCommand() {
594
- const result = await execa('node', ['src/mcp/server.js'], { stdio: 'inherit' });
598
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
599
+ const serverPath = path.resolve(__dirname, '..', 'mcp', 'server.js');
600
+ const result = await execa('node', [serverPath], { stdio: 'inherit' });
595
601
  return result;
596
602
  }
597
603
 
@@ -723,14 +723,24 @@ export async function exportPDF(html, options = {}) {
723
723
 
724
724
  if (htmlPath) {
725
725
  await page.goto(pathToFileURL(path.resolve(htmlPath)).toString(), {
726
- waitUntil: 'networkidle0',
726
+ waitUntil: 'domcontentloaded',
727
727
  });
728
728
  } else {
729
729
  await page.setContent(html, {
730
- waitUntil: 'networkidle0',
730
+ waitUntil: 'domcontentloaded',
731
731
  });
732
732
  }
733
733
 
734
+ // Wait for images and fonts to finish loading before generating PDF
735
+ await page.evaluate(() =>
736
+ Promise.all([
737
+ document.fonts?.ready,
738
+ ...Array.from(document.images).map((img) =>
739
+ img.complete ? Promise.resolve() : new Promise((r) => { img.onload = r; img.onerror = r; }),
740
+ ),
741
+ ]),
742
+ );
743
+
734
744
  await page.addStyleTag({
735
745
  content: `
736
746
  @page {
package/src/mcp/server.js CHANGED
@@ -72,7 +72,7 @@ async function saveHtmlResult(html, outputDir, name = 'output') {
72
72
 
73
73
  const server = new McpServer({
74
74
  name: 'agent-reader',
75
- version: '1.1.0',
75
+ version: '1.1.1',
76
76
  });
77
77
 
78
78
  server.registerTool(