/** * HA 实测:故意触发失败,看 invokeWithRetry 是否真的链式 fallback */ import * as dotenv from 'dotenv'; dotenv.config(); import { callLLMWithMessages, AllProvidersFailedError } from '/data/ai/audio/server/dist/services/llm/index'; const messages = [ { role: 'system', content: 'You are a test assistant.' }, { role: 'user', content: 'Reply with: HA_OK' }, ]; async function main() { const t0 = Date.now(); console.log(`\n[TEST-1] 故意不存在的 modelId (模拟调用失败)`); console.log('start:', new Date().toISOString()); try { const result = await callLLMWithMessages(messages, 'non-existent-model-id-xxx', 50); console.log(`[TEST-1] ❌ 意外成功: ${result.substring(0, 50)}`); } catch (e: any) { const elapsed = Date.now() - t0; console.log(`[TEST-1] ✅ 捕获错误 (${elapsed}ms)`); console.log(` 错误名: ${e.name}`); console.log(` 错误名(errorMessage): ${e.message?.substring(0, 200)}`); if (e.name === 'AllProvidersFailedError') { console.log(` ✅ HA 系统正确抛出了 AllProvidersFailedError`); console.log(` 尝试过的供应商: ${e.attempts?.length || 0}`); for (const a of e.attempts || []) { console.log(` - ${a.provider}/${a.model}: ${a.error.substring(0, 100)} (${a.attempts}次, ${a.errorType})`); } } else { console.log(` 错误类型: ${typeof e}, name=${e.name}`); } } } main().then(() => process.exit(0)).catch(e => { console.error('FATAL:', e); process.exit(1); });