Antes de cambio de ai-structured

This commit is contained in:
2026-01-19 16:33:08 -06:00
parent 3170ed6975
commit 7a29f1a87d
+26 -7
View File
@@ -21,7 +21,9 @@ Deno.serve(async (req) => {
const method = req.method;
if (method !== "POST") {
console.error(
`[${Date.now()}][${functionName}]: Invalid method: ${method}`,
`[${
new Date().toISOString()
}][${functionName}]: Invalid method: ${method}`,
);
return new Response(
JSON.stringify({ error: "Method not allowed" }),
@@ -36,7 +38,9 @@ Deno.serve(async (req) => {
req.headers.get("authorization");
if (!authHeaderRaw) {
console.error(
`[${Date.now()}][${functionName}]: Missing Authorization header`,
`[${
new Date().toISOString()
}][${functionName}]: Missing Authorization header`,
);
return new Response(
JSON.stringify({ error: "Authorization header missing" }),
@@ -50,7 +54,9 @@ Deno.serve(async (req) => {
const contentType = (req.headers.get("content-type") || "").toLowerCase();
if (!contentType.startsWith("multipart/form-data")) {
console.error(
`[${Date.now()}][${functionName}]: Unsupported content type: ${contentType}`,
`[${
new Date().toISOString()
}][${functionName}]: Unsupported content type: ${contentType}`,
);
return new Response(
JSON.stringify({ error: "Unsupported content type" }),
@@ -75,7 +81,15 @@ Deno.serve(async (req) => {
},
});
// TODO: iniciar sesion con el usuario e implementar RLS
// TODO: quitar hardcode de usuario
const { data: user, error: userError } = await supabaseAnon.auth
.signInWithPassword({
email: "guillermo.arrieta@lasalle.mx",
password: "admin",
});
if (userError) {
throw new Error("Error authenticating user: " + userError.message);
}
const SERVICE_ROLE_KEY = Deno.env.get("SUPABASE_SERVICE_ROLE_KEY");
if (!SERVICE_ROLE_KEY) {
@@ -91,7 +105,7 @@ Deno.serve(async (req) => {
const validation = parseAndValidate(formData);
if (!validation.success) {
console.error(
`[${Date.now()}][${functionName}]: Validation errors:`,
`[${new Date().toISOString()}][${functionName}]: Validation errors:`,
validation.errors,
);
return new Response(
@@ -128,7 +142,7 @@ Deno.serve(async (req) => {
{ role: "user", content: userPrompt },
],
},
estructuraPlan,
structured: estructuraPlan.definicion,
references: {
openaiFileIds: payload.iaConfig.archivosReferencia,
vectorStoreIds: payload.iaConfig.repositoriosIds,
@@ -145,6 +159,9 @@ Deno.serve(async (req) => {
const { data: aiJson, error } = await supabaseService.functions.invoke(
"ai-structured",
{
headers: {
Authorization: `Bearer ${user.session?.access_token}`,
},
method: "POST",
body: aiStructuredFormData,
},
@@ -244,7 +261,9 @@ Deno.serve(async (req) => {
// Log full error server-side for diagnostics
if (error instanceof Error) {
console.error(
`[${Date.now()}][${functionName}]: Request handler error:`,
`[${
new Date().toISOString()
}][${functionName}]: Request handler error:`,
error.message,
);
}