Spaces:
Running
Running
| 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, | |
| }; | |
| } | |
| } | |