fix: suppress VAD debug logs, spotify no-device graceful, filter tool names from response
Some checks failed
Deploy / deploy (push) Failing after 45s

This commit is contained in:
Cosmo
2026-05-01 11:25:15 +00:00
parent 70284c69cf
commit a94a40ffc6
3 changed files with 43 additions and 12 deletions

View File

@@ -203,7 +203,19 @@ export async function POST(req: Request) {
] ]
await saveHistory(agent, updatedHistory) await saveHistory(agent, updatedHistory)
const cleaned = cleanForSpeech(stripFillers(finalText)) // Убрать строки вида "get_weather ..." или "<function=...>" которые иногда генерирует LLM
const filteredText = finalText
.split('\n')
.filter(line => {
const l = line.trim()
return !(/^(get_|set_|control_|create_|update_|delete_|cancel_)[a-z_]+\s/.test(l) ||
l.startsWith('<function') ||
l.startsWith('function='))
})
.join('\n')
.trim()
const cleaned = cleanForSpeech(stripFillers(filteredText || finalText))
emitVoice('response', agent, cleaned) emitVoice('response', agent, cleaned)
return NextResponse.json({ text: cleaned }) return NextResponse.json({ text: cleaned })
} }

View File

@@ -15,12 +15,17 @@ async function spotifyFetch(path: string, method = 'GET', body?: any) {
if (res.status === 204) return { success: true } if (res.status === 204) return { success: true }
if (!res.ok) { if (!res.ok) {
const err = await res.text() const err = await res.text()
// Специальная обработка: нет активного устройства
if (res.status === 404 && err.includes('NO_ACTIVE_DEVICE')) {
throw Object.assign(new Error('NO_ACTIVE_DEVICE'), { code: 'NO_ACTIVE_DEVICE' })
}
throw new Error(`Spotify API ${res.status}: ${err}`) throw new Error(`Spotify API ${res.status}: ${err}`)
} }
return res.json().catch(() => ({ success: true })) return res.json().catch(() => ({ success: true }))
} }
export async function GET() { export async function GET() {
try {
// Get current playback state // Get current playback state
const data = await spotifyFetch('/me/player') const data = await spotifyFetch('/me/player')
if (!data || !data.item) return NextResponse.json({ playing: false }) if (!data || !data.item) return NextResponse.json({ playing: false })
@@ -32,12 +37,19 @@ export async function GET() {
volume: data.volume_percent, volume: data.volume_percent,
device: data.device?.name, device: data.device?.name,
}) })
} catch (e: any) {
if (e?.code === 'NO_ACTIVE_DEVICE' || e?.message === 'NO_ACTIVE_DEVICE') {
return NextResponse.json({ error: 'no_active_device', message: 'Нет активного устройства Spotify. Открой Spotify на телефоне или ноутбуке.' }, { status: 200 })
}
return NextResponse.json({ error: String(e?.message || e) }, { status: 500 })
}
} }
export async function POST(req: NextRequest) { export async function POST(req: NextRequest) {
const body = await req.json() const body = await req.json()
const { action, query, volume } = body const { action, query, volume } = body
try {
switch (action) { switch (action) {
case 'play': case 'play':
if (query) { if (query) {
@@ -75,4 +87,10 @@ export async function POST(req: NextRequest) {
default: default:
return NextResponse.json({ error: 'unknown action' }, { status: 400 }) return NextResponse.json({ error: 'unknown action' }, { status: 400 })
} }
} catch (e: any) {
if (e?.code === 'NO_ACTIVE_DEVICE' || e?.message === 'NO_ACTIVE_DEVICE') {
return NextResponse.json({ error: 'no_active_device', message: 'Нет активного устройства Spotify. Открой Spotify на телефоне или ноутбуке.' }, { status: 200 })
}
return NextResponse.json({ error: String(e?.message || e) }, { status: 500 })
}
} }

View File

@@ -114,6 +114,7 @@ export default function VoiceController() {
model: 'v5', model: 'v5',
baseAssetPath: '/vad/', baseAssetPath: '/vad/',
onnxWASMBasePath: '/vad/', onnxWASMBasePath: '/vad/',
logLevel: 'error',
ortConfig: (ort: any) => { ortConfig: (ort: any) => {
ort.env.wasm.numThreads = 1 ort.env.wasm.numThreads = 1
ort.env.wasm.simd = true ort.env.wasm.simd = true