Add the timestamp of the last event to the Developers tab (#81)

This commit is contained in:
John Richmond 2025-06-06 11:20:44 -07:00 committed by GitHub
parent fff8dc3474
commit 9fd31aaf6c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 28 additions and 2 deletions

View file

@ -191,6 +191,7 @@ const developerUsageSchema = z.object({
tasksCompleted: z.coerce.number(),
tokens: z.coerce.number(),
cost: z.coerce.number(),
lastEventTimestamp: z.coerce.number(),
});
export type DeveloperUsage = z.infer<typeof developerUsageSchema> & {
@ -237,7 +238,8 @@ export const getDeveloperUsage = async ({
SUM(CASE WHEN type = '${TelemetryEventName.TASK_CREATED}' THEN 1 ELSE 0 END) AS tasksStarted,
SUM(CASE WHEN type = '${TelemetryEventName.TASK_COMPLETED}' THEN 1 ELSE 0 END) AS tasksCompleted,
SUM(CASE WHEN type = '${TelemetryEventName.LLM_COMPLETION}' THEN COALESCE(inputTokens, 0) + COALESCE(outputTokens, 0) ELSE 0 END) AS tokens,
SUM(CASE WHEN type = '${TelemetryEventName.LLM_COMPLETION}' THEN COALESCE(cost, 0) ELSE 0 END) AS cost
SUM(CASE WHEN type = '${TelemetryEventName.LLM_COMPLETION}' THEN COALESCE(cost, 0) ELSE 0 END) AS cost,
MAX(timestamp) AS lastEventTimestamp
FROM events
WHERE orgId = {orgId: String}
AND timestamp >= toUnixTimestamp(now() - INTERVAL {timePeriod: Int32} DAY)

View file

@ -2,9 +2,14 @@ import { useMemo } from 'react';
import { useQuery } from '@tanstack/react-query';
import type { ColumnDef } from '@tanstack/react-table';
import { useAuth } from '@clerk/nextjs';
import { formatDistance } from 'date-fns';
import { type DeveloperUsage, getDeveloperUsage } from '@/actions/analytics';
import { formatCurrency, formatNumber } from '@/lib/formatters';
import {
formatCurrency,
formatNumber,
formatTimestamp,
} from '@/lib/formatters';
import { Button, Skeleton } from '@/components/ui';
import { DataTable } from '@/components/layout';
@ -63,6 +68,25 @@ export const Developers = ({
header: 'Cost (USD)',
cell: ({ row }) => formatCurrency(row.original.cost),
},
{
header: 'Last Event',
cell: ({ row }) => {
const timestamp = row.original.lastEventTimestamp;
if (!timestamp) return 'No activity';
const date = new Date(timestamp * 1000);
const relativeTime = formatDistance(date, new Date(), {
addSuffix: true,
});
const absoluteTime = formatTimestamp(timestamp);
return (
<span title={absoluteTime} className="cursor-help">
{relativeTime}
</span>
);
},
},
],
[onFilter],
);