Antes de cambio de ai-structured
This commit is contained in:
@@ -21,7 +21,9 @@ Deno.serve(async (req) => {
|
|||||||
const method = req.method;
|
const method = req.method;
|
||||||
if (method !== "POST") {
|
if (method !== "POST") {
|
||||||
console.error(
|
console.error(
|
||||||
`[${Date.now()}][${functionName}]: Invalid method: ${method}`,
|
`[${
|
||||||
|
new Date().toISOString()
|
||||||
|
}][${functionName}]: Invalid method: ${method}`,
|
||||||
);
|
);
|
||||||
return new Response(
|
return new Response(
|
||||||
JSON.stringify({ error: "Method not allowed" }),
|
JSON.stringify({ error: "Method not allowed" }),
|
||||||
@@ -36,7 +38,9 @@ Deno.serve(async (req) => {
|
|||||||
req.headers.get("authorization");
|
req.headers.get("authorization");
|
||||||
if (!authHeaderRaw) {
|
if (!authHeaderRaw) {
|
||||||
console.error(
|
console.error(
|
||||||
`[${Date.now()}][${functionName}]: Missing Authorization header`,
|
`[${
|
||||||
|
new Date().toISOString()
|
||||||
|
}][${functionName}]: Missing Authorization header`,
|
||||||
);
|
);
|
||||||
return new Response(
|
return new Response(
|
||||||
JSON.stringify({ error: "Authorization header missing" }),
|
JSON.stringify({ error: "Authorization header missing" }),
|
||||||
@@ -50,7 +54,9 @@ Deno.serve(async (req) => {
|
|||||||
const contentType = (req.headers.get("content-type") || "").toLowerCase();
|
const contentType = (req.headers.get("content-type") || "").toLowerCase();
|
||||||
if (!contentType.startsWith("multipart/form-data")) {
|
if (!contentType.startsWith("multipart/form-data")) {
|
||||||
console.error(
|
console.error(
|
||||||
`[${Date.now()}][${functionName}]: Unsupported content type: ${contentType}`,
|
`[${
|
||||||
|
new Date().toISOString()
|
||||||
|
}][${functionName}]: Unsupported content type: ${contentType}`,
|
||||||
);
|
);
|
||||||
return new Response(
|
return new Response(
|
||||||
JSON.stringify({ error: "Unsupported content type" }),
|
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");
|
const SERVICE_ROLE_KEY = Deno.env.get("SUPABASE_SERVICE_ROLE_KEY");
|
||||||
if (!SERVICE_ROLE_KEY) {
|
if (!SERVICE_ROLE_KEY) {
|
||||||
@@ -91,7 +105,7 @@ Deno.serve(async (req) => {
|
|||||||
const validation = parseAndValidate(formData);
|
const validation = parseAndValidate(formData);
|
||||||
if (!validation.success) {
|
if (!validation.success) {
|
||||||
console.error(
|
console.error(
|
||||||
`[${Date.now()}][${functionName}]: Validation errors:`,
|
`[${new Date().toISOString()}][${functionName}]: Validation errors:`,
|
||||||
validation.errors,
|
validation.errors,
|
||||||
);
|
);
|
||||||
return new Response(
|
return new Response(
|
||||||
@@ -128,7 +142,7 @@ Deno.serve(async (req) => {
|
|||||||
{ role: "user", content: userPrompt },
|
{ role: "user", content: userPrompt },
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
estructuraPlan,
|
structured: estructuraPlan.definicion,
|
||||||
references: {
|
references: {
|
||||||
openaiFileIds: payload.iaConfig.archivosReferencia,
|
openaiFileIds: payload.iaConfig.archivosReferencia,
|
||||||
vectorStoreIds: payload.iaConfig.repositoriosIds,
|
vectorStoreIds: payload.iaConfig.repositoriosIds,
|
||||||
@@ -145,6 +159,9 @@ Deno.serve(async (req) => {
|
|||||||
const { data: aiJson, error } = await supabaseService.functions.invoke(
|
const { data: aiJson, error } = await supabaseService.functions.invoke(
|
||||||
"ai-structured",
|
"ai-structured",
|
||||||
{
|
{
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${user.session?.access_token}`,
|
||||||
|
},
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: aiStructuredFormData,
|
body: aiStructuredFormData,
|
||||||
},
|
},
|
||||||
@@ -244,7 +261,9 @@ Deno.serve(async (req) => {
|
|||||||
// Log full error server-side for diagnostics
|
// Log full error server-side for diagnostics
|
||||||
if (error instanceof Error) {
|
if (error instanceof Error) {
|
||||||
console.error(
|
console.error(
|
||||||
`[${Date.now()}][${functionName}]: Request handler error:`,
|
`[${
|
||||||
|
new Date().toISOString()
|
||||||
|
}][${functionName}]: Request handler error:`,
|
||||||
error.message,
|
error.message,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user