hedgequantx 2.6.120 → 2.6.122
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 +1 -1
- package/src/services/ai/proxy-manager.js +48 -49
package/package.json
CHANGED
|
@@ -495,44 +495,6 @@ const getAuthUrl = async (provider) => {
|
|
|
495
495
|
};
|
|
496
496
|
|
|
497
497
|
/**
|
|
498
|
-
* Poll for OAuth authentication status
|
|
499
|
-
* @param {string} state - OAuth state from getAuthUrl
|
|
500
|
-
* @returns {Promise<{status: string, error?: string}>}
|
|
501
|
-
*/
|
|
502
|
-
const pollAuthStatus = async (state) => {
|
|
503
|
-
const response = await managementRequest('GET', `/v0/management/get-auth-status?state=${state}`);
|
|
504
|
-
return response;
|
|
505
|
-
};
|
|
506
|
-
|
|
507
|
-
/**
|
|
508
|
-
* Wait for OAuth authentication to complete
|
|
509
|
-
* @param {string} state - OAuth state
|
|
510
|
-
* @param {number} timeoutMs - Timeout in milliseconds
|
|
511
|
-
* @param {Function} onStatus - Status callback
|
|
512
|
-
* @returns {Promise<boolean>}
|
|
513
|
-
*/
|
|
514
|
-
const waitForAuth = async (state, timeoutMs = 300000, onStatus = () => {}) => {
|
|
515
|
-
const startTime = Date.now();
|
|
516
|
-
|
|
517
|
-
while (Date.now() - startTime < timeoutMs) {
|
|
518
|
-
const status = await pollAuthStatus(state);
|
|
519
|
-
|
|
520
|
-
if (status.status === 'ok') {
|
|
521
|
-
return true;
|
|
522
|
-
} else if (status.status === 'error') {
|
|
523
|
-
throw new Error(status.error || 'Authentication failed');
|
|
524
|
-
}
|
|
525
|
-
|
|
526
|
-
onStatus('Waiting for authorization...');
|
|
527
|
-
await new Promise(resolve => setTimeout(resolve, 2000));
|
|
528
|
-
}
|
|
529
|
-
|
|
530
|
-
throw new Error('Authentication timeout');
|
|
531
|
-
};
|
|
532
|
-
|
|
533
|
-
/**
|
|
534
|
-
* Submit OAuth callback URL manually (for remote/VPS use)
|
|
535
|
-
* Extracts code and state from callback URL and submits to proxy via main port
|
|
536
498
|
* @param {string} callbackUrl - Full callback URL (http://localhost:54545/callback?code=xxx&state=yyy)
|
|
537
499
|
* @param {string} provider - Provider ID (anthropic, openai, gemini, qwen, iflow)
|
|
538
500
|
* @returns {Promise<boolean>}
|
|
@@ -553,24 +515,25 @@ const submitCallback = async (callbackUrl, provider = 'anthropic') => {
|
|
|
553
515
|
throw new Error('Missing code or state in callback URL');
|
|
554
516
|
}
|
|
555
517
|
|
|
556
|
-
//
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
518
|
+
// Each provider has its own OAuth callback port and path in CLIProxyAPI
|
|
519
|
+
// We need to submit the callback to the correct port
|
|
520
|
+
const providerConfig = {
|
|
521
|
+
anthropic: { port: 54545, path: '/callback' },
|
|
522
|
+
openai: { port: 16168, path: '/callback' },
|
|
523
|
+
gemini: { port: 8085, path: '/oauth2callback' },
|
|
524
|
+
qwen: { port: 8087, path: '/oauth2callback' },
|
|
525
|
+
iflow: { port: 8088, path: '/callback' }
|
|
563
526
|
};
|
|
564
527
|
|
|
565
|
-
const
|
|
528
|
+
const config = providerConfig[provider] || providerConfig.anthropic;
|
|
566
529
|
|
|
567
|
-
// Submit to
|
|
530
|
+
// Submit to the provider's OAuth callback port directly
|
|
568
531
|
return new Promise((resolve, reject) => {
|
|
569
|
-
const callbackPath = `${
|
|
532
|
+
const callbackPath = `${config.path}?code=${encodeURIComponent(code)}&state=${encodeURIComponent(state)}`;
|
|
570
533
|
|
|
571
534
|
const req = http.request({
|
|
572
535
|
hostname: '127.0.0.1',
|
|
573
|
-
port:
|
|
536
|
+
port: config.port,
|
|
574
537
|
path: callbackPath,
|
|
575
538
|
method: 'GET',
|
|
576
539
|
timeout: 30000
|
|
@@ -600,6 +563,42 @@ const submitCallback = async (callbackUrl, provider = 'anthropic') => {
|
|
|
600
563
|
});
|
|
601
564
|
};
|
|
602
565
|
|
|
566
|
+
/**
|
|
567
|
+
* Poll OAuth authentication status
|
|
568
|
+
* @param {string} state - OAuth state
|
|
569
|
+
* @returns {Promise<{status: string, error?: string}>}
|
|
570
|
+
*/
|
|
571
|
+
const pollAuthStatus = async (state) => {
|
|
572
|
+
const response = await managementRequest('GET', `/v0/management/get-auth-status?state=${state}`);
|
|
573
|
+
return response;
|
|
574
|
+
};
|
|
575
|
+
|
|
576
|
+
/**
|
|
577
|
+
* Wait for OAuth authentication to complete
|
|
578
|
+
* @param {string} state - OAuth state
|
|
579
|
+
* @param {number} timeoutMs - Timeout in milliseconds
|
|
580
|
+
* @param {Function} onStatus - Status callback
|
|
581
|
+
* @returns {Promise<boolean>}
|
|
582
|
+
*/
|
|
583
|
+
const waitForAuth = async (state, timeoutMs = 300000, onStatus = () => {}) => {
|
|
584
|
+
const startTime = Date.now();
|
|
585
|
+
|
|
586
|
+
while (Date.now() - startTime < timeoutMs) {
|
|
587
|
+
const status = await pollAuthStatus(state);
|
|
588
|
+
|
|
589
|
+
if (status.status === 'ok') {
|
|
590
|
+
return true;
|
|
591
|
+
} else if (status.status === 'error') {
|
|
592
|
+
throw new Error(status.error || 'Authentication failed');
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
onStatus('Waiting for authorization...');
|
|
596
|
+
await new Promise(resolve => setTimeout(resolve, 2000));
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
throw new Error('Authentication timeout');
|
|
600
|
+
};
|
|
601
|
+
|
|
603
602
|
/**
|
|
604
603
|
* Get available models from the proxy
|
|
605
604
|
* @returns {Promise<Array<string>>}
|