fix: validate empty messages + trim relay host whitespace

Address code review: check for empty messages array in relay, and
trim whitespace from CN_RELAY_HOST to avoid silent connection failures.

Agent-Logs-Url: https://github.com/qinfendebingshuo/guanghulab/sessions/04495ae8-6c76-4458-bbb0-262e3205dccd

Co-authored-by: qinfendebingshuo <207279273+qinfendebingshuo@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2026-04-11 14:48:32 +00:00 committed by GitHub
parent f8824ac43f
commit d457ccd746
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 3 additions and 3 deletions

View File

@ -28,7 +28,7 @@ const http = require('http');
// ─── 广州CN中继配置 ───
// 当配置了 ZY_CN_LLM_RELAY_HOST 时,请求走广州中继(国内直连·低延迟)
// 广州不可达时降级为直连国内API跨境·高延迟但可用
const CN_RELAY_HOST = process.env.ZY_CN_LLM_RELAY_HOST || '';
const CN_RELAY_HOST = (process.env.ZY_CN_LLM_RELAY_HOST || '').trim();
const CN_RELAY_PORT = parseInt(process.env.ZY_CN_LLM_RELAY_PORT || '3900', 10);
const CN_RELAY_KEY = process.env.ZY_CN_LLM_RELAY_KEY || '';
const CN_RELAY_TIMEOUT = parseInt(process.env.ZY_CN_LLM_RELAY_TIMEOUT || '30000', 10);

View File

@ -203,10 +203,10 @@ app.post('/llm/chat', async (req, res) => {
try {
const { messages, model_id, temperature, max_tokens, fallback_order } = req.body;
if (!messages || !Array.isArray(messages)) {
if (!messages || !Array.isArray(messages) || messages.length === 0) {
return res.status(400).json({
error: true,
message: '缺少messages参数'
message: '缺少messages参数或消息列表为空'
});
}