General Utility Functions
Relevant source files
The following files were used as context for generating this wiki page:
General Utility Functions in the Recoup Admin project provide a standardized set of tools for data manipulation, API communication, and UI state presentation. These utilities ensure consistency across the dashboard when handling complex tasks such as calculating durations for background processes, formatting status indicators, and managing authenticated requests to the Recoup backend.
The utility layer is strategically divided into domain-specific modules, including task management helpers, API fetchers, and styling utilities. This modular approach allows the React components throughout the application to remain focused on presentation while offloading logic for data transformation and external service interaction.
Task and Run Utilities
These functions handle the visualization and parsing of task metadata, specifically for "runs" within the sandbox and account detail views.
Duration and Status Formatting
The system provides utilities to transform raw timestamp data into human-readable formats and visual indicators. The formatRunDuration function calculates the elapsed time between the start and completion of a task.
The logic accounts for active runs by defaulting to the current time if a completion timestamp is absent.
Sources: lib/tasks/formatRunDuration.ts:1-20
Visual consistency for task statuses (e.g., "completed", "failed") is maintained via the getStatusBadgeColor utility, which maps internal status strings to specific Tailwind CSS color classes.
Sources: lib/tasks/getStatusBadgeColor.ts:1-15
Tag Parsing
Specific utilities exist to extract metadata from task tags, such as identifying email IDs associated with a specific run.
| Function | Purpose | Logic |
|---|---|---|
getEmailIdFromTags | Extracts email ID | Finds a tag starting with email_id: and returns the suffix. |
Sources: lib/tasks/getEmailIdFromTags.ts:1-10
API Communication Utilities
These utilities facilitate communication with the Recoup backend API, handling authentication headers and URL construction for administrative endpoints.
Coding and Content Analytics
Utilities in the lib/recoup directory manage requests for specialized agent data. They utilize the API_BASE_URL and require a valid Privy access token for Bearer authentication.
| Utility File | Endpoint | Description |
|---|---|---|
fetchCodingPrStatus.ts | /api/admins/coding/pr | Checks the status (merged/open) of GitHub PR URLs. |
fetchContentSlackTags.ts | /api/admins/content/slack | Retrieves Content Agent usage tags for a specific period. |
Sources: lib/recoup/fetchCodingPrStatus.ts:14-36, lib/recoup/fetchContentSlackTags.ts:5-24
Styling and UI Helpers
The project uses a centralized utility for managing CSS class merging, particularly useful for dynamic component styling and Tailwind CSS integration.
Class Name Merging
The cn function is a wrapper around clsx and tailwind-merge. It allows developers to conditionally apply classes while ensuring that conflicting Tailwind utilities are resolved correctly (e.g., preventing duplicate padding or color definitions).
import { clsx, type ClassValue } from "clsx";
import { twMerge } from "tailwind-merge";
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}
Sources: lib/utils.ts:1-7
Summary
The General Utility Functions form the backbone of the Recoup Admin's data processing strategy. By isolating API fetching logic, task metadata parsing, and UI formatting into the lib/ directory, the codebase achieves high maintainability and ensures that business logic remains decoupled from the React view layer.