hedgequantx 2.9.14 → 2.9.16
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
|
@@ -334,13 +334,13 @@ const drawConnectionTest = async (agents, boxWidth, clearWithBanner) => {
|
|
|
334
334
|
|
|
335
335
|
const W = boxWidth - 2;
|
|
336
336
|
|
|
337
|
-
// Show loading state with complete box
|
|
337
|
+
// Show loading state with complete box (centered vertically and horizontally)
|
|
338
338
|
clearWithBanner();
|
|
339
339
|
console.log(chalk.cyan('╔' + '═'.repeat(W) + '╗'));
|
|
340
340
|
console.log(chalk.cyan('║') + chalk.yellow.bold(centerText('AI AGENTS CONNECTION TEST', W)) + chalk.cyan('║'));
|
|
341
341
|
console.log(chalk.cyan('╠' + '═'.repeat(W) + '╣'));
|
|
342
|
-
|
|
343
|
-
console.log(chalk.cyan('║') + chalk.yellow(
|
|
342
|
+
console.log(chalk.cyan('║') + ' '.repeat(W) + chalk.cyan('║'));
|
|
343
|
+
console.log(chalk.cyan('║') + chalk.yellow(centerText('Testing connections... Please wait', W)) + chalk.cyan('║'));
|
|
344
344
|
console.log(chalk.cyan('║') + ' '.repeat(W) + chalk.cyan('║'));
|
|
345
345
|
console.log(chalk.cyan('╚' + '═'.repeat(W) + '╝'));
|
|
346
346
|
|
|
@@ -56,73 +56,59 @@ const API_CHAT_ENDPOINTS = {
|
|
|
56
56
|
* @param {Object} agent - Agent config
|
|
57
57
|
* @returns {Promise<Object>} { success, latency, formatValid, error }
|
|
58
58
|
*/
|
|
59
|
-
const testApiKeyConnection = (agent) => {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
const
|
|
70
|
-
const body = JSON.stringify({
|
|
71
|
-
model: agent.modelId,
|
|
72
|
-
messages: [{ role: 'user', content: TEST_PROMPT }],
|
|
73
|
-
max_tokens: 100,
|
|
74
|
-
stream: false
|
|
75
|
-
});
|
|
59
|
+
const testApiKeyConnection = async (agent) => {
|
|
60
|
+
const startTime = Date.now();
|
|
61
|
+
const endpoint = API_CHAT_ENDPOINTS[agent.provider];
|
|
62
|
+
|
|
63
|
+
if (!endpoint || !agent.apiKey) {
|
|
64
|
+
return { success: false, latency: 0, formatValid: false, error: 'Missing endpoint or API key' };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
try {
|
|
68
|
+
const controller = new AbortController();
|
|
69
|
+
const timeoutId = setTimeout(() => controller.abort(), AGENT_TIMEOUT);
|
|
76
70
|
|
|
77
|
-
const
|
|
78
|
-
hostname: url.hostname,
|
|
79
|
-
path: url.pathname,
|
|
71
|
+
const response = await fetch(endpoint, {
|
|
80
72
|
method: 'POST',
|
|
81
73
|
headers: {
|
|
82
74
|
'Content-Type': 'application/json',
|
|
83
|
-
'Authorization': `Bearer ${agent.apiKey}
|
|
84
|
-
'Content-Length': Buffer.byteLength(body)
|
|
75
|
+
'Authorization': `Bearer ${agent.apiKey}`
|
|
85
76
|
},
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
const latency = Date.now() - startTime;
|
|
94
|
-
try {
|
|
95
|
-
const parsed = JSON.parse(data);
|
|
96
|
-
if (res.statusCode >= 200 && res.statusCode < 300) {
|
|
97
|
-
const content = parsed.choices?.[0]?.message?.content || '';
|
|
98
|
-
const formatResult = validateResponseFormat(content);
|
|
99
|
-
resolve({
|
|
100
|
-
success: formatResult.valid,
|
|
101
|
-
latency,
|
|
102
|
-
formatValid: formatResult.valid,
|
|
103
|
-
error: formatResult.valid ? null : formatResult.error,
|
|
104
|
-
response: content
|
|
105
|
-
});
|
|
106
|
-
} else {
|
|
107
|
-
resolve({ success: false, latency, formatValid: false,
|
|
108
|
-
error: parsed.error?.message || `HTTP ${res.statusCode}` });
|
|
109
|
-
}
|
|
110
|
-
} catch (e) {
|
|
111
|
-
resolve({ success: false, latency, formatValid: false, error: `Parse error: ${e.message}` });
|
|
112
|
-
}
|
|
113
|
-
});
|
|
77
|
+
body: JSON.stringify({
|
|
78
|
+
model: agent.modelId,
|
|
79
|
+
messages: [{ role: 'user', content: TEST_PROMPT }],
|
|
80
|
+
max_tokens: 100,
|
|
81
|
+
stream: false
|
|
82
|
+
}),
|
|
83
|
+
signal: controller.signal
|
|
114
84
|
});
|
|
115
85
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
86
|
+
clearTimeout(timeoutId);
|
|
87
|
+
const latency = Date.now() - startTime;
|
|
88
|
+
|
|
89
|
+
const data = await response.json();
|
|
90
|
+
|
|
91
|
+
if (response.ok) {
|
|
92
|
+
const content = data.choices?.[0]?.message?.content || '';
|
|
93
|
+
const formatResult = validateResponseFormat(content);
|
|
94
|
+
return {
|
|
95
|
+
success: formatResult.valid,
|
|
96
|
+
latency,
|
|
97
|
+
formatValid: formatResult.valid,
|
|
98
|
+
error: formatResult.valid ? null : formatResult.error,
|
|
99
|
+
response: content
|
|
100
|
+
};
|
|
101
|
+
} else {
|
|
102
|
+
return { success: false, latency, formatValid: false,
|
|
103
|
+
error: data.error?.message || `HTTP ${response.status}` };
|
|
104
|
+
}
|
|
105
|
+
} catch (e) {
|
|
106
|
+
const latency = Date.now() - startTime;
|
|
107
|
+
if (e.name === 'AbortError') {
|
|
108
|
+
return { success: false, latency: AGENT_TIMEOUT, formatValid: false, error: 'Timeout' };
|
|
109
|
+
}
|
|
110
|
+
return { success: false, latency, formatValid: false, error: e.message };
|
|
111
|
+
}
|
|
126
112
|
};
|
|
127
113
|
|
|
128
114
|
/**
|