-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #236 from giselles-ai/feat/agent-logs-view
feat: Add agent activity logs viewer with detailed dialog
- Loading branch information
Showing
6 changed files
with
198 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { Button } from "@/components/ui/button"; | ||
import { | ||
Dialog, | ||
DialogContent, | ||
DialogHeader, | ||
DialogTitle, | ||
DialogTrigger, | ||
} from "@/components/ui/dialog"; | ||
import { type AgentActivity, AgentUsageTable } from "./agent-usage-table"; | ||
|
||
type AgentUsageDialogProps = { | ||
activities: AgentActivity[]; | ||
}; | ||
|
||
export function AgentUsageDialog({ activities }: AgentUsageDialogProps) { | ||
return ( | ||
<Dialog> | ||
<DialogTrigger asChild> | ||
<Button variant="link">View all logs</Button> | ||
</DialogTrigger> | ||
<DialogContent className="max-w-7xl"> | ||
<DialogHeader> | ||
<DialogTitle>Agent Usage Logs</DialogTitle> | ||
</DialogHeader> | ||
<AgentUsageTable | ||
activities={activities} | ||
containerClassName="max-h-[60vh] overflow-y-auto" | ||
/> | ||
</DialogContent> | ||
</Dialog> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { LocalDateTime } from "./components/local-date-time"; | ||
|
||
export type AgentActivity = { | ||
agentId: string; | ||
agentName: string | null; | ||
startTime: Date; | ||
endTime: Date | null; | ||
usedCharge: number; | ||
}; | ||
|
||
type AgentUsageTableProps = { | ||
activities: AgentActivity[]; | ||
containerClassName?: string; | ||
}; | ||
|
||
export function AgentUsageTable({ | ||
activities, | ||
containerClassName, | ||
}: AgentUsageTableProps) { | ||
return ( | ||
<div className="font-avenir rounded-[16px]"> | ||
<div className="grid grid-cols-4 gap-4 border-b border-zinc-800 bg-zinc-900/50 p-4 font-medium text-zinc-200"> | ||
<div>Agent</div> | ||
<div>Start Time</div> | ||
<div>End Time</div> | ||
<div>Charge</div> | ||
</div> | ||
<div className={containerClassName}> | ||
<div className="divide-y divide-zinc-800"> | ||
{activities.length > 0 ? ( | ||
activities.map((activity) => ( | ||
<div | ||
key={`${activity.agentId}-${activity.startTime}`} | ||
className="grid grid-cols-4 gap-4 p-4 items-center text-zinc-200" | ||
> | ||
<div className="break-words max-w-xs"> | ||
{activity.agentName ?? activity.agentId} | ||
</div> | ||
<div className="text-zinc-400"> | ||
<LocalDateTime date={new Date(activity.startTime)} /> | ||
</div> | ||
<div className="text-zinc-400"> | ||
{activity.endTime ? ( | ||
<LocalDateTime date={new Date(activity.endTime)} /> | ||
) : ( | ||
"-" | ||
)} | ||
</div> | ||
<div>{activity.usedCharge} seconds</div> | ||
</div> | ||
)) | ||
) : ( | ||
<div className="p-4 text-zinc-400">No agent activities</div> | ||
)} | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { Card } from "@/app/(main)/settings/components/card"; | ||
import { getAgentActivities } from "./actions"; | ||
import { AgentUsageDialog } from "./agent-usage-dialog"; | ||
import { AgentUsageTable } from "./agent-usage-table"; | ||
|
||
export async function AgentUsage() { | ||
const result = await getAgentActivities({ limit: 50 }); | ||
|
||
if (!result.success || !result.data) { | ||
return ( | ||
<Card title="Recent Agent Usage"> | ||
<div className="text-zinc-400 p-4">Failed to load agent activities</div> | ||
</Card> | ||
); | ||
} | ||
|
||
const activities = result.data; | ||
const recentActivities = activities.slice(0, 3); | ||
|
||
return ( | ||
<Card | ||
title="Recent Agent Usage" | ||
action={{ | ||
component: | ||
activities.length > 0 ? ( | ||
<AgentUsageDialog activities={activities} /> | ||
) : null, | ||
}} | ||
> | ||
<AgentUsageTable activities={recentActivities} /> | ||
</Card> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
"use client"; | ||
|
||
export function LocalDateTime({ | ||
date, | ||
format = { | ||
year: "numeric", | ||
month: "long", | ||
day: "numeric", | ||
hour: "2-digit", | ||
minute: "2-digit", | ||
hour12: false, | ||
timeZoneName: "short", | ||
}, | ||
}: { | ||
date: Date; | ||
format?: Intl.DateTimeFormatOptions; | ||
}) { | ||
const formattedDate = new Intl.DateTimeFormat("en-US", format).format(date); | ||
|
||
return <time dateTime={date.toISOString()}>{formattedDate}</time>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters