diff --git a/src/modules/ai/roles/erp-roles.config.ts b/src/modules/ai/roles/erp-roles.config.ts index 500035b..210052b 100644 --- a/src/modules/ai/roles/erp-roles.config.ts +++ b/src/modules/ai/roles/erp-roles.config.ts @@ -1,17 +1,17 @@ /** - * ERP Roles Configuration + * ERP Vidrio Templado - Roles Configuration * - * Define roles, tools permitidos, y system prompts para cada rol en el ERP. - * Basado en: michangarrito MCH-012/MCH-013 (role-based chatbot) + * Roles específicos para plantas de vidrio templado. + * Adaptado desde erp-core v1.5.0 (PROP-CORE-004) * - * Roles disponibles: - * - ADMIN: Acceso completo a todas las operaciones - * - SUPERVISOR: Gestión de equipos y reportes de sucursal - * - OPERATOR: Operaciones de punto de venta - * - CUSTOMER: Acceso limitado para clientes (si se expone chatbot) + * Roles: + * - ADMIN: Gerente de planta - acceso completo + * - SUPERVISOR_PRODUCCION: Supervisor - órdenes y calidad + * - OPERADOR_CORTE: Operador de área de corte + * - OPERADOR_HORNO: Operador de hornos de templado */ -export type ERPRole = 'ADMIN' | 'SUPERVISOR' | 'OPERATOR' | 'CUSTOMER'; +export type ERPRole = 'ADMIN' | 'SUPERVISOR_PRODUCCION' | 'OPERADOR_CORTE' | 'OPERADOR_HORNO'; export interface ERPRoleConfig { name: string; @@ -19,234 +19,150 @@ export interface ERPRoleConfig { tools: string[]; systemPromptFile: string; maxConversationHistory: number; - allowedModels?: string[]; // Si vacío, usa el default del tenant + allowedModels?: string[]; rateLimit: { requestsPerMinute: number; tokensPerMinute: number; }; } -/** - * Configuración de roles ERP - */ export const ERP_ROLES: Record = { ADMIN: { - name: 'Administrador', - description: 'Acceso completo a todas las operaciones del sistema ERP', + name: 'Gerente de Planta', + description: 'Gerente con acceso completo a todas las operaciones de la planta', tools: [ - // Ventas - 'get_sales_summary', - 'get_sales_report', - 'get_top_products', - 'get_top_customers', - 'get_sales_by_branch', - 'create_sale', - 'void_sale', - - // Inventario - 'get_inventory_status', - 'get_low_stock_products', - 'get_inventory_value', - 'adjust_inventory', - 'transfer_inventory', - - // Compras - 'get_pending_orders', - 'get_supplier_info', - 'create_purchase_order', - 'approve_purchase', - + // Producción + 'get_production_summary', 'get_all_orders', 'get_production_kpis', + 'approve_production_order', + // Calidad + 'get_quality_metrics', 'get_defect_reports', 'approve_quality_cert', // Finanzas - 'get_financial_report', - 'get_accounts_receivable', - 'get_accounts_payable', - 'get_cash_flow', - - // Usuarios y configuración - 'manage_users', - 'view_audit_logs', - 'update_settings', - 'get_branch_info', - 'manage_branches', - - // Reportes avanzados - 'generate_report', - 'export_data', - 'get_kpis', + 'get_financial_report', 'get_accounts_receivable', 'get_accounts_payable', + 'get_cash_flow', 'get_kpis', + // Inventario (vidrio y materiales) + 'get_inventory_status', 'get_low_stock_products', 'get_inventory_value', + 'adjust_inventory', 'create_purchase_order', + // Cotizaciones + 'get_quotes_summary', 'approve_quote', + // Configuración + 'manage_users', 'view_audit_logs', 'update_settings', + 'get_branch_info', 'manage_branches', + // Reportes + 'generate_report', 'export_data', + // TPV (para mostrador) + 'configure_terminal', 'get_payment_history', 'process_refund', + // Hornos + 'get_furnace_status', 'get_furnace_schedule', ], systemPromptFile: 'admin-system-prompt', maxConversationHistory: 50, - rateLimit: { - requestsPerMinute: 100, - tokensPerMinute: 50000, - }, + rateLimit: { requestsPerMinute: 100, tokensPerMinute: 50000 }, }, - SUPERVISOR: { - name: 'Supervisor', - description: 'Gestión de equipos, reportes de sucursal y aprobaciones', + SUPERVISOR_PRODUCCION: { + name: 'Supervisor de Producción', + description: 'Supervisor con gestión de órdenes de producción y calidad', tools: [ - // Ventas (lectura + acciones limitadas) - 'get_sales_summary', - 'get_sales_report', - 'get_top_products', - 'get_sales_by_branch', - 'create_sale', - - // Inventario (lectura + ajustes) - 'get_inventory_status', - 'get_low_stock_products', - 'adjust_inventory', - + // Producción + 'get_production_queue', 'create_production_order', 'update_order_status', + 'assign_operator', 'get_pending_orders', 'prioritize_orders', + // Calidad + 'register_quality_inspection', 'get_defect_reports', 'approve_batch', // Equipo - 'get_team_performance', - 'get_employee_schedule', - 'manage_schedules', - - // Aprobaciones - 'approve_discounts', - 'approve_voids', - 'approve_refunds', - - // Sucursal - 'get_branch_info', - 'get_branch_report', - - // Clientes - 'get_customer_info', - 'get_customer_balance', + 'get_team_performance', 'get_operator_schedule', 'manage_schedules', + // Hornos + 'get_furnace_status', 'schedule_furnace', 'get_furnace_logs', + // Inventario + 'get_inventory_status', 'get_low_stock_products', 'request_materials', + // Sucursal/Planta + 'get_branch_info', 'get_branch_report', + // Despacho + 'get_pending_dispatches', 'approve_dispatch', ], systemPromptFile: 'supervisor-system-prompt', maxConversationHistory: 30, - rateLimit: { - requestsPerMinute: 60, - tokensPerMinute: 30000, - }, + rateLimit: { requestsPerMinute: 60, tokensPerMinute: 30000 }, }, - OPERATOR: { - name: 'Operador', - description: 'Operaciones de punto de venta y consultas básicas', + OPERADOR_CORTE: { + name: 'Operador de Corte', + description: 'Operador de área de corte con acceso a sus órdenes', tools: [ - // Productos - 'search_products', - 'get_product_price', - 'check_product_availability', - - // Ventas - 'create_sale', - 'get_my_sales', - 'apply_discount', // Con límite - - // Clientes - 'search_customers', - 'get_customer_balance', - 'register_payment', - - // Inventario (solo lectura) - 'check_stock', - + // Mis órdenes de corte + 'get_my_cutting_orders', 'start_cutting_order', 'complete_cutting_order', + 'register_cutting_result', 'report_defect', + // Optimización de corte + 'get_cutting_pattern', 'view_nesting_layout', + // Inventario (láminas) + 'check_glass_stock', 'request_glass_sheet', 'register_scrap', // Información - 'get_branch_hours', - 'get_promotions', + 'get_branch_hours', 'get_my_schedule', + // Registro + 'upload_photos', 'add_work_note', ], systemPromptFile: 'operator-system-prompt', maxConversationHistory: 20, - rateLimit: { - requestsPerMinute: 30, - tokensPerMinute: 15000, - }, + rateLimit: { requestsPerMinute: 30, tokensPerMinute: 15000 }, }, - CUSTOMER: { - name: 'Cliente', - description: 'Acceso limitado para clientes externos', + OPERADOR_HORNO: { + name: 'Operador de Horno', + description: 'Operador de hornos de templado con control de proceso', tools: [ - // Catálogo - 'view_catalog', - 'search_products', - 'check_availability', - - // Pedidos - 'get_my_orders', - 'track_order', - - // Cuenta - 'get_my_balance', - 'get_my_history', - - // Soporte - 'contact_support', - 'get_store_info', - 'get_promotions', + // Mis órdenes de templado + 'get_my_tempering_orders', 'start_tempering_batch', 'complete_tempering_batch', + 'register_tempering_params', 'report_defect', + // Control de horno + 'get_furnace_status', 'set_furnace_params', 'get_furnace_logs', + 'check_furnace_temperature', 'register_furnace_reading', + // Calidad + 'register_quality_check', 'mark_batch_passed', 'mark_batch_failed', + // Información + 'get_branch_hours', 'get_my_schedule', + // Registro + 'upload_photos', 'add_work_note', ], - systemPromptFile: 'customer-system-prompt', - maxConversationHistory: 10, - rateLimit: { - requestsPerMinute: 10, - tokensPerMinute: 5000, - }, + systemPromptFile: 'operator-system-prompt', + maxConversationHistory: 20, + rateLimit: { requestsPerMinute: 30, tokensPerMinute: 15000 }, }, }; -/** - * Mapeo de rol de base de datos a ERPRole - */ export const DB_ROLE_MAPPING: Record = { - // Roles típicos de sistema - admin: 'ADMIN', - administrator: 'ADMIN', - superadmin: 'ADMIN', - owner: 'ADMIN', - + // Administradores + admin: 'ADMIN', administrator: 'ADMIN', gerente: 'ADMIN', owner: 'ADMIN', + plant_manager: 'ADMIN', // Supervisores - supervisor: 'SUPERVISOR', - manager: 'SUPERVISOR', - branch_manager: 'SUPERVISOR', - store_manager: 'SUPERVISOR', - - // Operadores - operator: 'OPERATOR', - cashier: 'OPERATOR', - sales: 'OPERATOR', - employee: 'OPERATOR', - staff: 'OPERATOR', - - // Clientes - customer: 'CUSTOMER', - client: 'CUSTOMER', - guest: 'CUSTOMER', + supervisor: 'SUPERVISOR_PRODUCCION', supervisor_produccion: 'SUPERVISOR_PRODUCCION', + production_manager: 'SUPERVISOR_PRODUCCION', manager: 'SUPERVISOR_PRODUCCION', + jefe_produccion: 'SUPERVISOR_PRODUCCION', + // Operadores de corte + operador_corte: 'OPERADOR_CORTE', cortador: 'OPERADOR_CORTE', + cutter: 'OPERADOR_CORTE', cutting_operator: 'OPERADOR_CORTE', + // Operadores de horno + operador_horno: 'OPERADOR_HORNO', hornero: 'OPERADOR_HORNO', + furnace_operator: 'OPERADOR_HORNO', tempering_operator: 'OPERADOR_HORNO', + // Default para operadores genéricos + operator: 'OPERADOR_CORTE', employee: 'OPERADOR_CORTE', }; -/** - * Obtener rol ERP desde rol de base de datos - */ export function getERPRole(dbRole: string | undefined): ERPRole { - if (!dbRole) return 'CUSTOMER'; // Default para roles no mapeados + if (!dbRole) return 'OPERADOR_CORTE'; const normalized = dbRole.toLowerCase().trim(); - return DB_ROLE_MAPPING[normalized] || 'CUSTOMER'; + return DB_ROLE_MAPPING[normalized] || 'OPERADOR_CORTE'; } -/** - * Verificar si un rol tiene acceso a un tool - */ export function hasToolAccess(role: ERPRole, toolName: string): boolean { const roleConfig = ERP_ROLES[role]; if (!roleConfig) return false; return roleConfig.tools.includes(toolName); } -/** - * Obtener todos los tools para un rol - */ export function getToolsForRole(role: ERPRole): string[] { const roleConfig = ERP_ROLES[role]; return roleConfig?.tools || []; } -/** - * Obtener configuración completa de un rol - */ export function getRoleConfig(role: ERPRole): ERPRoleConfig | null { return ERP_ROLES[role] || null; }