@lmnr-ai/claude-code-proxy 0.1.1-alpha.1 → 0.1.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.
package/dist/index.js CHANGED
@@ -16,6 +16,7 @@ const HEALTH_CHECK_INTERVAL = 1000;
16
16
  let serverPort = 45667;
17
17
  let targetUrl = '';
18
18
  let monitorInterval = null;
19
+ let isHealthCheckRunning = false;
19
20
  /**
20
21
  * Set the current trace context by sending an HTTP request to the running proxy server.
21
22
  *
@@ -54,42 +55,54 @@ async function setCurrentTrace(context) {
54
55
  /**
55
56
  * Background function that monitors server health and restarts if needed.
56
57
  * Polls every HEALTH_CHECK_INTERVAL ms.
58
+ * Uses a flag to prevent concurrent execution, avoiding race conditions.
57
59
  */
58
60
  async function healthCheckMonitor() {
59
- const url = `http://127.0.0.1:${serverPort}/lmnr-internal/health`;
60
- try {
61
- const response = await fetch(url, {
62
- // Force new connection for each health check to avoid interfering with streaming
63
- headers: {
64
- 'Connection': 'close'
65
- },
66
- });
67
- if (response.status === 200) {
68
- // Server is healthy
69
- return;
70
- }
61
+ // Skip if a health check is already running to prevent concurrent restarts
62
+ if (isHealthCheckRunning) {
63
+ return;
71
64
  }
72
- catch (error) {
73
- // Server is not responding, try to restart
74
- console.warn(`Server health check failed: ${error}. Attempting to restart...`);
65
+ isHealthCheckRunning = true;
66
+ try {
67
+ const url = `http://127.0.0.1:${serverPort}/lmnr-internal/health`;
75
68
  try {
76
- // Try to stop the existing server (it might be stuck)
69
+ const response = await fetch(url, {
70
+ // Force new connection for each health check to avoid interfering with streaming
71
+ headers: {
72
+ 'Connection': 'close'
73
+ },
74
+ });
75
+ if (response.status === 200) {
76
+ // Server is healthy
77
+ return;
78
+ }
79
+ }
80
+ catch (error) {
81
+ // Server is not responding, try to restart
82
+ console.warn(`Server health check failed: ${error}. Attempting to restart...`);
77
83
  try {
78
- native.stop();
84
+ // Try to stop the existing server (it might be stuck)
85
+ try {
86
+ native.stop();
87
+ }
88
+ catch {
89
+ // Server might already be dead
90
+ }
91
+ // Wait a bit before restarting
92
+ await new Promise(resolve => setTimeout(resolve, 100));
93
+ // Restart the server
94
+ native.run(targetUrl, serverPort);
95
+ console.info('Server restarted successfully');
79
96
  }
80
- catch {
81
- // Server might already be dead
97
+ catch (restartError) {
98
+ console.error(`Failed to restart server: ${restartError}`);
82
99
  }
83
- // Wait a bit before restarting
84
- await new Promise(resolve => setTimeout(resolve, 100));
85
- // Restart the server
86
- native.run(targetUrl, serverPort);
87
- console.info('Server restarted successfully');
88
- }
89
- catch (restartError) {
90
- console.error(`Failed to restart server: ${restartError}`);
91
100
  }
92
101
  }
102
+ finally {
103
+ // Always reset the flag when done, even if an error occurred
104
+ isHealthCheckRunning = false;
105
+ }
93
106
  }
94
107
  /**
95
108
  * Run the proxy server in a background thread with health monitoring.
@@ -131,6 +144,8 @@ function stopServer() {
131
144
  clearInterval(monitorInterval);
132
145
  monitorInterval = null;
133
146
  }
147
+ // Reset the health check flag
148
+ isHealthCheckRunning = false;
134
149
  // Stop the server
135
150
  try {
136
151
  native.stop();
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lmnr-ai/claude-code-proxy",
3
- "version": "0.1.1-alpha.1",
3
+ "version": "0.1.1",
4
4
  "description": "HTTP proxy for Claude Desktop API requests with Laminar observability",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -39,6 +39,6 @@
39
39
  "build:napi": "cd ../bin && napi build --platform --release -o ../ts/dist",
40
40
  "build:ts": "tsc",
41
41
  "build": "node scripts/build.js",
42
- "test": "echo \"Error: no test specified\" && exit 1"
42
+ "test": "echo \"Error: no test specified\" && exit 0"
43
43
  }
44
44
  }