From 738d3970e3fb94fb15d85f973fdd311ef84e7cce Mon Sep 17 00:00:00 2001 From: Alejandro Rosales Date: Wed, 25 Feb 2026 08:03:00 -0600 Subject: [PATCH] fix: ensure campos is always an array in pickSchemaFields function --- supabase/functions/create-chat-conversation/index.ts | 2 +- supabase/functions/create-chat-conversation/lib/plan.ts | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/supabase/functions/create-chat-conversation/index.ts b/supabase/functions/create-chat-conversation/index.ts index b901766..8c352e4 100644 --- a/supabase/functions/create-chat-conversation/index.ts +++ b/supabase/functions/create-chat-conversation/index.ts @@ -300,7 +300,7 @@ app.post(`${prefix}/conversations/:id/messages`, async (c) => { } // Pedimos respuesta estructurada con responses.create - const schema = pickSchemaFields(definicion, body.campos); + const schema = pickSchemaFields(definicion, body.campos ?? []); const planForPrompt = safePlanForPrompt(plan); const model = CREATE_CHAT_CONVERSATION_STRUCTURED_MODELO; diff --git a/supabase/functions/create-chat-conversation/lib/plan.ts b/supabase/functions/create-chat-conversation/lib/plan.ts index c79d6aa..21ee075 100644 --- a/supabase/functions/create-chat-conversation/lib/plan.ts +++ b/supabase/functions/create-chat-conversation/lib/plan.ts @@ -2,7 +2,7 @@ import { HttpError } from "./errors.ts"; export function pickSchemaFields( definicion: any, - campos?: string[], + campos: string[], ) { if (!definicion || definicion.type !== "object" || !definicion.properties) { return definicion; @@ -18,6 +18,11 @@ export function pickSchemaFields( "Listo: mejoré la redacción del perfil de ingreso y propuse un tema de investigación alineado al plan.", ], }, + "is-refusal": { + type: "boolean", + description: + "Indica si el plan fue rechazado por el modelo. En caso de ser true, se espera un mensaje de rechazo en `ai-message`.", + }, }, };