The platform for continuously improving AI agents.
import { useQuery } from "@tanstack/react-query";
import apiClient from "@/client";
import type { Session } from "@/openapi";
export interface SessionRow {
readonly id: string;
readonly externalId: string;
readonly name: string;
project: string;
capability: string | null;
capabilityName: string | null;
traceCount: number;
spanCount: number;
firstSpanNs: number | null;
lastSpanNs: number | null;
sessionScore: number | null;
totalTokens: number | null;
totalCost: number | null;
model: string | null;
readonly createdAt: string;
}
const transformSession = (row: Session): SessionRow => ({
capability: row.capability,
capabilityName: row.capabilityName ?? null,
createdAt: row.createdAt instanceof Date ? row.createdAt.toISOString() : String(row.createdAt),
externalId: row.externalId,
firstSpanNs: row.firstSpanNs ?? null,
id: row.id,
lastSpanNs: row.lastSpanNs ?? null,
model: row.model ?? null,
name: row.name,
project: row.project,
sessionScore: row.sessionScore ?? null,
spanCount: row.spanCount,
totalCost: row.totalCost ?? null,
totalTokens: row.totalTokens ?? null,
traceCount: row.traceCount,
});
export function useSessionDetail(sessionId: string | undefined) {
return useQuery({
enabled: !!sessionId,
queryFn: async (): Promise<SessionRow> =>
transformSession(await apiClient.sessions.sessionsRetrieve({ id: sessionId! })),
queryKey: ["session", sessionId],
});
}