mirror of
https://github.com/BerriAI/litellm.git
synced 2026-12-01 01:18:34 +00:00
* test(ui): characterize shared migration surfaces * refactor(ui): migrate guardrail and duration controls * fix(ui): preserve duration select callback shape * fix(ui): narrow duration selection value
86 lines
2.8 KiB
TypeScript
86 lines
2.8 KiB
TypeScript
import React from "react";
|
|
import { Globe2 } from "lucide-react";
|
|
import { Badge } from "@/components/ui/badge";
|
|
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
|
|
import { cn } from "@/lib/cva.config";
|
|
|
|
interface GuardrailSettingsViewProps {
|
|
globalGuardrailNames: Set<string>;
|
|
teamGuardrails?: string[];
|
|
optedOutGlobalGuardrails?: string[];
|
|
killSwitchOn?: boolean;
|
|
variant?: "card" | "inline";
|
|
className?: string;
|
|
}
|
|
|
|
export function GuardrailSettingsView({
|
|
globalGuardrailNames,
|
|
teamGuardrails = [],
|
|
optedOutGlobalGuardrails = [],
|
|
killSwitchOn = false,
|
|
variant = "card",
|
|
className = "",
|
|
}: GuardrailSettingsViewProps) {
|
|
const optedOutSet = new Set(optedOutGlobalGuardrails);
|
|
const globalsRunning = Array.from(globalGuardrailNames).filter((n) => !optedOutSet.has(n));
|
|
const nonGlobalOptIns = teamGuardrails.filter((n) => !globalGuardrailNames.has(n));
|
|
|
|
const isEmpty = !killSwitchOn && globalsRunning.length === 0 && nonGlobalOptIns.length === 0;
|
|
|
|
const content = isEmpty ? (
|
|
<span className="block text-muted-foreground">No guardrails configured</span>
|
|
) : (
|
|
<div className="flex flex-col gap-4">
|
|
<div>
|
|
<span className="mb-2 flex items-center gap-1 text-sm font-medium text-foreground">
|
|
<Globe2 className="size-4" aria-label="Global guardrail" />
|
|
Global
|
|
</span>
|
|
{killSwitchOn ? (
|
|
<Badge variant="outline">Bypassed for this team</Badge>
|
|
) : globalsRunning.length > 0 ? (
|
|
<div className="flex flex-wrap gap-2">
|
|
{globalsRunning.map((name) => (
|
|
<Badge key={name}>{name}</Badge>
|
|
))}
|
|
</div>
|
|
) : (
|
|
<span className="block text-sm text-muted-foreground">None configured</span>
|
|
)}
|
|
</div>
|
|
<div>
|
|
<span className="mb-2 block text-sm font-medium text-foreground">Team-specific</span>
|
|
{nonGlobalOptIns.length > 0 ? (
|
|
<div className="flex flex-wrap gap-2">
|
|
{nonGlobalOptIns.map((name) => (
|
|
<Badge key={name}>{name}</Badge>
|
|
))}
|
|
</div>
|
|
) : (
|
|
<span className="block text-sm text-muted-foreground">None configured</span>
|
|
)}
|
|
</div>
|
|
</div>
|
|
);
|
|
|
|
if (variant === "card") {
|
|
return (
|
|
<Card className={className}>
|
|
<CardHeader>
|
|
<CardTitle>Guardrails Settings</CardTitle>
|
|
<CardDescription>Global and team-specific guardrails applied to this team</CardDescription>
|
|
</CardHeader>
|
|
<CardContent>{content}</CardContent>
|
|
</Card>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<div className={cn(className)}>
|
|
<span className="mb-3 block font-medium text-foreground">Guardrails Settings</span>
|
|
{content}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
export default GuardrailSettingsView;
|