LLM-Driven Extraction of Unstructured Data — Built for API Deployments & ETL Pipeline Workflows
Python ai-agentsdata-engineeringdocument-aigenerative-aiidpjson-extractionllmmcp-serverocrpdf-extractionprompt-engineeringstructured-output
import dayjs from "dayjs";
import relativeTime from "dayjs/plugin/relativeTime";
import {
CircleCheck,
CirclePlay,
CircleX,
Clock,
GitBranch,
Info,
Plug,
RefreshCw,
} from "lucide-react";
import PropTypes from "prop-types";
import { useNavigate } from "react-router-dom";
import { Empty, Spin, Tag } from "@/components/ui/shims/antd-leaves";
import { Tooltip } from "@/components/ui/shims/antd-overlays";
import { Card, List } from "@/components/ui/shims/antd-structure";
import { Text } from "@/components/ui/shims/antd-typography";
import { useSessionStore } from "../../store/session-store";
import "./MetricsDashboard.css";
dayjs.extend(relativeTime);
// Status configuration with colors and icons
const STATUS_CONFIG = {
COMPLETED: {
color: "success",
icon: <CircleCheck />,
label: "Completed",
},
RUNNING: {
color: "processing",
icon: <RefreshCw spin />,
label: "Processing",
},
QUEUED: {
color: "default",
icon: <Clock />,
label: "Queued",
},
ERROR: {
color: "error",
icon: <CircleX />,
label: "Failed",
},
};
// Execution type configuration
const TYPE_CONFIG = {
etl: {
label: "ETL Pipeline",
icon: <GitBranch />,
color: "#722ed1",
logType: "ETL",
},
api: {
label: "API Request",
icon: <Plug />,
color: "#1890ff",
logType: "API",
},
workflow: {
label: "Workflow",
icon: <CirclePlay />,
color: "#52c41a",
logType: "WF",
},
};
/**
* Recent Activity component showing latest processing events.
* Displays file executions categorized by type (ETL, API, Workflow).
*
* @return {JSX.Element} The rendered recent activity component.
*/
function RecentActivity({ data = null, loading = false }) {
const navigate = useNavigate();
const { sessionDetails } = useSessionStore();
const orgName = sessionDetails?.orgName;
const handleActivityClick = (item) => {
if (!item.execution_id || !orgName) {
return;
}
const typeConfig = TYPE_CONFIG[item.type] || TYPE_CONFIG.workflow;
navigate(`/${orgName}/logs/${typeConfig.logType}/${item.execution_id}`, {
state: { from: `/${orgName}/dashboard` },
});
};
if (loading) {
return (
<Card title="Recent Activity" className="metrics-chart-card">
<div className="metrics-loading">
<Spin />
</div>
</Card>
);
}
if (!data?.activity?.length) {
return (
<Card title="Recent Activity" className="metrics-chart-card">
<Empty description="No recent activity" />
</Card>
);
}
return (
<Card title="Recent Activity" className="metrics-chart-card chart-card">
<List
className="recent-activity-list"
dataSource={data.activity}
size="small"
split={false}
renderItem={(item) => {
const statusConfig =
STATUS_CONFIG[item.status] || STATUS_CONFIG.QUEUED;
const typeConfig = TYPE_CONFIG[item.type] || TYPE_CONFIG.workflow;
return (
<List.Item
className="recent-activity-item recent-activity-clickable"
tabIndex={0}
role="button"
onClick={() => handleActivityClick(item)}
onKeyDown={(e) => {
if (e.key === "Enter" || e.key === " ") {
e.preventDefault();
handleActivityClick(item);
}
}}
>
<div className="recent-activity-content">
<div className="recent-activity-header">
<span
className="recent-activity-type"
style={{ color: typeConfig.color }}
>
{typeConfig.icon}
<Text strong style={{ marginLeft: 6 }}>
{typeConfig.label}
</Text>
</span>
<Tag color={statusConfig.color}>{statusConfig.label}</Tag>
</div>
<Text className="recent-activity-file" ellipsis>
{item.file_name}
</Text>
{item.total_tokens > 0 && (
<Text type="secondary" className="recent-activity-meta">
<span>{item.total_tokens.toLocaleString()} tokens</span>
<Tooltip title="Total LLM tokens used to process this file">
<Info className="recent-activity-info" />
</Tooltip>
</Text>
)}
<Text type="secondary" className="recent-activity-time">
{dayjs(item.created_at).fromNow()}
</Text>
</div>
</List.Item>
);
}}
/>
</Card>
);
}
RecentActivity.propTypes = {
data: PropTypes.shape({
activity: PropTypes.arrayOf(
PropTypes.shape({
id: PropTypes.string.isRequired,
execution_id: PropTypes.string,
type: PropTypes.oneOf(["etl", "api", "workflow"]).isRequired,
file_name: PropTypes.string.isRequired,
status: PropTypes.string.isRequired,
workflow_name: PropTypes.string,
created_at: PropTypes.string.isRequired,
execution_time: PropTypes.number,
total_tokens: PropTypes.number,
}),
),
}),
loading: PropTypes.bool,
};
export { RecentActivity };