Agrega uMind: chat con IA embebible por tenant (F1 — widget web + RAG)
Multi-tenant dentro de soft_usite, reutilizando la infraestructura ya existente (AiConfig, motor de function-calling del agente de Telegram) en vez de un servicio nuevo aparte: - UmindTenant: sitio/cliente con dominios permitidos, config de IA para el chat y personalidad/tono. - Ingesta: crawler simple (mismo dominio, N páginas) + chunking + embeddings (config global con módulo "umind_embeddings", pensada para OpenAI ya que Claude no ofrece embeddings) guardados como JSON, con búsqueda por similitud coseno en memoria (sin pgvector todavía). - Agente acotado: única herramienta buscar_conocimiento, sin acceso a nada interno — si no encuentra la respuesta, lo dice en vez de inventar. - Widget público (/widget/umind.js + /widget/:site_key/*), autenticado por site_key + validación de dominio (Origin/Referer), no por secreto, ya que la key viaja en el HTML público del sitio instalado. - Panel /app/umind: tenants, estado de ingesta, historial de conversaciones por sesión.
This commit is contained in:
@@ -270,6 +270,17 @@ func AdminApiRoutes(api fiber.Router) {
|
||||
h.Post("/pagos-externos/servicios/:id/regenerar-token", controllers.RegenerarTokenServicioPagoHandler)
|
||||
h.Get("/pagos-externos/solicitudes", controllers.GetSolicitudesPagoExternoHandler)
|
||||
|
||||
// ─── uMind: chat con IA embebible por tenant ───────────────────────────────
|
||||
h.Get("/umind/tenants", controllers.GetUmindTenants)
|
||||
h.Post("/umind/tenants", controllers.CreateUmindTenantHandler)
|
||||
h.Put("/umind/tenants/:id", controllers.UpdateUmindTenantHandler)
|
||||
h.Delete("/umind/tenants/:id", controllers.DeleteUmindTenantHandler)
|
||||
h.Get("/umind/documentos", controllers.GetUmindDocumentosHandler)
|
||||
h.Post("/umind/documentos", controllers.CreateUmindDocumentoHandler)
|
||||
h.Delete("/umind/documentos/:id", controllers.DeleteUmindDocumentoHandler)
|
||||
h.Get("/umind/sesiones", controllers.GetUmindSesionesHandler)
|
||||
h.Get("/umind/historial", controllers.GetUmindHistorialHandler)
|
||||
|
||||
// ─── OSS API (almacenamiento) ────────────────────────────────────────────
|
||||
h.Get("/oss-api", controllers.GetOssApiConfigs)
|
||||
h.Get("/oss-api/active", controllers.GetActiveOssApiList)
|
||||
|
||||
@@ -96,4 +96,14 @@ func RutasPublicas(web fiber.Router) {
|
||||
web.Get("/landing/download/:token", apiControllers.LandingDownload)
|
||||
// Config de IA activa (para Landing Generator)
|
||||
web.Get("/landing/ai-config", apiControllers.LandingGetAiConfig)
|
||||
|
||||
// ─── uMind: widget de chat embebible por tenant ───────────────────────────
|
||||
// Público por diseño (lo llama el navegador del visitante de un sitio de
|
||||
// terceros) — la protección es site_key + validación de dominio, no
|
||||
// sesión. Excluido de AuthApi() por vivir fuera del grupo /api.
|
||||
web.Get("/widget/umind.js", apiControllers.UmindWidgetScript)
|
||||
widget := web.Group("/widget/:site_key")
|
||||
widget.Options("*", middlewares.UmindWidgetCORS)
|
||||
widget.Get("/init", middlewares.AuthUmindWidget, apiControllers.UmindWidgetInit)
|
||||
widget.Post("/mensaje", middlewares.AuthUmindWidget, apiControllers.UmindWidgetMensaje)
|
||||
}
|
||||
|
||||
@@ -340,6 +340,21 @@ func UserRoutes(app fiber.Router) {
|
||||
protected.Post("/pagos-externos/servicios/:id/regenerar-token", middlewares.SoloAdmin, controllers.RegenerarTokenServicioPagoHandler)
|
||||
protected.Get("/pagos-externos/solicitudes", controllers.GetSolicitudesPagoExternoHandler)
|
||||
|
||||
// ─── uMind: chat con IA embebible por tenant ───────────────────────────────
|
||||
// Sensible: un tenant queda ligado a una config de IA (API key) y controla
|
||||
// desde qué dominios se puede llamar al widget, así que crear/editar es
|
||||
// solo para administradores.
|
||||
protected.Get("/umind", middlewares.MenuMiddleware, controllers.UmindIndex)
|
||||
protected.Get("/umind/tenants", controllers.GetUmindTenants)
|
||||
protected.Post("/umind/tenants", middlewares.SoloAdmin, controllers.CreateUmindTenantHandler)
|
||||
protected.Put("/umind/tenants/:id", middlewares.SoloAdmin, controllers.UpdateUmindTenantHandler)
|
||||
protected.Delete("/umind/tenants/:id", middlewares.SoloAdmin, controllers.DeleteUmindTenantHandler)
|
||||
protected.Get("/umind/documentos", controllers.GetUmindDocumentosHandler)
|
||||
protected.Post("/umind/documentos", middlewares.SoloAdmin, controllers.CreateUmindDocumentoHandler)
|
||||
protected.Delete("/umind/documentos/:id", middlewares.SoloAdmin, controllers.DeleteUmindDocumentoHandler)
|
||||
protected.Get("/umind/sesiones", controllers.GetUmindSesionesHandler)
|
||||
protected.Get("/umind/historial", controllers.GetUmindHistorialHandler)
|
||||
|
||||
// ─── OSS API (Alibaba Cloud + S3/MinIO) ────────────────────────────────────
|
||||
protected.Get("/oss-api", middlewares.MenuMiddleware, controllers.OssApiIndex)
|
||||
protected.Get("/loadossapi", controllers.GetOssApiConfigs)
|
||||
|
||||
Reference in New Issue
Block a user