@cyuanxv/openrouter-analytics-mcp 0.0.0-stage → 0.6.0-alpha.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/LICENSE +204 -0
- package/README.md +104 -2
- package/dist/doctor.js +178 -0
- package/dist/index.js +2183 -0
- package/dist/stdio.js +63 -0
- package/drizzle/0000_personal_ops.sql +5 -0
- package/drizzle/0001_routing_presets.sql +7 -0
- package/package.json +50 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
Copyright 2026 cyuanxv
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
Apache License
|
|
5
|
+
Version 2.0, January 2004
|
|
6
|
+
http://www.apache.org/licenses/
|
|
7
|
+
|
|
8
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
9
|
+
|
|
10
|
+
1. Definitions.
|
|
11
|
+
|
|
12
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
13
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
14
|
+
|
|
15
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
16
|
+
the copyright owner that is granting the License.
|
|
17
|
+
|
|
18
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
19
|
+
other entities that control, are controlled by, or are under common
|
|
20
|
+
control with that entity. For the purposes of this definition,
|
|
21
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
22
|
+
direction or management of such entity, whether by contract or
|
|
23
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
24
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
25
|
+
|
|
26
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
27
|
+
exercising permissions granted by this License.
|
|
28
|
+
|
|
29
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
30
|
+
including but not limited to software source code, documentation
|
|
31
|
+
source, and configuration files.
|
|
32
|
+
|
|
33
|
+
"Object" form shall mean any form resulting from mechanical
|
|
34
|
+
transformation or translation of a Source form, including but
|
|
35
|
+
not limited to compiled object code, generated documentation,
|
|
36
|
+
and conversions to other media types.
|
|
37
|
+
|
|
38
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
39
|
+
Object form, made available under the License, as indicated by a
|
|
40
|
+
copyright notice that is included in or attached to the work
|
|
41
|
+
(an example is provided in the Appendix below).
|
|
42
|
+
|
|
43
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
44
|
+
form, that is based on (or derived from) the Work and for which the
|
|
45
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
46
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
47
|
+
of this License, Derivative Works shall not include works that remain
|
|
48
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
49
|
+
the Work and Derivative Works thereof.
|
|
50
|
+
|
|
51
|
+
"Contribution" shall mean any work of authorship, including
|
|
52
|
+
the original version of the Work and any modifications or additions
|
|
53
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
54
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
55
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
56
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
57
|
+
means any form of electronic, verbal, or written communication sent
|
|
58
|
+
to the Licensor or its representatives, including but not limited to
|
|
59
|
+
communication on electronic mailing lists, source code control systems,
|
|
60
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
61
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
62
|
+
excluding communication that is conspicuously marked or otherwise
|
|
63
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
64
|
+
|
|
65
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
66
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
67
|
+
subsequently incorporated within the Work.
|
|
68
|
+
|
|
69
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
70
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
71
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
72
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
73
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
74
|
+
Work and such Derivative Works in Source or Object form.
|
|
75
|
+
|
|
76
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
77
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
78
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
79
|
+
(except as stated in this section) patent license to make, have made,
|
|
80
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
81
|
+
where such license applies only to those patent claims licensable
|
|
82
|
+
by such Contributor that are necessarily infringed by their
|
|
83
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
84
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
85
|
+
institute patent litigation against any entity (including a
|
|
86
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
87
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
88
|
+
or contributory patent infringement, then any patent licenses
|
|
89
|
+
granted to You under this License for that Work shall terminate
|
|
90
|
+
as of the date such litigation is filed.
|
|
91
|
+
|
|
92
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
93
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
94
|
+
modifications, and in Source or Object form, provided that You
|
|
95
|
+
meet the following conditions:
|
|
96
|
+
|
|
97
|
+
(a) You must give any other recipients of the Work or
|
|
98
|
+
Derivative Works a copy of this License; and
|
|
99
|
+
|
|
100
|
+
(b) You must cause any modified files to carry prominent notices
|
|
101
|
+
stating that You changed the files; and
|
|
102
|
+
|
|
103
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
104
|
+
that You distribute, all copyright, patent, trademark, and
|
|
105
|
+
attribution notices from the Source form of the Work,
|
|
106
|
+
excluding those notices that do not pertain to any part of
|
|
107
|
+
the Derivative Works; and
|
|
108
|
+
|
|
109
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
110
|
+
distribution, then any Derivative Works that You distribute must
|
|
111
|
+
include a readable copy of the attribution notices contained
|
|
112
|
+
within such NOTICE file, excluding those notices that do not
|
|
113
|
+
pertain to any part of the Derivative Works, in at least one
|
|
114
|
+
of the following places: within a NOTICE text file distributed
|
|
115
|
+
as part of the Derivative Works; within the Source form or
|
|
116
|
+
documentation, if provided along with the Derivative Works; or,
|
|
117
|
+
within a display generated by the Derivative Works, if and
|
|
118
|
+
wherever such third-party notices normally appear. The contents
|
|
119
|
+
of the NOTICE file are for informational purposes only and
|
|
120
|
+
do not modify the License. You may add Your own attribution
|
|
121
|
+
notices within Derivative Works that You distribute, alongside
|
|
122
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
123
|
+
that such additional attribution notices cannot be construed
|
|
124
|
+
as modifying the License.
|
|
125
|
+
|
|
126
|
+
You may add Your own copyright statement to Your modifications and
|
|
127
|
+
may provide additional or different license terms and conditions
|
|
128
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
129
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
130
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
131
|
+
the conditions stated in this License.
|
|
132
|
+
|
|
133
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
134
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
135
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
136
|
+
this License, without any additional terms or conditions.
|
|
137
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
138
|
+
the terms of any separate license agreement you may have executed
|
|
139
|
+
with Licensor regarding such Contributions.
|
|
140
|
+
|
|
141
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
142
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
143
|
+
except as required for reasonable and customary use in describing the
|
|
144
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
145
|
+
|
|
146
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
147
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
148
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
149
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
150
|
+
implied, including, without limitation, any warranties or conditions
|
|
151
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
152
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
153
|
+
appropriateness of using or redistributing the Work and assume any
|
|
154
|
+
risks associated with Your exercise of permissions under this License.
|
|
155
|
+
|
|
156
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
157
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
158
|
+
unless required by applicable law (such as deliberate and grossly
|
|
159
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
160
|
+
liable to You for damages, including any direct, indirect, special,
|
|
161
|
+
incidental, or consequential damages of any character arising as a
|
|
162
|
+
result of this License or out of the use or inability to use the
|
|
163
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
164
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
165
|
+
other commercial damages or losses), even if such Contributor
|
|
166
|
+
has been advised of the possibility of such damages.
|
|
167
|
+
|
|
168
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
169
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
170
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
171
|
+
or other liability obligations and/or rights consistent with this
|
|
172
|
+
License. However, in accepting such obligations, You may act only
|
|
173
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
174
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
175
|
+
defend, and hold each Contributor harmless for any liability
|
|
176
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
177
|
+
of your accepting any such warranty or additional liability.
|
|
178
|
+
|
|
179
|
+
END OF TERMS AND CONDITIONS
|
|
180
|
+
|
|
181
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
182
|
+
|
|
183
|
+
To apply the Apache License to your work, attach the following
|
|
184
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
185
|
+
replaced with your own identifying information. (Don't include
|
|
186
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
187
|
+
comment syntax for the file format. We also recommend that a
|
|
188
|
+
file or class name and description of purpose be included on the
|
|
189
|
+
same "printed page" as the copyright notice for easier
|
|
190
|
+
identification within third-party archives.
|
|
191
|
+
|
|
192
|
+
Copyright [yyyy] [name of copyright owner]
|
|
193
|
+
|
|
194
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
195
|
+
you may not use this file except in compliance with the License.
|
|
196
|
+
You may obtain a copy of the License at
|
|
197
|
+
|
|
198
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
199
|
+
|
|
200
|
+
Unless required by applicable law or agreed to in writing, software
|
|
201
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
202
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
203
|
+
See the License for the specific language governing permissions and
|
|
204
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,105 @@
|
|
|
1
|
-
#
|
|
1
|
+
# OpenRouter 工作台 — Local MCP
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
完整的个人费用分析、报告、成本实验和模型预设工具,通过 MCP stdio 在本机运行,使用 SQLite 保存记录。包含与 Sites 版相同的 28 个工具。由 cyuanxv 维护:[X / Twitter @cyuanxv](https://x.com/cyuanxv)。第三方项目,非 OpenRouter 官方产品。
|
|
4
|
+
|
|
5
|
+
0.6.0-alpha.2 公开 alpha。本地版不附带网页、后台任务或自动 Telegram 发送;保留报告生成、通知认领和真实回执记录能力,不执行付费推理、充值、Key 修改或生产路由切换。
|
|
6
|
+
|
|
7
|
+
## 安装(中文)
|
|
8
|
+
|
|
9
|
+
需要 Node.js 22.22+(22 系列)或 24+。已测试 22.22.2、24.16.0;部分 Node 版本会向 stderr 输出 SQLite 实验性功能提示。
|
|
10
|
+
|
|
11
|
+
在新的空目录中,从 npm 安装固定版本(也提供 GitHub Release tarball):
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install --ignore-scripts @cyuanxv/openrouter-analytics-mcp@0.6.0-alpha.2
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
在支持本地 MCP stdio 的客户端中新增如下配置。Node 和安装文件都使用自己电脑的绝对路径。通过客户端安全环境设置填写 Key,不把真实密钥粘贴进聊天、Git 或终端命令。
|
|
18
|
+
|
|
19
|
+
```json
|
|
20
|
+
{
|
|
21
|
+
"mcpServers": {
|
|
22
|
+
"openrouter-analytics-mcp-local": {
|
|
23
|
+
"command": "/absolute/path/to/node",
|
|
24
|
+
"args": ["/absolute/path/to/install/node_modules/@cyuanxv/openrouter-analytics-mcp/dist/stdio.js"],
|
|
25
|
+
"env": {
|
|
26
|
+
"OPENROUTER_WORKBENCH_DATA_DIR": "/absolute/path/to/dedicated-private-data",
|
|
27
|
+
"OPENROUTER_MANAGEMENT_KEY": "REPLACE_IN_CLIENT_SECRET_SETTINGS"
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
数据目录必须是绝对路径、专用于本工具;不要指定根目录、家目录本身或源码目录。启动时会设目录权限为 0700、数据库文件为 0600(Windows 需使用者确保 ACL 私有)。数据库文件名 `workbench.sqlite`。符号链接目录、符号链接或硬链接数据库会被拒绝。缺少目录配置、权限不足或迁移失败时启动失败,不显示配置值。
|
|
35
|
+
|
|
36
|
+
先调用 `routerlens_status`:mode=local-stdio,adapter_version=0.6.0-alpha.2,version 保留共享核心版本 0.5.0。authentication_verified=false 表示没有 Sites 云端身份认证;connectivity_verified=false 表示未测试上游连接。实际账户工具成功才证明自己的 Key 可用。Key 缺失时仍能管理本地记录和访问公开模型目录,账单查询会报错。保留 routerlens_status 等工具 ID 以兼容现有调用。
|
|
37
|
+
|
|
38
|
+
## 安装与配置自检
|
|
39
|
+
|
|
40
|
+
从本地 npm 安装目录运行:
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
./node_modules/.bin/openrouter-analytics-mcp doctor
|
|
44
|
+
./node_modules/.bin/openrouter-analytics-mcp doctor --offline
|
|
45
|
+
./node_modules/.bin/openrouter-analytics-mcp doctor --json
|
|
46
|
+
./node_modules/.bin/openrouter-analytics-mcp doctor --help
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
从完整源码构建时,可在 `packages/local-mcp` 中运行 `node dist/stdio.js doctor`。同一包不带参数时仍启动原 MCP 服务。
|
|
50
|
+
|
|
51
|
+
- 检查 Node 版本、Key 配置及 Management 权限、基础账户读取、数据目录权限,用中文说明问题和解决办法。
|
|
52
|
+
- 默认只向固定 OpenRouter HTTPS 地址发送 `GET /api/v1/key`、`GET /api/v1/credits`,最多两个请求,每个最多等待 5 秒;普通 Key 或未确认权限时不继续查询余额。
|
|
53
|
+
- `--offline` 不联网,只检查本机配置;不能证明 Key 有效或账户可连接。
|
|
54
|
+
- 从当前进程的 `OPENROUTER_MANAGEMENT_KEY` 与 `OPENROUTER_WORKBENCH_DATA_DIR` 读取配置。终端不会自动获得 MCP 客户端里的秘密配置;不要把 Key 作为命令参数、写进 Git 或粘贴到聊天。
|
|
55
|
+
- 不打印 Key、账户标识或余额;不调用模型,不修改 Key,不创建目录、不试写文件、不打开数据库、不修改权限。检查目录权限不等于验证磁盘空间、数据库完整性或迁移成功。
|
|
56
|
+
- 缺少目录会报错;尚未创建但父目录可访问会提示“待确认”,正常启动创建后应再次检查。Windows 的私有 ACL 未自动验证。
|
|
57
|
+
- 退出码 `0`:基础检查通过;`1`:发现配置或权限错误;`2`:网络超时、离线、限流、待创建目录等导致未完整验证。`--json` 输出同样的中文诊断和稳定错误代码,便于提交脱敏问题报告。
|
|
58
|
+
|
|
59
|
+
详见仓库中的 [中文故障排查](https://github.com/cyuanxv/openrouter-analytics-mcp/blob/main/docs/DOCTOR.md)。
|
|
60
|
+
|
|
61
|
+
## 数据与运行边界
|
|
62
|
+
|
|
63
|
+
- 数据在自己的 SQLite 中持久保存;账户查询会访问 OpenRouter,返回结果还受 MCP 客户端的数据政策约束。
|
|
64
|
+
- 本机同一用户或具备足够文件权限的程序可能访问数据库。记录可能包含费用、请求标识、人工备注和回执,不能提交到公开仓库。
|
|
65
|
+
- 停止全部实例后备份整个数据目录;升级前备份。卸载包不会删除数据库。进程收到 SIGINT/SIGTERM 或客户端关闭时会关闭数据库。
|
|
66
|
+
- 电脑关闭或进程退出后不能继续运行定时任务。本地版不自动发送 Telegram;模拟回执不可当作真实发送记录。
|
|
67
|
+
- ChatGPT 云端不能直接启动本机 stdio 进程。需要云端运行时继续使用 Sites 版。此包不提供公共 HTTP 入口,不使用浏览器传入的 Sites 身份头。
|
|
68
|
+
|
|
69
|
+
## 从完整源码构建
|
|
70
|
+
|
|
71
|
+
在完整源码包的 packages/local-mcp 中执行:
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
npm ci --ignore-scripts
|
|
75
|
+
npm run build
|
|
76
|
+
npm test
|
|
77
|
+
npm pack --ignore-scripts
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
构建复用 ../../services/routerlens,不能只复制此子目录进行源码构建。生成的 `.tgz` 自带运行产物和迁移文件,用户安装后不需要完整源码树,也无需运行 build。
|
|
81
|
+
|
|
82
|
+
## English
|
|
83
|
+
|
|
84
|
+
A local stdio MCP server with all 28 tools from the personal Sites edition: OpenRouter cost analytics, call metadata, anomaly investigation, saved reports, experiments and versioned routing presets. Requires Node.js 22.22+ (22.x) or 24+, your own OpenRouter account and, for account queries, your own Management Key.
|
|
85
|
+
|
|
86
|
+
Install the pinned alpha into an empty directory using `npm install --ignore-scripts @cyuanxv/openrouter-analytics-mcp@0.6.0-alpha.2`. Configure a local MCP client to run the installed dist/stdio.js with an absolute Node.js path. Set OPENROUTER_WORKBENCH_DATA_DIR to a dedicated absolute private directory; provide OPENROUTER_MANAGEMENT_KEY through client secret settings. You can also install a downloaded release tarball with npm.
|
|
87
|
+
|
|
88
|
+
SQLite records survive process restarts and package removal. Back up the data directory while all instances are stopped. There is no dashboard, HTTP listener, Sites identity, built-in scheduler or automatic Telegram delivery. This is not a ChatGPT cloud connector. No paid inference, key writes or production routing changes are performed. Returned data is also subject to your MCP client's policies.
|
|
89
|
+
|
|
90
|
+
Public alpha on npm and GitHub, registered as io.github.cyuanxv/openrouter-analytics-mcp in the official MCP Registry. See the repository publication and verification record. Apache-2.0; independent of OpenRouter.
|
|
91
|
+
|
|
92
|
+
### Installation diagnostics
|
|
93
|
+
|
|
94
|
+
Run `./node_modules/.bin/openrouter-analytics-mcp doctor` after installing the package. From the complete source, build first and run `node dist/stdio.js doctor` in `packages/local-mcp`. `--offline` makes no network requests; `--json` emits structured Chinese diagnostics. Available starting with 0.6.0-alpha.2.
|
|
95
|
+
|
|
96
|
+
The check validates supported Node versions, Management Key identity, basic account credit-read access, and directory access. It only calls the fixed HTTPS `/api/v1/key` and `/api/v1/credits` GET endpoints, with bounded responses and timeouts, and never follows redirects. It prints no key, balance, account identity or raw upstream errors. It does not create folders, write files, open databases, change permissions, mutate keys or invoke models. It does not prove analytics access, database integrity, migration success, free disk space or Windows ACL privacy. Exit codes: 0 = basic checks passed, 1 = configuration/authentication error, 2 = incomplete verification. Terminal and MCP-client environments are separate.
|
|
97
|
+
|
|
98
|
+
## Release links / 发布链接
|
|
99
|
+
|
|
100
|
+
安装包、源码与登记标识:
|
|
101
|
+
|
|
102
|
+
- Repository : https://github.com/cyuanxv/openrouter-analytics-mcp
|
|
103
|
+
- npm : https://www.npmjs.com/package/@cyuanxv/openrouter-analytics-mcp
|
|
104
|
+
- MCP Registry name : `io.github.cyuanxv/openrouter-analytics-mcp`
|
|
105
|
+
- CLI: `openrouter-analytics-mcp`
|
package/dist/doctor.js
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
// src/doctor.ts
|
|
2
|
+
import { accessSync, constants, lstatSync, existsSync } from "node:fs";
|
|
3
|
+
import { dirname, isAbsolute, join, parse, resolve } from "node:path";
|
|
4
|
+
import { homedir } from "node:os";
|
|
5
|
+
var names = { node: "Node.js \u7248\u672C", key: "Key \u914D\u7F6E\u4E0E\u6743\u9650", account: "\u8D26\u6237\u8FDE\u63A5", directory: "\u6570\u636E\u76EE\u5F55" };
|
|
6
|
+
var check = (id, status, code, message, remedy) => ({ id, name: names[id], status, code, message, ...remedy ? { remedy } : {} });
|
|
7
|
+
function supportedNode(version) {
|
|
8
|
+
const match = /^(\d+)\.(\d+)\.(\d+)$/.exec(version);
|
|
9
|
+
if (!match) return false;
|
|
10
|
+
const [, major, minor] = match.map(Number);
|
|
11
|
+
return major >= 24 || major === 22 && minor >= 22;
|
|
12
|
+
}
|
|
13
|
+
function directoryCheck(directory, platform) {
|
|
14
|
+
const fix = "\u5C06 OPENROUTER_WORKBENCH_DATA_DIR \u8BBE\u4E3A\u672C\u5DE5\u5177\u4E13\u7528\u76EE\u5F55\u7684\u7EDD\u5BF9\u8DEF\u5F84\uFF1B\u4E0D\u8981\u4F7F\u7528\u6839\u76EE\u5F55\u3001\u5BB6\u76EE\u5F55\u6216\u6E90\u7801\u76EE\u5F55\u3002";
|
|
15
|
+
if (!directory) return check("directory", "fail", "DATA_DIR_MISSING", "\u5C1A\u672A\u914D\u7F6E\u6570\u636E\u76EE\u5F55\u3002", fix);
|
|
16
|
+
if (!isAbsolute(directory)) return check("directory", "fail", "DATA_DIR_RELATIVE", "\u6570\u636E\u76EE\u5F55\u4E0D\u662F\u7EDD\u5BF9\u8DEF\u5F84\u3002", fix);
|
|
17
|
+
const dir = resolve(directory);
|
|
18
|
+
if ([parse(dir).root, resolve(homedir())].includes(dir)) return check("directory", "fail", "DATA_DIR_NOT_DEDICATED", "\u6570\u636E\u76EE\u5F55\u5FC5\u987B\u662F\u4E13\u7528\u76EE\u5F55\u3002", fix);
|
|
19
|
+
const mode = constants.R_OK | constants.W_OK | (platform === "win32" ? 0 : constants.X_OK);
|
|
20
|
+
try {
|
|
21
|
+
let info;
|
|
22
|
+
try {
|
|
23
|
+
info = lstatSync(dir);
|
|
24
|
+
} catch (error) {
|
|
25
|
+
if (error.code !== "ENOENT") throw error;
|
|
26
|
+
}
|
|
27
|
+
if (!info) {
|
|
28
|
+
let parent = dirname(dir);
|
|
29
|
+
while (!existsSync(parent) && parent !== dirname(parent)) parent = dirname(parent);
|
|
30
|
+
if (!lstatSync(parent).isDirectory()) return check("directory", "fail", "DATA_PARENT_NOT_DIRECTORY", "\u6570\u636E\u76EE\u5F55\u7684\u7236\u8DEF\u5F84\u4E0D\u662F\u76EE\u5F55\u3002", fix);
|
|
31
|
+
accessSync(parent, mode);
|
|
32
|
+
return check("directory", "warn", "DATA_DIR_NOT_CREATED", "\u76EE\u5F55\u5C1A\u672A\u521B\u5EFA\uFF1B\u7236\u76EE\u5F55\u6743\u9650\u68C0\u67E5\u901A\u8FC7\u3002", "\u9996\u6B21\u6B63\u5E38\u542F\u52A8\u4F1A\u521B\u5EFA\u4E13\u7528\u76EE\u5F55\u3002\u81EA\u68C0\u672A\u521B\u5EFA\u76EE\u5F55\uFF0C\u4E5F\u672A\u8BD5\u5199\u6587\u4EF6\uFF1B\u521B\u5EFA\u6210\u529F\u540E\u91CD\u65B0\u81EA\u68C0\u3002");
|
|
33
|
+
}
|
|
34
|
+
if (info.isSymbolicLink() || !info.isDirectory()) return check("directory", "fail", "DATA_DIR_UNSAFE", "\u6570\u636E\u76EE\u5F55\u662F\u7B26\u53F7\u94FE\u63A5\u6216\u666E\u901A\u6587\u4EF6\uFF0C\u4E0D\u80FD\u5B89\u5168\u4F7F\u7528\u3002", fix);
|
|
35
|
+
if (existsSync(join(dir, "package.json")) || existsSync(join(dir, ".git"))) return check("directory", "fail", "DATA_DIR_SOURCE", "\u6570\u636E\u76EE\u5F55\u6307\u5411\u6E90\u7801\u6216\u5B89\u88C5\u76EE\u5F55\u3002", fix);
|
|
36
|
+
accessSync(dir, mode);
|
|
37
|
+
let db;
|
|
38
|
+
try {
|
|
39
|
+
db = lstatSync(join(dir, "workbench.sqlite"));
|
|
40
|
+
} catch (error) {
|
|
41
|
+
if (error.code !== "ENOENT") throw error;
|
|
42
|
+
}
|
|
43
|
+
if (db) {
|
|
44
|
+
if (!db.isFile() || db.isSymbolicLink() || db.nlink !== 1) return check("directory", "fail", "DATABASE_UNSAFE", "\u6570\u636E\u5E93\u662F\u94FE\u63A5\u6216\u4E0D\u662F\u666E\u901A\u6587\u4EF6\uFF0C\u4E0D\u80FD\u5B89\u5168\u4F7F\u7528\u3002", "\u4FDD\u7559\u539F\u6587\u4EF6\u4E0E\u5907\u4EFD\uFF0C\u9009\u62E9\u65B0\u7684\u4E13\u7528\u6570\u636E\u76EE\u5F55\uFF1B\u4E0D\u8981\u5220\u9664\u6216\u8986\u76D6\u73B0\u6709\u6570\u636E\u5E93\u3002");
|
|
45
|
+
accessSync(join(dir, "workbench.sqlite"), constants.R_OK | constants.W_OK);
|
|
46
|
+
}
|
|
47
|
+
if (platform === "win32") return check("directory", "warn", "DATA_ACL_UNVERIFIED", "\u76EE\u5F55\u8BFB\u5199\u6743\u9650\u68C0\u67E5\u901A\u8FC7\uFF1B\u5C1A\u672A\u9A8C\u8BC1 Windows \u79C1\u6709\u8BBF\u95EE\u63A7\u5236\u3002", "\u5728\u76EE\u5F55\u5B89\u5168\u8BBE\u7F6E\u4E2D\u786E\u8BA4\u4EC5\u5F53\u524D\u7528\u6237\u53EF\u8BBF\u95EE\u3002\u81EA\u68C0\u4E0D\u4F1A\u4FEE\u6539 ACL\u3002");
|
|
48
|
+
if (info.mode & 63 || db && db.mode & 63) return check("directory", "warn", "DATA_PERMISSIONS_BROAD", "\u76EE\u5F55\u6216\u6570\u636E\u5E93\u5141\u8BB8\u5176\u4ED6\u7528\u6237\u8BBF\u95EE\u3002", "\u505C\u6B62\u672C\u5DE5\u5177\u7684\u6240\u6709\u5B9E\u4F8B\uFF0C\u786E\u8BA4\u76EE\u5F55\u4E13\u7528\u5E76\u5907\u4EFD\u540E\uFF0C\u5C06\u76EE\u5F55\u6743\u9650\u8BBE\u4E3A 0700\u3001\u6570\u636E\u5E93\u8BBE\u4E3A 0600\u3002\u81EA\u68C0\u4E0D\u4F1A\u4FEE\u6539\u6743\u9650\u3002");
|
|
49
|
+
return check("directory", "pass", "DATA_DIR_ACCESS_OK", "\u76EE\u5F55\u53CA\u73B0\u6709\u6570\u636E\u5E93\u7684\u6743\u9650\u68C0\u67E5\u901A\u8FC7\uFF1B\u672A\u8BD5\u5199\u3001\u672A\u6253\u5F00\u6570\u636E\u5E93\uFF0C\u672A\u9A8C\u8BC1\u8FC1\u79FB\u6216\u5269\u4F59\u78C1\u76D8\u7A7A\u95F4\u3002");
|
|
50
|
+
} catch {
|
|
51
|
+
return check("directory", "fail", "DATA_DIR_INACCESSIBLE", "\u6570\u636E\u76EE\u5F55\u3001\u7236\u76EE\u5F55\u6216\u6570\u636E\u5E93\u65E0\u6CD5\u8BBF\u95EE\uFF0C\u6216\u6CA1\u6709\u6240\u9700\u8BFB\u5199\u6743\u9650\u3002", "\u68C0\u67E5\u76EE\u5F55\u662F\u5426\u5B58\u5728\u3001\u5F53\u524D\u7528\u6237\u6743\u9650\u548C\u53EA\u8BFB\u78C1\u76D8\u72B6\u6001\uFF1B\u9009\u62E9\u53EF\u8BBF\u95EE\u7684\u4E13\u7528\u76EE\u5F55\uFF0C\u4E0D\u8981\u4EE5\u7BA1\u7406\u5458\u6743\u9650\u8FD0\u884C\u6765\u7ED5\u8FC7\u95EE\u9898\u3002");
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
var ProbeError = class extends Error {
|
|
55
|
+
constructor(code) {
|
|
56
|
+
super(code);
|
|
57
|
+
this.code = code;
|
|
58
|
+
}
|
|
59
|
+
code;
|
|
60
|
+
};
|
|
61
|
+
async function readData(path, key, transport, timeoutMs) {
|
|
62
|
+
const controller = new AbortController();
|
|
63
|
+
let timer;
|
|
64
|
+
const deadline = new Promise((_, reject) => {
|
|
65
|
+
timer = setTimeout(() => {
|
|
66
|
+
controller.abort();
|
|
67
|
+
reject(new ProbeError("TIMEOUT"));
|
|
68
|
+
}, timeoutMs);
|
|
69
|
+
});
|
|
70
|
+
const request = (async () => {
|
|
71
|
+
const response = await transport("https://openrouter.ai/api/v1" + path, { method: "GET", headers: { Accept: "application/json", Authorization: "Bearer " + key }, redirect: "manual", cache: "no-store", credentials: "omit", signal: controller.signal });
|
|
72
|
+
if (!response.ok) {
|
|
73
|
+
void response.body?.cancel().catch(() => {
|
|
74
|
+
});
|
|
75
|
+
throw new ProbeError("HTTP_" + response.status);
|
|
76
|
+
}
|
|
77
|
+
if (!response.body) throw new ProbeError("INVALID_RESPONSE");
|
|
78
|
+
const reader = response.body.getReader();
|
|
79
|
+
const chunks = [];
|
|
80
|
+
let size = 0;
|
|
81
|
+
try {
|
|
82
|
+
while (true) {
|
|
83
|
+
const { done, value } = await reader.read();
|
|
84
|
+
if (done) break;
|
|
85
|
+
size += value.byteLength;
|
|
86
|
+
if (size > 64 * 1024) throw new ProbeError("INVALID_RESPONSE");
|
|
87
|
+
chunks.push(value);
|
|
88
|
+
}
|
|
89
|
+
const bytes = new Uint8Array(size);
|
|
90
|
+
let offset = 0;
|
|
91
|
+
for (const chunk of chunks) {
|
|
92
|
+
bytes.set(chunk, offset);
|
|
93
|
+
offset += chunk.length;
|
|
94
|
+
}
|
|
95
|
+
const body = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(bytes));
|
|
96
|
+
if (!body || typeof body.data !== "object" || body.data === null || Array.isArray(body.data)) throw new ProbeError("INVALID_RESPONSE");
|
|
97
|
+
return body.data;
|
|
98
|
+
} catch (error) {
|
|
99
|
+
if (error instanceof ProbeError) throw error;
|
|
100
|
+
throw new ProbeError("INVALID_RESPONSE");
|
|
101
|
+
} finally {
|
|
102
|
+
void reader.cancel().catch(() => {
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
})();
|
|
106
|
+
try {
|
|
107
|
+
return await Promise.race([request, deadline]);
|
|
108
|
+
} finally {
|
|
109
|
+
clearTimeout(timer);
|
|
110
|
+
controller.abort();
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
function upstreamProblem(id, error) {
|
|
114
|
+
const code = error instanceof ProbeError ? error.code : "NETWORK_ERROR";
|
|
115
|
+
if (code === "HTTP_401") return check(id, "fail", "AUTH_REJECTED", "OpenRouter \u62D2\u7EDD\u4E86\u6B64 Key\uFF0C\u53EF\u80FD\u5DF2\u5931\u6548\u6216\u914D\u7F6E\u9519\u8BEF\u3002", "\u68C0\u67E5\u5F53\u524D\u5BA2\u6237\u7AEF\u7684\u79D8\u5BC6\u73AF\u5883\u914D\u7F6E\u548C OpenRouter Key \u72B6\u6001\uFF1B\u4E0D\u8981\u628A Key \u53D1\u5230\u804A\u5929\u6216\u4F5C\u4E3A\u547D\u4EE4\u884C\u53C2\u6570\u3002");
|
|
116
|
+
if (code === "HTTP_403") return check(id, "fail", "PERMISSION_DENIED", "OpenRouter \u62D2\u7EDD\u6B64\u9879\u8BFB\u53D6\u6743\u9650\u3002", "\u786E\u8BA4\u4F7F\u7528 Management Key\uFF0C\u5E76\u68C0\u67E5\u8D26\u6237\u6216\u7EC4\u7EC7\u8BBF\u95EE\u9650\u5236\uFF1B\u666E\u901A\u6A21\u578B\u8C03\u7528 Key \u4E0D\u8DB3\u4EE5\u8BFB\u53D6\u8D26\u6237\u4F59\u989D\u3002");
|
|
117
|
+
if (code === "HTTP_429") return check(id, "warn", "RATE_LIMITED", "OpenRouter \u6682\u65F6\u9650\u6D41\uFF0C\u5C1A\u672A\u5B8C\u6210\u9A8C\u8BC1\u3002", "\u7A0D\u540E\u91CD\u65B0\u81EA\u68C0\uFF1B\u4E0D\u8981\u8FDE\u7EED\u91CD\u8BD5\u6216\u636E\u6B64\u66F4\u6362 Key\u3002");
|
|
118
|
+
if (code === "TIMEOUT") return check(id, "warn", code, "\u8FDE\u63A5\u6216\u8BFB\u53D6 OpenRouter \u8D85\u65F6\uFF0C\u65E0\u6CD5\u786E\u8BA4\u7ED3\u679C\u3002", "\u68C0\u67E5\u7F51\u7EDC\u3001\u4EE3\u7406\u4E0E\u9632\u706B\u5899\u540E\u91CD\u8BD5\uFF1B\u8FD9\u4E0D\u8868\u793A Key \u65E0\u6548\u3002");
|
|
119
|
+
if (/^HTTP_3\d\d$/.test(code)) return check(id, "fail", "REDIRECT_BLOCKED", "OpenRouter \u8FD4\u56DE\u91CD\u5B9A\u5411\uFF0C\u5DF2\u505C\u6B62\u4EE5\u907F\u514D\u5411\u5176\u4ED6\u5730\u5740\u4F20\u9001 Key\u3002", "\u68C0\u67E5\u7F51\u7EDC\u4EE3\u7406\u6216\u95E8\u6237\u767B\u5F55\u72B6\u6001\uFF1B\u81EA\u68C0\u53EA\u5141\u8BB8\u56FA\u5B9A\u7684 OpenRouter HTTPS \u5730\u5740\uFF0C\u4E0D\u8DDF\u968F\u91CD\u5B9A\u5411\u3002");
|
|
120
|
+
if (/^HTTP_5\d\d$/.test(code)) return check(id, "warn", "UPSTREAM_UNAVAILABLE", "OpenRouter \u670D\u52A1\u6682\u65F6\u4E0D\u53EF\u7528\uFF0C\u5C1A\u672A\u5B8C\u6210\u9A8C\u8BC1\u3002", "\u7A0D\u540E\u91CD\u8BD5\uFF1B\u65E0\u9700\u4FEE\u6539 Key \u6216\u672C\u5730\u6570\u636E\u5E93\u3002");
|
|
121
|
+
if (code === "INVALID_RESPONSE") return check(id, "warn", code, "OpenRouter \u8FD4\u56DE\u7684\u6570\u636E\u683C\u5F0F\u4E0D\u7B26\u5408\u9884\u671F\uFF0C\u5C1A\u672A\u5B8C\u6210\u9A8C\u8BC1\u3002", "\u68C0\u67E5\u7F51\u7EDC\u4EE3\u7406\u6216\u670D\u52A1\u72B6\u6001\u540E\u91CD\u8BD5\uFF1B\u539F\u59CB\u54CD\u5E94\u4E0D\u4F1A\u663E\u793A\uFF0C\u4E5F\u4E0D\u4F1A\u628A\u672A\u77E5\u7ED3\u679C\u5F53\u4F5C\u901A\u8FC7\u3002");
|
|
122
|
+
return check(id, "warn", "NETWORK_ERROR", "\u672A\u80FD\u8FDE\u63A5 OpenRouter\uFF0C\u65E0\u6CD5\u786E\u8BA4\u7ED3\u679C\u3002", "\u68C0\u67E5\u7F51\u7EDC\u3001DNS\u3001HTTPS \u8BC1\u4E66\u548C\u4EE3\u7406\u8BBE\u7F6E\uFF1B\u4E0D\u8981\u5173\u95ED\u8BC1\u4E66\u9A8C\u8BC1\uFF0C\u4E5F\u4E0D\u8981\u636E\u6B64\u8BA4\u5B9A Key \u65E0\u6548\u3002");
|
|
123
|
+
}
|
|
124
|
+
async function runDoctor(options = {}) {
|
|
125
|
+
const { env = process.env, nodeVersion = process.versions.node, offline = false, transport = globalThis.fetch, timeoutMs = 5e3, platform = process.platform } = options;
|
|
126
|
+
const node = supportedNode(nodeVersion) ? check("node", "pass", "NODE_SUPPORTED", "Node.js \u7248\u672C\u7B26\u5408\u8981\u6C42\u3002") : check("node", "fail", "NODE_UNSUPPORTED", "\u5F53\u524D Node.js \u7248\u672C\u4E0D\u5728\u652F\u6301\u8303\u56F4\u5185\u3002", "\u8BF7\u4F7F\u7528 Node.js 22.22+\uFF0822 \u7CFB\u5217\uFF09\u6216 24+\uFF1BNode.js 23 \u4E0D\u53D7\u652F\u6301\u3002\u68C0\u67E5 MCP \u5BA2\u6237\u7AEF\u5B9E\u9645\u4F7F\u7528\u7684 Node \u8DEF\u5F84\u3002");
|
|
127
|
+
const dir = directoryCheck(env.OPENROUTER_WORKBENCH_DATA_DIR, platform);
|
|
128
|
+
const key = env.OPENROUTER_MANAGEMENT_KEY;
|
|
129
|
+
let permission;
|
|
130
|
+
let account;
|
|
131
|
+
const skipped = (message) => check("account", "skip", "ACCOUNT_NOT_CHECKED", message);
|
|
132
|
+
if (!key) {
|
|
133
|
+
permission = check("key", "fail", "KEY_MISSING", "\u5C1A\u672A\u914D\u7F6E OPENROUTER_MANAGEMENT_KEY\u3002", "\u901A\u8FC7\u5F53\u524D\u7EC8\u7AEF\u6216 MCP \u5BA2\u6237\u7AEF\u7684\u79D8\u5BC6\u73AF\u5883\u8BBE\u7F6E\u63D0\u4F9B Management Key\uFF1B\u7EC8\u7AEF\u4E0D\u4F1A\u81EA\u52A8\u7EE7\u627F\u5BA2\u6237\u7AEF\u7684\u914D\u7F6E\u3002\u4E0D\u8981\u628A Key \u5199\u8FDB\u547D\u4EE4\u53C2\u6570\u6216\u63D0\u4EA4\u5230 Git\u3002");
|
|
134
|
+
account = skipped("\u7F3A\u5C11 Key\uFF0C\u672A\u53D1\u9001\u8D26\u6237\u8BF7\u6C42\u3002");
|
|
135
|
+
} else if (key.length > 4096 || /[^\x21-\x7e]/.test(key) || /REPLACE_|YOUR_|[<>]/i.test(key)) {
|
|
136
|
+
permission = check("key", "fail", "KEY_FORMAT_INVALID", "Key \u542B\u7A7A\u767D\u3001\u5360\u4F4D\u6587\u672C\u6216\u4E0D\u652F\u6301\u7684\u5B57\u7B26\u3002", "\u5728\u79D8\u5BC6\u73AF\u5883\u8BBE\u7F6E\u4E2D\u68C0\u67E5\u590D\u5236\u5185\u5BB9\uFF1B\u4E0D\u8981\u5305\u542B Bearer \u524D\u7F00\u3001\u5F15\u53F7\u6216\u6362\u884C\u3002\u81EA\u68C0\u672A\u53D1\u9001\u6B64 Key\u3002");
|
|
137
|
+
account = skipped("Key \u683C\u5F0F\u4E0D\u6B63\u786E\uFF0C\u672A\u53D1\u9001\u8D26\u6237\u8BF7\u6C42\u3002");
|
|
138
|
+
} else if (node.status === "fail") {
|
|
139
|
+
permission = check("key", "skip", "NODE_BLOCKED", "\u5DF2\u8BBE\u7F6E Key\uFF1BNode.js \u4E0D\u53D7\u652F\u6301\uFF0C\u672A\u8054\u7F51\u9A8C\u8BC1\u6743\u9650\u3002");
|
|
140
|
+
account = skipped("\u8BF7\u5148\u5904\u7406 Node.js \u7248\u672C\u95EE\u9898\u3002");
|
|
141
|
+
} else if (offline) {
|
|
142
|
+
permission = check("key", "skip", "OFFLINE", "Key \u683C\u5F0F\u68C0\u67E5\u901A\u8FC7\uFF1B\u79BB\u7EBF\u6A21\u5F0F\u672A\u9A8C\u8BC1\u6709\u6548\u6027\u6216\u6743\u9650\u3002");
|
|
143
|
+
account = skipped("\u79BB\u7EBF\u6A21\u5F0F\u672A\u53D1\u9001\u4EFB\u4F55\u7F51\u7EDC\u8BF7\u6C42\u3002");
|
|
144
|
+
} else {
|
|
145
|
+
try {
|
|
146
|
+
const current = await readData("/key", key, transport, timeoutMs);
|
|
147
|
+
if (typeof current.is_management_key !== "boolean") throw new ProbeError("INVALID_RESPONSE");
|
|
148
|
+
if (!current.is_management_key) {
|
|
149
|
+
permission = check("key", "fail", "NOT_MANAGEMENT_KEY", "Key \u6709\u6548\uFF0C\u4F46\u4E0D\u662F Management Key\u3002", "\u5728 OpenRouter \u7684 Management Keys \u9875\u9762\u521B\u5EFA\u6216\u9009\u7528\u7BA1\u7406\u5BC6\u94A5\uFF0C\u518D\u5B89\u5168\u914D\u7F6E\u5230\u5BA2\u6237\u7AEF\uFF1B\u81EA\u68C0\u4E0D\u4F1A\u521B\u5EFA\u3001\u66F4\u6362\u6216\u64A4\u9500\u4EFB\u4F55 Key\u3002");
|
|
150
|
+
account = skipped("\u666E\u901A Key \u4E0D\u8DB3\u4EE5\u5B8C\u6210\u5DE5\u4F5C\u53F0\u7684\u8D26\u6237\u8BFB\u53D6\uFF0C\u5DF2\u505C\u6B62\u540E\u7EED\u8BF7\u6C42\u3002");
|
|
151
|
+
} else {
|
|
152
|
+
permission = check("key", "pass", "MANAGEMENT_KEY_VERIFIED", "OpenRouter \u5DF2\u786E\u8BA4\u8FD9\u662F Management Key\u3002");
|
|
153
|
+
try {
|
|
154
|
+
const credits = await readData("/credits", key, transport, timeoutMs);
|
|
155
|
+
if (![credits.total_credits, credits.total_usage].every((v) => typeof v === "number" && Number.isFinite(v) && v >= 0)) throw new ProbeError("INVALID_RESPONSE");
|
|
156
|
+
account = check("account", "pass", "ACCOUNT_READ_OK", "\u8D26\u6237\u4F59\u989D\u63A5\u53E3\u8BFB\u53D6\u6210\u529F\uFF1B\u4E0D\u663E\u793A\u4F59\u989D\u6216\u8D26\u6237\u6807\u8BC6\u3002\u4EC5\u9A8C\u8BC1\u57FA\u7840\u8D26\u6237\u8BFB\u53D6\uFF0C\u4E0D\u4FDD\u8BC1\u6240\u6709\u5206\u6790\u63A5\u53E3\u5747\u53EF\u7528\u3002");
|
|
157
|
+
} catch (error) {
|
|
158
|
+
account = upstreamProblem("account", error);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
} catch (error) {
|
|
162
|
+
permission = upstreamProblem("key", error);
|
|
163
|
+
account = skipped("Key \u6743\u9650\u5C1A\u672A\u786E\u8BA4\uFF0C\u672A\u8BF7\u6C42\u8D26\u6237\u4F59\u989D\u3002");
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
const checks = [node, permission, account, dir];
|
|
167
|
+
const status = checks.some((c) => c.status === "fail") ? "failed" : checks.some((c) => c.status !== "pass") ? "incomplete" : "ready";
|
|
168
|
+
return { schema_version: 1, status, exit_code: status === "failed" ? 1 : status === "incomplete" ? 2 : 0, checks };
|
|
169
|
+
}
|
|
170
|
+
function formatDoctor(report) {
|
|
171
|
+
const labels = { pass: "\u901A\u8FC7", fail: "\u9700\u5904\u7406", warn: "\u5F85\u786E\u8BA4", skip: "\u672A\u68C0\u67E5" };
|
|
172
|
+
return ["OpenRouter \u5DE5\u4F5C\u53F0 \xB7 \u5B89\u88C5\u4E0E\u914D\u7F6E\u81EA\u68C0", ...report.checks.map((c) => `[${labels[c.status]}] ${c.name}\uFF1A${c.message}${c.remedy ? "\n \u89E3\u51B3\u529E\u6CD5\uFF1A" + c.remedy : ""}`), `\u7ED3\u8BBA\uFF1A${report.status === "ready" ? "\u57FA\u7840\u81EA\u68C0\u901A\u8FC7\uFF0C\u53EF\u7EE7\u7EED\u542F\u52A8\u672C\u5730 MCP\u3002" : report.status === "failed" ? "\u8BF7\u5148\u5904\u7406\u4EE5\u4E0A\u95EE\u9898\uFF0C\u518D\u91CD\u65B0\u81EA\u68C0\u3002" : "\u5C1A\u672A\u5B8C\u6574\u9A8C\u8BC1\uFF0C\u8BF7\u6309\u63D0\u793A\u5904\u7406\u540E\u91CD\u65B0\u81EA\u68C0\u3002"}`, "\u81EA\u68C0\u4EC5\u8C03\u7528\u53EA\u8BFB\u8D26\u6237\u63A5\u53E3\uFF1B\u4E0D\u6267\u884C\u6A21\u578B\u8C03\u7528\u3001\u4E0D\u8F93\u51FA Key\u3001\u4E0D\u66F4\u6539\u5BC6\u94A5\u3001\u76EE\u5F55\u6743\u9650\u6216\u6570\u636E\u5E93\u3002"].join("\n");
|
|
173
|
+
}
|
|
174
|
+
export {
|
|
175
|
+
formatDoctor,
|
|
176
|
+
runDoctor,
|
|
177
|
+
supportedNode
|
|
178
|
+
};
|