Skip to content

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

873 B
Raw Blame
import { api } from "@/src/utils/api";

export type UseMediaParams = {
  projectId: string;
  traceId: string;
  observationId?: string;
  /** Skip the lookup on surfaces that render many observations at once. */
  enabled?: boolean;
};

/**
 * Hook to fetch media attachments for a trace or observation.
 *
 * @param projectId - Project ID
 * @param traceId - Trace ID (required)
 * @param observationId - Observation ID (optional, for observation-level media)
 */
export function useMedia({
  projectId,
  traceId,
  observationId,
  enabled = true,
}: UseMediaParams) {
  return api.media.getByTraceOrObservationId.useQuery(
    {
      projectId,
      traceId,
      observationId,
    },
    {
      enabled,
      refetchOnWindowFocus: false,
      refetchOnMount: false,
      refetchOnReconnect: false,
      staleTime: 50 * 60 * 1000, // 50 minutes
    },
  );
}