hedgequantx 2.6.120 → 2.6.121

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hedgequantx",
3
- "version": "2.6.120",
3
+ "version": "2.6.121",
4
4
  "description": "HedgeQuantX - Prop Futures Trading CLI",
5
5
  "main": "src/app.js",
6
6
  "bin": {
@@ -495,13 +495,72 @@ 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}>}
498
+ * @param {string} callbackUrl - Full callback URL (http://localhost:54545/callback?code=xxx&state=yyy)
499
+ * @param {string} provider - Provider ID (anthropic, openai, gemini, qwen, iflow)
500
+ * @returns {Promise<boolean>}
501
501
  */
502
- const pollAuthStatus = async (state) => {
503
- const response = await managementRequest('GET', `/v0/management/get-auth-status?state=${state}`);
504
- return response;
502
+ const submitCallback = async (callbackUrl, provider = 'anthropic') => {
503
+ // Parse the callback URL
504
+ let url;
505
+ try {
506
+ url = new URL(callbackUrl);
507
+ } catch (e) {
508
+ throw new Error('Invalid callback URL format');
509
+ }
510
+
511
+ const code = url.searchParams.get('code');
512
+ const state = url.searchParams.get('state');
513
+
514
+ if (!code || !state) {
515
+ throw new Error('Missing code or state in callback URL');
516
+ }
517
+
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' }
526
+ };
527
+
528
+ const config = providerConfig[provider] || providerConfig.anthropic;
529
+
530
+ // Submit to the provider's OAuth callback port directly
531
+ return new Promise((resolve, reject) => {
532
+ const callbackPath = `${config.path}?code=${encodeURIComponent(code)}&state=${encodeURIComponent(state)}`;
533
+
534
+ const req = http.request({
535
+ hostname: '127.0.0.1',
536
+ port: config.port,
537
+ path: callbackPath,
538
+ method: 'GET',
539
+ timeout: 30000
540
+ }, (res) => {
541
+ let data = '';
542
+ res.on('data', chunk => data += chunk);
543
+ res.on('end', () => {
544
+ // Success if we get a redirect or success page
545
+ if (res.statusCode === 200 || res.statusCode === 302 || res.statusCode === 301) {
546
+ resolve(true);
547
+ } else {
548
+ reject(new Error(`Callback failed with status ${res.statusCode}`));
549
+ }
550
+ });
551
+ });
552
+
553
+ req.on('error', (e) => {
554
+ reject(new Error(`Failed to submit callback: ${e.message}`));
555
+ });
556
+
557
+ req.on('timeout', () => {
558
+ req.destroy();
559
+ reject(new Error('Callback request timeout'));
560
+ });
561
+
562
+ req.end();
563
+ });
505
564
  };
506
565
 
507
566
  /**