Skip to content

OpenRAG is a comprehensive, single package Retrieval-Augmented Generation platform built on Langflow, Docling, and Opensearch.

Python
1.8 KB
Raw Blame
import { type UseQueryOptions, useQuery } from "@tanstack/react-query";
import { apiClient } from "@/lib/api-client";
import { getApiError } from "@/lib/status-utils";

export type ComponentState = "healthy" | "degraded" | "unhealthy" | "unknown";

export interface ComponentBuild {
  git_sha?: string | null;
  build_time?: string | null;
  image?: string | null;
  image_digest?: string | null;
}

export interface ComponentStatus {
  name: string;
  display_name: string;
  status: ComponentState;
  required: boolean;
  latency_ms?: number | null;
  message?: string | null;
  version?: string | null;
  build?: ComponentBuild;
  metadata?: Record<string, unknown>;
  /** Non-null when the last health-check failed; used to gate the Logs button. */
  last_error?: string | null;
  /** ISO-8601 UTC of when this component was last checked (drives "Last Sync"). */
  checked_at?: string | null;
}

export interface ConsoleStatusResponse {
  overall_status: ComponentState;
  checked_at: string;
  components: ComponentStatus[];
}

async function fetchConsoleStatus(): Promise<ConsoleStatusResponse> {
  const response = await apiClient.get<ConsoleStatusResponse>("/status");
  if (response.status < 200 || response.status >= 300) {
    const body = response.data;
    throw new Error(getApiError(body, response.status));
  }
  return response.data;
}

export const useConsoleStatusQuery = (
  options?: Omit<
    UseQueryOptions<ConsoleStatusResponse>,
    "queryKey" | "queryFn"
  >,
) => {
  return useQuery({
    queryKey: ["console-status"],
    queryFn: fetchConsoleStatus,
    retry: 1,
    refetchInterval: 30000,
    // Re-check when the user returns to the tab so a status change that
    // happened while away surfaces promptly (drives the header notification).
    refetchOnWindowFocus: true,
    staleTime: 15000,
    ...options,
  });
};