yymaxapi 1.0.57 → 1.0.59
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/bin/yymaxapi.js +36 -12
- package/package.json +1 -1
package/bin/yymaxapi.js
CHANGED
|
@@ -2602,13 +2602,19 @@ async function autoActivate(paths, args = {}) {
|
|
|
2602
2602
|
'OPENAI_API_KEY',
|
|
2603
2603
|
'OPENCLAW_API_KEY'
|
|
2604
2604
|
];
|
|
2605
|
+
const existingConfig = readConfig(paths.openclawConfig) || {};
|
|
2606
|
+
const existingProviders = existingConfig.models?.providers || {};
|
|
2607
|
+
const existingKey = existingProviders[claudeProviderName]?.apiKey
|
|
2608
|
+
|| existingProviders[codexProviderName]?.apiKey
|
|
2609
|
+
|| Object.values(existingProviders).find(p => p.apiKey)?.apiKey
|
|
2610
|
+
|| '';
|
|
2605
2611
|
const directKey = (args['api-key'] || args.apiKey || args.key || '').toString().trim();
|
|
2606
2612
|
let apiKey;
|
|
2607
2613
|
if (directKey) {
|
|
2608
2614
|
apiKey = directKey;
|
|
2609
2615
|
} else {
|
|
2610
2616
|
const envKey = getApiKeyFromArgs({}, apiKeyEnvFallbacks);
|
|
2611
|
-
apiKey = await promptApiKey('请输入 API Key:', envKey || '');
|
|
2617
|
+
apiKey = await promptApiKey('请输入 API Key:', envKey || existingKey || '');
|
|
2612
2618
|
}
|
|
2613
2619
|
if (!apiKey) { console.log(chalk.gray('已取消')); return; }
|
|
2614
2620
|
|
|
@@ -3829,15 +3835,21 @@ async function testConnection(paths, args = {}) {
|
|
|
3829
3835
|
}
|
|
3830
3836
|
}
|
|
3831
3837
|
|
|
3832
|
-
|
|
3838
|
+
// 根据当前主模型类型选择测试端点
|
|
3839
|
+
const primaryProvider = primary.split('/')[0] || '';
|
|
3840
|
+
const primaryApi = config.models?.providers?.[primaryProvider]?.api || '';
|
|
3841
|
+
const isAnthropic = primaryApi.startsWith('anthropic');
|
|
3842
|
+
const testEndpoint = isAnthropic ? '/v1/messages' : '/v1/chat/completions';
|
|
3843
|
+
console.log(chalk.gray(` 端点: http://127.0.0.1:${gatewayPort}${testEndpoint}`));
|
|
3833
3844
|
const startTime = Date.now();
|
|
3834
|
-
let result = await testGatewayApi(gatewayPort, gatewayToken, primary);
|
|
3845
|
+
let result = await testGatewayApi(gatewayPort, gatewayToken, primary, testEndpoint);
|
|
3835
3846
|
const latency = Date.now() - startTime;
|
|
3836
3847
|
|
|
3837
|
-
//
|
|
3848
|
+
// 回退:如果首选端点返回 404/405,尝试另一个
|
|
3838
3849
|
if (!result.success && result.reachable && [404, 405].includes(result.status)) {
|
|
3839
|
-
|
|
3840
|
-
|
|
3850
|
+
const fallbackEndpoint = isAnthropic ? '/v1/chat/completions' : '/v1/responses';
|
|
3851
|
+
console.log(chalk.gray(` ${testEndpoint} 不支持,回退测试 ${fallbackEndpoint}...`));
|
|
3852
|
+
result = await testGatewayApi(gatewayPort, gatewayToken, primary, fallbackEndpoint);
|
|
3841
3853
|
}
|
|
3842
3854
|
|
|
3843
3855
|
// CLI 对话已成功 + Gateway 可达(404/405)= Dashboard 通过 WebSocket 工作,视为通过
|
|
@@ -4153,18 +4165,28 @@ function printGatewayDiagnostics(resolved) {
|
|
|
4153
4165
|
}
|
|
4154
4166
|
|
|
4155
4167
|
// Gateway API 测试 - 通过本地 Gateway 端口测试
|
|
4156
|
-
function testGatewayApi(port, token, model, endpoint = '/v1/
|
|
4168
|
+
function testGatewayApi(port, token, model, endpoint = '/v1/chat/completions') {
|
|
4157
4169
|
return new Promise((resolve) => {
|
|
4170
|
+
const isMessages = endpoint.includes('/messages');
|
|
4158
4171
|
const isChatCompletions = endpoint.includes('chat/completions');
|
|
4159
|
-
|
|
4160
|
-
|
|
4172
|
+
let postData;
|
|
4173
|
+
if (isMessages) {
|
|
4174
|
+
postData = JSON.stringify({
|
|
4175
|
+
model: model.includes('/') ? model.split('/')[1] : model,
|
|
4176
|
+
max_tokens: 150,
|
|
4177
|
+
messages: [{ role: 'user', content: '你是什么模型?请用一句话回答。' }]
|
|
4178
|
+
});
|
|
4179
|
+
} else if (isChatCompletions) {
|
|
4180
|
+
postData = JSON.stringify({
|
|
4161
4181
|
model: model,
|
|
4162
4182
|
messages: [{ role: 'user', content: '你是什么模型?' }]
|
|
4163
|
-
})
|
|
4164
|
-
|
|
4183
|
+
});
|
|
4184
|
+
} else {
|
|
4185
|
+
postData = JSON.stringify({
|
|
4165
4186
|
model: model,
|
|
4166
4187
|
input: '你是什么模型?'
|
|
4167
4188
|
});
|
|
4189
|
+
}
|
|
4168
4190
|
|
|
4169
4191
|
const options = {
|
|
4170
4192
|
hostname: '127.0.0.1',
|
|
@@ -4198,11 +4220,13 @@ function testGatewayApi(port, token, model, endpoint = '/v1/responses') {
|
|
|
4198
4220
|
|
|
4199
4221
|
try {
|
|
4200
4222
|
const json = JSON.parse(data);
|
|
4223
|
+
// Anthropic Messages 格式响应
|
|
4224
|
+
const anthropicText = json.content?.[0]?.text;
|
|
4201
4225
|
// OpenResponses 格式响应
|
|
4202
4226
|
const outputText = json.output?.[0]?.content?.[0]?.text;
|
|
4203
4227
|
// Chat Completions 格式响应
|
|
4204
4228
|
const chatText = json.choices?.[0]?.message?.content;
|
|
4205
|
-
const message = outputText || chatText;
|
|
4229
|
+
const message = anthropicText || outputText || chatText;
|
|
4206
4230
|
if (message) {
|
|
4207
4231
|
resolve({ success: true, message });
|
|
4208
4232
|
} else if (json.error) {
|