fix: update database queries to use 'template' instead of 'template_id' and adjust related references in ai_generate_plan function
This commit is contained in:
@@ -324,7 +324,7 @@ Deno.serve(async (req) => {
|
||||
log("Using estructuraId from payload", { estructuraIdFromPayload });
|
||||
const { data, error } = await supabaseAdmin
|
||||
.from("estructuras_plan")
|
||||
.select("id,nombre,tipo,template_id,definicion")
|
||||
.select("id,nombre,tipo,template,definicion")
|
||||
.eq("id", estructuraIdFromPayload)
|
||||
.single();
|
||||
if (error) {
|
||||
@@ -336,7 +336,7 @@ Deno.serve(async (req) => {
|
||||
// default: la más reciente tipo CURRICULAR, si no existe, la más reciente en general
|
||||
const { data, error } = await supabaseAdmin
|
||||
.from("estructuras_plan")
|
||||
.select("id,nombre,tipo,template_id,definicion")
|
||||
.select("id,nombre,tipo,template,definicion")
|
||||
.eq("tipo", "CURRICULAR")
|
||||
.order("actualizado_en", { ascending: false })
|
||||
.limit(1)
|
||||
@@ -350,7 +350,7 @@ Deno.serve(async (req) => {
|
||||
if (!estructura) {
|
||||
const { data: anyE, error: anyErr } = await supabaseAdmin
|
||||
.from("estructuras_plan")
|
||||
.select("id,nombre,tipo,template_id,definicion")
|
||||
.select("id,nombre,tipo,template,definicion")
|
||||
.order("actualizado_en", { ascending: false })
|
||||
.limit(1)
|
||||
.maybeSingle();
|
||||
@@ -367,7 +367,7 @@ Deno.serve(async (req) => {
|
||||
estructuraId: estructura?.id ?? null,
|
||||
nombre: estructura?.nombre ?? null,
|
||||
tipo: estructura?.tipo ?? null,
|
||||
template_id: estructura?.template_id ?? null,
|
||||
template: estructura?.template ?? null,
|
||||
definicionKeys: estructura?.definicion ? Object.keys(estructura.definicion) : null,
|
||||
});
|
||||
|
||||
@@ -378,15 +378,15 @@ Deno.serve(async (req) => {
|
||||
|
||||
// 6) Resolver referencias (archivos / repositorios) 📎
|
||||
log("Step 6: Resolve references 📎");
|
||||
const archivosReferenciaIds: string[] = Array.isArray(iaConfig?.archivosReferencia)
|
||||
? iaConfig.archivosReferencia
|
||||
const uploadedToStorage: string[] = Array.isArray(iaConfig?.uploadedToStorage)
|
||||
? iaConfig.uploadedToStorage
|
||||
: [];
|
||||
const repositoriosIds: string[] = Array.isArray(iaConfig?.repositoriosIds)
|
||||
? iaConfig.repositoriosIds
|
||||
: [];
|
||||
|
||||
log("Reference IDs received", {
|
||||
archivosReferenciaIdsCount: archivosReferenciaIds.length,
|
||||
uploadedToStorageCount: uploadedToStorage.length,
|
||||
repositoriosIdsCount: repositoriosIds.length,
|
||||
usarMCP: Boolean(iaConfig?.usarMCP),
|
||||
});
|
||||
@@ -394,11 +394,11 @@ Deno.serve(async (req) => {
|
||||
const archivosInfo: any[] = [];
|
||||
const vectorInfo: any[] = [];
|
||||
|
||||
if (archivosReferenciaIds.length) {
|
||||
if (uploadedToStorage.length) {
|
||||
const { data, error } = await supabaseAdmin
|
||||
.from("archivos")
|
||||
.select("id,nombre,mime_type,openai_file_id,ruta_storage")
|
||||
.in("id", archivosReferenciaIds);
|
||||
.in("id", uploadedToStorage);
|
||||
if (error) warn("archivos lookup failed (continuing)", { message: error.message });
|
||||
for (const a of data ?? []) archivosInfo.push(a);
|
||||
}
|
||||
@@ -481,7 +481,7 @@ Deno.serve(async (req) => {
|
||||
references: {
|
||||
openaiFileIds,
|
||||
vectorStoreIds,
|
||||
archivosReferenciaIds,
|
||||
uploadedToStorage,
|
||||
},
|
||||
usarMCP: Boolean(iaConfig?.usarMCP),
|
||||
};
|
||||
@@ -544,14 +544,14 @@ Deno.serve(async (req) => {
|
||||
prompt: {
|
||||
datosBasicos,
|
||||
iaConfig,
|
||||
estructura: { id: estructura.id, nombre: estructura.nombre, template_id: estructura.template_id, tipo: estructura.tipo },
|
||||
estructura: { id: estructura.id, nombre: estructura.nombre, template: estructura.template, tipo: estructura.tipo },
|
||||
request: aiStructuredBody,
|
||||
computed,
|
||||
},
|
||||
respuesta: aiJson,
|
||||
aceptada: false,
|
||||
conversacion_id: aiJson?.conversationId ?? null,
|
||||
ids_archivos: archivosReferenciaIds,
|
||||
ids_archivos: uploadedToStorage,
|
||||
ids_vector_store: repositoriosIds,
|
||||
rutas_storage: rutasStorage,
|
||||
})
|
||||
@@ -596,7 +596,7 @@ Deno.serve(async (req) => {
|
||||
estructura: {
|
||||
id: estructura.id,
|
||||
nombre: estructura.nombre,
|
||||
template_id: estructura.template_id,
|
||||
template: estructura.template,
|
||||
tipo: estructura.tipo,
|
||||
},
|
||||
request: aiStructuredBody,
|
||||
@@ -605,7 +605,7 @@ Deno.serve(async (req) => {
|
||||
respuesta: aiJson,
|
||||
aceptada: true, // se está usando para crear el plan
|
||||
conversacion_id: aiJson?.conversationId ?? null,
|
||||
ids_archivos: archivosReferenciaIds,
|
||||
ids_archivos: uploadedToStorage,
|
||||
ids_vector_store: repositoriosIds,
|
||||
rutas_storage: rutasStorage,
|
||||
})
|
||||
@@ -672,7 +672,7 @@ Deno.serve(async (req) => {
|
||||
usage: aiJson?.usage ?? null,
|
||||
},
|
||||
referencias: {
|
||||
archivosReferenciaIds,
|
||||
uploadedToStorage,
|
||||
repositoriosIds,
|
||||
openaiFileIds,
|
||||
vectorStoreIds,
|
||||
@@ -761,7 +761,7 @@ Deno.serve(async (req) => {
|
||||
usage: aiJson?.usage ?? null,
|
||||
},
|
||||
references: {
|
||||
archivosReferenciaIds,
|
||||
uploadedToStorage,
|
||||
repositoriosIds,
|
||||
openaiFileIds,
|
||||
vectorStoreIds,
|
||||
|
||||
Reference in New Issue
Block a user