protocol-proxy 1.0.2 → 1.0.3

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/package.json +1 -1
  2. package/server.js +25 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "protocol-proxy",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "OpenAI / Anthropic 协议转换透明代理",
5
5
  "main": "server.js",
6
6
  "bin": {
package/server.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  const path = require('path');
3
- const { exec } = require('child_process');
3
+ const { exec, spawn } = require('child_process');
4
4
  const os = require('os');
5
5
  const fs = require('fs');
6
6
 
@@ -30,9 +30,9 @@ function showHelp() {
30
30
  protocol-proxy - OpenAI / Anthropic 协议转换透明代理
31
31
 
32
32
  用法:
33
- protocol-proxy 启动服务
34
- protocol-proxy start 启动服务
35
- protocol-proxy stop 停止服务
33
+ protocol-proxy 前台启动服务(Ctrl+C 停止)
34
+ protocol-proxy start 后台启动服务
35
+ protocol-proxy stop 停止后台服务
36
36
  protocol-proxy status 查看运行状态
37
37
  protocol-proxy help 显示帮助信息
38
38
  protocol-proxy -v, --version 显示版本号
@@ -40,6 +40,22 @@ protocol-proxy - OpenAI / Anthropic 协议转换透明代理
40
40
  `);
41
41
  }
42
42
 
43
+ function startDaemon() {
44
+ const pid = readPid();
45
+ if (pid && isProcessAlive(pid)) {
46
+ console.log(`服务已在运行 (PID: ${pid})`);
47
+ return;
48
+ }
49
+
50
+ const child = spawn(process.execPath, [__filename, '--daemon'], {
51
+ detached: true,
52
+ stdio: 'ignore',
53
+ });
54
+ fs.writeFileSync(PID_FILE, String(child.pid));
55
+ child.unref();
56
+ console.log(`服务已在后台启动 (PID: ${child.pid})`);
57
+ }
58
+
43
59
  function showVersion() {
44
60
  console.log(pkg.version);
45
61
  }
@@ -323,6 +339,11 @@ switch (cmd) {
323
339
  showStatus();
324
340
  break;
325
341
  case 'start':
342
+ startDaemon();
343
+ break;
344
+ case '--daemon':
345
+ init();
346
+ break;
326
347
  case undefined:
327
348
  init();
328
349
  break;