primera versión funcional de creación de plan con IA
This commit is contained in:
@@ -18,7 +18,7 @@ import type { UploadedFile } from "@/components/planes/wizard/PasoDetallesPanel/
|
||||
|
||||
const EDGE = {
|
||||
plans_create_manual: "plans_create_manual",
|
||||
ai_generate_plan: "ai_generate_plan",
|
||||
ai_generate_plan: "ai-generate-plan",
|
||||
plans_persist_from_ai: "plans_persist_from_ai",
|
||||
plans_clone_from_existing: "plans_clone_from_existing",
|
||||
|
||||
@@ -214,10 +214,10 @@ export type AIGeneratePlanInput = {
|
||||
nivel: string;
|
||||
tipoCiclo: TipoCiclo;
|
||||
numCiclos: number;
|
||||
estructuraPlanId: UUID;
|
||||
};
|
||||
iaConfig: {
|
||||
descripcionEnfoque: string;
|
||||
poblacionObjetivo?: string;
|
||||
notasAdicionales?: string;
|
||||
archivosReferencia?: Array<UUID>;
|
||||
repositoriosIds?: Array<UUID>;
|
||||
@@ -229,7 +229,27 @@ export type AIGeneratePlanInput = {
|
||||
export async function ai_generate_plan(
|
||||
input: AIGeneratePlanInput,
|
||||
): Promise<any> {
|
||||
return invokeEdge<any>(EDGE.ai_generate_plan, input);
|
||||
console.log("input ai generate", input);
|
||||
|
||||
const edgeFunctionBody = new FormData();
|
||||
edgeFunctionBody.append("datosBasicos", JSON.stringify(input.datosBasicos));
|
||||
edgeFunctionBody.append(
|
||||
"iaConfig",
|
||||
JSON.stringify({
|
||||
...input.iaConfig,
|
||||
archivosAdjuntos: undefined, // los manejamos aparte
|
||||
}),
|
||||
);
|
||||
input.iaConfig.archivosAdjuntos.forEach((file, index) => {
|
||||
edgeFunctionBody.append(`archivosAdjuntos`, file.file);
|
||||
});
|
||||
|
||||
return invokeEdge<any>(
|
||||
EDGE.ai_generate_plan,
|
||||
edgeFunctionBody,
|
||||
undefined,
|
||||
supabaseBrowser(),
|
||||
);
|
||||
}
|
||||
|
||||
export async function plans_persist_from_ai(
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import type { SupabaseClient } from "@supabase/supabase-js";
|
||||
import type { Database } from "../types/database";
|
||||
import { supabaseBrowser } from "./client";
|
||||
|
||||
import type { Database } from "@/types/supabase";
|
||||
import type { SupabaseClient } from "@supabase/supabase-js";
|
||||
|
||||
export type EdgeInvokeOptions = {
|
||||
method?: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
||||
headers?: Record<string, string>;
|
||||
@@ -12,7 +13,7 @@ export class EdgeFunctionError extends Error {
|
||||
message: string,
|
||||
public readonly functionName: string,
|
||||
public readonly status?: number,
|
||||
public readonly details?: unknown
|
||||
public readonly details?: unknown,
|
||||
) {
|
||||
super(message);
|
||||
this.name = "EdgeFunctionError";
|
||||
@@ -21,9 +22,17 @@ export class EdgeFunctionError extends Error {
|
||||
|
||||
export async function invokeEdge<TOut>(
|
||||
functionName: string,
|
||||
body?: unknown,
|
||||
body?:
|
||||
| string
|
||||
| File
|
||||
| Blob
|
||||
| ArrayBuffer
|
||||
| FormData
|
||||
| ReadableStream<Uint8Array<ArrayBufferLike>>
|
||||
| Record<string, unknown>
|
||||
| undefined,
|
||||
opts: EdgeInvokeOptions = {},
|
||||
client?: SupabaseClient<Database>
|
||||
client?: SupabaseClient<Database>,
|
||||
): Promise<TOut> {
|
||||
const supabase = client ?? supabaseBrowser();
|
||||
|
||||
@@ -34,12 +43,12 @@ export async function invokeEdge<TOut>(
|
||||
});
|
||||
|
||||
if (error) {
|
||||
const anyErr = error as any;
|
||||
const anyErr = error;
|
||||
throw new EdgeFunctionError(
|
||||
anyErr.message ?? "Error en Edge Function",
|
||||
functionName,
|
||||
anyErr.status,
|
||||
anyErr
|
||||
anyErr,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user