fix: suppress VAD debug logs, spotify no-device graceful, filter tool names from response
Some checks failed
Deploy / deploy (push) Failing after 45s
Some checks failed
Deploy / deploy (push) Failing after 45s
This commit is contained in:
@@ -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 })
|
||||
}
|
||||
|
||||
@@ -15,12 +15,17 @@ 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() {
|
||||
try {
|
||||
// Get current playback state
|
||||
const data = await spotifyFetch('/me/player')
|
||||
if (!data || !data.item) return NextResponse.json({ playing: false })
|
||||
@@ -32,12 +37,19 @@ export async function GET() {
|
||||
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 })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user