hedgequantx 2.7.25 → 2.7.26
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/package.json
CHANGED
|
@@ -256,6 +256,26 @@ const isRunning = async () => {
|
|
|
256
256
|
});
|
|
257
257
|
};
|
|
258
258
|
|
|
259
|
+
// Config file path
|
|
260
|
+
const CONFIG_PATH = path.join(INSTALL_DIR, 'config.yaml');
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Create config file if not exists
|
|
264
|
+
*/
|
|
265
|
+
const ensureConfig = () => {
|
|
266
|
+
if (fs.existsSync(CONFIG_PATH)) return;
|
|
267
|
+
|
|
268
|
+
const config = `# HQX CLIProxyAPI Config
|
|
269
|
+
host: "127.0.0.1"
|
|
270
|
+
port: ${DEFAULT_PORT}
|
|
271
|
+
auth-dir: "${AUTH_DIR}"
|
|
272
|
+
debug: false
|
|
273
|
+
api-keys:
|
|
274
|
+
- "hqx-internal-key"
|
|
275
|
+
`;
|
|
276
|
+
fs.writeFileSync(CONFIG_PATH, config);
|
|
277
|
+
};
|
|
278
|
+
|
|
259
279
|
/**
|
|
260
280
|
* Start CLIProxyAPI
|
|
261
281
|
* @returns {Promise<Object>} { success, error, pid }
|
|
@@ -271,30 +291,42 @@ const start = async () => {
|
|
|
271
291
|
}
|
|
272
292
|
|
|
273
293
|
try {
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
294
|
+
// Ensure config and auth dir exist
|
|
295
|
+
if (!fs.existsSync(AUTH_DIR)) fs.mkdirSync(AUTH_DIR, { recursive: true });
|
|
296
|
+
ensureConfig();
|
|
297
|
+
|
|
298
|
+
const args = ['-config', CONFIG_PATH];
|
|
299
|
+
|
|
300
|
+
// Capture stderr for debugging
|
|
301
|
+
const logPath = path.join(INSTALL_DIR, 'cliproxy.log');
|
|
302
|
+
const logFd = fs.openSync(logPath, 'a');
|
|
278
303
|
|
|
279
304
|
const child = spawn(BINARY_PATH, args, {
|
|
280
305
|
detached: true,
|
|
281
|
-
stdio: 'ignore',
|
|
306
|
+
stdio: ['ignore', logFd, logFd],
|
|
282
307
|
cwd: INSTALL_DIR
|
|
283
308
|
});
|
|
284
309
|
|
|
285
310
|
child.unref();
|
|
311
|
+
fs.closeSync(logFd);
|
|
286
312
|
|
|
287
313
|
// Save PID
|
|
288
314
|
fs.writeFileSync(PID_FILE, String(child.pid));
|
|
289
315
|
|
|
290
316
|
// Wait for startup
|
|
291
|
-
await new Promise(r => setTimeout(r,
|
|
317
|
+
await new Promise(r => setTimeout(r, 3000));
|
|
292
318
|
|
|
293
319
|
const runStatus = await isRunning();
|
|
294
320
|
if (runStatus.running) {
|
|
295
321
|
return { success: true, error: null, pid: child.pid };
|
|
296
322
|
} else {
|
|
297
|
-
|
|
323
|
+
// Read log for error details
|
|
324
|
+
let errorDetail = 'Failed to start CLIProxyAPI';
|
|
325
|
+
if (fs.existsSync(logPath)) {
|
|
326
|
+
const log = fs.readFileSync(logPath, 'utf8').slice(-500);
|
|
327
|
+
if (log) errorDetail += `: ${log.split('\n').pop()}`;
|
|
328
|
+
}
|
|
329
|
+
return { success: false, error: errorDetail, pid: null };
|
|
298
330
|
}
|
|
299
331
|
} catch (error) {
|
|
300
332
|
return { success: false, error: error.message, pid: null };
|