Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 4x 4x 7x 7x 7x 7x 7x 4x 4x 4x 4x 4x 4x 4x 4x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 1x 1x 5x 5x 5x 5x 5x 5x 5x 1x 1x 6x 1x 1x 1x 1x 1x 1x 5x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 7x 7x 7x 7x 7x | 'use client';
import { type AIProvider, PrettyAIProvider } from '@shared/types/constants';
import type { Model } from '@shared/types/data/model';
import { deleteModel } from '@web/api/v1/super-agents/models';
import { Badge } from '@web/components/ui/badge';
import { Button } from '@web/components/ui/button';
import {
Card,
CardContent,
CardDescription,
CardHeader,
CardTitle,
} from '@web/components/ui/card';
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuTrigger,
} from '@web/components/ui/dropdown-menu';
import { Input } from '@web/components/ui/input';
import { PageHeader } from '@web/components/ui/page-header';
import { PermissiveLink as Link } from '@web/components/ui/permissive-link';
import { Skeleton } from '@web/components/ui/skeleton';
import {
Table,
TableBody,
TableCell,
TableHead,
TableHeader,
TableRow,
} from '@web/components/ui/table';
import {
Tooltip,
TooltipContent,
TooltipTrigger,
} from '@web/components/ui/tooltip';
import { useToast } from '@web/hooks/use-toast';
import { useAIProviders } from '@web/providers/ai-providers';
import { useModels } from '@web/providers/models';
import { compareModels } from '@web/utils/model-sorting';
import { format } from 'date-fns';
import {
CalendarIcon,
CpuIcon,
MoreHorizontalIcon,
PlusIcon,
RefreshCwIcon,
SearchIcon,
TrashIcon,
} from 'lucide-react';
import { nanoid } from 'nanoid';
import type { ReactElement } from 'react';
import { useEffect, useState } from 'react';
export function ModelsListView(): ReactElement {
const { toast } = useToast();
const { models, isLoading, error, setQueryParams, refetch } = useModels();
const { aiProviderConfigs: apiKeys } = useAIProviders();
const [searchQuery, setSearchQuery] = useState('');
const [isDeleting, setIsDeleting] = useState<string | null>(null);
// Initialize with empty query params to load all models
useEffect(() => {
setQueryParams({});
}, [setQueryParams]);
// Filter models and sort alphabetically by model name, then by provider
const filteredModels = models
.filter((model) => {
if (searchQuery) {
const searchLower = searchQuery.toLowerCase();
const apiKey = apiKeys.find((key) => key.id === model.ai_provider_id);
return (
model.model_name.toLowerCase().includes(searchLower) ||
apiKey?.ai_provider?.toLowerCase().includes(searchLower) ||
apiKey?.name?.toLowerCase().includes(searchLower)
);
}
return true;
})
.sort((a, b) => {
const providerA = apiKeys.find((k) => k.id === a.ai_provider_id);
const providerB = apiKeys.find((k) => k.id === b.ai_provider_id);
return compareModels(
{ modelName: a.model_name, providerName: providerA?.name || '' },
{ modelName: b.model_name, providerName: providerB?.name || '' },
);
});
const handleDeleteModel = async (model: Model) => {
if (isDeleting) return;
try {
setIsDeleting(model.id);
await deleteModel(model.id);
toast({
title: 'Model deleted',
description: `Model "${model.model_name}" has been deleted successfully.`,
});
await refetch();
} catch (error) {
toast({
title: 'Failed to delete model',
description:
error instanceof Error
? error.message
: 'An unexpected error occurred.',
variant: 'destructive',
});
} finally {
setIsDeleting(null);
}
};
const getProviderInfo = (apiKeyId: string) => {
const apiKey = apiKeys.find((key) => key.id === apiKeyId);
const rawProvider = apiKey?.ai_provider as AIProvider;
return {
provider: rawProvider
? PrettyAIProvider[rawProvider] || rawProvider
: 'Unknown',
name: apiKey?.name || 'Unknown',
};
};
return (
<>
<PageHeader
title="Models"
description="Manage AI models available in your workspace"
actions={
<Button asChild>
<Link to="/models/create">
<PlusIcon className="h-4 w-4 mr-2" />
Add Model
</Link>
</Button>
}
/>
<div className="p-6 space-y-6">
{/* Search and Controls */}
<Card>
<CardHeader>
<CardTitle>Filter Models</CardTitle>
<CardDescription>Search and filter your AI models</CardDescription>
</CardHeader>
<CardContent className="space-y-4">
<div className="flex flex-col sm:flex-row gap-4">
<div className="flex-1">
<div className="relative">
<SearchIcon className="absolute left-3 top-1/2 transform -translate-y-1/2 text-muted-foreground h-4 w-4" />
<Input
placeholder="Search models or providers..."
value={searchQuery}
onChange={(e) => setSearchQuery(e.target.value)}
className="pl-10"
/>
</div>
</div>
<Button variant="outline" size="icon" onClick={refetch}>
<RefreshCwIcon className="h-4 w-4" />
</Button>
</div>
</CardContent>
</Card>
{/* Models List */}
<Card>
<CardHeader>
<div className="flex items-center justify-between">
<div>
<CardTitle className="flex items-center gap-2">
<CpuIcon className="h-5 w-5" />
Models ({filteredModels.length})
</CardTitle>
<CardDescription>
AI models configured in your workspace
</CardDescription>
</div>
{!searchQuery && (
<Button asChild>
<Link to="/models/create">
<PlusIcon className="h-4 w-4 mr-2" />
Add Model
</Link>
</Button>
)}
</div>
</CardHeader>
<CardContent>
{isLoading ? (
<div className="space-y-3">
{Array.from({ length: 5 }).map((_) => (
<div key={nanoid()} className="flex items-center space-x-4">
<Skeleton className="h-12 w-12 rounded-full" />
<div className="space-y-2 flex-1">
<Skeleton className="h-4 w-3/4" />
<Skeleton className="h-3 w-1/2" />
</div>
</div>
))}
</div>
) : error ? (
<div className="text-center py-8">
<p className="text-destructive mb-4">{error}</p>
<Button variant="outline" onClick={refetch}>
<RefreshCwIcon className="h-4 w-4 mr-2" />
Retry
</Button>
</div>
) : filteredModels.length === 0 ? (
<div className="text-center py-8">
<CpuIcon className="h-12 w-12 text-muted-foreground mx-auto mb-4" />
<h3 className="text-lg font-semibold mb-2">
{searchQuery ? 'No models found' : 'No models configured'}
</h3>
<p className="text-muted-foreground mb-4">
{searchQuery
? 'No models match your search criteria.'
: 'Get started by adding your first AI model.'}
</p>
{!searchQuery && (
<Button asChild>
<Link to="/models/create">
<PlusIcon className="h-4 w-4 mr-2" />
Add Your First Model
</Link>
</Button>
)}
</div>
) : (
<div className="overflow-x-auto">
<Table>
<TableHeader>
<TableRow>
<TableHead>Model</TableHead>
<TableHead>Type</TableHead>
<TableHead>Provider</TableHead>
<TableHead>API Key</TableHead>
<TableHead>Created</TableHead>
<TableHead className="w-20">Actions</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{filteredModels.map((model) => {
const providerInfo = getProviderInfo(
model.ai_provider_id,
);
return (
<TableRow key={model.id}>
<TableCell>
<div className="flex items-center space-x-3">
<div className="flex h-10 w-10 items-center justify-center rounded-full bg-muted">
<CpuIcon className="h-5 w-5" />
</div>
<div>
<div className="font-medium">
{model.model_name}
</div>
<div className="text-sm text-muted-foreground">
ID: {model.id.slice(0, 8)}...
</div>
</div>
</div>
</TableCell>
<TableCell>
<Badge variant="outline">
{model.model_type === 'embed'
? `Embed (${model.embedding_dimensions})`
: 'Text'}
</Badge>
</TableCell>
<TableCell>
<Badge variant="outline">
{providerInfo.provider}
</Badge>
</TableCell>
<TableCell>
<div className="font-medium">
{providerInfo.name}
</div>
</TableCell>
<TableCell>
<Tooltip>
<TooltipTrigger>
<div className="flex items-center text-sm text-muted-foreground">
<CalendarIcon className="h-4 w-4 mr-1" />
{format(
new Date(model.created_at),
'MMM dd, yyyy',
)}
</div>
</TooltipTrigger>
<TooltipContent>
<p>
{format(new Date(model.created_at), 'PPpp')}
</p>
</TooltipContent>
</Tooltip>
</TableCell>
<TableCell>
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button
variant="ghost"
size="icon"
className="h-8 w-8"
>
<MoreHorizontalIcon className="h-4 w-4" />
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end">
<DropdownMenuItem asChild>
<Link to={`/models/${model.id}/edit`}>
Edit
</Link>
</DropdownMenuItem>
<DropdownMenuItem
className="text-destructive"
onClick={() => handleDeleteModel(model)}
disabled={isDeleting === model.id}
>
<TrashIcon className="h-4 w-4 mr-2" />
{isDeleting === model.id
? 'Deleting...'
: 'Delete'}
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</TableCell>
</TableRow>
);
})}
</TableBody>
</Table>
</div>
)}
</CardContent>
</Card>
</div>
</>
);
}
|