mn-docs-mcp 0.3.0 → 0.3.2

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/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,11 +125,23 @@ async function getExtractor() {
117
125
  if (extractorPromise) return extractorPromise;
118
126
  loadEnv();
119
127
  setupProxy();
128
+
129
+ // 抑制 Hugging Face Transformers 的警告输出
130
+ env.cacheDir = path.join(MCP_DIR, 'models');
120
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
+
121
140
  if (process.env.HF_ENDPOINT) {
122
141
  env.HF_ENDPOINT = process.env.HF_ENDPOINT;
123
142
  }
124
143
 
144
+ const modelDir = path.join(env.cacheDir, 'Xenova', 'bge-small-zh-v1.5');
125
145
  const create = async () =>
126
146
  pipeline('feature-extraction', MODEL_ID, {
127
147
  progress_callback: logDownloadProgress,
@@ -143,7 +163,10 @@ async function getExtractor() {
143
163
  throw error;
144
164
  }
145
165
 
166
+ // 清除上次的进度状态,为重试做准备
167
+ lastDownloadProgress = -1;
146
168
  logInfo(`模型下载失败,准备重试(${attempt}/${MAX_EXTRACTOR_RETRIES})...`);
169
+ await fs.rm(modelDir, { recursive: true, force: true });
147
170
  }
148
171
  }
149
172
  throw new Error('模型加载失败');
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mn-docs-mcp",
3
3
  "type": "module",
4
- "version": "0.3.0",
4
+ "version": "0.3.2",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/Temsys-Shen/marginnote-addon-docs.git"
@@ -23,7 +23,7 @@ self.webView.evaluateJavaScript(script, null);
23
23
 
24
24
  // 或执行并取回结果
25
25
  self.webView.evaluateJavaScript("document.title", function (result) {
26
- JSB.log("页面标题: %@", result);
26
+ console.log("页面标题: %@", result);
27
27
  });
28
28
  ```
29
29
 
@@ -42,7 +42,7 @@ description: 理解 scene/notebook/document 生命周期及何时可安全使用
42
42
 
43
43
  ```javascript
44
44
  notebookWillOpen: function (topicid) {
45
- JSB.log("MNLOG Open Notebook: %@", topicid);
45
+ console.log("MNLOG Open Notebook: %@", topicid);
46
46
 
47
47
  NSTimer.scheduledTimerWithTimeInterval(0.2, false, function () {
48
48
  var showPanel = NSUserDefaults.standardUserDefaults().objectForKey("my_addon_show_panel");
@@ -56,9 +56,9 @@ UIAlertView.showWithTitleMessageStyleCancelButtonTitleOtherButtonTitlesTapBlock(
56
56
  ["确定"],
57
57
  function (alert, buttonIndex) {
58
58
  if (buttonIndex === 0) {
59
- JSB.log("用户点击了确定");
59
+ console.log("用户点击了确定");
60
60
  } else {
61
- JSB.log("用户取消");
61
+ console.log("用户取消");
62
62
  }
63
63
  }
64
64
  );
@@ -118,7 +118,7 @@ webViewShouldStartLoadWithRequestNavigationType: function (webView, request, typ
118
118
 
119
119
  ```javascript
120
120
  self.webView.evaluateJavaScript("document.title", function (result) {
121
- JSB.log("页面标题: %@", result);
121
+ console.log("页面标题: %@", result);
122
122
  });
123
123
  ```
124
124
 
@@ -2,7 +2,6 @@
2
2
  title: JSB
3
3
  description: JavaScript 桥接核心,连接插件 JS 与运行时对象的入口对象。
4
4
  ---
5
-
6
5
  JSB(JavaScript Bridge)是插件运行时的桥接核心对象:类定义、插件入口、日志与包内脚本加载都通过它完成。
7
6
 
8
7
  ## 实例成员 (Instance members)
@@ -23,11 +22,11 @@ defineClass(declaration: string, instanceMembers: object, classMembers?: object)
23
22
 
24
23
  **Parameters:**
25
24
 
26
- | Name | Type | Description |
27
- | :--- | :--- | :--- |
28
- | `declaration` | `string` | 类声明,例如 `'MyAddon : JSExtension'`。 |
29
- | `instanceMembers` | `object` | 实例方法与属性的集合。在此对象中定义的方法/属性在**实例**上调用(如 `sceneWillConnect`、`notebookWillOpen`、`queryAddonCommandStatus` 等)。 |
30
- | `classMembers` | `object?` | 类方法与属性的集合。在此对象中定义的方法在**类**上调用(如 `addonDidConnect`)。 |
25
+ | Name | Type | Description |
26
+ | :------------------ | :---------- | :------------------------------------------------------------------------------------------------------------------------------------------------------- |
27
+ | `declaration` | `string` | 类声明,例如 `'MyAddon : JSExtension'`。 |
28
+ | `instanceMembers` | `object` | 实例方法与属性的集合。在此对象中定义的方法/属性在**实例**上调用(如 `sceneWillConnect`、`notebookWillOpen`、`queryAddonCommandStatus` 等)。 |
29
+ | `classMembers` | `object?` | 类方法与属性的集合。在此对象中定义的方法在**类**上调用(如 `addonDidConnect`)。 |
31
30
 
32
31
  **Return Value:**
33
32
 
@@ -43,8 +42,8 @@ newAddon(mainPath: string): any
43
42
 
44
43
  **Parameters:**
45
44
 
46
- | Name | Type | Description |
47
- | :--- | :--- | :--- |
45
+ | Name | Type | Description |
46
+ | :----------- | :--------- | :----------------- |
48
47
  | `mainPath` | `string` | 插件包根目录路径。 |
49
48
 
50
49
  **Return Value:**
@@ -53,7 +52,7 @@ newAddon(mainPath: string): any
53
52
 
54
53
  ### `log`
55
54
 
56
- MarginNote 控制台输出日志,类似 `console.log`。
55
+ 向系统控制台输出日志,类似 `console.log`。在MN4已不可用。MN3中使用参考[log,error](https://ohmymn.marginnote.cn/api/marginnote/#log-error)
57
56
 
58
57
  ```javascript
59
58
  log(format: string, ...args: any[]): void
@@ -61,10 +60,10 @@ log(format: string, ...args: any[]): void
61
60
 
62
61
  **Parameters:**
63
62
 
64
- | Name | Type | Description |
65
- | :--- | :--- | :--- |
66
- | `format` | `string` | 格式化字符串,支持 `%@`、`%d` 等 Objective-C 格式。 |
67
- | `...args` | `any[]` | 对应格式化字符串的参数。 |
63
+ | Name | Type | Description |
64
+ | :---------- | :--------- | :------------------------------------------------------ |
65
+ | `format` | `string` | 格式化字符串,支持 `%@`、`%d` 等 Objective-C 格式。 |
66
+ | `...args` | `any[]` | 对应格式化字符串的参数。 |
68
67
 
69
68
  ### `require`
70
69
 
@@ -76,8 +75,8 @@ require(name: string): void
76
75
 
77
76
  **Parameters:**
78
77
 
79
- | Name | Type | Description |
80
- | :--- | :--- | :--- |
78
+ | Name | Type | Description |
79
+ | :------- | :--------- | :---------------------------- |
81
80
  | `name` | `string` | 插件包内 JS 文件路径/文件名。 |
82
81
 
83
82
  **Note:**