Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

2.2 KB
Raw Blame
import { useRouter } from "next/router";
import { usePeekData } from "@/src/components/table/peek/hooks/usePeekData";
import { TraceDetailBody } from "@/src/features/traces/components/TraceDetailBody";
import { TablePeekView } from "@/src/components/table/peek";
import { ExperimentPeekFooter } from "@/src/features/experiments/components/ExperimentPeekFooter";
import { useExperimentPeekNavigation } from "@/src/features/experiments/hooks/useExperimentPeekNavigation";
import { parseTraceTimestampFromQuery } from "@/src/fns/parseTraceTimestampFromQuery/parseTraceTimestampFromQuery";

const PeekViewExperimentItemDetail = ({ projectId }: { projectId: string }) => {
  const router = useRouter();
  const peekId = router.query.peek as string | undefined;
  const timestamp = parseTraceTimestampFromQuery(router.query.timestamp);
  const traceId = router.query.traceId as string | undefined;

  const trace = usePeekData({
    projectId,
    traceId,
    timestamp,
  });

  // No trace target means the current experiment has no run for this item;
  // without this guard the disabled trace query would show a skeleton forever.
  if (!traceId) {
    return (
      <div className="flex h-full items-center justify-center p-4">
        <span className="text-muted-foreground text-sm">
          No run for this item in the selected experiment
        </span>
      </div>
    );
  }

  return (
    <TraceDetailBody
      trace={trace.data}
      isPlaceholderData={trace.isPlaceholderData}
      context="peek"
      keySuffix={peekId}
      truncatedAtObservations={trace.truncatedAtObservations}
    />
  );
};

export const TablePeekViewExperimentItemDetail = (
  props: Omit<
    React.ComponentProps<typeof TablePeekView>,
    "children" | "title" | "footer"
  > & {
    projectId: string;
  },
) => {
  const { projectId } = props;
  const router = useRouter();
  const peekId = router.query.peek as string | undefined;
  const { canSwitch } = useExperimentPeekNavigation();

  return (
    <TablePeekView
      {...props}
      title={peekId ? `Experiment Item: ${peekId}` : undefined}
      footer={
        canSwitch ? <ExperimentPeekFooter projectId={projectId} /> : undefined
      }
    >
      <PeekViewExperimentItemDetail projectId={projectId} />
    </TablePeekView>
  );
};