hedgequantx 2.6.102 → 2.6.103
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
|
@@ -27,6 +27,7 @@ const PROXY_BIN = path.join(PROXY_DIR, process.platform === 'win32' ? 'cli-proxy
|
|
|
27
27
|
const PROXY_CONFIG = path.join(PROXY_DIR, 'config.yaml');
|
|
28
28
|
const PROXY_AUTH_DIR = path.join(PROXY_DIR, 'auths');
|
|
29
29
|
const API_KEY = 'hqx-local-key';
|
|
30
|
+
const MANAGEMENT_KEY = 'hqx-mgmt-key';
|
|
30
31
|
|
|
31
32
|
// GitHub release URLs
|
|
32
33
|
const getDownloadUrl = () => {
|
|
@@ -202,6 +203,9 @@ const install = async (onProgress = () => {}) => {
|
|
|
202
203
|
auth-dir: "${PROXY_AUTH_DIR}"
|
|
203
204
|
api-keys:
|
|
204
205
|
- "${API_KEY}"
|
|
206
|
+
remote-management:
|
|
207
|
+
secret-key: "${MANAGEMENT_KEY}"
|
|
208
|
+
allow-remote-management: false
|
|
205
209
|
request-retry: 3
|
|
206
210
|
quota-exceeded:
|
|
207
211
|
switch-project: true
|
|
@@ -288,7 +292,7 @@ const ensureRunning = async (onProgress = () => {}) => {
|
|
|
288
292
|
};
|
|
289
293
|
|
|
290
294
|
/**
|
|
291
|
-
* Make request to local proxy
|
|
295
|
+
* Make request to local proxy (API endpoints)
|
|
292
296
|
*/
|
|
293
297
|
const proxyRequest = (method, endpoint, body = null) => {
|
|
294
298
|
return new Promise((resolve, reject) => {
|
|
@@ -329,6 +333,58 @@ const proxyRequest = (method, endpoint, body = null) => {
|
|
|
329
333
|
});
|
|
330
334
|
};
|
|
331
335
|
|
|
336
|
+
/**
|
|
337
|
+
* Make request to local proxy (Management API endpoints)
|
|
338
|
+
* Uses management key for authentication
|
|
339
|
+
*/
|
|
340
|
+
const managementRequest = (method, endpoint, body = null) => {
|
|
341
|
+
return new Promise((resolve, reject) => {
|
|
342
|
+
const options = {
|
|
343
|
+
hostname: '127.0.0.1',
|
|
344
|
+
port: PROXY_PORT,
|
|
345
|
+
path: endpoint,
|
|
346
|
+
method,
|
|
347
|
+
headers: {
|
|
348
|
+
'Authorization': `Bearer ${MANAGEMENT_KEY}`,
|
|
349
|
+
'Content-Type': 'application/json'
|
|
350
|
+
},
|
|
351
|
+
timeout: 30000
|
|
352
|
+
};
|
|
353
|
+
|
|
354
|
+
const req = http.request(options, (res) => {
|
|
355
|
+
let data = '';
|
|
356
|
+
res.on('data', chunk => data += chunk);
|
|
357
|
+
res.on('end', () => {
|
|
358
|
+
try {
|
|
359
|
+
const json = JSON.parse(data);
|
|
360
|
+
if (res.statusCode >= 400) {
|
|
361
|
+
reject(new Error(json.error || `HTTP ${res.statusCode}`));
|
|
362
|
+
} else {
|
|
363
|
+
resolve(json);
|
|
364
|
+
}
|
|
365
|
+
} catch (e) {
|
|
366
|
+
if (res.statusCode >= 400) {
|
|
367
|
+
reject(new Error(`HTTP ${res.statusCode}: ${data}`));
|
|
368
|
+
} else {
|
|
369
|
+
resolve(data);
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
});
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
req.on('error', reject);
|
|
376
|
+
req.on('timeout', () => {
|
|
377
|
+
req.destroy();
|
|
378
|
+
reject(new Error('Request timeout'));
|
|
379
|
+
});
|
|
380
|
+
|
|
381
|
+
if (body) {
|
|
382
|
+
req.write(JSON.stringify(body));
|
|
383
|
+
}
|
|
384
|
+
req.end();
|
|
385
|
+
});
|
|
386
|
+
};
|
|
387
|
+
|
|
332
388
|
/**
|
|
333
389
|
* Get OAuth authorization URL for a provider
|
|
334
390
|
* @param {string} provider - Provider ID (anthropic, openai, gemini, qwen, iflow)
|
|
@@ -350,7 +406,7 @@ const getAuthUrl = async (provider) => {
|
|
|
350
406
|
throw new Error(`Unknown provider: ${provider}`);
|
|
351
407
|
}
|
|
352
408
|
|
|
353
|
-
const response = await
|
|
409
|
+
const response = await managementRequest('GET', endpoint);
|
|
354
410
|
|
|
355
411
|
if (response.status !== 'ok') {
|
|
356
412
|
throw new Error(response.error || 'Failed to get auth URL');
|
|
@@ -368,7 +424,7 @@ const getAuthUrl = async (provider) => {
|
|
|
368
424
|
* @returns {Promise<{status: string, error?: string}>}
|
|
369
425
|
*/
|
|
370
426
|
const pollAuthStatus = async (state) => {
|
|
371
|
-
const response = await
|
|
427
|
+
const response = await managementRequest('GET', `/v0/management/get-auth-status?state=${state}`);
|
|
372
428
|
return response;
|
|
373
429
|
};
|
|
374
430
|
|
|
@@ -422,7 +478,7 @@ const getAuthFiles = async () => {
|
|
|
422
478
|
await ensureRunning();
|
|
423
479
|
|
|
424
480
|
try {
|
|
425
|
-
const response = await
|
|
481
|
+
const response = await managementRequest('GET', '/v0/management/auth-files');
|
|
426
482
|
return response.files || [];
|
|
427
483
|
} catch (e) {
|
|
428
484
|
return [];
|