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)
|
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 })
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,29 +15,41 @@ 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() {
|
||||||
// Get current playback state
|
try {
|
||||||
const data = await spotifyFetch('/me/player')
|
// Get current playback state
|
||||||
if (!data || !data.item) return NextResponse.json({ playing: false })
|
const data = await spotifyFetch('/me/player')
|
||||||
return NextResponse.json({
|
if (!data || !data.item) return NextResponse.json({ playing: false })
|
||||||
playing: data.is_playing,
|
return NextResponse.json({
|
||||||
track: data.item.name,
|
playing: data.is_playing,
|
||||||
artist: data.item.artists?.map((a: any) => a.name).join(', '),
|
track: data.item.name,
|
||||||
album: data.item.album?.name,
|
artist: data.item.artists?.map((a: any) => a.name).join(', '),
|
||||||
volume: data.volume_percent,
|
album: data.item.album?.name,
|
||||||
device: data.device?.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) {
|
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 })
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user