[PROP-CORE-004] feat: Adapt AI roles for diesel mechanics domain
- Roles: ADMIN, JEFE_TALLER, MECANICO, CLIENTE - Domain-specific tools (diagnostics, vehicles, OBD codes) - Automotive workshop terminology Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
5c7134cc03
commit
940095a170
@ -1,17 +1,17 @@
|
|||||||
/**
|
/**
|
||||||
* ERP Roles Configuration
|
* ERP Mecánicas Diesel - Roles Configuration
|
||||||
*
|
*
|
||||||
* Define roles, tools permitidos, y system prompts para cada rol en el ERP.
|
* Roles específicos para talleres mecánicos de motores diesel.
|
||||||
* 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: Dueño del taller - acceso completo
|
||||||
* - SUPERVISOR: Gestión de equipos y reportes de sucursal
|
* - JEFE_TALLER: Jefe de taller - órdenes, diagnósticos, inventario
|
||||||
* - OPERATOR: Operaciones de punto de venta
|
* - MECANICO: Mecánico - solo órdenes asignadas
|
||||||
* - CUSTOMER: Acceso limitado para clientes (si se expone chatbot)
|
* - CLIENTE: Cliente - estado de su vehículo
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export type ERPRole = 'ADMIN' | 'SUPERVISOR' | 'OPERATOR' | 'CUSTOMER';
|
export type ERPRole = 'ADMIN' | 'JEFE_TALLER' | 'MECANICO' | 'CLIENTE';
|
||||||
|
|
||||||
export interface ERPRoleConfig {
|
export interface ERPRoleConfig {
|
||||||
name: string;
|
name: string;
|
||||||
@ -19,234 +19,143 @@ 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: 'Dueño del Taller',
|
||||||
description: 'Acceso completo a todas las operaciones del sistema ERP',
|
description: 'Propietario con acceso completo a todas las operaciones',
|
||||||
tools: [
|
tools: [
|
||||||
// Ventas
|
// Órdenes de servicio
|
||||||
'get_sales_summary',
|
'get_orders_summary', 'get_all_orders', 'void_order', 'get_order_history',
|
||||||
'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',
|
|
||||||
|
|
||||||
// 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 (refacciones)
|
||||||
'get_cash_flow',
|
'get_inventory_status', 'get_low_stock_products', 'get_inventory_value',
|
||||||
|
'adjust_inventory', 'create_purchase_order',
|
||||||
// Usuarios y configuración
|
// Proveedores
|
||||||
'manage_users',
|
'get_supplier_info', 'approve_purchase',
|
||||||
'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
|
||||||
'generate_report',
|
'configure_terminal', 'get_payment_history', 'process_refund',
|
||||||
'export_data',
|
// Vehículos
|
||||||
'get_kpis',
|
'get_vehicle_history', 'get_fleet_summary',
|
||||||
],
|
],
|
||||||
systemPromptFile: 'admin-system-prompt',
|
systemPromptFile: 'admin-system-prompt',
|
||||||
maxConversationHistory: 50,
|
maxConversationHistory: 50,
|
||||||
rateLimit: {
|
rateLimit: { requestsPerMinute: 100, tokensPerMinute: 50000 },
|
||||||
requestsPerMinute: 100,
|
|
||||||
tokensPerMinute: 50000,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
|
|
||||||
SUPERVISOR: {
|
JEFE_TALLER: {
|
||||||
name: 'Supervisor',
|
name: 'Jefe de Taller',
|
||||||
description: 'Gestión de equipos, reportes de sucursal y aprobaciones',
|
description: 'Jefe con gestión de órdenes, diagnósticos y equipo',
|
||||||
tools: [
|
tools: [
|
||||||
// Ventas (lectura + acciones limitadas)
|
// Órdenes
|
||||||
'get_sales_summary',
|
'get_orders_summary', 'create_order', 'update_order_status',
|
||||||
'get_sales_report',
|
'assign_mechanic', 'get_pending_orders',
|
||||||
'get_top_products',
|
// Diagnósticos
|
||||||
'get_sales_by_branch',
|
'diagnose_fault_code', 'get_diagnostic_history', 'add_diagnostic_note',
|
||||||
'create_sale',
|
|
||||||
|
|
||||||
// Inventario (lectura + ajustes)
|
|
||||||
'get_inventory_status',
|
|
||||||
'get_low_stock_products',
|
|
||||||
'adjust_inventory',
|
|
||||||
|
|
||||||
// Equipo
|
// Equipo
|
||||||
'get_team_performance',
|
'get_team_performance', 'get_mechanic_schedule', 'manage_schedules',
|
||||||
'get_employee_schedule',
|
|
||||||
'manage_schedules',
|
|
||||||
|
|
||||||
// Aprobaciones
|
// Aprobaciones
|
||||||
'approve_discounts',
|
'approve_discounts', 'approve_additional_work',
|
||||||
'approve_voids',
|
// Inventario
|
||||||
'approve_refunds',
|
'get_inventory_status', 'get_low_stock_products', 'request_parts',
|
||||||
|
'check_part_stock', 'search_parts',
|
||||||
|
// Cotizaciones
|
||||||
|
'create_quote', 'get_quote_history',
|
||||||
// Sucursal
|
// Sucursal
|
||||||
'get_branch_info',
|
'get_branch_info', 'get_branch_report',
|
||||||
'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: {
|
MECANICO: {
|
||||||
name: 'Operador',
|
name: 'Mecánico',
|
||||||
description: 'Operaciones de punto de venta y consultas básicas',
|
description: 'Mecánico con acceso a órdenes asignadas y diagnósticos',
|
||||||
tools: [
|
tools: [
|
||||||
// Productos
|
// Mis órdenes
|
||||||
'search_products',
|
'get_my_orders', 'update_order_progress', 'complete_order',
|
||||||
'get_product_price',
|
'add_work_note', 'upload_photos',
|
||||||
'check_product_availability',
|
// Diagnósticos
|
||||||
|
'diagnose_fault_code', 'add_diagnostic_note', 'get_obd_codes',
|
||||||
// Ventas
|
// Refacciones
|
||||||
'create_sale',
|
'check_part_stock', 'search_parts', 'request_parts_for_order',
|
||||||
'get_my_sales',
|
// Vehículo
|
||||||
'apply_discount', // Con límite
|
'get_vehicle_info', 'get_vehicle_history',
|
||||||
|
|
||||||
// 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',
|
|
||||||
],
|
],
|
||||||
systemPromptFile: 'operator-system-prompt',
|
systemPromptFile: 'operator-system-prompt',
|
||||||
maxConversationHistory: 20,
|
maxConversationHistory: 20,
|
||||||
rateLimit: {
|
rateLimit: { requestsPerMinute: 30, tokensPerMinute: 15000 },
|
||||||
requestsPerMinute: 30,
|
|
||||||
tokensPerMinute: 15000,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
|
|
||||||
CUSTOMER: {
|
CLIENTE: {
|
||||||
name: 'Cliente',
|
name: 'Cliente',
|
||||||
description: 'Acceso limitado para clientes externos',
|
description: 'Cliente con acceso al estado de su vehículo y órdenes',
|
||||||
tools: [
|
tools: [
|
||||||
// Catálogo
|
// Mi vehículo
|
||||||
'view_catalog',
|
'get_my_vehicles', 'get_vehicle_status', 'get_service_history',
|
||||||
'search_products',
|
// Mis órdenes
|
||||||
'check_availability',
|
'get_my_orders', 'track_order',
|
||||||
|
|
||||||
// Pedidos
|
|
||||||
'get_my_orders',
|
|
||||||
'track_order',
|
|
||||||
|
|
||||||
// Cuenta
|
// Cuenta
|
||||||
'get_my_balance',
|
'get_my_balance', 'get_my_invoices',
|
||||||
'get_my_history',
|
// Cotizaciones
|
||||||
|
'request_quote', 'get_my_quotes', 'approve_quote',
|
||||||
// Soporte
|
// Soporte
|
||||||
'contact_support',
|
'contact_support', 'get_workshop_info', 'get_workshop_hours',
|
||||||
'get_store_info',
|
// Recordatorios
|
||||||
'get_promotions',
|
'get_service_reminders', 'schedule_service',
|
||||||
],
|
],
|
||||||
systemPromptFile: 'customer-system-prompt',
|
systemPromptFile: 'customer-system-prompt',
|
||||||
maxConversationHistory: 10,
|
maxConversationHistory: 10,
|
||||||
rateLimit: {
|
rateLimit: { requestsPerMinute: 10, tokensPerMinute: 5000 },
|
||||||
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', owner: 'ADMIN', dueno: 'ADMIN',
|
||||||
administrator: 'ADMIN',
|
// Jefes de taller
|
||||||
superadmin: 'ADMIN',
|
jefe_taller: 'JEFE_TALLER', jefe: 'JEFE_TALLER', supervisor: 'JEFE_TALLER',
|
||||||
owner: 'ADMIN',
|
manager: 'JEFE_TALLER', encargado: 'JEFE_TALLER',
|
||||||
|
// Mecánicos
|
||||||
// Supervisores
|
mecanico: 'MECANICO', mechanic: 'MECANICO', operator: 'MECANICO',
|
||||||
supervisor: 'SUPERVISOR',
|
tecnico: 'MECANICO', technician: 'MECANICO', employee: 'MECANICO',
|
||||||
manager: 'SUPERVISOR',
|
|
||||||
branch_manager: 'SUPERVISOR',
|
|
||||||
store_manager: 'SUPERVISOR',
|
|
||||||
|
|
||||||
// Operadores
|
|
||||||
operator: 'OPERATOR',
|
|
||||||
cashier: 'OPERATOR',
|
|
||||||
sales: 'OPERATOR',
|
|
||||||
employee: 'OPERATOR',
|
|
||||||
staff: 'OPERATOR',
|
|
||||||
|
|
||||||
// Clientes
|
// Clientes
|
||||||
customer: 'CUSTOMER',
|
cliente: 'CLIENTE', customer: 'CLIENTE', client: 'CLIENTE', guest: 'CLIENTE',
|
||||||
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 'CLIENTE';
|
||||||
const normalized = dbRole.toLowerCase().trim();
|
const normalized = dbRole.toLowerCase().trim();
|
||||||
return DB_ROLE_MAPPING[normalized] || 'CUSTOMER';
|
return DB_ROLE_MAPPING[normalized] || 'CLIENTE';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 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;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user