- Roles: ADMIN, SUPERVISOR_OBRA, RESIDENTE, ALMACENISTA - Domain-specific tools (projects, progress, materials) - Construction industry terminology Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
159 lines
5.3 KiB
TypeScript
159 lines
5.3 KiB
TypeScript
/**
|
|
* ERP Construcción - Roles Configuration
|
|
*
|
|
* Roles específicos para operaciones de construcción y obras.
|
|
* Adaptado desde erp-core v1.5.0 (PROP-CORE-004)
|
|
*
|
|
* Roles:
|
|
* - ADMIN: Gerente General - acceso completo
|
|
* - SUPERVISOR_OBRA: Supervisor de obra - gestión de proyectos
|
|
* - RESIDENTE: Residente de obra - operaciones en sitio
|
|
* - ALMACENISTA: Control de almacén y materiales
|
|
*/
|
|
|
|
export type ERPRole = 'ADMIN' | 'SUPERVISOR_OBRA' | 'RESIDENTE' | 'ALMACENISTA';
|
|
|
|
export interface ERPRoleConfig {
|
|
name: string;
|
|
description: string;
|
|
tools: string[];
|
|
systemPromptFile: string;
|
|
maxConversationHistory: number;
|
|
allowedModels?: string[];
|
|
rateLimit: {
|
|
requestsPerMinute: number;
|
|
tokensPerMinute: number;
|
|
};
|
|
}
|
|
|
|
export const ERP_ROLES: Record<ERPRole, ERPRoleConfig> = {
|
|
ADMIN: {
|
|
name: 'Gerente General',
|
|
description: 'Gerente con acceso completo a todas las obras y operaciones',
|
|
tools: [
|
|
// Proyectos/Obras
|
|
'get_projects_summary', 'get_project_status', 'get_project_budget',
|
|
'approve_budget_change', 'get_all_projects',
|
|
// Finanzas
|
|
'get_financial_report', 'get_accounts_receivable', 'get_accounts_payable',
|
|
'get_cash_flow', 'get_kpis',
|
|
// Compras
|
|
'get_pending_orders', 'get_supplier_info', 'create_purchase_order', 'approve_purchase',
|
|
// Inventario
|
|
'get_inventory_status', 'get_inventory_value', 'transfer_inventory',
|
|
// Configuración
|
|
'manage_users', 'view_audit_logs', 'update_settings',
|
|
'get_branch_info', 'manage_branches',
|
|
// Reportes
|
|
'generate_report', 'export_data',
|
|
// TPV
|
|
'configure_terminal', 'get_payment_history', 'process_refund',
|
|
// Presupuestos
|
|
'get_estimates', 'approve_estimate',
|
|
],
|
|
systemPromptFile: 'admin-system-prompt',
|
|
maxConversationHistory: 50,
|
|
rateLimit: { requestsPerMinute: 100, tokensPerMinute: 50000 },
|
|
},
|
|
|
|
SUPERVISOR_OBRA: {
|
|
name: 'Supervisor de Obra',
|
|
description: 'Supervisor con gestión de proyectos asignados y equipo',
|
|
tools: [
|
|
// Proyectos
|
|
'get_my_projects', 'get_project_status', 'update_project_progress',
|
|
'get_project_budget', 'request_budget_change',
|
|
// Equipo
|
|
'get_team_performance', 'get_worker_schedule', 'manage_schedules',
|
|
// Compras (solicitud)
|
|
'create_purchase_request', 'get_pending_requests',
|
|
// Inventario
|
|
'get_inventory_status', 'request_materials', 'get_low_stock_products',
|
|
// Sucursal/Obra
|
|
'get_branch_info', 'get_branch_report',
|
|
// Avances
|
|
'register_progress', 'upload_evidence', 'get_progress_report',
|
|
],
|
|
systemPromptFile: 'supervisor-system-prompt',
|
|
maxConversationHistory: 30,
|
|
rateLimit: { requestsPerMinute: 60, tokensPerMinute: 30000 },
|
|
},
|
|
|
|
RESIDENTE: {
|
|
name: 'Residente de Obra',
|
|
description: 'Residente con operaciones en sitio y registro de avances',
|
|
tools: [
|
|
// Avances
|
|
'register_daily_progress', 'upload_photos', 'register_incidents',
|
|
// Materiales
|
|
'request_materials', 'confirm_material_receipt', 'check_stock',
|
|
// Personal
|
|
'register_attendance', 'get_daily_crew',
|
|
// Información
|
|
'get_project_info', 'get_branch_hours', 'get_my_tasks',
|
|
// Comunicación
|
|
'report_issue', 'request_support',
|
|
],
|
|
systemPromptFile: 'operator-system-prompt',
|
|
maxConversationHistory: 20,
|
|
rateLimit: { requestsPerMinute: 30, tokensPerMinute: 15000 },
|
|
},
|
|
|
|
ALMACENISTA: {
|
|
name: 'Almacenista',
|
|
description: 'Control de almacén, recepción y despacho de materiales',
|
|
tools: [
|
|
// Inventario
|
|
'get_inventory_status', 'check_stock', 'adjust_inventory',
|
|
'register_material_entry', 'register_material_exit',
|
|
// Recepción
|
|
'confirm_purchase_receipt', 'register_quality_inspection',
|
|
// Despacho
|
|
'prepare_dispatch', 'confirm_dispatch',
|
|
// Proveedores
|
|
'get_pending_deliveries', 'get_supplier_info',
|
|
// Alertas
|
|
'get_low_stock_products', 'get_expiring_materials',
|
|
],
|
|
systemPromptFile: 'operator-system-prompt',
|
|
maxConversationHistory: 20,
|
|
rateLimit: { requestsPerMinute: 30, tokensPerMinute: 15000 },
|
|
},
|
|
};
|
|
|
|
export const DB_ROLE_MAPPING: Record<string, ERPRole> = {
|
|
// Administradores
|
|
admin: 'ADMIN', administrator: 'ADMIN', gerente: 'ADMIN', owner: 'ADMIN',
|
|
director: 'ADMIN',
|
|
// Supervisores
|
|
supervisor: 'SUPERVISOR_OBRA', supervisor_obra: 'SUPERVISOR_OBRA',
|
|
project_manager: 'SUPERVISOR_OBRA', manager: 'SUPERVISOR_OBRA',
|
|
// Residentes
|
|
residente: 'RESIDENTE', resident: 'RESIDENTE', operator: 'RESIDENTE',
|
|
ingeniero: 'RESIDENTE', field_engineer: 'RESIDENTE',
|
|
// Almacenistas
|
|
almacenista: 'ALMACENISTA', warehouse: 'ALMACENISTA', bodeguero: 'ALMACENISTA',
|
|
storekeeper: 'ALMACENISTA',
|
|
};
|
|
|
|
export function getERPRole(dbRole: string | undefined): ERPRole {
|
|
if (!dbRole) return 'RESIDENTE';
|
|
const normalized = dbRole.toLowerCase().trim();
|
|
return DB_ROLE_MAPPING[normalized] || 'RESIDENTE';
|
|
}
|
|
|
|
export function hasToolAccess(role: ERPRole, toolName: string): boolean {
|
|
const roleConfig = ERP_ROLES[role];
|
|
if (!roleConfig) return false;
|
|
return roleConfig.tools.includes(toolName);
|
|
}
|
|
|
|
export function getToolsForRole(role: ERPRole): string[] {
|
|
const roleConfig = ERP_ROLES[role];
|
|
return roleConfig?.tools || [];
|
|
}
|
|
|
|
export function getRoleConfig(role: ERPRole): ERPRoleConfig | null {
|
|
return ERP_ROLES[role] || null;
|
|
}
|