fix: resolver FUNCTION_INVOCATION_FAILED y pipeline de Instagram

- transcriptor: restaurar await toFile() — sin él Whisper recibía una
  Promise en vez del archivo y devolvía 400
- transcriptor: detectar MIME type real (m4a para Instagram, mp3 TikTok)
- analizar: normalizar duración (TikTok→ms, Instagram→s float) a entero
  antes de guardar en Supabase y pasar a GPT-4o
- analizar/server: reemplazar .catch() en insert de error por try/catch —
  el builder de Supabase no expone .catch() directamente; el TypeError
  escapaba al outer catch y causaba FUNCTION_INVOCATION_FAILED en Vercel
- validador: fallback de último recurso en enums cuando GPT-4o devuelve
  valor inválido (ej. "ninguno" para desarrollo_tipo)

Probado end-to-end: Instagram Reel → OK en 27s

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-01 10:57:49 -05:00
parent 4aecbef343
commit b11d57465e
4 changed files with 38 additions and 22 deletions

View File

@ -42,7 +42,8 @@ export async function transcribir(audioUrl, idioma = 'es') {
const ext = audioUrl.split('?')[0].split('.').pop()?.toLowerCase() || 'mp3'
const mimeMap = { mp3: 'audio/mpeg', m4a: 'audio/mp4', mp4: 'audio/mp4', webm: 'audio/webm', ogg: 'audio/ogg', wav: 'audio/wav' }
const mimeType = mimeMap[ext] || 'audio/mpeg'
const audioFile = toFile(audioResponse, `audio.${ext}`, { type: mimeType })
// toFile es async en el SDK de OpenAI — await es necesario aunque el IDE lo marque como hint
const audioFile = await toFile(audioResponse, `audio.${ext}`, { type: mimeType })
const transcripcion = await openai.audio.transcriptions.create({
file: audioFile,