UNPKG

@coretext-ai/qa-gusto-c0d1e2f3-a4b5-4678-b901-012345678901

Version:
969 lines 41.1 kB
import { Logger } from '../services/logger.js'; export class GustoTools { constructor(client) { this.initialized = false; this.client = client; // Get logger from client if available, otherwise create fallback this.logger = client.logger || new Logger({ logLevel: 'ERROR', component: 'tools', enableConsole: true, enableShipping: false, serverName: '' }); } async ensureInitialized() { if (!this.initialized) { // Log tools initialization now that client is ready this.logger.info('TOOLS_INIT', 'Tools instance initialization started', { integration: 'gusto', isOAuth: false }); this.logger.info('CLIENT_INITIALIZATION', 'Starting client initialization', { isOAuth: false }); this.initialized = true; this.logger.info('CLIENT_INITIALIZATION', 'Client initialization completed', { initialized: this.initialized }); } } getToolDefinitions() { return [ { name: 'gusto_create_company', description: 'Create a new partner-managed company for embedded payroll', inputSchema: { type: 'object', properties: { name: { type: 'string', description: 'Company name' }, trade_name: { type: 'string', description: 'Trade name if different from legal name' }, ein: { type: 'string', description: 'Employer Identification Number (EIN)' }, entity_type: { type: 'string', description: 'Business entity type (LLC, Corporation, Partnership, etc.)' }, company_uuid: { type: 'string', description: 'Optional UUID for the company' }, }, required: ['name',] } }, { name: 'gusto_get_company', description: 'Get company details by UUID', inputSchema: { type: 'object', properties: { company_uuid: { type: 'string', description: 'Company UUID' }, }, required: ['company_uuid'] } }, { name: 'gusto_update_company', description: 'Update company information', inputSchema: { type: 'object', properties: { company_uuid: { type: 'string', description: 'Company UUID' }, name: { type: 'string', description: 'Company name' }, trade_name: { type: 'string', description: 'Trade name' }, ein: { type: 'string', description: 'Employer Identification Number' }, }, required: ['company_uuid',] } }, { name: 'gusto_create_location', description: 'Create a new company location', inputSchema: { type: 'object', properties: { company_uuid: { type: 'string', description: 'Company UUID' }, street_1: { type: 'string', description: 'Street address line 1' }, street_2: { type: 'string', description: 'Street address line 2' }, city: { type: 'string', description: 'City name' }, state: { type: 'string', description: 'State abbreviation' }, zip: { type: 'string', description: 'ZIP code' }, country: { type: 'string', description: 'Country (defaults to USA)' }, }, required: ['company_uuid', 'street_1', 'city', 'state', 'zip',] } }, { name: 'gusto_list_locations', description: 'List all locations for a company', inputSchema: { type: 'object', properties: { company_uuid: { type: 'string', description: 'Company UUID' }, }, required: ['company_uuid'] } }, { name: 'gusto_create_employee', description: 'Create a new employee in the company', inputSchema: { type: 'object', properties: { company_uuid: { type: 'string', description: 'Company UUID' }, first_name: { type: 'string', description: 'Employee first name' }, last_name: { type: 'string', description: 'Employee last name' }, email: { type: 'string', description: 'Employee email address' }, date_of_birth: { type: 'string', description: 'Date of birth (YYYY-MM-DD)' }, ssn: { type: 'string', description: 'Social Security Number' }, work_location_uuid: { type: 'string', description: 'UUID of the work location' }, home_address: { type: 'object', description: 'Employee home address object' }, phone: { type: 'string', description: 'Employee phone number' }, }, required: ['company_uuid', 'first_name', 'last_name', 'email', 'work_location_uuid',] } }, { name: 'gusto_get_employee', description: 'Get employee details by UUID', inputSchema: { type: 'object', properties: { employee_uuid: { type: 'string', description: 'Employee UUID' }, }, required: ['employee_uuid'] } }, { name: 'gusto_update_employee', description: 'Update employee information', inputSchema: { type: 'object', properties: { employee_uuid: { type: 'string', description: 'Employee UUID' }, first_name: { type: 'string', description: 'Employee first name' }, last_name: { type: 'string', description: 'Employee last name' }, email: { type: 'string', description: 'Employee email address' }, phone: { type: 'string', description: 'Employee phone number' }, home_address: { type: 'object', description: 'Employee home address object' }, }, required: ['employee_uuid',] } }, { name: 'gusto_list_employees', description: 'List all employees for a company', inputSchema: { type: 'object', properties: { company_uuid: { type: 'string', description: 'Company UUID' }, page: { type: 'number', description: 'Page number for pagination' }, per: { type: 'number', description: 'Number of employees per page' }, }, required: ['company_uuid',] } }, { name: 'gusto_create_job', description: 'Create a job for an employee', inputSchema: { type: 'object', properties: { employee_uuid: { type: 'string', description: 'Employee UUID' }, title: { type: 'string', description: 'Job title' }, hire_date: { type: 'string', description: 'Hire date (YYYY-MM-DD)' }, location_uuid: { type: 'string', description: 'Work location UUID' }, rate: { type: 'string', description: 'Pay rate amount' }, payment_unit: { type: 'string', description: 'Payment unit (Hour, Week, Month, Year)' }, flsa_status: { type: 'string', description: 'FLSA status (Exempt, Nonexempt)' }, }, required: ['employee_uuid', 'title', 'hire_date', 'location_uuid', 'rate', 'payment_unit',] } }, { name: 'gusto_get_job', description: 'Get job details by UUID', inputSchema: { type: 'object', properties: { job_uuid: { type: 'string', description: 'Job UUID' }, }, required: ['job_uuid'] } }, { name: 'gusto_update_job', description: 'Update job information', inputSchema: { type: 'object', properties: { job_uuid: { type: 'string', description: 'Job UUID' }, title: { type: 'string', description: 'Job title' }, rate: { type: 'string', description: 'Pay rate amount' }, payment_unit: { type: 'string', description: 'Payment unit (Hour, Week, Month, Year)' }, flsa_status: { type: 'string', description: 'FLSA status (Exempt, Nonexempt)' }, }, required: ['job_uuid',] } }, { name: 'gusto_list_payrolls', description: 'List payrolls for a company', inputSchema: { type: 'object', properties: { company_uuid: { type: 'string', description: 'Company UUID' }, start_date: { type: 'string', description: 'Start date filter (YYYY-MM-DD)' }, end_date: { type: 'string', description: 'End date filter (YYYY-MM-DD)' }, processed: { type: 'boolean', description: 'Filter by processed status' }, }, required: ['company_uuid',] } }, { name: 'gusto_get_payroll', description: 'Get payroll details by UUID', inputSchema: { type: 'object', properties: { payroll_uuid: { type: 'string', description: 'Payroll UUID' }, }, required: ['payroll_uuid'] } }, { name: 'gusto_create_payroll', description: 'Create a new payroll for a company', inputSchema: { type: 'object', properties: { company_uuid: { type: 'string', description: 'Company UUID' }, start_date: { type: 'string', description: 'Payroll start date (YYYY-MM-DD)' }, end_date: { type: 'string', description: 'Payroll end date (YYYY-MM-DD)' }, check_date: { type: 'string', description: 'Check date (YYYY-MM-DD)' }, }, required: ['company_uuid', 'start_date', 'end_date', 'check_date'] } }, { name: 'gusto_submit_payroll', description: 'Submit payroll for processing', inputSchema: { type: 'object', properties: { payroll_uuid: { type: 'string', description: 'Payroll UUID' }, }, required: ['payroll_uuid'] } }, { name: 'gusto_list_pay_schedules', description: 'List pay schedules for a company', inputSchema: { type: 'object', properties: { company_uuid: { type: 'string', description: 'Company UUID' }, }, required: ['company_uuid'] } }, { name: 'gusto_create_pay_schedule', description: 'Create a new pay schedule for a company', inputSchema: { type: 'object', properties: { company_uuid: { type: 'string', description: 'Company UUID' }, frequency: { type: 'string', description: 'Pay frequency (Weekly, Biweekly, Semimonthly, Monthly)' }, anchor_pay_date: { type: 'string', description: 'Anchor pay date (YYYY-MM-DD)' }, anchor_end_of_pay_period: { type: 'string', description: 'Anchor end of pay period (YYYY-MM-DD)' }, }, required: ['company_uuid', 'frequency', 'anchor_pay_date', 'anchor_end_of_pay_period'] } }, { name: 'gusto_list_contractors', description: 'List contractors for a company', inputSchema: { type: 'object', properties: { company_uuid: { type: 'string', description: 'Company UUID' }, }, required: ['company_uuid'] } }, { name: 'gusto_create_contractor', description: 'Create a new contractor for a company', inputSchema: { type: 'object', properties: { company_uuid: { type: 'string', description: 'Company UUID' }, first_name: { type: 'string', description: 'Contractor first name' }, last_name: { type: 'string', description: 'Contractor last name' }, email: { type: 'string', description: 'Contractor email address' }, business_name: { type: 'string', description: 'Contractor business name' }, ein: { type: 'string', description: 'Contractor EIN' }, ssn: { type: 'string', description: 'Contractor SSN' }, start_date: { type: 'string', description: 'Contractor start date (YYYY-MM-DD)' }, }, required: ['company_uuid', 'first_name', 'last_name', 'email', 'start_date'] } }, { name: 'gusto_get_contractor', description: 'Get contractor details by UUID', inputSchema: { type: 'object', properties: { contractor_uuid: { type: 'string', description: 'Contractor UUID' }, }, required: ['contractor_uuid'] } }, { name: 'gusto_create_contractor_payment', description: 'Create a payment for a contractor', inputSchema: { type: 'object', properties: { company_uuid: { type: 'string', description: 'Company UUID' }, contractor_uuid: { type: 'string', description: 'Contractor UUID' }, wage: { type: 'string', description: 'Payment amount' }, start_date: { type: 'string', description: 'Payment start date (YYYY-MM-DD)' }, end_date: { type: 'string', description: 'Payment end date (YYYY-MM-DD)' }, payment_date: { type: 'string', description: 'Payment date (YYYY-MM-DD)' }, }, required: ['company_uuid', 'contractor_uuid', 'wage', 'start_date', 'end_date', 'payment_date'] } }, { name: 'gusto_get_contractor_payment', description: 'Get contractor payment details', inputSchema: { type: 'object', properties: { company_uuid: { type: 'string', description: 'Company UUID' }, contractor_payment_uuid: { type: 'string', description: 'Contractor payment UUID' }, }, required: ['company_uuid', 'contractor_payment_uuid'] } }, { name: 'gusto_list_company_benefits', description: 'List benefits offered by a company', inputSchema: { type: 'object', properties: { company_uuid: { type: 'string', description: 'Company UUID' }, }, required: ['company_uuid'] } }, { name: 'gusto_get_company_benefit', description: 'Get company benefit details', inputSchema: { type: 'object', properties: { company_benefit_uuid: { type: 'string', description: 'Company benefit UUID' }, }, required: ['company_benefit_uuid'] } }, { name: 'gusto_get_company_benefit_summary', description: 'Get summary of company benefit including enrollment stats', inputSchema: { type: 'object', properties: { company_benefit_uuid: { type: 'string', description: 'Company benefit UUID' }, }, required: ['company_benefit_uuid'] } }, { name: 'gusto_create_time_off_policy', description: 'Create a time off policy for a company', inputSchema: { type: 'object', properties: { company_uuid: { type: 'string', description: 'Company UUID' }, name: { type: 'string', description: 'Time off policy name' }, policy_type: { type: 'string', description: 'Policy type (vacation, sick, personal, etc.)' }, accrual_unit: { type: 'string', description: 'Accrual unit (hour, day)' }, accrual_rate: { type: 'string', description: 'Accrual rate per period' }, accrual_period: { type: 'string', description: 'Accrual period (year, pay_period)' }, }, required: ['company_uuid', 'name', 'policy_type',] } }, { name: 'gusto_list_time_off_policies', description: 'List time off policies for a company', inputSchema: { type: 'object', properties: { company_uuid: { type: 'string', description: 'Company UUID' }, }, required: ['company_uuid'] } }, { name: 'gusto_get_current_user', description: 'Get current authenticated user information', inputSchema: { type: 'object', properties: {}, required: [] } } ]; } canHandle(toolName) { const supportedTools = [ 'gusto_create_company', 'gusto_get_company', 'gusto_update_company', 'gusto_create_location', 'gusto_list_locations', 'gusto_create_employee', 'gusto_get_employee', 'gusto_update_employee', 'gusto_list_employees', 'gusto_create_job', 'gusto_get_job', 'gusto_update_job', 'gusto_list_payrolls', 'gusto_get_payroll', 'gusto_create_payroll', 'gusto_submit_payroll', 'gusto_list_pay_schedules', 'gusto_create_pay_schedule', 'gusto_list_contractors', 'gusto_create_contractor', 'gusto_get_contractor', 'gusto_create_contractor_payment', 'gusto_get_contractor_payment', 'gusto_list_company_benefits', 'gusto_get_company_benefit', 'gusto_get_company_benefit_summary', 'gusto_create_time_off_policy', 'gusto_list_time_off_policies', 'gusto_get_current_user' ]; return supportedTools.includes(toolName); } async executeTool(name, args) { const startTime = Date.now(); this.logger.logToolStart(name, args); await this.ensureInitialized(); // Validate tool is supported if (!this.canHandle(name)) { this.logger.error('TOOL_ERROR', 'Unknown tool requested', { tool: name, supportedTools: ['gusto_create_company', 'gusto_get_company', 'gusto_update_company', 'gusto_create_location', 'gusto_list_locations', 'gusto_create_employee', 'gusto_get_employee', 'gusto_update_employee', 'gusto_list_employees', 'gusto_create_job', 'gusto_get_job', 'gusto_update_job', 'gusto_list_payrolls', 'gusto_get_payroll', 'gusto_create_payroll', 'gusto_submit_payroll', 'gusto_list_pay_schedules', 'gusto_create_pay_schedule', 'gusto_list_contractors', 'gusto_create_contractor', 'gusto_get_contractor', 'gusto_create_contractor_payment', 'gusto_get_contractor_payment', 'gusto_list_company_benefits', 'gusto_get_company_benefit', 'gusto_get_company_benefit_summary', 'gusto_create_time_off_policy', 'gusto_list_time_off_policies', 'gusto_get_current_user'] }); throw new Error(`Unknown tool: ${name}`); } // Validate required parameters this.logger.debug('PARAM_VALIDATION', 'Validating tool parameters', { tool: name, providedArgs: Object.keys(args || {}) }); try { let result; switch (name) { case 'gusto_create_company': this.logger.debug('TOOL_EXECUTE', 'Calling client method', { tool: 'gusto_create_company', clientMethod: 'createCompany' }); result = await this.client.createCompany(args); break; case 'gusto_get_company': this.logger.debug('TOOL_EXECUTE', 'Calling client method', { tool: 'gusto_get_company', clientMethod: 'getCompany' }); result = await this.client.getCompany(args); break; case 'gusto_update_company': this.logger.debug('TOOL_EXECUTE', 'Calling client method', { tool: 'gusto_update_company', clientMethod: 'updateCompany' }); result = await this.client.updateCompany(args); break; case 'gusto_create_location': this.logger.debug('TOOL_EXECUTE', 'Calling client method', { tool: 'gusto_create_location', clientMethod: 'createLocation' }); result = await this.client.createLocation(args); break; case 'gusto_list_locations': this.logger.debug('TOOL_EXECUTE', 'Calling client method', { tool: 'gusto_list_locations', clientMethod: 'listLocations' }); result = await this.client.listLocations(args); break; case 'gusto_create_employee': this.logger.debug('TOOL_EXECUTE', 'Calling client method', { tool: 'gusto_create_employee', clientMethod: 'createEmployee' }); result = await this.client.createEmployee(args); break; case 'gusto_get_employee': this.logger.debug('TOOL_EXECUTE', 'Calling client method', { tool: 'gusto_get_employee', clientMethod: 'getEmployee' }); result = await this.client.getEmployee(args); break; case 'gusto_update_employee': this.logger.debug('TOOL_EXECUTE', 'Calling client method', { tool: 'gusto_update_employee', clientMethod: 'updateEmployee' }); result = await this.client.updateEmployee(args); break; case 'gusto_list_employees': this.logger.debug('TOOL_EXECUTE', 'Calling client method', { tool: 'gusto_list_employees', clientMethod: 'listEmployees' }); result = await this.client.listEmployees(args); break; case 'gusto_create_job': this.logger.debug('TOOL_EXECUTE', 'Calling client method', { tool: 'gusto_create_job', clientMethod: 'createJob' }); result = await this.client.createJob(args); break; case 'gusto_get_job': this.logger.debug('TOOL_EXECUTE', 'Calling client method', { tool: 'gusto_get_job', clientMethod: 'getJob' }); result = await this.client.getJob(args); break; case 'gusto_update_job': this.logger.debug('TOOL_EXECUTE', 'Calling client method', { tool: 'gusto_update_job', clientMethod: 'updateJob' }); result = await this.client.updateJob(args); break; case 'gusto_list_payrolls': this.logger.debug('TOOL_EXECUTE', 'Calling client method', { tool: 'gusto_list_payrolls', clientMethod: 'listPayrolls' }); result = await this.client.listPayrolls(args); break; case 'gusto_get_payroll': this.logger.debug('TOOL_EXECUTE', 'Calling client method', { tool: 'gusto_get_payroll', clientMethod: 'getPayroll' }); result = await this.client.getPayroll(args); break; case 'gusto_create_payroll': this.logger.debug('TOOL_EXECUTE', 'Calling client method', { tool: 'gusto_create_payroll', clientMethod: 'createPayroll' }); result = await this.client.createPayroll(args); break; case 'gusto_submit_payroll': this.logger.debug('TOOL_EXECUTE', 'Calling client method', { tool: 'gusto_submit_payroll', clientMethod: 'submitPayroll' }); result = await this.client.submitPayroll(args); break; case 'gusto_list_pay_schedules': this.logger.debug('TOOL_EXECUTE', 'Calling client method', { tool: 'gusto_list_pay_schedules', clientMethod: 'listPaySchedules' }); result = await this.client.listPaySchedules(args); break; case 'gusto_create_pay_schedule': this.logger.debug('TOOL_EXECUTE', 'Calling client method', { tool: 'gusto_create_pay_schedule', clientMethod: 'createPaySchedule' }); result = await this.client.createPaySchedule(args); break; case 'gusto_list_contractors': this.logger.debug('TOOL_EXECUTE', 'Calling client method', { tool: 'gusto_list_contractors', clientMethod: 'listContractors' }); result = await this.client.listContractors(args); break; case 'gusto_create_contractor': this.logger.debug('TOOL_EXECUTE', 'Calling client method', { tool: 'gusto_create_contractor', clientMethod: 'createContractor' }); result = await this.client.createContractor(args); break; case 'gusto_get_contractor': this.logger.debug('TOOL_EXECUTE', 'Calling client method', { tool: 'gusto_get_contractor', clientMethod: 'getContractor' }); result = await this.client.getContractor(args); break; case 'gusto_create_contractor_payment': this.logger.debug('TOOL_EXECUTE', 'Calling client method', { tool: 'gusto_create_contractor_payment', clientMethod: 'createContractorPayment' }); result = await this.client.createContractorPayment(args); break; case 'gusto_get_contractor_payment': this.logger.debug('TOOL_EXECUTE', 'Calling client method', { tool: 'gusto_get_contractor_payment', clientMethod: 'getContractorPayment' }); result = await this.client.getContractorPayment(args); break; case 'gusto_list_company_benefits': this.logger.debug('TOOL_EXECUTE', 'Calling client method', { tool: 'gusto_list_company_benefits', clientMethod: 'listCompanyBenefits' }); result = await this.client.listCompanyBenefits(args); break; case 'gusto_get_company_benefit': this.logger.debug('TOOL_EXECUTE', 'Calling client method', { tool: 'gusto_get_company_benefit', clientMethod: 'getCompanyBenefit' }); result = await this.client.getCompanyBenefit(args); break; case 'gusto_get_company_benefit_summary': this.logger.debug('TOOL_EXECUTE', 'Calling client method', { tool: 'gusto_get_company_benefit_summary', clientMethod: 'getCompanyBenefitSummary' }); result = await this.client.getCompanyBenefitSummary(args); break; case 'gusto_create_time_off_policy': this.logger.debug('TOOL_EXECUTE', 'Calling client method', { tool: 'gusto_create_time_off_policy', clientMethod: 'createTimeOffPolicy' }); result = await this.client.createTimeOffPolicy(args); break; case 'gusto_list_time_off_policies': this.logger.debug('TOOL_EXECUTE', 'Calling client method', { tool: 'gusto_list_time_off_policies', clientMethod: 'listTimeOffPolicies' }); result = await this.client.listTimeOffPolicies(args); break; case 'gusto_get_current_user': this.logger.debug('TOOL_EXECUTE', 'Calling client method', { tool: 'gusto_get_current_user', clientMethod: 'getCurrentUser' }); result = await this.client.getCurrentUser(args); break; default: throw new Error(`Unknown tool: ${name}`); } const duration = Date.now() - startTime; this.logger.logToolSuccess(name, duration, result); // Return raw result for non-OAuth templates return result; } catch (error) { const duration = Date.now() - startTime; const errorMessage = error instanceof Error ? error.message : String(error); this.logger.logToolError(name, error, duration, args); throw error; } } } //# sourceMappingURL=gusto-tools.js.map