panrouter 1.0.1 → 1.0.4

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.
@@ -95,7 +95,7 @@ function writeConfig() {
95
95
 
96
96
  // ─── 3. 启动代理服务器(后台运行) ───────────────────────────────────────
97
97
 
98
- function startServer() {
98
+ async function startServer() {
99
99
  const serverPath = path.join(__dirname, "server.mjs");
100
100
 
101
101
  // 关掉旧的 Pan Router
@@ -109,23 +109,27 @@ function startServer() {
109
109
 
110
110
  log("..", "正在启动 Pan Router(端口 50816)...", "yellow");
111
111
 
112
- // 后台启动,不阻塞终端
113
- const child = spawn("node", [serverPath], {
114
- cwd: __dirname,
115
- stdio: "ignore",
116
- detached: true,
117
- });
118
- child.unref();
112
+ // Windows: 用 start 命令开新窗口,不依赖 node 后台进程
113
+ if (process.platform === "win32") {
114
+ execSync(`start "Pan Router" cmd /c "node ${serverPath} & pause"`, { stdio: "pipe" });
115
+ } else {
116
+ const child = spawn("node", [serverPath], { cwd: __dirname, stdio: "ignore", detached: true });
117
+ child.unref();
118
+ }
119
119
 
120
- // 等 2 秒确认启动
121
- setTimeout(() => {
120
+ // 等待服务启动
121
+ for (let i = 0; i < 15; i++) {
122
122
  try {
123
- const req = http.get("http://127.0.0.1:50816/health", () => {});
123
+ const req = http.get("http://127.0.0.1:50816/health", (res) => {});
124
124
  req.on("error", () => {});
125
+ const check = await new Promise(rs => { req.on("response", () => rs(true)); req.on("error", () => rs(false)); setTimeout(() => rs(false), 1000); });
126
+ if (check) { break; }
125
127
  } catch {}
126
- log("OK", "Pan Router 已启动(端口 50816)", "green");
127
- console.log("\n 现在可以运行: \x1b[33mclaude \"你好\"\x1b[0m\n");
128
- }, 2000);
128
+ await new Promise(rs => setTimeout(rs, 1000));
129
+ }
130
+
131
+ log("OK", "Pan Router 已启动(端口 50816)", "green");
132
+ console.log("\n 现在可以运行: \x1b[33mclaude \"你好\"\x1b[0m\n");
129
133
  }
130
134
 
131
135
  // ─── 主流程 ──────────────────────────────────────────────────────────────
@@ -139,7 +143,7 @@ function printBanner() {
139
143
  `);
140
144
  }
141
145
 
142
- function main() {
146
+ async function main() {
143
147
  const args = process.argv.slice(2);
144
148
 
145
149
  if (args.includes("--help") || args.includes("-h")) {
@@ -168,7 +172,7 @@ function main() {
168
172
  }
169
173
 
170
174
  if (args.includes("--server") || args.includes("-s")) {
171
- startServer();
175
+ await startServer();
172
176
  return;
173
177
  }
174
178
 
@@ -176,7 +180,7 @@ function main() {
176
180
  printBanner();
177
181
  if (!installClaudeCode()) process.exit(1);
178
182
  writeConfig();
179
- startServer();
183
+ await startServer();
180
184
  }
181
185
 
182
186
  main();
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "panrouter",
3
- "version": "1.0.1",
3
+ "version": "1.0.4",
4
4
  "description": "让 Claude Code 免费使用 DeepSeek 等模型,无需 API Key",
5
5
  "type": "module",
6
6
  "bin": {
7
- "panrouter": "cli.js"
7
+ "panrouter": "cli.mjs"
8
8
  },
9
9
  "files": [
10
- "cli.js",
10
+ "cli.mjs",
11
11
  "server.mjs"
12
12
  ],
13
13
  "license": "MIT"