fix: AI Gateway content safety 空值检查导致所有 AI 输出被误拦
All checks were successful
Deploy API Server / build-and-deploy (push) Successful in 41s

contentSafety 未注入时 safetyCheck 为 undefined,!undefined?.safe = true,
错误抛出 "AI output blocked by content safety",实际 DeepSeek 正常返回。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
wangdl 2026-06-06 14:23:55 +08:00
parent 55221116b7
commit 3d8246cf6e

View File

@ -64,7 +64,7 @@ export class AiGatewayService {
}); });
const safetyCheck = await this.contentSafety?.check(output.rawText, { contentType: 'ai_output' }).catch(() => ({ safe: true })); const safetyCheck = await this.contentSafety?.check(output.rawText, { contentType: 'ai_output' }).catch(() => ({ safe: true }));
if (!safetyCheck?.safe) throw new Error('AI output blocked by content safety'); if (safetyCheck && !safetyCheck.safe) throw new Error('AI output blocked by content safety');
const parsed = this.parseJson(output.rawText, request.outputSchema); const parsed = this.parseJson(output.rawText, request.outputSchema);
const estimatedCost = this.costCalculator.calculate( const estimatedCost = this.costCalculator.calculate(