Spaces:
Running
Running
File size: 2,107 Bytes
c2ea5ed |
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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
import { TemporalGraphData } from "@/types/temporal";
/**
* Fetch temporal graph data for a trace
*/
export async function fetchTemporalGraphData(
traceId: string,
processingRunId?: string
): Promise<TemporalGraphData> {
try {
let apiUrl = `/api/temporal-graph/${traceId}`;
if (processingRunId) {
apiUrl += `?processing_run_id=${processingRunId}`;
}
const response = await fetch(apiUrl);
if (!response.ok) {
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
}
const data = await response.json();
console.log("Loaded temporal graph data:", data);
return {
trace_id: data.trace_id,
trace_title: data.trace_title,
trace_description: data.trace_description,
windows: data.windows || [],
full_kg: data.full_kg || null,
has_full_version: data.has_full_version || false,
processing_run_id: processingRunId,
};
} catch (error) {
console.error("Error fetching temporal graph data:", error);
throw error;
}
}
/**
* Validate that temporal data exists and has sufficient windows for replay
*/
export async function validateTemporalData(
traceId: string,
processingRunId?: string
): Promise<boolean> {
try {
const data = await fetchTemporalGraphData(traceId, processingRunId);
return data.windows && data.windows.length >= 2;
} catch (error) {
console.error("Error validating temporal data:", error);
return false;
}
}
/**
* Check if a trace has temporal data available
*/
export async function checkTemporalDataAvailability(traceId: string): Promise<{
hasTemporalData: boolean;
windowCount: number;
hasFullVersion: boolean;
}> {
try {
const data = await fetchTemporalGraphData(traceId);
return {
hasTemporalData: data.windows.length > 0,
windowCount: data.windows.length,
hasFullVersion: data.has_full_version,
};
} catch (error) {
console.error("Error checking temporal data availability:", error);
return {
hasTemporalData: false,
windowCount: 0,
hasFullVersion: false,
};
}
}
|