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)
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)
return NextResponse.json({ text: cleaned })
}

View File

@@ -15,29 +15,41 @@ async function spotifyFetch(path: string, method = 'GET', body?: any) {
if (res.status === 204) return { success: true }
if (!res.ok) {
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}`)
}
return res.json().catch(() => ({ success: true }))
}
export async function GET() {
// Get current playback state
const data = await spotifyFetch('/me/player')
if (!data || !data.item) return NextResponse.json({ playing: false })
return NextResponse.json({
playing: data.is_playing,
track: data.item.name,
artist: data.item.artists?.map((a: any) => a.name).join(', '),
album: data.item.album?.name,
volume: data.volume_percent,
device: data.device?.name,
})
try {
// Get current playback state
const data = await spotifyFetch('/me/player')
if (!data || !data.item) return NextResponse.json({ playing: false })
return NextResponse.json({
playing: data.is_playing,
track: data.item.name,
artist: data.item.artists?.map((a: any) => a.name).join(', '),
album: data.item.album?.name,
volume: data.volume_percent,
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) {
const body = await req.json()
const { action, query, volume } = body
try {
switch (action) {
case 'play':
if (query) {
@@ -75,4 +87,10 @@ export async function POST(req: NextRequest) {
default:
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',
baseAssetPath: '/vad/',
onnxWASMBasePath: '/vad/',
logLevel: 'error',
ortConfig: (ort: any) => {
ort.env.wasm.numThreads = 1
ort.env.wasm.simd = true