Some checks failed
build-images / web (push) Has been cancelled
vision2026-ci / Python SDK resource tests (push) Has been cancelled
build-images / api (push) Has been cancelled
build-images / worker-gpu (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (comfy-workflow-schema) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (effects-core) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (eventbus-types) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (growth-analytics) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (provider-adapter-kit) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (publishing-connectors) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (render-core) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (shot-template-schema) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (trends-schema) (push) Has been cancelled
vision2026-ci / Desktop engine crates (test + clippy + fmt) (push) Has been cancelled
codeql / Analyze (javascript-typescript) (push) Has been cancelled
codeql / Analyze (python) (push) Has been cancelled
perf / API hot-path micro-smoke (budgeted) (push) Has been cancelled
perf / Desktop engine crates (release build check) (push) Has been cancelled
vision2026-ci / API phase modules (ruff + pytest) (push) Has been cancelled
vision2026-ci / Alembic upgrade + drift check (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (caption-engine) (push) Has been cancelled
Paid, hosted product at menivor.com, now retired as a company project. Fresh squashed history of the cleaned working tree (secret-scanned, no .env, no customer data, no outreach logs). Built on MoneyPrinterTurbo (MIT, harry0703) — see NOTICE.
74 lines
2.2 KiB
TypeScript
74 lines
2.2 KiB
TypeScript
/**
|
|
* Small provider-health status badge shared by the model compare, model detail,
|
|
* and provider-health screens. Renders the normalized health state as a colored
|
|
* pill; an optional uptime percentage is appended when known.
|
|
*/
|
|
|
|
import type { ReactElement } from "react";
|
|
import { StyleSheet, Text, View } from "react-native";
|
|
|
|
import { colors } from "@/components/me/theme";
|
|
import type { ProviderHealthState } from "@/lib/marketplace";
|
|
|
|
const STATE_COLOR: Record<ProviderHealthState, string> = {
|
|
healthy: colors.success,
|
|
degraded: "#fbbf24",
|
|
down: colors.error,
|
|
unknown: colors.muted,
|
|
};
|
|
|
|
const STATE_LABEL: Record<ProviderHealthState, string> = {
|
|
healthy: "Healthy",
|
|
degraded: "Degraded",
|
|
down: "Down",
|
|
unknown: "Unknown",
|
|
};
|
|
|
|
interface HealthBadgeProps {
|
|
/** Accepts a raw provider `health_state` string; coerced to a known state. */
|
|
state: ProviderHealthState | string | undefined;
|
|
/** Uptime fraction 0..1; shown as a percentage when finite and > 0 samples. */
|
|
uptime?: number;
|
|
samples?: number;
|
|
}
|
|
|
|
/** Coerce an arbitrary string into a known health state (defaults to unknown). */
|
|
export function coerceHealthState(value: string | undefined): ProviderHealthState {
|
|
if (value === "healthy" || value === "degraded" || value === "down") return value;
|
|
return "unknown";
|
|
}
|
|
|
|
export function HealthBadge({ state, uptime, samples }: HealthBadgeProps): ReactElement {
|
|
const resolved = coerceHealthState(state);
|
|
const color = STATE_COLOR[resolved];
|
|
const hasUptime =
|
|
typeof uptime === "number" &&
|
|
Number.isFinite(uptime) &&
|
|
(samples === undefined || samples > 0) &&
|
|
resolved !== "unknown";
|
|
const label = hasUptime
|
|
? `${STATE_LABEL[resolved]} · ${Math.round((uptime as number) * 100)}%`
|
|
: STATE_LABEL[resolved];
|
|
|
|
return (
|
|
<View style={[styles.badge, { borderColor: color }]}>
|
|
<View style={[styles.dot, { backgroundColor: color }]} />
|
|
<Text style={[styles.text, { color }]}>{label}</Text>
|
|
</View>
|
|
);
|
|
}
|
|
|
|
const styles = StyleSheet.create({
|
|
badge: {
|
|
flexDirection: "row",
|
|
alignItems: "center",
|
|
gap: 6,
|
|
borderWidth: 1,
|
|
borderRadius: 999,
|
|
paddingHorizontal: 8,
|
|
paddingVertical: 3,
|
|
},
|
|
dot: { width: 7, height: 7, borderRadius: 999 },
|
|
text: { fontSize: 11, fontWeight: "700" },
|
|
});
|