feat: uMind pasa a multi-agente por tenant
Un tenant (negocio/sitio, dueño de los dominios permitidos) puede tener varios UmindAgente independientes (ej. "Ventas", "Soporte"), cada uno con su propia config de IA, tono, base de conocimiento, tools, canales y conexión de correo. El site_key también pasa a ser por agente, así cada uno tiene su propio <script> de widget embebible y su propio color. Backend: - Nuevo modelo UmindAgente (pkg/models/umind_agente.go), con SiteKey, AiConfigID, Tono, MensajeBienvenida y Color — campos que antes vivían en UmindTenant y se sacan de ahí (las columnas viejas quedan huérfanas sin usar, no se hace DROP COLUMN). - UmindDocumento, UmindChunk, UmindHerramienta, UmindCanal, UmindConexion y UmindMensaje pasan de TenantID a AgenteID. El campo se agrega sin "not null" para no romper el ALTER TABLE en Postgres sobre tablas que ya tienen filas (ej. emetropolitana). - migrations.MigrarUmindAgentes(): idempotente, crea un agente "Principal" por cada tenant existente heredando lo que ya tenía configurado, y mueve sus datos de tenant_id a agente_id. Corre en cada arranque normal, mismo criterio que los Seed* — nada se rompe para los tenants ya en producción. - Motor del agente, widget, canales (Telegram/WhatsApp) y OAuth de correo ahora operan sobre UmindAgente; el tenant solo se consulta para el chequeo de dominio permitido y el nombre del negocio que ve el visitante. Frontend: nueva jerarquía de navegación tenant → lista de agentes (TenantAgentes.vue) → detalle de un agente (AgenteDetail.vue, antes TenantDetail.vue) con las mismas 6 tabs de siempre, ahora por agente. El modal de tenant en el sidebar se achica a nombre/dominios/activo. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
8eba3ab97f
commit
f3f2f421d6
@@ -11,20 +11,20 @@ import (
|
||||
)
|
||||
|
||||
// GetUmindConexionesHandler lista las cuentas de correo conectadas de un
|
||||
// tenant, sin exponer los tokens (ni cifrados ni en claro).
|
||||
// agente, sin exponer los tokens (ni cifrados ni en claro).
|
||||
func GetUmindConexionesHandler(c *fiber.Ctx) error {
|
||||
tenantID, err := strconv.ParseUint(c.Query("tenant_id"), 10, 64)
|
||||
if err != nil || tenantID == 0 {
|
||||
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": "tenant_id requerido"})
|
||||
agenteID, err := strconv.ParseUint(c.Query("agente_id"), 10, 64)
|
||||
if err != nil || agenteID == 0 {
|
||||
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": "agente_id requerido"})
|
||||
}
|
||||
items, err := models.GetUmindConexionesByTenant(uint(tenantID))
|
||||
items, err := models.GetUmindConexionesByAgente(uint(agenteID))
|
||||
if err != nil {
|
||||
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{"error": err.Error()})
|
||||
}
|
||||
out := make([]fiber.Map, len(items))
|
||||
for i, cx := range items {
|
||||
out[i] = fiber.Map{
|
||||
"ID": cx.ID, "tenant_id": cx.TenantID, "proveedor": cx.Proveedor,
|
||||
"ID": cx.ID, "agente_id": cx.AgenteID, "proveedor": cx.Proveedor,
|
||||
"email": cx.Email, "activo": cx.Activo, "expira_en": cx.ExpiraEn,
|
||||
}
|
||||
}
|
||||
@@ -32,18 +32,18 @@ func GetUmindConexionesHandler(c *fiber.Ctx) error {
|
||||
}
|
||||
|
||||
// UmindConectarHandler redirige al staff a la pantalla de consentimiento de
|
||||
// Google/Microsoft. Ruta: GET /app/umind/conexiones/conectar?tenant_id=&proveedor=
|
||||
// Google/Microsoft. Ruta: GET /app/umind/conexiones/conectar?agente_id=&proveedor=
|
||||
func UmindConectarHandler(c *fiber.Ctx) error {
|
||||
tenantID, err := strconv.ParseUint(c.Query("tenant_id"), 10, 64)
|
||||
if err != nil || tenantID == 0 {
|
||||
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": "tenant_id requerido"})
|
||||
agenteID, err := strconv.ParseUint(c.Query("agente_id"), 10, 64)
|
||||
if err != nil || agenteID == 0 {
|
||||
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": "agente_id requerido"})
|
||||
}
|
||||
proveedor := c.Query("proveedor")
|
||||
if _, err := models.GetUmindTenantByID(uint(tenantID)); err != nil {
|
||||
return c.Status(fiber.StatusNotFound).JSON(fiber.Map{"error": "tenant no encontrado"})
|
||||
if _, err := models.GetUmindAgenteByID(uint(agenteID)); err != nil {
|
||||
return c.Status(fiber.StatusNotFound).JSON(fiber.Map{"error": "agente no encontrado"})
|
||||
}
|
||||
|
||||
url, err := services.IniciarConexionOAuth(proveedor, uint(tenantID))
|
||||
url, err := services.IniciarConexionOAuth(proveedor, uint(agenteID))
|
||||
if err != nil {
|
||||
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": err.Error()})
|
||||
}
|
||||
@@ -69,7 +69,11 @@ func UmindOAuthCallbackHandler(c *fiber.Ctx) error {
|
||||
log.Printf("[UMIND_OAUTH] error completando conexión (%s): %v", proveedor, err)
|
||||
return c.Redirect("/orchestrator/?oauth_error=1", fiber.StatusFound)
|
||||
}
|
||||
return c.Redirect(fmt.Sprintf("/orchestrator/tenants/%d?tab=conexiones", conexion.TenantID), fiber.StatusFound)
|
||||
agente, err := models.GetUmindAgenteByID(conexion.AgenteID)
|
||||
if err != nil {
|
||||
return c.Redirect("/orchestrator/?oauth_error=1", fiber.StatusFound)
|
||||
}
|
||||
return c.Redirect(fmt.Sprintf("/orchestrator/tenants/%d/agentes/%d?tab=conexiones", agente.TenantID, agente.ID), fiber.StatusFound)
|
||||
}
|
||||
|
||||
func DeleteUmindConexionHandler(c *fiber.Ctx) error {
|
||||
|
||||
Reference in New Issue
Block a user