2025-06-09 15:50:15 -07:00
|
|
|
"use client";
|
|
|
|
|
|
2025-12-11 13:42:33 +02:00
|
|
|
import { useAtomValue } from "jotai";
|
2025-07-27 10:05:37 -07:00
|
|
|
import {
|
2025-07-27 10:41:15 -07:00
|
|
|
AlertCircle,
|
|
|
|
|
Edit3,
|
2025-12-23 01:16:25 -08:00
|
|
|
FileText,
|
2026-02-10 21:31:43 -08:00
|
|
|
Info,
|
2025-12-23 01:16:25 -08:00
|
|
|
MessageSquareQuote,
|
2025-07-27 10:41:15 -07:00
|
|
|
Plus,
|
|
|
|
|
RefreshCw,
|
|
|
|
|
Trash2,
|
2025-12-23 01:16:25 -08:00
|
|
|
Wand2,
|
2025-07-27 10:41:15 -07:00
|
|
|
} from "lucide-react";
|
2025-09-30 21:53:10 -07:00
|
|
|
import { AnimatePresence, motion } from "motion/react";
|
2026-02-09 19:00:57 +05:30
|
|
|
import Image from "next/image";
|
|
|
|
|
import { useCallback, useMemo, useState } from "react";
|
2026-02-09 19:37:59 +05:30
|
|
|
import { membersAtom, myAccessAtom } from "@/atoms/members/members-query.atoms";
|
2025-12-11 13:42:33 +02:00
|
|
|
import {
|
2025-12-23 01:16:25 -08:00
|
|
|
createNewLLMConfigMutationAtom,
|
|
|
|
|
deleteNewLLMConfigMutationAtom,
|
|
|
|
|
updateNewLLMConfigMutationAtom,
|
|
|
|
|
} from "@/atoms/new-llm-config/new-llm-config-mutation.atoms";
|
|
|
|
|
import {
|
|
|
|
|
globalNewLLMConfigsAtom,
|
|
|
|
|
newLLMConfigsAtom,
|
|
|
|
|
} from "@/atoms/new-llm-config/new-llm-config-query.atoms";
|
|
|
|
|
import { LLMConfigForm, type LLMConfigFormData } from "@/components/shared/llm-config-form";
|
2025-07-27 10:41:15 -07:00
|
|
|
import { Alert, AlertDescription } from "@/components/ui/alert";
|
2025-12-13 22:43:38 -08:00
|
|
|
import {
|
|
|
|
|
AlertDialog,
|
|
|
|
|
AlertDialogAction,
|
|
|
|
|
AlertDialogCancel,
|
|
|
|
|
AlertDialogContent,
|
|
|
|
|
AlertDialogDescription,
|
|
|
|
|
AlertDialogFooter,
|
|
|
|
|
AlertDialogHeader,
|
|
|
|
|
AlertDialogTitle,
|
|
|
|
|
} from "@/components/ui/alert-dialog";
|
2025-07-27 10:05:37 -07:00
|
|
|
import { Badge } from "@/components/ui/badge";
|
2025-07-27 10:41:15 -07:00
|
|
|
import { Button } from "@/components/ui/button";
|
|
|
|
|
import { Card, CardContent } from "@/components/ui/card";
|
2025-07-27 10:05:37 -07:00
|
|
|
import {
|
|
|
|
|
Dialog,
|
|
|
|
|
DialogContent,
|
|
|
|
|
DialogDescription,
|
|
|
|
|
DialogHeader,
|
|
|
|
|
DialogTitle,
|
|
|
|
|
} from "@/components/ui/dialog";
|
2026-02-09 19:26:23 +05:30
|
|
|
import { Skeleton } from "@/components/ui/skeleton";
|
2026-01-25 15:23:45 +05:30
|
|
|
import { Spinner } from "@/components/ui/spinner";
|
2026-01-26 23:32:30 -08:00
|
|
|
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip";
|
2025-12-23 01:16:25 -08:00
|
|
|
import type { NewLLMConfig } from "@/contracts/types/new-llm-config.types";
|
2026-02-09 20:48:42 +05:30
|
|
|
import { getProviderIcon } from "@/lib/provider-icons";
|
2026-02-10 21:31:43 -08:00
|
|
|
import { cn } from "@/lib/utils";
|
2025-06-09 15:50:15 -07:00
|
|
|
|
2025-10-10 00:50:29 -07:00
|
|
|
interface ModelConfigManagerProps {
|
|
|
|
|
searchSpaceId: number;
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-23 01:16:25 -08:00
|
|
|
const container = {
|
|
|
|
|
hidden: { opacity: 0 },
|
|
|
|
|
show: {
|
|
|
|
|
opacity: 1,
|
|
|
|
|
transition: {
|
|
|
|
|
staggerChildren: 0.05,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const item = {
|
|
|
|
|
hidden: { opacity: 0, y: 20 },
|
|
|
|
|
show: { opacity: 1, y: 0 },
|
|
|
|
|
};
|
|
|
|
|
|
2026-02-09 19:00:57 +05:30
|
|
|
function getInitials(name: string): string {
|
|
|
|
|
const parts = name.trim().split(/\s+/);
|
|
|
|
|
if (parts.length >= 2) {
|
|
|
|
|
return (parts[0][0] + parts[1][0]).toUpperCase();
|
|
|
|
|
}
|
|
|
|
|
return name.slice(0, 2).toUpperCase();
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-10 00:50:29 -07:00
|
|
|
export function ModelConfigManager({ searchSpaceId }: ModelConfigManagerProps) {
|
2025-12-23 01:16:25 -08:00
|
|
|
// Mutations
|
2026-02-10 19:06:21 +05:30
|
|
|
const { mutateAsync: createConfig, isPending: isCreating } = useAtomValue(
|
|
|
|
|
createNewLLMConfigMutationAtom
|
|
|
|
|
);
|
|
|
|
|
const { mutateAsync: updateConfig, isPending: isUpdating } = useAtomValue(
|
|
|
|
|
updateNewLLMConfigMutationAtom
|
|
|
|
|
);
|
|
|
|
|
const { mutateAsync: deleteConfig, isPending: isDeleting } = useAtomValue(
|
|
|
|
|
deleteNewLLMConfigMutationAtom
|
|
|
|
|
);
|
2025-12-23 01:16:25 -08:00
|
|
|
|
|
|
|
|
// Queries
|
2025-12-11 13:42:33 +02:00
|
|
|
const {
|
2025-12-23 01:16:25 -08:00
|
|
|
data: configs,
|
|
|
|
|
isFetching: isLoading,
|
|
|
|
|
error: fetchError,
|
2025-12-11 13:42:33 +02:00
|
|
|
refetch: refreshConfigs,
|
2025-12-23 01:16:25 -08:00
|
|
|
} = useAtomValue(newLLMConfigsAtom);
|
|
|
|
|
const { data: globalConfigs = [] } = useAtomValue(globalNewLLMConfigsAtom);
|
|
|
|
|
|
2026-02-09 19:00:57 +05:30
|
|
|
// Members for user resolution
|
|
|
|
|
const { data: members } = useAtomValue(membersAtom);
|
|
|
|
|
const memberMap = useMemo(() => {
|
|
|
|
|
const map = new Map<string, { name: string; email?: string; avatarUrl?: string }>();
|
|
|
|
|
if (members) {
|
|
|
|
|
for (const m of members) {
|
|
|
|
|
map.set(m.user_id, {
|
|
|
|
|
name: m.user_display_name || m.user_email || "Unknown",
|
|
|
|
|
email: m.user_email || undefined,
|
|
|
|
|
avatarUrl: m.user_avatar_url || undefined,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return map;
|
|
|
|
|
}, [members]);
|
|
|
|
|
|
2026-02-09 19:37:59 +05:30
|
|
|
// Permissions
|
|
|
|
|
const { data: access } = useAtomValue(myAccessAtom);
|
|
|
|
|
const canCreate = useMemo(() => {
|
|
|
|
|
if (!access) return false;
|
|
|
|
|
if (access.is_owner) return true;
|
|
|
|
|
return access.permissions?.includes("llm_configs:create") ?? false;
|
|
|
|
|
}, [access]);
|
|
|
|
|
const canUpdate = useMemo(() => {
|
|
|
|
|
if (!access) return false;
|
|
|
|
|
if (access.is_owner) return true;
|
|
|
|
|
return access.permissions?.includes("llm_configs:update") ?? false;
|
|
|
|
|
}, [access]);
|
|
|
|
|
const canDelete = useMemo(() => {
|
|
|
|
|
if (!access) return false;
|
|
|
|
|
if (access.is_owner) return true;
|
|
|
|
|
return access.permissions?.includes("llm_configs:delete") ?? false;
|
|
|
|
|
}, [access]);
|
|
|
|
|
const isReadOnly = !canCreate && !canUpdate && !canDelete;
|
|
|
|
|
|
2025-12-23 01:16:25 -08:00
|
|
|
// Local state
|
|
|
|
|
const [isDialogOpen, setIsDialogOpen] = useState(false);
|
|
|
|
|
const [editingConfig, setEditingConfig] = useState<NewLLMConfig | null>(null);
|
|
|
|
|
const [configToDelete, setConfigToDelete] = useState<NewLLMConfig | null>(null);
|
|
|
|
|
|
|
|
|
|
const isSubmitting = isCreating || isUpdating;
|
|
|
|
|
|
|
|
|
|
const handleFormSubmit = useCallback(
|
|
|
|
|
async (formData: LLMConfigFormData) => {
|
|
|
|
|
try {
|
|
|
|
|
if (editingConfig) {
|
2026-01-23 18:37:09 +05:30
|
|
|
const { search_space_id, ...updateData } = formData;
|
2025-12-23 01:16:25 -08:00
|
|
|
await updateConfig({
|
|
|
|
|
id: editingConfig.id,
|
2026-01-23 18:37:09 +05:30
|
|
|
data: updateData,
|
2025-12-23 01:16:25 -08:00
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
await createConfig(formData);
|
|
|
|
|
}
|
|
|
|
|
setIsDialogOpen(false);
|
|
|
|
|
setEditingConfig(null);
|
|
|
|
|
} catch {
|
2026-02-09 19:26:23 +05:30
|
|
|
// Error is displayed inside the dialog by the form
|
2025-12-23 01:16:25 -08:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
[editingConfig, createConfig, updateConfig]
|
|
|
|
|
);
|
2025-07-27 10:05:37 -07:00
|
|
|
|
2025-12-23 01:16:25 -08:00
|
|
|
const handleDelete = async () => {
|
|
|
|
|
if (!configToDelete) return;
|
|
|
|
|
try {
|
|
|
|
|
await deleteConfig({ id: configToDelete.id });
|
|
|
|
|
setConfigToDelete(null);
|
|
|
|
|
} catch {
|
2026-02-09 19:26:23 +05:30
|
|
|
// Error handled by mutation state
|
2025-07-27 10:05:37 -07:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2025-12-23 01:16:25 -08:00
|
|
|
const openEditDialog = (config: NewLLMConfig) => {
|
|
|
|
|
setEditingConfig(config);
|
|
|
|
|
setIsDialogOpen(true);
|
2025-10-12 19:10:46 +08:00
|
|
|
};
|
|
|
|
|
|
2025-12-23 01:16:25 -08:00
|
|
|
const openNewDialog = () => {
|
|
|
|
|
setEditingConfig(null);
|
|
|
|
|
setIsDialogOpen(true);
|
2025-07-27 10:05:37 -07:00
|
|
|
};
|
|
|
|
|
|
2025-12-23 01:16:25 -08:00
|
|
|
const closeDialog = () => {
|
|
|
|
|
setIsDialogOpen(false);
|
|
|
|
|
setEditingConfig(null);
|
2025-07-27 10:05:37 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
2026-02-09 19:00:57 +05:30
|
|
|
<div className="space-y-5 md:space-y-6">
|
|
|
|
|
{/* Header actions */}
|
|
|
|
|
<div className="flex items-center justify-between">
|
|
|
|
|
<Button
|
|
|
|
|
variant="outline"
|
|
|
|
|
size="sm"
|
|
|
|
|
onClick={() => refreshConfigs()}
|
|
|
|
|
disabled={isLoading}
|
|
|
|
|
className="flex items-center gap-2 text-xs md:text-sm h-8 md:h-9"
|
|
|
|
|
>
|
|
|
|
|
<RefreshCw className={cn("h-3 w-3 md:h-4 md:w-4", isLoading && "animate-spin")} />
|
|
|
|
|
Refresh
|
|
|
|
|
</Button>
|
2026-02-09 19:37:59 +05:30
|
|
|
{canCreate && (
|
|
|
|
|
<Button
|
|
|
|
|
onClick={openNewDialog}
|
|
|
|
|
size="sm"
|
|
|
|
|
className="flex items-center gap-2 text-xs md:text-sm h-8 md:h-9"
|
|
|
|
|
>
|
|
|
|
|
Add Configuration
|
|
|
|
|
</Button>
|
|
|
|
|
)}
|
2025-07-27 10:05:37 -07:00
|
|
|
</div>
|
|
|
|
|
|
2026-02-09 19:26:23 +05:30
|
|
|
{/* Fetch Error Alert */}
|
2025-12-23 01:16:25 -08:00
|
|
|
<AnimatePresence>
|
2026-02-09 19:26:23 +05:30
|
|
|
{fetchError && (
|
|
|
|
|
<motion.div
|
|
|
|
|
key="fetch-error"
|
|
|
|
|
initial={{ opacity: 0, y: -10 }}
|
|
|
|
|
animate={{ opacity: 1, y: 0 }}
|
|
|
|
|
exit={{ opacity: 0, y: -10 }}
|
|
|
|
|
>
|
|
|
|
|
<Alert variant="destructive" className="py-3 md:py-4">
|
|
|
|
|
<AlertCircle className="h-3 w-3 md:h-4 md:w-4 shrink-0" />
|
|
|
|
|
<AlertDescription className="text-xs md:text-sm">
|
|
|
|
|
{fetchError?.message ?? "Failed to load configurations"}
|
|
|
|
|
</AlertDescription>
|
|
|
|
|
</Alert>
|
|
|
|
|
</motion.div>
|
|
|
|
|
)}
|
2025-12-23 01:16:25 -08:00
|
|
|
</AnimatePresence>
|
|
|
|
|
|
2026-02-09 19:37:59 +05:30
|
|
|
{/* Read-only / Limited permissions notice */}
|
|
|
|
|
{access && !isLoading && isReadOnly && (
|
|
|
|
|
<motion.div initial={{ opacity: 0, y: -10 }} animate={{ opacity: 1, y: 0 }}>
|
|
|
|
|
<Alert className="bg-muted/50 py-3 md:py-4">
|
|
|
|
|
<Info className="h-3 w-3 md:h-4 md:w-4 shrink-0" />
|
|
|
|
|
<AlertDescription className="text-xs md:text-sm">
|
|
|
|
|
You have <span className="font-medium">read-only</span> access to LLM configurations.
|
|
|
|
|
Contact a space owner to request additional permissions.
|
|
|
|
|
</AlertDescription>
|
|
|
|
|
</Alert>
|
|
|
|
|
</motion.div>
|
|
|
|
|
)}
|
|
|
|
|
{access && !isLoading && !isReadOnly && (!canCreate || !canUpdate || !canDelete) && (
|
|
|
|
|
<motion.div initial={{ opacity: 0, y: -10 }} animate={{ opacity: 1, y: 0 }}>
|
|
|
|
|
<Alert className="bg-muted/50 py-3 md:py-4">
|
|
|
|
|
<Info className="h-3 w-3 md:h-4 md:w-4 shrink-0" />
|
|
|
|
|
<AlertDescription className="text-xs md:text-sm">
|
|
|
|
|
You can{" "}
|
|
|
|
|
{[canCreate && "create", canUpdate && "edit", canDelete && "delete"]
|
|
|
|
|
.filter(Boolean)
|
|
|
|
|
.join(" and ")}{" "}
|
|
|
|
|
configurations
|
|
|
|
|
{!canDelete && ", but cannot delete them"}.
|
|
|
|
|
</AlertDescription>
|
|
|
|
|
</Alert>
|
|
|
|
|
</motion.div>
|
|
|
|
|
)}
|
|
|
|
|
|
2025-12-23 01:16:25 -08:00
|
|
|
{/* Global Configs Info */}
|
|
|
|
|
{globalConfigs.length > 0 && (
|
|
|
|
|
<motion.div initial={{ opacity: 0, y: -10 }} animate={{ opacity: 1, y: 0 }}>
|
2026-02-09 19:00:57 +05:30
|
|
|
<Alert className="bg-muted/50 py-3 md:py-4">
|
|
|
|
|
<Info className="h-3 w-3 md:h-4 md:w-4 shrink-0" />
|
|
|
|
|
<AlertDescription className="text-xs md:text-sm">
|
2025-12-23 01:16:25 -08:00
|
|
|
<span className="font-medium">{globalConfigs.length} global configuration(s)</span>{" "}
|
|
|
|
|
available from your administrator. These are pre-configured and ready to use.{" "}
|
2026-02-09 19:00:57 +05:30
|
|
|
<span className="text-muted-foreground">
|
2025-12-23 01:16:25 -08:00
|
|
|
Global configs: {globalConfigs.map((g) => g.name).join(", ")}
|
|
|
|
|
</span>
|
|
|
|
|
</AlertDescription>
|
|
|
|
|
</Alert>
|
|
|
|
|
</motion.div>
|
2025-11-14 21:53:46 -08:00
|
|
|
)}
|
|
|
|
|
|
2026-02-09 19:26:23 +05:30
|
|
|
{/* Loading Skeleton */}
|
2025-12-23 01:16:25 -08:00
|
|
|
{isLoading && (
|
2026-02-09 19:26:23 +05:30
|
|
|
<div className="grid gap-3 grid-cols-1 sm:grid-cols-2 xl:grid-cols-3">
|
|
|
|
|
{["skeleton-a", "skeleton-b", "skeleton-c"].map((key) => (
|
|
|
|
|
<Card key={key} className="border-border/60">
|
|
|
|
|
<CardContent className="p-4 flex flex-col gap-3">
|
|
|
|
|
{/* Header */}
|
|
|
|
|
<div className="flex items-start justify-between gap-2">
|
|
|
|
|
<div className="space-y-1.5 flex-1 min-w-0">
|
|
|
|
|
<Skeleton className="h-4 w-28 md:w-32" />
|
|
|
|
|
<Skeleton className="h-3 w-40 md:w-48" />
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
{/* Provider + Model */}
|
|
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
|
<Skeleton className="h-5 w-16 rounded-full" />
|
|
|
|
|
<Skeleton className="h-5 w-24 rounded-md" />
|
|
|
|
|
</div>
|
|
|
|
|
{/* Feature badges */}
|
|
|
|
|
<div className="flex items-center gap-1.5">
|
|
|
|
|
<Skeleton className="h-5 w-20 rounded-full" />
|
|
|
|
|
<Skeleton className="h-5 w-16 rounded-full" />
|
|
|
|
|
</div>
|
|
|
|
|
{/* Footer */}
|
|
|
|
|
<div className="flex items-center gap-2 pt-2 border-t border-border/40">
|
|
|
|
|
<Skeleton className="h-3 w-20" />
|
|
|
|
|
<Skeleton className="h-4 w-4 rounded-full" />
|
|
|
|
|
<Skeleton className="h-3 w-16" />
|
|
|
|
|
</div>
|
|
|
|
|
</CardContent>
|
|
|
|
|
</Card>
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
2025-07-27 10:05:37 -07:00
|
|
|
)}
|
|
|
|
|
|
2025-12-23 01:16:25 -08:00
|
|
|
{/* Configurations List */}
|
|
|
|
|
{!isLoading && (
|
2026-02-09 19:00:57 +05:30
|
|
|
<div className="space-y-4">
|
2025-12-23 01:16:25 -08:00
|
|
|
{configs?.length === 0 ? (
|
|
|
|
|
<motion.div initial={{ opacity: 0, y: 20 }} animate={{ opacity: 1, y: 0 }}>
|
|
|
|
|
<Card className="border-dashed border-2 border-muted-foreground/25">
|
2025-12-29 01:22:22 +05:30
|
|
|
<CardContent className="flex flex-col items-center justify-center py-10 md:py-16 text-center">
|
|
|
|
|
<div className="rounded-full bg-gradient-to-br from-violet-500/10 to-purple-500/10 p-4 md:p-6 mb-4 md:mb-6">
|
|
|
|
|
<Wand2 className="h-8 w-8 md:h-12 md:w-12 text-violet-600 dark:text-violet-400" />
|
2025-12-23 01:16:25 -08:00
|
|
|
</div>
|
2025-12-29 01:22:22 +05:30
|
|
|
<div className="space-y-2 mb-4 md:mb-6">
|
|
|
|
|
<h3 className="text-lg md:text-xl font-semibold">No Configurations Yet</h3>
|
|
|
|
|
<p className="text-xs md:text-sm text-muted-foreground max-w-sm">
|
2026-02-09 19:37:59 +05:30
|
|
|
{canCreate
|
|
|
|
|
? "Create your first AI configuration to customize how your agent responds"
|
|
|
|
|
: "No AI configurations have been added to this space yet. Contact a space owner to add one."}
|
2025-12-23 01:16:25 -08:00
|
|
|
</p>
|
|
|
|
|
</div>
|
2026-02-09 19:37:59 +05:30
|
|
|
{canCreate && (
|
|
|
|
|
<Button
|
|
|
|
|
onClick={openNewDialog}
|
|
|
|
|
size="lg"
|
|
|
|
|
className="gap-2 text-xs md:text-sm h-9 md:h-10"
|
|
|
|
|
>
|
|
|
|
|
<Plus className="h-3 w-3 md:h-4 md:w-4" />
|
|
|
|
|
Create First Configuration
|
|
|
|
|
</Button>
|
|
|
|
|
)}
|
2025-12-23 01:16:25 -08:00
|
|
|
</CardContent>
|
|
|
|
|
</Card>
|
|
|
|
|
</motion.div>
|
2025-07-27 10:05:37 -07:00
|
|
|
) : (
|
2026-02-09 19:00:57 +05:30
|
|
|
<motion.div
|
|
|
|
|
variants={container}
|
|
|
|
|
initial="hidden"
|
|
|
|
|
animate="show"
|
|
|
|
|
className="grid gap-3 grid-cols-1 sm:grid-cols-2 xl:grid-cols-3"
|
|
|
|
|
>
|
2025-12-23 01:16:25 -08:00
|
|
|
<AnimatePresence mode="popLayout">
|
|
|
|
|
{configs?.map((config) => {
|
2026-02-09 19:00:57 +05:30
|
|
|
const member = config.user_id ? memberMap.get(config.user_id) : null;
|
|
|
|
|
|
2025-07-27 10:05:37 -07:00
|
|
|
return (
|
|
|
|
|
<motion.div
|
|
|
|
|
key={config.id}
|
2025-12-23 01:16:25 -08:00
|
|
|
variants={item}
|
|
|
|
|
layout
|
|
|
|
|
exit={{ opacity: 0, scale: 0.95 }}
|
2025-07-27 10:05:37 -07:00
|
|
|
>
|
2026-02-09 19:00:57 +05:30
|
|
|
<Card className="group relative overflow-hidden transition-all duration-200 border-border/60 hover:shadow-md h-full">
|
|
|
|
|
<CardContent className="p-4 flex flex-col gap-3 h-full">
|
|
|
|
|
{/* Header: Name + Actions */}
|
|
|
|
|
<div className="flex items-start justify-between gap-2">
|
|
|
|
|
<div className="min-w-0 flex-1">
|
|
|
|
|
<h4 className="text-sm font-semibold tracking-tight truncate">
|
|
|
|
|
{config.name}
|
|
|
|
|
</h4>
|
|
|
|
|
{config.description && (
|
|
|
|
|
<p className="text-[11px] text-muted-foreground/70 truncate mt-0.5">
|
|
|
|
|
{config.description}
|
|
|
|
|
</p>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
2026-02-09 19:37:59 +05:30
|
|
|
{(canUpdate || canDelete) && (
|
2026-02-10 19:06:21 +05:30
|
|
|
<div className="flex items-center gap-0.5 shrink-0 sm:opacity-0 sm:group-hover:opacity-100 transition-opacity duration-150">
|
|
|
|
|
{canUpdate && (
|
|
|
|
|
<TooltipProvider>
|
|
|
|
|
<Tooltip>
|
|
|
|
|
<TooltipTrigger asChild>
|
|
|
|
|
<Button
|
|
|
|
|
variant="ghost"
|
|
|
|
|
size="icon"
|
|
|
|
|
onClick={() => openEditDialog(config)}
|
|
|
|
|
className="h-7 w-7 text-muted-foreground hover:text-foreground"
|
|
|
|
|
>
|
|
|
|
|
<Edit3 className="h-3 w-3" />
|
|
|
|
|
</Button>
|
|
|
|
|
</TooltipTrigger>
|
|
|
|
|
<TooltipContent>Edit</TooltipContent>
|
|
|
|
|
</Tooltip>
|
|
|
|
|
</TooltipProvider>
|
|
|
|
|
)}
|
|
|
|
|
{canDelete && (
|
|
|
|
|
<TooltipProvider>
|
|
|
|
|
<Tooltip>
|
|
|
|
|
<TooltipTrigger asChild>
|
|
|
|
|
<Button
|
|
|
|
|
variant="ghost"
|
|
|
|
|
size="icon"
|
|
|
|
|
onClick={() => setConfigToDelete(config)}
|
|
|
|
|
className="h-7 w-7 text-muted-foreground hover:text-destructive"
|
|
|
|
|
>
|
|
|
|
|
<Trash2 className="h-3 w-3" />
|
|
|
|
|
</Button>
|
|
|
|
|
</TooltipTrigger>
|
|
|
|
|
<TooltipContent>Delete</TooltipContent>
|
|
|
|
|
</Tooltip>
|
|
|
|
|
</TooltipProvider>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
2026-02-09 19:00:57 +05:30
|
|
|
</div>
|
2025-12-13 22:43:38 -08:00
|
|
|
|
2026-02-09 19:00:57 +05:30
|
|
|
{/* Provider + Model */}
|
|
|
|
|
<div className="flex items-center gap-2 flex-wrap">
|
2026-02-09 20:48:42 +05:30
|
|
|
{getProviderIcon(config.provider, { className: "size-3.5 shrink-0" })}
|
2026-02-09 19:00:57 +05:30
|
|
|
<code className="text-[11px] font-mono text-muted-foreground bg-muted/60 px-2 py-0.5 rounded-md truncate max-w-[160px]">
|
|
|
|
|
{config.model_name}
|
|
|
|
|
</code>
|
|
|
|
|
</div>
|
2025-12-23 01:16:25 -08:00
|
|
|
|
2026-02-09 19:00:57 +05:30
|
|
|
{/* Feature badges */}
|
|
|
|
|
<div className="flex items-center gap-1.5 flex-wrap">
|
|
|
|
|
{config.citations_enabled && (
|
|
|
|
|
<Badge
|
|
|
|
|
variant="outline"
|
|
|
|
|
className="text-[10px] px-1.5 py-0.5 border-emerald-500/30 text-emerald-700 dark:text-emerald-300 bg-emerald-500/5"
|
|
|
|
|
>
|
|
|
|
|
<MessageSquareQuote className="h-2.5 w-2.5 mr-1" />
|
|
|
|
|
Citations
|
|
|
|
|
</Badge>
|
|
|
|
|
)}
|
|
|
|
|
{!config.use_default_system_instructions &&
|
|
|
|
|
config.system_instructions && (
|
|
|
|
|
<Badge
|
|
|
|
|
variant="outline"
|
|
|
|
|
className="text-[10px] px-1.5 py-0.5 border-blue-500/30 text-blue-700 dark:text-blue-300 bg-blue-500/5"
|
|
|
|
|
>
|
|
|
|
|
<FileText className="h-2.5 w-2.5 mr-1" />
|
|
|
|
|
Custom
|
|
|
|
|
</Badge>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
2025-07-27 10:05:37 -07:00
|
|
|
|
2026-02-09 19:00:57 +05:30
|
|
|
{/* Footer: Date + Creator */}
|
|
|
|
|
<div className="flex items-center gap-2 pt-2 border-t border-border/40 mt-auto">
|
|
|
|
|
<span className="text-[11px] text-muted-foreground/60">
|
2026-02-10 19:06:21 +05:30
|
|
|
{new Date(config.created_at).toLocaleDateString(undefined, {
|
|
|
|
|
year: "numeric",
|
|
|
|
|
month: "short",
|
|
|
|
|
day: "numeric",
|
|
|
|
|
})}
|
2026-02-09 19:00:57 +05:30
|
|
|
</span>
|
|
|
|
|
{member && (
|
|
|
|
|
<>
|
|
|
|
|
<span className="text-muted-foreground/30">·</span>
|
|
|
|
|
<TooltipProvider>
|
|
|
|
|
<Tooltip>
|
|
|
|
|
<TooltipTrigger asChild>
|
|
|
|
|
<div className="flex items-center gap-1.5 cursor-default">
|
|
|
|
|
{member.avatarUrl ? (
|
|
|
|
|
<Image
|
|
|
|
|
src={member.avatarUrl}
|
|
|
|
|
alt={member.name}
|
|
|
|
|
width={18}
|
|
|
|
|
height={18}
|
|
|
|
|
className="h-4.5 w-4.5 rounded-full object-cover shrink-0"
|
|
|
|
|
/>
|
|
|
|
|
) : (
|
|
|
|
|
<div className="flex h-4.5 w-4.5 items-center justify-center rounded-full bg-gradient-to-br from-primary/20 to-primary/5 shrink-0">
|
|
|
|
|
<span className="text-[9px] font-semibold text-primary">
|
|
|
|
|
{getInitials(member.name)}
|
|
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
2026-02-09 19:26:23 +05:30
|
|
|
<span className="text-[11px] text-muted-foreground/60 truncate max-w-[120px]">
|
2026-02-09 19:00:57 +05:30
|
|
|
{member.name}
|
2025-12-13 22:43:38 -08:00
|
|
|
</span>
|
|
|
|
|
</div>
|
2026-02-09 19:00:57 +05:30
|
|
|
</TooltipTrigger>
|
|
|
|
|
<TooltipContent side="bottom">
|
|
|
|
|
{member.email || member.name}
|
|
|
|
|
</TooltipContent>
|
|
|
|
|
</Tooltip>
|
|
|
|
|
</TooltipProvider>
|
|
|
|
|
</>
|
|
|
|
|
)}
|
2025-07-27 10:05:37 -07:00
|
|
|
</div>
|
|
|
|
|
</CardContent>
|
|
|
|
|
</Card>
|
|
|
|
|
</motion.div>
|
|
|
|
|
);
|
|
|
|
|
})}
|
|
|
|
|
</AnimatePresence>
|
2025-12-23 01:16:25 -08:00
|
|
|
</motion.div>
|
2025-07-27 10:05:37 -07:00
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
{/* Add/Edit Configuration Dialog */}
|
2025-12-23 01:16:25 -08:00
|
|
|
<Dialog open={isDialogOpen} onOpenChange={(open) => !open && closeDialog()}>
|
2026-02-09 19:00:57 +05:30
|
|
|
<DialogContent
|
|
|
|
|
className="max-w-2xl max-h-[90vh] overflow-y-auto"
|
|
|
|
|
onOpenAutoFocus={(e) => e.preventDefault()}
|
|
|
|
|
>
|
2025-07-27 10:05:37 -07:00
|
|
|
<DialogHeader>
|
2026-02-09 19:26:23 +05:30
|
|
|
<DialogTitle>
|
2025-12-23 01:16:25 -08:00
|
|
|
{editingConfig ? "Edit Configuration" : "Create New Configuration"}
|
2025-07-27 10:05:37 -07:00
|
|
|
</DialogTitle>
|
|
|
|
|
<DialogDescription>
|
|
|
|
|
{editingConfig
|
2025-12-23 01:16:25 -08:00
|
|
|
? "Update your AI model and prompt configuration"
|
|
|
|
|
: "Set up a new AI model with custom prompts and citation settings"}
|
2025-07-27 10:05:37 -07:00
|
|
|
</DialogDescription>
|
|
|
|
|
</DialogHeader>
|
|
|
|
|
|
2025-12-23 01:16:25 -08:00
|
|
|
<LLMConfigForm
|
|
|
|
|
key={editingConfig ? `edit-${editingConfig.id}` : "create"}
|
|
|
|
|
searchSpaceId={searchSpaceId}
|
|
|
|
|
initialData={
|
|
|
|
|
editingConfig
|
|
|
|
|
? {
|
|
|
|
|
name: editingConfig.name,
|
|
|
|
|
description: editingConfig.description || "",
|
|
|
|
|
provider: editingConfig.provider,
|
|
|
|
|
custom_provider: editingConfig.custom_provider || "",
|
|
|
|
|
model_name: editingConfig.model_name,
|
|
|
|
|
api_key: editingConfig.api_key,
|
|
|
|
|
api_base: editingConfig.api_base || "",
|
|
|
|
|
litellm_params: editingConfig.litellm_params || {},
|
|
|
|
|
system_instructions: editingConfig.system_instructions || "",
|
|
|
|
|
use_default_system_instructions: editingConfig.use_default_system_instructions,
|
|
|
|
|
citations_enabled: editingConfig.citations_enabled,
|
|
|
|
|
}
|
|
|
|
|
: {
|
|
|
|
|
citations_enabled: true,
|
|
|
|
|
use_default_system_instructions: true,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
onSubmit={handleFormSubmit}
|
|
|
|
|
onCancel={closeDialog}
|
|
|
|
|
isSubmitting={isSubmitting}
|
|
|
|
|
mode={editingConfig ? "edit" : "create"}
|
|
|
|
|
showAdvanced={true}
|
|
|
|
|
compact={true}
|
|
|
|
|
/>
|
2025-07-27 10:05:37 -07:00
|
|
|
</DialogContent>
|
|
|
|
|
</Dialog>
|
2025-12-13 22:43:38 -08:00
|
|
|
|
|
|
|
|
{/* Delete Confirmation Dialog */}
|
|
|
|
|
<AlertDialog
|
|
|
|
|
open={!!configToDelete}
|
|
|
|
|
onOpenChange={(open) => !open && setConfigToDelete(null)}
|
|
|
|
|
>
|
|
|
|
|
<AlertDialogContent>
|
|
|
|
|
<AlertDialogHeader>
|
|
|
|
|
<AlertDialogTitle className="flex items-center gap-2">
|
|
|
|
|
<Trash2 className="h-5 w-5 text-destructive" />
|
|
|
|
|
Delete Configuration
|
|
|
|
|
</AlertDialogTitle>
|
|
|
|
|
<AlertDialogDescription>
|
|
|
|
|
Are you sure you want to delete{" "}
|
|
|
|
|
<span className="font-semibold text-foreground">{configToDelete?.name}</span>? This
|
2025-12-23 01:16:25 -08:00
|
|
|
action cannot be undone.
|
2025-12-13 22:43:38 -08:00
|
|
|
</AlertDialogDescription>
|
|
|
|
|
</AlertDialogHeader>
|
|
|
|
|
<AlertDialogFooter>
|
|
|
|
|
<AlertDialogCancel disabled={isDeleting}>Cancel</AlertDialogCancel>
|
|
|
|
|
<AlertDialogAction
|
2025-12-23 01:16:25 -08:00
|
|
|
onClick={handleDelete}
|
2025-12-13 22:43:38 -08:00
|
|
|
disabled={isDeleting}
|
|
|
|
|
className="bg-destructive text-destructive-foreground hover:bg-destructive/90"
|
|
|
|
|
>
|
|
|
|
|
{isDeleting ? (
|
|
|
|
|
<>
|
2026-01-25 15:23:45 +05:30
|
|
|
<Spinner size="sm" className="mr-2" />
|
2026-01-23 18:37:09 +05:30
|
|
|
Deleting
|
2025-12-13 22:43:38 -08:00
|
|
|
</>
|
|
|
|
|
) : (
|
|
|
|
|
<>
|
|
|
|
|
<Trash2 className="mr-2 h-4 w-4" />
|
|
|
|
|
Delete
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
</AlertDialogAction>
|
|
|
|
|
</AlertDialogFooter>
|
|
|
|
|
</AlertDialogContent>
|
|
|
|
|
</AlertDialog>
|
2025-07-27 10:05:37 -07:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|