mn-docs-mcp 0.2.4 → 0.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.
Files changed (2) hide show
  1. package/mcp/lib.mjs +23 -3
  2. package/package.json +1 -1
package/mcp/lib.mjs CHANGED
@@ -75,7 +75,15 @@ function formatBytes(bytes) {
75
75
  function logDownloadProgress(info) {
76
76
  if (IS_SILENT) return;
77
77
  if (info?.status === 'download') {
78
- logInfo(color('开始下载模型...', '38;5;45'));
78
+ // 清除当前行(如果之前有内容)
79
+ if (IS_STDIO) {
80
+ process.stderr.write('\r\x1b[K'); // 清除整行
81
+ process.stderr.write(color('开始下载模型...', '38;5;45') + '\n');
82
+ } else {
83
+ process.stdout.write('\r\x1b[K'); // 清除整行
84
+ console.log(color('开始下载模型...', '38;5;45'));
85
+ }
86
+ lastDownloadProgress = -1;
79
87
  return;
80
88
  }
81
89
  if (info?.status === 'progress' && typeof info.progress === 'number') {
@@ -87,10 +95,10 @@ function logDownloadProgress(info) {
87
95
  const suffix = loaded && total ? ` ${loaded}/${total}` : '';
88
96
  const line = `${color('模型下载进度', '38;5;45')}: ${pct}%${suffix}`;
89
97
  if (IS_STDIO) {
90
- process.stderr.write(`\r${line}`);
98
+ process.stderr.write(`\r\x1b[K${line}`); // \x1b[K 清除从光标到行尾的内容
91
99
  if (pct === 100) process.stderr.write('\n');
92
100
  } else {
93
- process.stdout.write(`\r${line}`);
101
+ process.stdout.write(`\r\x1b[K${line}`);
94
102
  if (pct === 100) process.stdout.write('\n');
95
103
  }
96
104
  }
@@ -117,8 +125,18 @@ async function getExtractor() {
117
125
  if (extractorPromise) return extractorPromise;
118
126
  loadEnv();
119
127
  setupProxy();
128
+
129
+ // 抑制 Hugging Face Transformers 的警告输出
120
130
  env.cacheDir = path.join(MCP_DIR, 'models');
121
131
  env.allowRemoteModels = true;
132
+ env.disableProgressBars = true; // 禁用库自带的进度条
133
+ env.disableSymlinksWarning = true; // 禁用符号链接警告
134
+
135
+ // 设置日志级别为 error,避免 info/warning 级别日志干扰
136
+ if (!process.env.LOG_LEVEL) {
137
+ process.env.LOG_LEVEL = 'error';
138
+ }
139
+
122
140
  if (process.env.HF_ENDPOINT) {
123
141
  env.HF_ENDPOINT = process.env.HF_ENDPOINT;
124
142
  }
@@ -145,6 +163,8 @@ async function getExtractor() {
145
163
  throw error;
146
164
  }
147
165
 
166
+ // 清除上次的进度状态,为重试做准备
167
+ lastDownloadProgress = -1;
148
168
  logInfo(`模型下载失败,准备重试(${attempt}/${MAX_EXTRACTOR_RETRIES})...`);
149
169
  await fs.rm(modelDir, { recursive: true, force: true });
150
170
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mn-docs-mcp",
3
3
  "type": "module",
4
- "version": "0.2.4",
4
+ "version": "0.3.1",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/Temsys-Shen/marginnote-addon-docs.git"