All files / web/src/utils log-ground-truth.ts

100% Statements 18/18
100% Branches 8/8
100% Functions 3/3
100% Lines 18/18

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41    1x             4x 4x 4x   2x 2x 2x             1x 7x 7x   5x 5x             4x 4x 4x 4x 4x 4x  
import type { ImprovedResponse } from '@shared/types/data/improved-response';
import type { Log } from '@shared/types/data/log';
import { getImprovedResponseByLogId } from '@web/api/v1/super-agents/improved-responses';
 
/**
 * Determines if a log has ground truth based on improved responses
 * @param log - The log to check
 * @returns Promise<boolean> - True if the log has an improved response (ground truth)
 */
export async function hasGroundTruth(log: Log): Promise<boolean> {
  const logId = log.id;
  if (!logId) return false;
 
  const improvedResponse = await getImprovedResponseByLogId(logId);
  return improvedResponse !== null;
}
 
/**
 * Gets the ground truth (improved response) for a log
 * @param log - The log to get ground truth for
 * @returns Promise<ImprovedResponse | null> - The improved response if it exists, null otherwise
 */
export function getGroundTruth(log: Log): Promise<ImprovedResponse | null> {
  const logId = log.id;
  if (!logId) return Promise.resolve(null);
 
  return getImprovedResponseByLogId(logId);
}
 
/**
 * Gets the ground truth response body for display purposes
 * @param log - The log to get ground truth for
 * @returns Promise<Record<string, unknown> | null> - The improved response body if it exists
 */
export async function getGroundTruthResponseBody(
  log: Log,
): Promise<Record<string, unknown> | null> {
  const improvedResponse = await getGroundTruth(log);
  return improvedResponse?.improved_response_body || null;
}