[PROP-CORE-004] feat: Adapt AI roles for tempered glass domain

- Roles: ADMIN, SUPERVISOR_PRODUCCION, OPERADOR_CORTE, OPERADOR_HORNO
- Domain-specific tools (furnace, cutting, tempering)
- Glass manufacturing terminology

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Adrian Flores Cortes 2026-01-25 02:57:54 -06:00
parent bc5a389edb
commit db06c9effd

View File

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