yymaxapi 1.0.56 → 1.0.58

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.
Files changed (2) hide show
  1. package/bin/yymaxapi.js +34 -16
  2. package/package.json +1 -1
package/bin/yymaxapi.js CHANGED
@@ -3829,19 +3829,25 @@ async function testConnection(paths, args = {}) {
3829
3829
  }
3830
3830
  }
3831
3831
 
3832
- console.log(chalk.gray(` 端点: http://127.0.0.1:${gatewayPort}/v1/responses`));
3832
+ // 根据当前主模型类型选择测试端点
3833
+ const primaryProvider = primary.split('/')[0] || '';
3834
+ const primaryApi = config.models?.providers?.[primaryProvider]?.api || '';
3835
+ const isAnthropic = primaryApi.startsWith('anthropic');
3836
+ const testEndpoint = isAnthropic ? '/v1/messages' : '/v1/chat/completions';
3837
+ console.log(chalk.gray(` 端点: http://127.0.0.1:${gatewayPort}${testEndpoint}`));
3833
3838
  const startTime = Date.now();
3834
- let result = await testGatewayApi(gatewayPort, gatewayToken, primary);
3839
+ let result = await testGatewayApi(gatewayPort, gatewayToken, primary, testEndpoint);
3835
3840
  const latency = Date.now() - startTime;
3836
3841
 
3837
- // /v1/responses 返回 405 时,回退测试 /v1/chat/completions
3838
- if (!result.success && result.reachable && result.status === 405) {
3839
- console.log(chalk.gray(' /v1/responses 不支持,回退测试 /v1/chat/completions...'));
3840
- result = await testGatewayApi(gatewayPort, gatewayToken, primary, '/v1/chat/completions');
3842
+ // 回退:如果首选端点返回 404/405,尝试另一个
3843
+ if (!result.success && result.reachable && [404, 405].includes(result.status)) {
3844
+ const fallbackEndpoint = isAnthropic ? '/v1/chat/completions' : '/v1/responses';
3845
+ console.log(chalk.gray(` ${testEndpoint} 不支持,回退测试 ${fallbackEndpoint}...`));
3846
+ result = await testGatewayApi(gatewayPort, gatewayToken, primary, fallbackEndpoint);
3841
3847
  }
3842
3848
 
3843
- // CLI 对话已成功 + Gateway 可达(405)= Dashboard 通过 WebSocket 工作,视为通过
3844
- if (!result.success && cliPassed && result.reachable && result.status === 405) {
3849
+ // CLI 对话已成功 + Gateway 可达(404/405)= Dashboard 通过 WebSocket 工作,视为通过
3850
+ if (!result.success && cliPassed && result.reachable && [404, 405].includes(result.status)) {
3845
3851
  console.log(chalk.green(`\n✅ Gateway 测试通过`));
3846
3852
  console.log(chalk.cyan(` CLI 对话正常,Gateway 可达`));
3847
3853
  console.log(chalk.gray(` 注: Gateway Dashboard 通过 WebSocket 通信,REST 端点返回 405 属正常现象`));
@@ -3876,8 +3882,8 @@ async function testConnection(paths, args = {}) {
3876
3882
  console.log(chalk.gray(` 3) 若仍 401,检查是否存在多个配置目录(.openclaw 与 .clawdbot)`));
3877
3883
  }
3878
3884
 
3879
- if (cliPassed && /\b405\b/.test(String(result.error || ''))) {
3880
- console.log(chalk.yellow(`\n⚠️ 已定位:Gateway 可达(HTTP 405),Web API 端点不支持当前请求方法`));
3885
+ if (cliPassed && /\b(404|405)\b/.test(String(result.error || ''))) {
3886
+ console.log(chalk.yellow(`\n⚠️ 已定位:Gateway 可达,Web REST 端点返回 ${result.status || '404/405'}`));
3881
3887
  console.log(chalk.gray(` CLI 对话正常,Web Dashboard 应可正常使用。`));
3882
3888
  console.log(chalk.gray(` 如遇问题,尝试更新 Gateway: npm install -g openclaw@latest && openclaw gateway restart`));
3883
3889
  }
@@ -4153,18 +4159,28 @@ function printGatewayDiagnostics(resolved) {
4153
4159
  }
4154
4160
 
4155
4161
  // Gateway API 测试 - 通过本地 Gateway 端口测试
4156
- function testGatewayApi(port, token, model, endpoint = '/v1/responses') {
4162
+ function testGatewayApi(port, token, model, endpoint = '/v1/chat/completions') {
4157
4163
  return new Promise((resolve) => {
4164
+ const isMessages = endpoint.includes('/messages');
4158
4165
  const isChatCompletions = endpoint.includes('chat/completions');
4159
- const postData = isChatCompletions
4160
- ? JSON.stringify({
4166
+ let postData;
4167
+ if (isMessages) {
4168
+ postData = JSON.stringify({
4169
+ model: model.includes('/') ? model.split('/')[1] : model,
4170
+ max_tokens: 150,
4171
+ messages: [{ role: 'user', content: '你是什么模型?请用一句话回答。' }]
4172
+ });
4173
+ } else if (isChatCompletions) {
4174
+ postData = JSON.stringify({
4161
4175
  model: model,
4162
4176
  messages: [{ role: 'user', content: '你是什么模型?' }]
4163
- })
4164
- : JSON.stringify({
4177
+ });
4178
+ } else {
4179
+ postData = JSON.stringify({
4165
4180
  model: model,
4166
4181
  input: '你是什么模型?'
4167
4182
  });
4183
+ }
4168
4184
 
4169
4185
  const options = {
4170
4186
  hostname: '127.0.0.1',
@@ -4198,11 +4214,13 @@ function testGatewayApi(port, token, model, endpoint = '/v1/responses') {
4198
4214
 
4199
4215
  try {
4200
4216
  const json = JSON.parse(data);
4217
+ // Anthropic Messages 格式响应
4218
+ const anthropicText = json.content?.[0]?.text;
4201
4219
  // OpenResponses 格式响应
4202
4220
  const outputText = json.output?.[0]?.content?.[0]?.text;
4203
4221
  // Chat Completions 格式响应
4204
4222
  const chatText = json.choices?.[0]?.message?.content;
4205
- const message = outputText || chatText;
4223
+ const message = anthropicText || outputText || chatText;
4206
4224
  if (message) {
4207
4225
  resolve({ success: true, message });
4208
4226
  } else if (json.error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yymaxapi",
3
- "version": "1.0.56",
3
+ "version": "1.0.58",
4
4
  "description": "跨平台 OpenClaw/Clawdbot 配置管理工具 - 管理中转地址、模型切换、API Keys、测速优化",
5
5
  "main": "bin/yymaxapi.js",
6
6
  "bin": {