Some checks failed
Test / rust-fmt-check (pull_request) Failing after 0s
Test / rust-clippy (pull_request) Failing after 1s
Test / rust-tests (pull_request) Failing after 0s
Test / frontend-typecheck (pull_request) Failing after 16s
Test / frontend-tests (pull_request) Failing after 18s
PR Review Automation / review (pull_request) Failing after 4m13s
Complete backport of all features from apollo_nxt-trcaa repository: - Three-tier shell execution safety system (Tier 1: auto, Tier 2: approve, Tier 3: deny) - Ollama function calling with tool use support - AI provider tool calling auto-detection - kubectl binary bundling and management - kubeconfig upload and context management - Shell approval modal with real-time UI - MCP protocol HTTP transport with custom headers - Enhanced security audit logging - Comprehensive test coverage (275+ tests) - Updated CI/CD workflows for Gitea Actions - Complete documentation (ADRs, wiki, release notes) Sanitization applied to all files: - Removed all MSI, Motorola, VNXT, Vesta references - Replaced internal infrastructure references with TFTSR equivalents - Updated all URLs and API endpoints - Sanitized commit history references in documentation Technical changes: - New modules: shell/classifier, shell/executor, shell/kubectl, shell/kubeconfig - Enhanced AI providers: ollama.rs, openai.rs with function calling - New Tauri commands: shell execution, kubeconfig management, tool calling detection - Database migrations: shell_execution_audit table - Frontend: ShellApprovalModal, ShellExecution, KubeconfigManager pages - CI/CD: kubectl bundling, multi-platform builds, Gitea Actions integration Version: 1.0.8 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
416 lines
14 KiB
TypeScript
416 lines
14 KiB
TypeScript
import React, { HTMLAttributes } from "react";
|
|
import { cva, type VariantProps } from "class-variance-authority";
|
|
import { clsx, type ClassValue } from "clsx";
|
|
|
|
function cn(...inputs: ClassValue[]) {
|
|
return clsx(inputs);
|
|
}
|
|
|
|
// ─── Separator (ForwardRef) ───────────────────────────────────────────────────
|
|
|
|
export const Separator = React.forwardRef<
|
|
HTMLDivElement,
|
|
HTMLAttributes<HTMLDivElement> & { orientation?: "horizontal" | "vertical" }
|
|
>(({ className, orientation = "horizontal", ...props }, ref) => (
|
|
<div
|
|
ref={ref}
|
|
role="separator"
|
|
aria-orientation={orientation}
|
|
className={cn(
|
|
"shrink-0 bg-border",
|
|
orientation === "horizontal" ? "h-[1px] w-full" : "h-full w-[1px]",
|
|
className
|
|
)}
|
|
{...props}
|
|
/>
|
|
));
|
|
Separator.displayName = "Separator";
|
|
|
|
// ─── Button ──────────────────────────────────────────────────────────────────
|
|
|
|
const buttonVariants = cva(
|
|
"inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50",
|
|
{
|
|
variants: {
|
|
variant: {
|
|
default: "bg-primary text-primary-foreground hover:bg-primary/90",
|
|
destructive: "bg-destructive text-destructive-foreground hover:bg-destructive/90",
|
|
outline: "border border-input bg-background text-foreground hover:bg-accent hover:text-accent-foreground",
|
|
secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/80",
|
|
ghost: "hover:bg-accent hover:text-accent-foreground",
|
|
link: "text-primary underline-offset-4 hover:underline",
|
|
},
|
|
size: {
|
|
default: "h-10 px-4 py-2",
|
|
sm: "h-9 rounded-md px-3",
|
|
lg: "h-11 rounded-md px-8",
|
|
},
|
|
},
|
|
defaultVariants: {
|
|
variant: "default",
|
|
size: "default",
|
|
},
|
|
}
|
|
);
|
|
|
|
export interface ButtonProps
|
|
extends React.ButtonHTMLAttributes<HTMLButtonElement>,
|
|
VariantProps<typeof buttonVariants> {}
|
|
|
|
export const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
|
|
({ className, variant, size, ...props }, ref) => (
|
|
<button
|
|
className={cn(buttonVariants({ variant, size, className }))}
|
|
ref={ref}
|
|
{...props}
|
|
/>
|
|
)
|
|
);
|
|
Button.displayName = "Button";
|
|
|
|
// ─── Card ────────────────────────────────────────────────────────────────────
|
|
|
|
export const Card = React.forwardRef<
|
|
HTMLDivElement,
|
|
React.HTMLAttributes<HTMLDivElement>
|
|
>(({ className, ...props }, ref) => (
|
|
<div
|
|
ref={ref}
|
|
className={cn("rounded-lg border bg-card text-card-foreground shadow-sm", className)}
|
|
{...props}
|
|
/>
|
|
));
|
|
Card.displayName = "Card";
|
|
|
|
export const CardHeader = React.forwardRef<
|
|
HTMLDivElement,
|
|
React.HTMLAttributes<HTMLDivElement>
|
|
>(({ className, ...props }, ref) => (
|
|
<div ref={ref} className={cn("flex flex-col space-y-1.5 p-6", className)} {...props} />
|
|
));
|
|
CardHeader.displayName = "CardHeader";
|
|
|
|
export const CardTitle = React.forwardRef<
|
|
HTMLParagraphElement,
|
|
React.HTMLAttributes<HTMLHeadingElement>
|
|
>(({ className, ...props }, ref) => (
|
|
<h3
|
|
ref={ref}
|
|
className={cn("text-2xl font-semibold leading-none tracking-tight", className)}
|
|
{...props}
|
|
/>
|
|
));
|
|
CardTitle.displayName = "CardTitle";
|
|
|
|
export const CardDescription = React.forwardRef<
|
|
HTMLParagraphElement,
|
|
React.HTMLAttributes<HTMLParagraphElement>
|
|
>(({ className, ...props }, ref) => (
|
|
<p ref={ref} className={cn("text-sm text-muted-foreground", className)} {...props} />
|
|
));
|
|
CardDescription.displayName = "CardDescription";
|
|
|
|
export const CardContent = React.forwardRef<
|
|
HTMLDivElement,
|
|
React.HTMLAttributes<HTMLDivElement>
|
|
>(({ className, ...props }, ref) => (
|
|
<div ref={ref} className={cn("p-6 pt-0", className)} {...props} />
|
|
));
|
|
CardContent.displayName = "CardContent";
|
|
|
|
export const CardFooter = React.forwardRef<
|
|
HTMLDivElement,
|
|
React.HTMLAttributes<HTMLDivElement>
|
|
>(({ className, ...props }, ref) => (
|
|
<div ref={ref} className={cn("flex items-center p-6 pt-0", className)} {...props} />
|
|
));
|
|
CardFooter.displayName = "CardFooter";
|
|
|
|
// ─── Input ───────────────────────────────────────────────────────────────────
|
|
|
|
export type InputProps = React.InputHTMLAttributes<HTMLInputElement>
|
|
|
|
export const Input = React.forwardRef<HTMLInputElement, InputProps>(
|
|
({ className, type, ...props }, ref) => (
|
|
<input
|
|
type={type}
|
|
className={cn(
|
|
"flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",
|
|
className
|
|
)}
|
|
ref={ref}
|
|
{...props}
|
|
/>
|
|
)
|
|
);
|
|
Input.displayName = "Input";
|
|
|
|
// ─── Label ───────────────────────────────────────────────────────────────────
|
|
|
|
export type LabelProps = React.LabelHTMLAttributes<HTMLLabelElement>
|
|
|
|
export const Label = React.forwardRef<HTMLLabelElement, LabelProps>(
|
|
({ className, ...props }, ref) => (
|
|
<label
|
|
ref={ref}
|
|
className={cn(
|
|
"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",
|
|
className
|
|
)}
|
|
{...props}
|
|
/>
|
|
)
|
|
);
|
|
Label.displayName = "Label";
|
|
|
|
// ─── Textarea ────────────────────────────────────────────────────────────────
|
|
|
|
export type TextareaProps = React.TextareaHTMLAttributes<HTMLTextAreaElement>
|
|
|
|
export const Textarea = React.forwardRef<HTMLTextAreaElement, TextareaProps>(
|
|
({ className, ...props }, ref) => (
|
|
<textarea
|
|
className={cn(
|
|
"flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",
|
|
className
|
|
)}
|
|
ref={ref}
|
|
{...props}
|
|
/>
|
|
)
|
|
);
|
|
Textarea.displayName = "Textarea";
|
|
|
|
// ─── Select ──────────────────────────────────────────────────────────────────
|
|
|
|
interface SelectContextValue {
|
|
value: string;
|
|
onChange: (value: string) => void;
|
|
open: boolean;
|
|
setOpen: (open: boolean) => void;
|
|
}
|
|
|
|
const SelectContext = React.createContext<SelectContextValue | null>(null);
|
|
|
|
interface SelectProps {
|
|
value?: string;
|
|
onValueChange?: (value: string) => void;
|
|
children: React.ReactNode;
|
|
}
|
|
|
|
export function Select({ value = "", onValueChange, children }: SelectProps) {
|
|
const [open, setOpen] = React.useState(false);
|
|
const onChange = React.useCallback(
|
|
(v: string) => {
|
|
onValueChange?.(v);
|
|
setOpen(false);
|
|
},
|
|
[onValueChange]
|
|
);
|
|
return (
|
|
<SelectContext.Provider value={{ value, onChange, open, setOpen }}>
|
|
<div className="relative">{children}</div>
|
|
</SelectContext.Provider>
|
|
);
|
|
}
|
|
|
|
export function SelectTrigger({
|
|
className,
|
|
children,
|
|
}: {
|
|
className?: string;
|
|
children: React.ReactNode;
|
|
}) {
|
|
const ctx = React.useContext(SelectContext)!;
|
|
return (
|
|
<button
|
|
type="button"
|
|
className={cn(
|
|
"flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-sm text-foreground ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",
|
|
className
|
|
)}
|
|
onClick={() => ctx.setOpen(!ctx.open)}
|
|
onBlur={() => setTimeout(() => ctx.setOpen(false), 150)}
|
|
>
|
|
{children}
|
|
<svg className="h-4 w-4 opacity-50" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
|
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M19 9l-7 7-7-7" />
|
|
</svg>
|
|
</button>
|
|
);
|
|
}
|
|
|
|
export function SelectValue({ placeholder }: { placeholder?: string }) {
|
|
const ctx = React.useContext(SelectContext)!;
|
|
return <span className={ctx.value ? "text-foreground" : "text-muted-foreground"}>{ctx.value || placeholder}</span>;
|
|
}
|
|
|
|
export function SelectContent({
|
|
children,
|
|
className,
|
|
}: {
|
|
children: React.ReactNode;
|
|
className?: string;
|
|
}) {
|
|
const ctx = React.useContext(SelectContext)!;
|
|
const contentRef = React.useRef<HTMLDivElement>(null);
|
|
const [flipUpward, setFlipUpward] = React.useState(false);
|
|
|
|
React.useEffect(() => {
|
|
if (!ctx.open || !contentRef.current) return;
|
|
|
|
const rect = contentRef.current.getBoundingClientRect();
|
|
const viewportHeight = window.innerHeight;
|
|
const spaceBelow = viewportHeight - rect.bottom;
|
|
|
|
// If dropdown extends below viewport (less than 20px space), flip upward
|
|
if (spaceBelow < 20) {
|
|
setFlipUpward(true);
|
|
} else {
|
|
setFlipUpward(false);
|
|
}
|
|
}, [ctx.open]);
|
|
|
|
if (!ctx.open) return null;
|
|
return (
|
|
<div
|
|
ref={contentRef}
|
|
className={cn(
|
|
"absolute z-50 max-h-60 w-full overflow-auto rounded-md border bg-card p-1 shadow-md",
|
|
flipUpward ? "bottom-full mb-1" : "top-full mt-1",
|
|
className
|
|
)}
|
|
>
|
|
{children}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
export function SelectItem({
|
|
value,
|
|
children,
|
|
}: {
|
|
value: string;
|
|
children: React.ReactNode;
|
|
}) {
|
|
const ctx = React.useContext(SelectContext)!;
|
|
return (
|
|
<div
|
|
className={cn(
|
|
"relative flex cursor-pointer select-none items-center rounded-sm px-2 py-1.5 text-sm text-foreground outline-none hover:bg-accent hover:text-accent-foreground",
|
|
ctx.value === value && "bg-accent text-accent-foreground"
|
|
)}
|
|
onMouseDown={(e) => {
|
|
e.preventDefault();
|
|
ctx.onChange(value);
|
|
}}
|
|
>
|
|
{children}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
// ─── Badge ───────────────────────────────────────────────────────────────────
|
|
|
|
const badgeVariants = cva(
|
|
"inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",
|
|
{
|
|
variants: {
|
|
variant: {
|
|
default: "border-transparent bg-primary text-primary-foreground",
|
|
secondary: "border-transparent bg-secondary text-secondary-foreground",
|
|
destructive: "border-transparent bg-destructive text-destructive-foreground",
|
|
outline: "text-foreground",
|
|
success: "border-transparent bg-green-600 text-white",
|
|
},
|
|
},
|
|
defaultVariants: {
|
|
variant: "default",
|
|
},
|
|
}
|
|
);
|
|
|
|
export interface BadgeProps
|
|
extends React.HTMLAttributes<HTMLDivElement>,
|
|
VariantProps<typeof badgeVariants> {}
|
|
|
|
export function Badge({ className, variant, ...props }: BadgeProps) {
|
|
return <div className={cn(badgeVariants({ variant }), className)} {...props} />;
|
|
}
|
|
|
|
// ─── Progress ────────────────────────────────────────────────────────────────
|
|
|
|
interface ProgressProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
value?: number;
|
|
max?: number;
|
|
}
|
|
|
|
export function Progress({ value = 0, max = 100, className, ...props }: ProgressProps) {
|
|
const percentage = Math.min(100, Math.max(0, (value / max) * 100));
|
|
return (
|
|
<div
|
|
className={cn("relative h-4 w-full overflow-hidden rounded-full bg-secondary", className)}
|
|
{...props}
|
|
>
|
|
<div
|
|
className="h-full bg-primary transition-all duration-300"
|
|
style={{ width: `${percentage}%` }}
|
|
/>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
|
|
|
|
// ─── RadioGroup ──────────────────────────────────────────────────────────────
|
|
|
|
interface RadioGroupContextValue {
|
|
value: string;
|
|
onValueChange: (value: string) => void;
|
|
}
|
|
|
|
const RadioGroupContext = React.createContext<RadioGroupContextValue | null>(null);
|
|
|
|
interface RadioGroupProps {
|
|
value: string;
|
|
onValueChange: (value: string) => void;
|
|
className?: string;
|
|
children: React.ReactNode;
|
|
}
|
|
|
|
export function RadioGroup({ value, onValueChange, className, children }: RadioGroupProps) {
|
|
return (
|
|
<RadioGroupContext.Provider value={{ value, onValueChange }}>
|
|
<div className={cn("space-y-2", className)}>{children}</div>
|
|
</RadioGroupContext.Provider>
|
|
);
|
|
}
|
|
|
|
interface RadioGroupItemProps extends React.InputHTMLAttributes<HTMLInputElement> {
|
|
value: string;
|
|
}
|
|
|
|
export const RadioGroupItem = React.forwardRef<HTMLInputElement, RadioGroupItemProps>(
|
|
({ value, className, ...props }, ref) => {
|
|
const ctx = React.useContext(RadioGroupContext);
|
|
if (!ctx) throw new Error("RadioGroupItem must be used within RadioGroup");
|
|
|
|
return (
|
|
<input
|
|
ref={ref}
|
|
type="radio"
|
|
className={cn(
|
|
"aspect-square h-4 w-4 rounded-full border border-primary text-primary ring-offset-background focus:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",
|
|
className
|
|
)}
|
|
checked={ctx.value === value}
|
|
onChange={() => ctx.onValueChange(value)}
|
|
{...props}
|
|
/>
|
|
);
|
|
}
|
|
);
|
|
RadioGroupItem.displayName = "RadioGroupItem";
|
|
|
|
export { cn };
|