AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
import type { HomeDashboardResponse } from "@/app/api/__generated__/models/homeDashboardResponse";
export function getTimeOfDayGreeting(hour = new Date().getHours()) {
if (hour < 12) return "Good morning";
if (hour < 18) return "Good afternoon";
return "Good evening";
}
export function getHomeStatusLine(dashboard: HomeDashboardResponse): string {
const attention = dashboard.attention.length;
const active = dashboard.active_tasks.length;
if (attention > 0 && active > 0) {
return `${attention} ${attention === 1 ? "decision" : "decisions"} waiting · ${active} ${active === 1 ? "workflow is" : "workflows are"} running now`;
}
if (attention > 0) {
return `${attention} ${attention === 1 ? "decision needs" : "decisions need"} you`;
}
if (active > 0) {
return `All clear · ${active} ${active === 1 ? "workflow is" : "workflows are"} running now`;
}
return "Nothing needs you right now";
}
export function formatHeaderDate(
value: Date,
timeZone: string,
locale?: string,
) {
const date = new Date(value);
const options = { timeZone };
return {
weekday: new Intl.DateTimeFormat(locale, {
...options,
weekday: "long",
}).format(date),
calendarDate: new Intl.DateTimeFormat(locale, {
...options,
month: "long",
day: "numeric",
}).format(date),
};
}
export function formatDuration(totalSeconds: number): string {
const totalMinutes = Math.round(totalSeconds / 60);
const hours = Math.floor(totalMinutes / 60);
const minutes = totalMinutes % 60;
if (hours === 0) return `${minutes}m`;
if (minutes === 0) return `${hours}h`;
return `${hours}h ${minutes}m`;
}
// Null rather than "$0.00 this week" so a brand-new or idle expert reads as
// having no spend line at all instead of an explicit zero.
export function formatWeeklySpend(cents: number | undefined): string | null {
if (!cents || cents <= 0) return null;
return `${formatCurrency(cents)} this week`;
}
export function formatCurrency(cents: number): string {
return new Intl.NumberFormat(undefined, {
style: "currency",
currency: "USD",
minimumFractionDigits: 2,
}).format(cents / 100);
}