hedgequantx 2.5.24 → 2.5.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/README.md +87 -14
- package/package.json +1 -1
- package/src/menus/ai-agent.js +161 -250
- package/src/services/ai/client.js +3 -2
- package/src/services/ai/index.js +10 -40
- package/src/services/ai/providers/index.js +3 -12
- package/src/services/ai/token-scanner.js +0 -1414
|
@@ -357,11 +357,12 @@ const fetchAnthropicModelsOAuth = async (accessToken) => {
|
|
|
357
357
|
try {
|
|
358
358
|
const response = await makeRequest(url, { method: 'GET', headers, timeout: 10000 });
|
|
359
359
|
if (response.data && Array.isArray(response.data)) {
|
|
360
|
-
|
|
360
|
+
const models = response.data.map(m => m.id).filter(Boolean);
|
|
361
|
+
if (models.length > 0) return models;
|
|
361
362
|
}
|
|
362
363
|
return null;
|
|
363
364
|
} catch (error) {
|
|
364
|
-
// OAuth may not support /models endpoint
|
|
365
|
+
// OAuth token may not support /models endpoint
|
|
365
366
|
return null;
|
|
366
367
|
}
|
|
367
368
|
};
|
package/src/services/ai/index.js
CHANGED
|
@@ -374,58 +374,28 @@ const validateConnection = async (providerId, optionId, credentials) => {
|
|
|
374
374
|
const validateAnthropic = async (credentials) => {
|
|
375
375
|
try {
|
|
376
376
|
const token = credentials.apiKey || credentials.sessionKey || credentials.accessToken;
|
|
377
|
+
if (!token) return { valid: false, error: 'No API key provided' };
|
|
377
378
|
|
|
378
|
-
//
|
|
379
|
-
const
|
|
380
|
-
|
|
381
|
-
if (isOAuthToken) {
|
|
382
|
-
// OAuth tokens (from Claude Max/Pro subscription) cannot be validated via public API
|
|
383
|
-
// They use a different authentication flow through claude.ai
|
|
384
|
-
// Trust them if they have the correct format (sk-ant-oatXX-...)
|
|
385
|
-
if (token.length > 50 && /^sk-ant-oat\d{2}-[a-zA-Z0-9_-]+$/.test(token)) {
|
|
386
|
-
return {
|
|
387
|
-
valid: true,
|
|
388
|
-
tokenType: 'oauth',
|
|
389
|
-
subscriptionType: credentials.subscriptionType || 'max',
|
|
390
|
-
trusted: credentials.fromKeychain || false
|
|
391
|
-
};
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
return { valid: false, error: 'Invalid OAuth token format' };
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
// Standard API key validation (sk-ant-api...)
|
|
398
|
-
const response = await fetch('https://api.anthropic.com/v1/messages', {
|
|
399
|
-
method: 'POST',
|
|
379
|
+
// Validate by fetching models from API - this proves the token works
|
|
380
|
+
const response = await fetch('https://api.anthropic.com/v1/models', {
|
|
381
|
+
method: 'GET',
|
|
400
382
|
headers: {
|
|
401
|
-
'Content-Type': 'application/json',
|
|
402
383
|
'x-api-key': token,
|
|
403
384
|
'anthropic-version': '2023-06-01'
|
|
404
|
-
}
|
|
405
|
-
body: JSON.stringify({
|
|
406
|
-
model: 'claude-sonnet-4-5-20250929',
|
|
407
|
-
max_tokens: 10,
|
|
408
|
-
messages: [{ role: 'user', content: 'Hi' }]
|
|
409
|
-
})
|
|
385
|
+
}
|
|
410
386
|
});
|
|
411
387
|
|
|
412
388
|
if (response.ok) {
|
|
413
|
-
|
|
389
|
+
const data = await response.json();
|
|
390
|
+
if (data.data && Array.isArray(data.data) && data.data.length > 0) {
|
|
391
|
+
return { valid: true, tokenType: 'api_key' };
|
|
392
|
+
}
|
|
393
|
+
return { valid: false, error: 'API returned no models' };
|
|
414
394
|
}
|
|
415
395
|
|
|
416
396
|
const error = await response.json();
|
|
417
397
|
return { valid: false, error: error.error?.message || 'Invalid API key' };
|
|
418
398
|
} catch (e) {
|
|
419
|
-
// Network error - if it's an OAuth token, still accept it (can't validate anyway)
|
|
420
|
-
const token = credentials.apiKey || credentials.sessionKey || credentials.accessToken;
|
|
421
|
-
if (token && token.startsWith('sk-ant-oat') && token.length > 50) {
|
|
422
|
-
return {
|
|
423
|
-
valid: true,
|
|
424
|
-
tokenType: 'oauth',
|
|
425
|
-
subscriptionType: credentials.subscriptionType || 'max',
|
|
426
|
-
warning: 'Could not validate online (network error), but token format is valid'
|
|
427
|
-
};
|
|
428
|
-
}
|
|
429
399
|
return { valid: false, error: e.message };
|
|
430
400
|
}
|
|
431
401
|
};
|
|
@@ -10,17 +10,8 @@ const PROVIDERS = {
|
|
|
10
10
|
name: 'OPENROUTER (RECOMMENDED)',
|
|
11
11
|
description: '1 API key for 100+ models',
|
|
12
12
|
category: 'unified',
|
|
13
|
-
models: [
|
|
14
|
-
|
|
15
|
-
'anthropic/claude-3-opus',
|
|
16
|
-
'openai/gpt-4o',
|
|
17
|
-
'openai/gpt-4-turbo',
|
|
18
|
-
'google/gemini-pro-1.5',
|
|
19
|
-
'meta-llama/llama-3-70b',
|
|
20
|
-
'mistralai/mistral-large',
|
|
21
|
-
'deepseek/deepseek-chat'
|
|
22
|
-
],
|
|
23
|
-
defaultModel: 'anthropic/claude-sonnet-4',
|
|
13
|
+
models: [], // Fetched from API at runtime
|
|
14
|
+
defaultModel: null, // Will use first model from API
|
|
24
15
|
options: [
|
|
25
16
|
{
|
|
26
17
|
id: 'api_key',
|
|
@@ -345,7 +336,7 @@ const PROVIDERS = {
|
|
|
345
336
|
baichuan: {
|
|
346
337
|
id: 'baichuan',
|
|
347
338
|
name: 'BAICHUAN',
|
|
348
|
-
description: '
|
|
339
|
+
description: 'Multilingual AI model',
|
|
349
340
|
category: 'direct',
|
|
350
341
|
models: ['Baichuan4', 'Baichuan3-Turbo', 'Baichuan2-Turbo'],
|
|
351
342
|
defaultModel: 'Baichuan4',
|