mirror of
https://github.com/tiennm99/ccs.git
synced 2026-09-02 10:19:37 +00:00
refactor(ui): remove old flat component files after reorganization
- delete 42 root-level component files - files moved to domain directories (account/, health/, layout/, etc.)
This commit is contained in:
@@ -1,150 +0,0 @@
|
|||||||
/**
|
|
||||||
* Accounts Table Component
|
|
||||||
* Phase 03: REST API Routes & CRUD
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { useReactTable, getCoreRowModel, flexRender, type ColumnDef } from '@tanstack/react-table';
|
|
||||||
import {
|
|
||||||
Table,
|
|
||||||
TableBody,
|
|
||||||
TableCell,
|
|
||||||
TableHead,
|
|
||||||
TableHeader,
|
|
||||||
TableRow,
|
|
||||||
} from '@/components/ui/table';
|
|
||||||
import { Button } from '@/components/ui/button';
|
|
||||||
import { Check } from 'lucide-react';
|
|
||||||
import { useSetDefaultAccount } from '@/hooks/use-accounts';
|
|
||||||
import type { Account } from '@/lib/api-client';
|
|
||||||
|
|
||||||
interface AccountsTableProps {
|
|
||||||
data: Account[];
|
|
||||||
defaultAccount: string | null;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function AccountsTable({ data, defaultAccount }: AccountsTableProps) {
|
|
||||||
const setDefaultMutation = useSetDefaultAccount();
|
|
||||||
|
|
||||||
const columns: ColumnDef<Account>[] = [
|
|
||||||
{
|
|
||||||
accessorKey: 'name',
|
|
||||||
header: 'Name',
|
|
||||||
size: 200,
|
|
||||||
cell: ({ row }) => (
|
|
||||||
<div className="flex items-center gap-2">
|
|
||||||
<span className="font-medium">{row.original.name}</span>
|
|
||||||
{row.original.name === defaultAccount && (
|
|
||||||
<span className="text-xs bg-primary/10 text-primary px-1.5 py-0.5 rounded border border-primary/20">
|
|
||||||
default
|
|
||||||
</span>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
accessorKey: 'type',
|
|
||||||
header: 'Type',
|
|
||||||
size: 100,
|
|
||||||
cell: ({ row }) => (
|
|
||||||
<span className="capitalize text-muted-foreground">{row.original.type || 'oauth'}</span>
|
|
||||||
),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
accessorKey: 'created',
|
|
||||||
header: 'Created',
|
|
||||||
size: 150,
|
|
||||||
cell: ({ row }) => {
|
|
||||||
const date = new Date(row.original.created);
|
|
||||||
return <span className="text-muted-foreground">{date.toLocaleDateString()}</span>;
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
accessorKey: 'last_used',
|
|
||||||
header: 'Last Used',
|
|
||||||
size: 150,
|
|
||||||
cell: ({ row }) => {
|
|
||||||
if (!row.original.last_used) return <span className="text-muted-foreground/50">-</span>;
|
|
||||||
const date = new Date(row.original.last_used);
|
|
||||||
return <span className="text-muted-foreground">{date.toLocaleDateString()}</span>;
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 'actions',
|
|
||||||
header: 'Actions',
|
|
||||||
size: 100,
|
|
||||||
cell: ({ row }) => {
|
|
||||||
const isDefault = row.original.name === defaultAccount;
|
|
||||||
return (
|
|
||||||
<Button
|
|
||||||
variant={isDefault ? 'secondary' : 'default'}
|
|
||||||
size="sm"
|
|
||||||
className="h-8 px-2 w-full"
|
|
||||||
disabled={isDefault || setDefaultMutation.isPending}
|
|
||||||
onClick={() => setDefaultMutation.mutate(row.original.name)}
|
|
||||||
>
|
|
||||||
<Check className={`w-3 h-3 mr-1.5 ${isDefault ? 'opacity-50' : ''}`} />
|
|
||||||
{isDefault ? 'Active' : 'Set Default'}
|
|
||||||
</Button>
|
|
||||||
);
|
|
||||||
},
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
// eslint-disable-next-line react-hooks/incompatible-library
|
|
||||||
const table = useReactTable({
|
|
||||||
data,
|
|
||||||
columns,
|
|
||||||
getCoreRowModel: getCoreRowModel(),
|
|
||||||
});
|
|
||||||
|
|
||||||
if (data.length === 0) {
|
|
||||||
return (
|
|
||||||
<div className="text-center py-8 text-muted-foreground">
|
|
||||||
No accounts found. Use <code className="text-sm bg-muted px-1 rounded">ccs login</code> to
|
|
||||||
add accounts.
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="border rounded-md">
|
|
||||||
<Table>
|
|
||||||
<TableHeader>
|
|
||||||
{table.getHeaderGroups().map((headerGroup) => (
|
|
||||||
<TableRow key={headerGroup.id}>
|
|
||||||
{headerGroup.headers.map((header) => {
|
|
||||||
const widthClass =
|
|
||||||
{
|
|
||||||
name: 'w-[200px]',
|
|
||||||
type: 'w-[100px]',
|
|
||||||
created: 'w-[150px]',
|
|
||||||
last_used: 'w-[150px]',
|
|
||||||
actions: 'w-[100px]',
|
|
||||||
}[header.id] || 'w-auto';
|
|
||||||
|
|
||||||
return (
|
|
||||||
<TableHead key={header.id} className={widthClass}>
|
|
||||||
{header.isPlaceholder
|
|
||||||
? null
|
|
||||||
: flexRender(header.column.columnDef.header, header.getContext())}
|
|
||||||
</TableHead>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</TableRow>
|
|
||||||
))}
|
|
||||||
</TableHeader>
|
|
||||||
<TableBody>
|
|
||||||
{table.getRowModel().rows.map((row) => (
|
|
||||||
<TableRow key={row.id}>
|
|
||||||
{row.getVisibleCells().map((cell) => (
|
|
||||||
<TableCell key={cell.id}>
|
|
||||||
{flexRender(cell.column.columnDef.cell, cell.getContext())}
|
|
||||||
</TableCell>
|
|
||||||
))}
|
|
||||||
</TableRow>
|
|
||||||
))}
|
|
||||||
</TableBody>
|
|
||||||
</Table>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,128 +0,0 @@
|
|||||||
/**
|
|
||||||
* Add Account Dialog Component
|
|
||||||
* Triggers OAuth flow server-side to add another account to a provider
|
|
||||||
* Applies default preset when adding first account
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { useState } from 'react';
|
|
||||||
import {
|
|
||||||
Dialog,
|
|
||||||
DialogContent,
|
|
||||||
DialogHeader,
|
|
||||||
DialogTitle,
|
|
||||||
DialogDescription,
|
|
||||||
} from '@/components/ui/dialog';
|
|
||||||
import { Button } from '@/components/ui/button';
|
|
||||||
import { Input } from '@/components/ui/input';
|
|
||||||
import { Label } from '@/components/ui/label';
|
|
||||||
import { Loader2, ExternalLink, User } from 'lucide-react';
|
|
||||||
import { useStartAuth } from '@/hooks/use-cliproxy';
|
|
||||||
import { applyDefaultPreset } from '@/lib/preset-utils';
|
|
||||||
import { toast } from 'sonner';
|
|
||||||
|
|
||||||
interface AddAccountDialogProps {
|
|
||||||
open: boolean;
|
|
||||||
onClose: () => void;
|
|
||||||
provider: string;
|
|
||||||
displayName: string;
|
|
||||||
/** Whether this is the first account being added (triggers preset application) */
|
|
||||||
isFirstAccount?: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function AddAccountDialog({
|
|
||||||
open,
|
|
||||||
onClose,
|
|
||||||
provider,
|
|
||||||
displayName,
|
|
||||||
isFirstAccount = false,
|
|
||||||
}: AddAccountDialogProps) {
|
|
||||||
const [nickname, setNickname] = useState('');
|
|
||||||
const startAuthMutation = useStartAuth();
|
|
||||||
|
|
||||||
const handleStartAuth = () => {
|
|
||||||
startAuthMutation.mutate(
|
|
||||||
{ provider, nickname: nickname.trim() || undefined },
|
|
||||||
{
|
|
||||||
onSuccess: async () => {
|
|
||||||
// Apply default preset if this is the first account
|
|
||||||
if (isFirstAccount) {
|
|
||||||
const result = await applyDefaultPreset(provider);
|
|
||||||
if (result.success && result.presetName) {
|
|
||||||
toast.success(`Applied "${result.presetName}" preset`);
|
|
||||||
} else if (!result.success) {
|
|
||||||
toast.warning('Account added, but failed to apply default preset');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
setNickname('');
|
|
||||||
onClose();
|
|
||||||
},
|
|
||||||
}
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleOpenChange = (isOpen: boolean) => {
|
|
||||||
if (!isOpen && !startAuthMutation.isPending) {
|
|
||||||
setNickname('');
|
|
||||||
onClose();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Dialog open={open} onOpenChange={handleOpenChange}>
|
|
||||||
<DialogContent className="sm:max-w-md">
|
|
||||||
<DialogHeader>
|
|
||||||
<DialogTitle>Add {displayName} Account</DialogTitle>
|
|
||||||
<DialogDescription>
|
|
||||||
Click the button below to authenticate a new account. A browser window will open for
|
|
||||||
OAuth.
|
|
||||||
</DialogDescription>
|
|
||||||
</DialogHeader>
|
|
||||||
|
|
||||||
<div className="space-y-4 py-4">
|
|
||||||
<div className="space-y-2">
|
|
||||||
<Label htmlFor="nickname">Nickname (optional)</Label>
|
|
||||||
<div className="flex items-center gap-2">
|
|
||||||
<User className="w-4 h-4 text-muted-foreground" />
|
|
||||||
<Input
|
|
||||||
id="nickname"
|
|
||||||
value={nickname}
|
|
||||||
onChange={(e) => setNickname(e.target.value)}
|
|
||||||
placeholder="e.g., work, personal"
|
|
||||||
disabled={startAuthMutation.isPending}
|
|
||||||
className="flex-1"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<p className="text-xs text-muted-foreground">
|
|
||||||
A friendly name to identify this account. Auto-generated from email if left empty.
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="flex items-center justify-end gap-2 pt-2">
|
|
||||||
<Button variant="ghost" onClick={onClose} disabled={startAuthMutation.isPending}>
|
|
||||||
Cancel
|
|
||||||
</Button>
|
|
||||||
<Button onClick={handleStartAuth} disabled={startAuthMutation.isPending}>
|
|
||||||
{startAuthMutation.isPending ? (
|
|
||||||
<>
|
|
||||||
<Loader2 className="w-4 h-4 mr-2 animate-spin" />
|
|
||||||
Authenticating...
|
|
||||||
</>
|
|
||||||
) : (
|
|
||||||
<>
|
|
||||||
<ExternalLink className="w-4 h-4 mr-2" />
|
|
||||||
Authenticate
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{startAuthMutation.isPending && (
|
|
||||||
<p className="text-sm text-center text-muted-foreground">
|
|
||||||
Complete the OAuth flow in your browser...
|
|
||||||
</p>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</DialogContent>
|
|
||||||
</Dialog>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,167 +0,0 @@
|
|||||||
import { Link, useLocation } from 'react-router-dom';
|
|
||||||
import {
|
|
||||||
Home,
|
|
||||||
Key,
|
|
||||||
Zap,
|
|
||||||
Users,
|
|
||||||
Settings,
|
|
||||||
Activity,
|
|
||||||
FolderOpen,
|
|
||||||
ChevronRight,
|
|
||||||
BarChart3,
|
|
||||||
Gauge,
|
|
||||||
Github,
|
|
||||||
} from 'lucide-react';
|
|
||||||
import {
|
|
||||||
Sidebar,
|
|
||||||
SidebarContent,
|
|
||||||
SidebarMenu,
|
|
||||||
SidebarMenuItem,
|
|
||||||
SidebarMenuButton,
|
|
||||||
SidebarMenuSub,
|
|
||||||
SidebarMenuSubItem,
|
|
||||||
SidebarMenuSubButton,
|
|
||||||
SidebarGroup,
|
|
||||||
SidebarGroupLabel,
|
|
||||||
SidebarHeader,
|
|
||||||
SidebarFooter,
|
|
||||||
SidebarTrigger,
|
|
||||||
SidebarGroupContent,
|
|
||||||
} from '@/components/ui/sidebar';
|
|
||||||
import { CcsLogo } from '@/components/ccs-logo';
|
|
||||||
import { useSidebar } from '@/hooks/use-sidebar';
|
|
||||||
import { Collapsible, CollapsibleContent, CollapsibleTrigger } from '@/components/ui/collapsible';
|
|
||||||
|
|
||||||
// Define navigation groups
|
|
||||||
const navGroups = [
|
|
||||||
{
|
|
||||||
title: 'General',
|
|
||||||
items: [
|
|
||||||
{ path: '/', icon: Home, label: 'Home' },
|
|
||||||
{ path: '/analytics', icon: BarChart3, label: 'Analytics' },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: 'Identity & Access',
|
|
||||||
items: [
|
|
||||||
{ path: '/api', icon: Key, label: 'API Profiles' },
|
|
||||||
{
|
|
||||||
path: '/cliproxy',
|
|
||||||
icon: Zap,
|
|
||||||
label: 'CLIProxy',
|
|
||||||
isCollapsible: true,
|
|
||||||
children: [
|
|
||||||
{ path: '/cliproxy', label: 'Overview' },
|
|
||||||
{ path: '/cliproxy/control-panel', icon: Gauge, label: 'Control Panel' },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{ path: '/copilot', icon: Github, label: 'GitHub Copilot' },
|
|
||||||
{
|
|
||||||
path: '/accounts',
|
|
||||||
icon: Users,
|
|
||||||
label: 'Accounts',
|
|
||||||
isCollapsible: true,
|
|
||||||
children: [
|
|
||||||
{ path: '/accounts', label: 'All Accounts' },
|
|
||||||
{ path: '/shared', icon: FolderOpen, label: 'Shared Data' },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: 'System',
|
|
||||||
items: [
|
|
||||||
{ path: '/health', icon: Activity, label: 'Health' },
|
|
||||||
{ path: '/settings', icon: Settings, label: 'Settings' },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
export function AppSidebar() {
|
|
||||||
const location = useLocation();
|
|
||||||
const { state } = useSidebar();
|
|
||||||
|
|
||||||
// Helper to check if a route is active (exact match)
|
|
||||||
const isRouteActive = (path: string) => location.pathname === path;
|
|
||||||
|
|
||||||
// Helper to check if a group/parent should be open based on active child
|
|
||||||
// Also handles sub-routes (e.g., /cliproxy/control-panel matches /cliproxy)
|
|
||||||
const isParentActive = (children: { path: string }[]) => {
|
|
||||||
return children.some(
|
|
||||||
(child) => isRouteActive(child.path) || location.pathname.startsWith(child.path + '/')
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Sidebar collapsible="icon">
|
|
||||||
<SidebarHeader className="h-12 flex items-center justify-center">
|
|
||||||
<CcsLogo size="sm" showText={state === 'expanded'} />
|
|
||||||
</SidebarHeader>
|
|
||||||
|
|
||||||
<SidebarContent>
|
|
||||||
{navGroups.map((group, index) => (
|
|
||||||
<SidebarGroup key={group.title || index}>
|
|
||||||
{group.title && <SidebarGroupLabel>{group.title}</SidebarGroupLabel>}
|
|
||||||
<SidebarGroupContent>
|
|
||||||
<SidebarMenu>
|
|
||||||
{group.items.map((item) => (
|
|
||||||
<SidebarMenuItem key={item.path}>
|
|
||||||
{item.isCollapsible && item.children ? (
|
|
||||||
<Collapsible
|
|
||||||
defaultOpen={isParentActive(item.children) || isRouteActive(item.path)}
|
|
||||||
className="group/collapsible"
|
|
||||||
>
|
|
||||||
<SidebarMenuItem>
|
|
||||||
<CollapsibleTrigger asChild>
|
|
||||||
<SidebarMenuButton tooltip={item.label}>
|
|
||||||
{item.icon && <item.icon className="w-4 h-4" />}
|
|
||||||
<span className="group-data-[collapsible=icon]:hidden">
|
|
||||||
{item.label}
|
|
||||||
</span>
|
|
||||||
<ChevronRight className="ml-auto transition-transform duration-200 group-data-[state=open]/collapsible:rotate-90 group-data-[collapsible=icon]:hidden" />
|
|
||||||
</SidebarMenuButton>
|
|
||||||
</CollapsibleTrigger>
|
|
||||||
<CollapsibleContent>
|
|
||||||
<SidebarMenuSub>
|
|
||||||
{item.children.map((child) => (
|
|
||||||
<SidebarMenuSubItem key={child.path}>
|
|
||||||
<SidebarMenuSubButton
|
|
||||||
asChild
|
|
||||||
isActive={isRouteActive(child.path)}
|
|
||||||
>
|
|
||||||
<Link to={child.path}>
|
|
||||||
<span>{child.label}</span>
|
|
||||||
</Link>
|
|
||||||
</SidebarMenuSubButton>
|
|
||||||
</SidebarMenuSubItem>
|
|
||||||
))}
|
|
||||||
</SidebarMenuSub>
|
|
||||||
</CollapsibleContent>
|
|
||||||
</SidebarMenuItem>
|
|
||||||
</Collapsible>
|
|
||||||
) : (
|
|
||||||
<SidebarMenuButton
|
|
||||||
asChild
|
|
||||||
isActive={isRouteActive(item.path)}
|
|
||||||
tooltip={item.label}
|
|
||||||
>
|
|
||||||
<Link to={item.path}>
|
|
||||||
{item.icon && <item.icon className="w-4 h-4" />}
|
|
||||||
<span className="group-data-[collapsible=icon]:hidden">{item.label}</span>
|
|
||||||
</Link>
|
|
||||||
</SidebarMenuButton>
|
|
||||||
)}
|
|
||||||
</SidebarMenuItem>
|
|
||||||
))}
|
|
||||||
</SidebarMenu>
|
|
||||||
</SidebarGroupContent>
|
|
||||||
</SidebarGroup>
|
|
||||||
))}
|
|
||||||
</SidebarContent>
|
|
||||||
|
|
||||||
<SidebarFooter className="p-4 border-t flex items-center justify-center">
|
|
||||||
<SidebarTrigger />
|
|
||||||
</SidebarFooter>
|
|
||||||
</Sidebar>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,465 +0,0 @@
|
|||||||
/**
|
|
||||||
* Auth Monitor Component with Account Flow Visualization
|
|
||||||
* Shows request flow from accounts to providers using custom SVG bezier curves
|
|
||||||
* Uses glass panel aesthetic with hover interactions and glow effects
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { useState, useMemo, useEffect } from 'react';
|
|
||||||
import { useCliproxyAuth } from '@/hooks/use-cliproxy';
|
|
||||||
import { useCliproxyStats, type AccountUsageStats } from '@/hooks/use-cliproxy-stats';
|
|
||||||
import { cn, STATUS_COLORS } from '@/lib/utils';
|
|
||||||
import { getProviderDisplayName, PROVIDER_COLORS } from '@/lib/provider-config';
|
|
||||||
import { Skeleton } from '@/components/ui/skeleton';
|
|
||||||
import { ProviderIcon } from '@/components/provider-icon';
|
|
||||||
import { AccountFlowViz } from '@/components/account-flow-viz';
|
|
||||||
import { usePrivacy } from '@/contexts/privacy-context';
|
|
||||||
import type { AuthStatus, OAuthAccount } from '@/lib/api-client';
|
|
||||||
import { Activity, CheckCircle2, XCircle, ChevronRight, Radio } from 'lucide-react';
|
|
||||||
|
|
||||||
interface AccountRow {
|
|
||||||
id: string;
|
|
||||||
email: string;
|
|
||||||
provider: string;
|
|
||||||
displayName: string;
|
|
||||||
isDefault: boolean;
|
|
||||||
successCount: number;
|
|
||||||
failureCount: number;
|
|
||||||
lastUsedAt?: string;
|
|
||||||
color: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface ProviderStats {
|
|
||||||
provider: string;
|
|
||||||
displayName: string;
|
|
||||||
totalRequests: number;
|
|
||||||
successCount: number;
|
|
||||||
failureCount: number;
|
|
||||||
accountCount: number;
|
|
||||||
accounts: AccountRow[];
|
|
||||||
}
|
|
||||||
|
|
||||||
function getSuccessRate(success: number, failure: number): number {
|
|
||||||
const total = success + failure;
|
|
||||||
if (total === 0) return 100;
|
|
||||||
return Math.round((success / total) * 100);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Strip common email domains for cleaner display */
|
|
||||||
function cleanEmail(email: string): string {
|
|
||||||
return email.replace(/@(gmail|yahoo|hotmail|outlook|icloud)\.com$/i, '');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Vibrant colors for account segments - darker for light theme contrast
|
|
||||||
const ACCOUNT_COLORS = [
|
|
||||||
'#1e6091', // Deep Cerulean (was #277da1)
|
|
||||||
'#2d8a6e', // Deep Seaweed (was #43aa8b)
|
|
||||||
'#d4a012', // Dark Tuscan (was #f9c74f)
|
|
||||||
'#c92a2d', // Deep Strawberry (was #f94144)
|
|
||||||
'#c45a1a', // Deep Pumpkin (was #f3722c)
|
|
||||||
'#6b9c4d', // Dark Willow (was #90be6d)
|
|
||||||
'#3d5a73', // Deep Blue Slate (was #577590)
|
|
||||||
'#cc7614', // Dark Carrot (was #f8961e)
|
|
||||||
'#3a7371', // Deep Cyan (was #4d908e)
|
|
||||||
'#7c5fc4', // Deep Purple (was #a78bfa)
|
|
||||||
];
|
|
||||||
|
|
||||||
/** Enhanced live pulse indicator with multi-ring animation */
|
|
||||||
function LivePulse() {
|
|
||||||
return (
|
|
||||||
<div className="relative flex items-center justify-center w-5 h-5">
|
|
||||||
{/* Outer ping ring */}
|
|
||||||
<div
|
|
||||||
className="absolute w-4 h-4 rounded-full animate-ping opacity-20"
|
|
||||||
style={{ backgroundColor: STATUS_COLORS.success }}
|
|
||||||
/>
|
|
||||||
{/* Middle pulse ring */}
|
|
||||||
<div
|
|
||||||
className="absolute w-3 h-3 rounded-full animate-pulse opacity-40"
|
|
||||||
style={{ backgroundColor: STATUS_COLORS.success }}
|
|
||||||
/>
|
|
||||||
{/* Inner solid dot */}
|
|
||||||
<div
|
|
||||||
className="relative w-2 h-2 rounded-full z-10"
|
|
||||||
style={{ backgroundColor: STATUS_COLORS.success }}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Inline success/failure badge for provider cards */
|
|
||||||
function InlineStatsBadge({ success, failure }: { success: number; failure: number }) {
|
|
||||||
if (success === 0 && failure === 0) {
|
|
||||||
return <span className="text-[9px] text-muted-foreground/50 font-mono">no activity</span>;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="flex items-center gap-2">
|
|
||||||
<div className="flex items-center gap-0.5">
|
|
||||||
<CheckCircle2 className="w-3 h-3 text-emerald-700 dark:text-emerald-500" />
|
|
||||||
<span className="text-[10px] font-mono font-medium text-emerald-700 dark:text-emerald-500">
|
|
||||||
{success.toLocaleString()}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
{failure > 0 && (
|
|
||||||
<div className="flex items-center gap-0.5">
|
|
||||||
<XCircle className="w-3 h-3 text-red-700 dark:text-red-500" />
|
|
||||||
<span className="text-[10px] font-mono font-medium text-red-700 dark:text-red-500">
|
|
||||||
{failure.toLocaleString()}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function AuthMonitor() {
|
|
||||||
const { data, isLoading, error } = useCliproxyAuth();
|
|
||||||
const { data: statsData, isLoading: statsLoading, dataUpdatedAt } = useCliproxyStats();
|
|
||||||
const { privacyMode } = usePrivacy();
|
|
||||||
const [selectedProvider, setSelectedProvider] = useState<string | null>(null);
|
|
||||||
const [hoveredProvider, setHoveredProvider] = useState<string | null>(null);
|
|
||||||
const [timeSinceUpdate, setTimeSinceUpdate] = useState('');
|
|
||||||
|
|
||||||
// Live countdown showing time since last data update
|
|
||||||
useEffect(() => {
|
|
||||||
if (!dataUpdatedAt) return;
|
|
||||||
const updateTime = () => {
|
|
||||||
const diff = Math.floor((Date.now() - dataUpdatedAt) / 1000);
|
|
||||||
if (diff < 60) {
|
|
||||||
setTimeSinceUpdate(`${diff}s ago`);
|
|
||||||
} else {
|
|
||||||
setTimeSinceUpdate(`${Math.floor(diff / 60)}m ago`);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
updateTime();
|
|
||||||
const interval = setInterval(updateTime, 1000);
|
|
||||||
return () => clearInterval(interval);
|
|
||||||
}, [dataUpdatedAt]);
|
|
||||||
|
|
||||||
// Build a map of account email -> usage stats from CLIProxy
|
|
||||||
const accountStatsMap = useMemo(() => {
|
|
||||||
if (!statsData?.accountStats) return new Map<string, AccountUsageStats>();
|
|
||||||
return new Map(Object.entries(statsData.accountStats));
|
|
||||||
}, [statsData?.accountStats]);
|
|
||||||
|
|
||||||
// Transform auth status data into account rows
|
|
||||||
const { accounts, totalSuccess, totalFailure, totalRequests, providerStats } = useMemo(() => {
|
|
||||||
if (!data?.authStatus) {
|
|
||||||
return {
|
|
||||||
accounts: [],
|
|
||||||
totalSuccess: 0,
|
|
||||||
totalFailure: 0,
|
|
||||||
totalRequests: 0,
|
|
||||||
providerStats: [],
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const accountsList: AccountRow[] = [];
|
|
||||||
const providerMap = new Map<
|
|
||||||
string,
|
|
||||||
{ success: number; failure: number; accounts: AccountRow[] }
|
|
||||||
>();
|
|
||||||
let tSuccess = 0;
|
|
||||||
let tFailure = 0;
|
|
||||||
let colorIndex = 0;
|
|
||||||
|
|
||||||
data.authStatus.forEach((status: AuthStatus) => {
|
|
||||||
const providerKey = status.provider;
|
|
||||||
if (!providerMap.has(providerKey)) {
|
|
||||||
providerMap.set(providerKey, { success: 0, failure: 0, accounts: [] });
|
|
||||||
}
|
|
||||||
const providerData = providerMap.get(providerKey);
|
|
||||||
if (!providerData) return;
|
|
||||||
|
|
||||||
status.accounts?.forEach((account: OAuthAccount) => {
|
|
||||||
// Get real stats from CLIProxy - try email first, then id
|
|
||||||
const accountEmail = account.email || account.id;
|
|
||||||
const realStats = accountStatsMap.get(accountEmail);
|
|
||||||
const success = realStats?.successCount ?? 0;
|
|
||||||
const failure = realStats?.failureCount ?? 0;
|
|
||||||
tSuccess += success;
|
|
||||||
tFailure += failure;
|
|
||||||
providerData.success += success;
|
|
||||||
providerData.failure += failure;
|
|
||||||
|
|
||||||
const row: AccountRow = {
|
|
||||||
id: account.id,
|
|
||||||
email: account.email || account.id,
|
|
||||||
provider: status.provider,
|
|
||||||
displayName: status.displayName,
|
|
||||||
isDefault: account.isDefault,
|
|
||||||
successCount: success,
|
|
||||||
failureCount: failure,
|
|
||||||
lastUsedAt: realStats?.lastUsedAt ?? account.lastUsedAt,
|
|
||||||
color: ACCOUNT_COLORS[colorIndex % ACCOUNT_COLORS.length],
|
|
||||||
};
|
|
||||||
accountsList.push(row);
|
|
||||||
providerData.accounts.push(row);
|
|
||||||
colorIndex++;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// Build provider stats array
|
|
||||||
const providerStatsArr: ProviderStats[] = [];
|
|
||||||
providerMap.forEach((pData, provider) => {
|
|
||||||
if (pData.accounts.length === 0) return;
|
|
||||||
providerStatsArr.push({
|
|
||||||
provider,
|
|
||||||
displayName: getProviderDisplayName(provider),
|
|
||||||
totalRequests: pData.success + pData.failure,
|
|
||||||
successCount: pData.success,
|
|
||||||
failureCount: pData.failure,
|
|
||||||
accountCount: pData.accounts.length,
|
|
||||||
accounts: pData.accounts,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
providerStatsArr.sort((a, b) => b.totalRequests - a.totalRequests);
|
|
||||||
|
|
||||||
return {
|
|
||||||
accounts: accountsList,
|
|
||||||
totalSuccess: tSuccess,
|
|
||||||
totalFailure: tFailure,
|
|
||||||
totalRequests: tSuccess + tFailure,
|
|
||||||
providerStats: providerStatsArr,
|
|
||||||
};
|
|
||||||
}, [data?.authStatus, accountStatsMap]);
|
|
||||||
|
|
||||||
const overallSuccessRate =
|
|
||||||
totalRequests > 0 ? Math.round((totalSuccess / totalRequests) * 100) : 100;
|
|
||||||
|
|
||||||
// Get selected provider data for detail view
|
|
||||||
const selectedProviderData = selectedProvider
|
|
||||||
? providerStats.find((ps) => ps.provider === selectedProvider)
|
|
||||||
: null;
|
|
||||||
|
|
||||||
if (isLoading || statsLoading) {
|
|
||||||
return (
|
|
||||||
<div className="rounded-xl border border-border overflow-hidden font-mono text-[13px] bg-card/50 dark:bg-zinc-900/60 backdrop-blur-sm">
|
|
||||||
<div className="flex items-center justify-between px-4 py-3 border-b border-border">
|
|
||||||
<Skeleton className="h-4 w-32" />
|
|
||||||
<Skeleton className="h-4 w-20" />
|
|
||||||
</div>
|
|
||||||
<div className="p-4 space-y-4">
|
|
||||||
<div className="flex gap-3">
|
|
||||||
{[1, 2, 3, 4].map((i) => (
|
|
||||||
<Skeleton key={i} className="h-16 flex-1 rounded-lg" />
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
<Skeleton className="h-48 w-full rounded-lg" />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (error || !data?.authStatus || accounts.length === 0) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="rounded-xl border border-border overflow-hidden font-mono text-[13px] text-foreground bg-card/50 dark:bg-zinc-900/60 backdrop-blur-sm">
|
|
||||||
{/* Enhanced Live Header with gradient glow */}
|
|
||||||
<div className="flex items-center justify-between px-4 py-2.5 border-b border-border bg-gradient-to-r from-emerald-500/5 via-transparent to-transparent dark:from-emerald-500/10">
|
|
||||||
<div className="flex items-center gap-2">
|
|
||||||
<LivePulse />
|
|
||||||
<span className="text-xs font-semibold tracking-tight text-foreground">LIVE</span>
|
|
||||||
<span className="text-[10px] text-muted-foreground">Account Monitor</span>
|
|
||||||
</div>
|
|
||||||
<div className="flex items-center gap-4 text-[10px] text-muted-foreground">
|
|
||||||
<div className="flex items-center gap-1.5">
|
|
||||||
<Radio className="w-3 h-3 animate-pulse" />
|
|
||||||
<span>Updated {timeSinceUpdate || 'now'}</span>
|
|
||||||
</div>
|
|
||||||
<span className="text-muted-foreground/50">|</span>
|
|
||||||
<span>{accounts.length} accounts</span>
|
|
||||||
<span className="font-mono">{totalRequests.toLocaleString()} req</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Summary Stats Row */}
|
|
||||||
<div className="grid grid-cols-4 gap-3 p-4 border-b border-border bg-muted/20 dark:bg-zinc-900/30">
|
|
||||||
<SummaryCard
|
|
||||||
icon={<Activity className="w-4 h-4" />}
|
|
||||||
label="Accounts"
|
|
||||||
value={accounts.length}
|
|
||||||
color="var(--accent)"
|
|
||||||
/>
|
|
||||||
<SummaryCard
|
|
||||||
icon={<CheckCircle2 className="w-4 h-4" />}
|
|
||||||
label="Success"
|
|
||||||
value={totalSuccess.toLocaleString()}
|
|
||||||
color={STATUS_COLORS.success}
|
|
||||||
/>
|
|
||||||
<SummaryCard
|
|
||||||
icon={<XCircle className="w-4 h-4" />}
|
|
||||||
label="Failed"
|
|
||||||
value={totalFailure.toLocaleString()}
|
|
||||||
color={totalFailure > 0 ? STATUS_COLORS.failed : undefined}
|
|
||||||
/>
|
|
||||||
<SummaryCard
|
|
||||||
icon={<Activity className="w-4 h-4" />}
|
|
||||||
label="Success Rate"
|
|
||||||
value={`${overallSuccessRate}%`}
|
|
||||||
color={
|
|
||||||
overallSuccessRate === 100
|
|
||||||
? STATUS_COLORS.success
|
|
||||||
: overallSuccessRate >= 95
|
|
||||||
? STATUS_COLORS.degraded
|
|
||||||
: STATUS_COLORS.failed
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Flow Visualization */}
|
|
||||||
<div className="relative overflow-hidden">
|
|
||||||
{selectedProviderData ? (
|
|
||||||
// Account-level flow view
|
|
||||||
<AccountFlowViz
|
|
||||||
providerData={selectedProviderData}
|
|
||||||
onBack={() => setSelectedProvider(null)}
|
|
||||||
/>
|
|
||||||
) : (
|
|
||||||
// Provider cards view
|
|
||||||
<div className="p-6">
|
|
||||||
<div className="text-[10px] text-muted-foreground uppercase tracking-widest mb-4">
|
|
||||||
Request Distribution by Provider
|
|
||||||
</div>
|
|
||||||
<div className="grid grid-cols-2 lg:grid-cols-3 gap-4">
|
|
||||||
{providerStats.map((ps) => {
|
|
||||||
const successRate = getSuccessRate(ps.successCount, ps.failureCount);
|
|
||||||
const providerColor = PROVIDER_COLORS[ps.provider.toLowerCase()] || '#6b7280';
|
|
||||||
const isHovered = hoveredProvider === ps.provider;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<button
|
|
||||||
key={ps.provider}
|
|
||||||
onClick={() => setSelectedProvider(ps.provider)}
|
|
||||||
onMouseEnter={() => setHoveredProvider(ps.provider)}
|
|
||||||
onMouseLeave={() => setHoveredProvider(null)}
|
|
||||||
className={cn(
|
|
||||||
'group relative rounded-xl p-4 text-left transition-all duration-300',
|
|
||||||
'bg-muted/30 dark:bg-zinc-900/60 backdrop-blur-sm',
|
|
||||||
'border border-border/50 dark:border-white/[0.08]',
|
|
||||||
'hover:border-opacity-50 hover:scale-[1.02] hover:shadow-lg',
|
|
||||||
isHovered && 'ring-1'
|
|
||||||
)}
|
|
||||||
style={
|
|
||||||
{
|
|
||||||
borderColor: isHovered ? providerColor : undefined,
|
|
||||||
'--ring-color': providerColor,
|
|
||||||
} as React.CSSProperties
|
|
||||||
}
|
|
||||||
>
|
|
||||||
<div className="flex items-center gap-3 mb-3">
|
|
||||||
<ProviderIcon provider={ps.provider} size={36} withBackground />
|
|
||||||
<div>
|
|
||||||
<h3 className="text-sm font-semibold text-foreground tracking-tight">
|
|
||||||
{ps.displayName}
|
|
||||||
</h3>
|
|
||||||
<p className="text-[10px] text-muted-foreground">
|
|
||||||
{ps.accountCount} account{ps.accountCount !== 1 ? 's' : ''}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<ChevronRight
|
|
||||||
className={cn(
|
|
||||||
'w-4 h-4 ml-auto text-muted-foreground transition-all',
|
|
||||||
isHovered ? 'opacity-100 translate-x-0' : 'opacity-0 -translate-x-2'
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="space-y-2">
|
|
||||||
{/* Inline success/failure stats - immediately visible */}
|
|
||||||
<div className="flex justify-between items-center text-xs">
|
|
||||||
<span className="text-muted-foreground">Stats</span>
|
|
||||||
<InlineStatsBadge success={ps.successCount} failure={ps.failureCount} />
|
|
||||||
</div>
|
|
||||||
<div className="flex justify-between text-xs">
|
|
||||||
<span className="text-muted-foreground">Success Rate</span>
|
|
||||||
<span
|
|
||||||
className="font-mono font-semibold"
|
|
||||||
style={{
|
|
||||||
color:
|
|
||||||
successRate === 100
|
|
||||||
? STATUS_COLORS.success
|
|
||||||
: successRate >= 95
|
|
||||||
? STATUS_COLORS.degraded
|
|
||||||
: STATUS_COLORS.failed,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{successRate}%
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
{/* Progress bar */}
|
|
||||||
<div className="w-full bg-muted dark:bg-zinc-800/50 h-1 rounded-full overflow-hidden">
|
|
||||||
<div
|
|
||||||
className="h-full rounded-full transition-all duration-500"
|
|
||||||
style={{
|
|
||||||
width: `${successRate}%`,
|
|
||||||
backgroundColor: providerColor,
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Account color dots */}
|
|
||||||
<div className="flex gap-1 mt-3">
|
|
||||||
{ps.accounts.slice(0, 5).map((acc) => (
|
|
||||||
<div
|
|
||||||
key={acc.id}
|
|
||||||
className="w-2 h-2 rounded-full"
|
|
||||||
style={{ backgroundColor: acc.color }}
|
|
||||||
title={privacyMode ? '••••••' : cleanEmail(acc.email)}
|
|
||||||
/>
|
|
||||||
))}
|
|
||||||
{ps.accounts.length > 5 && (
|
|
||||||
<span className="text-[10px] text-muted-foreground ml-1">
|
|
||||||
+{ps.accounts.length - 5}
|
|
||||||
</span>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</button>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Summary Card Component
|
|
||||||
function SummaryCard({
|
|
||||||
icon,
|
|
||||||
label,
|
|
||||||
value,
|
|
||||||
color,
|
|
||||||
}: {
|
|
||||||
icon: React.ReactNode;
|
|
||||||
label: string;
|
|
||||||
value: string | number;
|
|
||||||
color?: string;
|
|
||||||
}) {
|
|
||||||
return (
|
|
||||||
<div className="flex items-center gap-3 p-3 rounded-lg bg-card/50 dark:bg-zinc-900/50 border border-border/50 dark:border-white/[0.06]">
|
|
||||||
<div
|
|
||||||
className="w-8 h-8 rounded-md flex items-center justify-center"
|
|
||||||
style={{
|
|
||||||
backgroundColor: color ? `${color}15` : 'var(--muted)',
|
|
||||||
color: color || 'var(--muted-foreground)',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{icon}
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<div className="text-[10px] text-muted-foreground uppercase tracking-wider">{label}</div>
|
|
||||||
<div
|
|
||||||
className="text-lg font-semibold font-mono leading-tight"
|
|
||||||
style={{ color: color || 'var(--foreground)' }}
|
|
||||||
>
|
|
||||||
{value}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
import { cn } from '@/lib/utils';
|
|
||||||
|
|
||||||
interface CcsLogoProps {
|
|
||||||
size?: 'sm' | 'md' | 'lg';
|
|
||||||
className?: string;
|
|
||||||
showText?: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
const sizeMap = {
|
|
||||||
sm: 24,
|
|
||||||
md: 32,
|
|
||||||
lg: 48,
|
|
||||||
};
|
|
||||||
|
|
||||||
export function CcsLogo({ size = 'md', className, showText = true }: CcsLogoProps) {
|
|
||||||
const dimension = sizeMap[size];
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className={cn('flex items-center gap-2', className)}>
|
|
||||||
<img
|
|
||||||
src="/logo/ccs-logo-256.png"
|
|
||||||
alt="CCS Logo"
|
|
||||||
width={dimension}
|
|
||||||
height={dimension}
|
|
||||||
className="rounded"
|
|
||||||
/>
|
|
||||||
{showText && <span className="font-bold text-lg">CCS Config</span>}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,49 +0,0 @@
|
|||||||
/**
|
|
||||||
* ClaudeKit Badge Button
|
|
||||||
*
|
|
||||||
* "Powered by ClaudeKit" badge for navbar, inspired by landing page design.
|
|
||||||
* Compact version optimized for header placement.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { cn } from '@/lib/utils';
|
|
||||||
|
|
||||||
const CLAUDEKIT_URL = 'https://claudekit.cc?ref=HMNKXOHN';
|
|
||||||
|
|
||||||
export function ClaudeKitBadge() {
|
|
||||||
return (
|
|
||||||
<a
|
|
||||||
href={CLAUDEKIT_URL}
|
|
||||||
target="_blank"
|
|
||||||
rel="noopener noreferrer"
|
|
||||||
className={cn(
|
|
||||||
'group inline-flex items-center gap-2 px-3 py-1.5 rounded-lg',
|
|
||||||
'bg-accent/10 border-2 border-accent/40',
|
|
||||||
'hover:bg-accent hover:border-accent',
|
|
||||||
'transition-all duration-200 shadow-sm hover:shadow-md'
|
|
||||||
)}
|
|
||||||
title="Powered by ClaudeKit Framework"
|
|
||||||
>
|
|
||||||
<img src="/logos/claudekit-logo.png" alt="ClaudeKit" className="w-5 h-5" />
|
|
||||||
<span className="flex items-baseline gap-1.5 whitespace-nowrap">
|
|
||||||
<span
|
|
||||||
className={cn(
|
|
||||||
'text-[10px] font-medium uppercase tracking-wide',
|
|
||||||
'text-muted-foreground group-hover:text-accent-foreground/80',
|
|
||||||
'transition-colors'
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
Powered by
|
|
||||||
</span>
|
|
||||||
<span
|
|
||||||
className={cn(
|
|
||||||
'text-xs font-bold text-foreground',
|
|
||||||
'group-hover:text-accent-foreground',
|
|
||||||
'transition-colors'
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
ClaudeKit
|
|
||||||
</span>
|
|
||||||
</span>
|
|
||||||
</a>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,157 +0,0 @@
|
|||||||
/**
|
|
||||||
* CLIProxy Variant Dialog Component
|
|
||||||
* Phase 03: REST API Routes & CRUD
|
|
||||||
* Phase 06: Multi-Account Support
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { useForm, useWatch } from 'react-hook-form';
|
|
||||||
import { zodResolver } from '@hookform/resolvers/zod';
|
|
||||||
import * as z from 'zod';
|
|
||||||
import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/components/ui/dialog';
|
|
||||||
import { Button } from '@/components/ui/button';
|
|
||||||
import { Input } from '@/components/ui/input';
|
|
||||||
import { Label } from '@/components/ui/label';
|
|
||||||
import { useCreateVariant, useCliproxyAuth } from '@/hooks/use-cliproxy';
|
|
||||||
import { usePrivacy } from '@/contexts/privacy-context';
|
|
||||||
|
|
||||||
const providers = ['gemini', 'codex', 'agy', 'qwen', 'iflow'] as const;
|
|
||||||
|
|
||||||
const schema = z.object({
|
|
||||||
name: z
|
|
||||||
.string()
|
|
||||||
.min(1, 'Name is required')
|
|
||||||
.regex(/^[a-zA-Z][a-zA-Z0-9._-]*$/, 'Invalid variant name'),
|
|
||||||
provider: z.enum(providers, { message: 'Provider is required' }),
|
|
||||||
model: z.string().optional(),
|
|
||||||
account: z.string().optional(),
|
|
||||||
});
|
|
||||||
|
|
||||||
type FormData = z.infer<typeof schema>;
|
|
||||||
|
|
||||||
interface CliproxyDialogProps {
|
|
||||||
open: boolean;
|
|
||||||
onClose: () => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
const providerOptions = [
|
|
||||||
{ value: 'gemini', label: 'Google Gemini' },
|
|
||||||
{ value: 'codex', label: 'OpenAI Codex' },
|
|
||||||
{ value: 'agy', label: 'Antigravity' },
|
|
||||||
{ value: 'qwen', label: 'Alibaba Qwen' },
|
|
||||||
{ value: 'iflow', label: 'iFlow' },
|
|
||||||
];
|
|
||||||
|
|
||||||
export function CliproxyDialog({ open, onClose }: CliproxyDialogProps) {
|
|
||||||
const createMutation = useCreateVariant();
|
|
||||||
const { data: authData } = useCliproxyAuth();
|
|
||||||
const { privacyMode } = usePrivacy();
|
|
||||||
|
|
||||||
const {
|
|
||||||
register,
|
|
||||||
handleSubmit,
|
|
||||||
control,
|
|
||||||
formState: { errors },
|
|
||||||
reset,
|
|
||||||
} = useForm<FormData>({
|
|
||||||
resolver: zodResolver(schema),
|
|
||||||
});
|
|
||||||
|
|
||||||
// Watch provider to show relevant accounts
|
|
||||||
const selectedProvider = useWatch({ control, name: 'provider' });
|
|
||||||
|
|
||||||
// Get accounts for selected provider
|
|
||||||
const providerAuth = authData?.authStatus.find((s) => s.provider === selectedProvider);
|
|
||||||
const providerAccounts = providerAuth?.accounts || [];
|
|
||||||
|
|
||||||
const onSubmit = async (data: FormData) => {
|
|
||||||
try {
|
|
||||||
await createMutation.mutateAsync(data);
|
|
||||||
reset();
|
|
||||||
onClose();
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Failed to create variant:', error);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Dialog open={open} onOpenChange={onClose}>
|
|
||||||
<DialogContent>
|
|
||||||
<DialogHeader>
|
|
||||||
<DialogTitle>Create CLIProxy Variant</DialogTitle>
|
|
||||||
</DialogHeader>
|
|
||||||
<form onSubmit={handleSubmit(onSubmit)} className="space-y-4">
|
|
||||||
<div>
|
|
||||||
<Label htmlFor="name">Name</Label>
|
|
||||||
<Input id="name" {...register('name')} placeholder="my-gemini" />
|
|
||||||
{errors.name && <span className="text-xs text-red-500">{errors.name.message}</span>}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<Label htmlFor="provider">Provider</Label>
|
|
||||||
<select
|
|
||||||
id="provider"
|
|
||||||
{...register('provider')}
|
|
||||||
className="flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-sm shadow-sm transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring"
|
|
||||||
>
|
|
||||||
<option value="">Select provider...</option>
|
|
||||||
{providerOptions.map((opt) => (
|
|
||||||
<option key={opt.value} value={opt.value}>
|
|
||||||
{opt.label}
|
|
||||||
</option>
|
|
||||||
))}
|
|
||||||
</select>
|
|
||||||
{errors.provider && (
|
|
||||||
<span className="text-xs text-red-500">{errors.provider.message}</span>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Account selector - only show if provider has accounts */}
|
|
||||||
{selectedProvider && providerAccounts.length > 0 && (
|
|
||||||
<div>
|
|
||||||
<Label htmlFor="account">Account</Label>
|
|
||||||
<select
|
|
||||||
id="account"
|
|
||||||
{...register('account')}
|
|
||||||
className="flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-sm shadow-sm transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring"
|
|
||||||
>
|
|
||||||
<option value="">Use default account</option>
|
|
||||||
{providerAccounts.map((acc) => (
|
|
||||||
<option key={acc.id} value={acc.id}>
|
|
||||||
{privacyMode ? '••••••' : acc.email || acc.id}
|
|
||||||
{acc.isDefault ? ' (default)' : ''}
|
|
||||||
</option>
|
|
||||||
))}
|
|
||||||
</select>
|
|
||||||
<span className="text-xs text-muted-foreground mt-1 block">
|
|
||||||
Select which OAuth account this variant should use
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{/* Show message if provider selected but no accounts */}
|
|
||||||
{selectedProvider && providerAccounts.length === 0 && providerAuth && (
|
|
||||||
<div className="text-sm text-amber-600 bg-amber-50 dark:bg-amber-950/20 p-3 rounded-md">
|
|
||||||
No accounts authenticated for {providerAuth.displayName}.
|
|
||||||
<br />
|
|
||||||
<code className="text-xs bg-muted px-1 rounded">ccs {selectedProvider} --auth</code>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<Label htmlFor="model">Model (optional)</Label>
|
|
||||||
<Input id="model" {...register('model')} placeholder="gemini-2.5-pro" />
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="flex justify-end gap-2 pt-2">
|
|
||||||
<Button type="button" variant="outline" onClick={onClose}>
|
|
||||||
Cancel
|
|
||||||
</Button>
|
|
||||||
<Button type="submit" disabled={createMutation.isPending}>
|
|
||||||
{createMutation.isPending ? 'Creating...' : 'Create'}
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</DialogContent>
|
|
||||||
</Dialog>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,349 +0,0 @@
|
|||||||
/**
|
|
||||||
* CLIProxy Stats Overview Component
|
|
||||||
*
|
|
||||||
* Full-width dashboard section showing comprehensive CLIProxyAPI statistics.
|
|
||||||
* Features:
|
|
||||||
* - Status indicator with uptime
|
|
||||||
* - Request metrics with success rate visualization
|
|
||||||
* - Token usage with cost estimation
|
|
||||||
* - Model breakdown with usage distribution
|
|
||||||
* - Session history
|
|
||||||
* Respects privacy mode to blur sensitive data.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
|
||||||
import { Badge } from '@/components/ui/badge';
|
|
||||||
import { Skeleton } from '@/components/ui/skeleton';
|
|
||||||
import {
|
|
||||||
Server,
|
|
||||||
Zap,
|
|
||||||
ZapOff,
|
|
||||||
Activity,
|
|
||||||
Coins,
|
|
||||||
Cpu,
|
|
||||||
CheckCircle2,
|
|
||||||
XCircle,
|
|
||||||
TrendingUp,
|
|
||||||
} from 'lucide-react';
|
|
||||||
import { cn } from '@/lib/utils';
|
|
||||||
import { useCliproxyStats, useCliproxyStatus } from '@/hooks/use-cliproxy-stats';
|
|
||||||
import { usePrivacy, PRIVACY_BLUR_CLASS } from '@/contexts/privacy-context';
|
|
||||||
|
|
||||||
interface CliproxyStatsOverviewProps {
|
|
||||||
className?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function CliproxyStatsOverview({ className }: CliproxyStatsOverviewProps) {
|
|
||||||
const { privacyMode } = usePrivacy();
|
|
||||||
const { data: status, isLoading: statusLoading } = useCliproxyStatus();
|
|
||||||
const { data: stats, isLoading: statsLoading, error } = useCliproxyStats(status?.running);
|
|
||||||
|
|
||||||
const isLoading = statusLoading || (status?.running && statsLoading);
|
|
||||||
|
|
||||||
// Loading state
|
|
||||||
if (isLoading) {
|
|
||||||
return (
|
|
||||||
<div className={cn('space-y-4', className)}>
|
|
||||||
<div className="flex items-center justify-between">
|
|
||||||
<div className="space-y-1">
|
|
||||||
<Skeleton className="h-6 w-48" />
|
|
||||||
<Skeleton className="h-4 w-72" />
|
|
||||||
</div>
|
|
||||||
<Skeleton className="h-8 w-24" />
|
|
||||||
</div>
|
|
||||||
<div className="grid grid-cols-2 md:grid-cols-4 gap-4">
|
|
||||||
{[1, 2, 3, 4].map((i) => (
|
|
||||||
<Skeleton key={i} className="h-28" />
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Offline state
|
|
||||||
if (!status?.running) {
|
|
||||||
return (
|
|
||||||
<div className={cn('space-y-4', className)}>
|
|
||||||
<div className="flex flex-col sm:flex-row sm:items-center justify-between gap-4">
|
|
||||||
<div>
|
|
||||||
<h2 className="text-lg font-semibold tracking-tight flex items-center gap-2">
|
|
||||||
<Activity className="h-5 w-5" />
|
|
||||||
Session Statistics
|
|
||||||
</h2>
|
|
||||||
<p className="text-sm text-muted-foreground">
|
|
||||||
Real-time usage metrics from CLIProxyAPI
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<Badge variant="secondary" className="w-fit gap-1.5">
|
|
||||||
<ZapOff className="h-3.5 w-3.5" />
|
|
||||||
Offline
|
|
||||||
</Badge>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<Card className="border-dashed">
|
|
||||||
<CardContent className="flex flex-col items-center justify-center py-12 text-center">
|
|
||||||
<div className="p-4 rounded-full bg-muted/50 mb-4">
|
|
||||||
<Server className="h-8 w-8 text-muted-foreground" />
|
|
||||||
</div>
|
|
||||||
<h3 className="font-medium mb-1">No Active Session</h3>
|
|
||||||
<p className="text-sm text-muted-foreground max-w-md">
|
|
||||||
Start a CLIProxy session using{' '}
|
|
||||||
<code className="px-1.5 py-0.5 bg-muted rounded text-xs font-mono">ccs gemini</code>,{' '}
|
|
||||||
<code className="px-1.5 py-0.5 bg-muted rounded text-xs font-mono">ccs codex</code>,
|
|
||||||
or <code className="px-1.5 py-0.5 bg-muted rounded text-xs font-mono">ccs agy</code>{' '}
|
|
||||||
to view real-time statistics.
|
|
||||||
</p>
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Error state
|
|
||||||
if (error) {
|
|
||||||
return (
|
|
||||||
<div className={cn('space-y-4', className)}>
|
|
||||||
<Card className="border-destructive/50">
|
|
||||||
<CardContent className="flex items-center gap-4 py-6">
|
|
||||||
<XCircle className="h-8 w-8 text-destructive shrink-0" />
|
|
||||||
<div>
|
|
||||||
<h3 className="font-medium">Failed to Load Statistics</h3>
|
|
||||||
<p className="text-sm text-muted-foreground">{error.message}</p>
|
|
||||||
</div>
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Calculate derived stats
|
|
||||||
const totalRequests = stats?.totalRequests ?? 0;
|
|
||||||
const failedRequests = stats?.quotaExceededCount ?? 0;
|
|
||||||
const successRequests = totalRequests - failedRequests;
|
|
||||||
const successRate = totalRequests > 0 ? Math.round((successRequests / totalRequests) * 100) : 100;
|
|
||||||
const totalTokens = stats?.tokens?.total ?? 0;
|
|
||||||
|
|
||||||
// Get model breakdown sorted by usage
|
|
||||||
const models = Object.entries(stats?.requestsByModel ?? {}).sort((a, b) => b[1] - a[1]);
|
|
||||||
const maxModelRequests = models.length > 0 ? models[0][1] : 1;
|
|
||||||
|
|
||||||
// Define color palette for models
|
|
||||||
const modelColors = [
|
|
||||||
'bg-blue-500',
|
|
||||||
'bg-purple-500',
|
|
||||||
'bg-amber-500',
|
|
||||||
'bg-emerald-500',
|
|
||||||
'bg-rose-500',
|
|
||||||
'bg-cyan-500',
|
|
||||||
];
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className={cn('space-y-4', className)}>
|
|
||||||
{/* Header */}
|
|
||||||
<div className="flex flex-col sm:flex-row sm:items-center justify-between gap-4">
|
|
||||||
<div>
|
|
||||||
<h2 className="text-lg font-semibold tracking-tight flex items-center gap-2">
|
|
||||||
<Activity className="h-5 w-5" />
|
|
||||||
Session Statistics
|
|
||||||
</h2>
|
|
||||||
<p className="text-sm text-muted-foreground">Real-time usage metrics from CLIProxyAPI</p>
|
|
||||||
</div>
|
|
||||||
<Badge
|
|
||||||
variant="outline"
|
|
||||||
className="w-fit gap-1.5 text-green-600 border-green-200 bg-green-50 dark:bg-green-900/10 dark:border-green-800"
|
|
||||||
>
|
|
||||||
<Zap className="h-3.5 w-3.5" />
|
|
||||||
Running
|
|
||||||
</Badge>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Stats Grid */}
|
|
||||||
<div className="grid grid-cols-2 lg:grid-cols-4 gap-4">
|
|
||||||
{/* Requests Card */}
|
|
||||||
<Card className="hover:shadow-md transition-shadow">
|
|
||||||
<CardContent className="p-4">
|
|
||||||
<div className="flex items-start justify-between">
|
|
||||||
<div className="space-y-1">
|
|
||||||
<p className="text-xs font-medium text-muted-foreground">Total Requests</p>
|
|
||||||
<p className="text-2xl font-bold">{formatNumber(totalRequests)}</p>
|
|
||||||
<div className="flex items-center gap-1.5 text-[10px]">
|
|
||||||
<CheckCircle2 className="h-3 w-3 text-green-500" />
|
|
||||||
<span className="text-muted-foreground">{successRequests} success</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div className="p-2 rounded-lg bg-blue-100 dark:bg-blue-900/20">
|
|
||||||
<TrendingUp className="h-4 w-4 text-blue-600" />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
|
|
||||||
{/* Success Rate Card */}
|
|
||||||
<Card className="hover:shadow-md transition-shadow">
|
|
||||||
<CardContent className="p-4">
|
|
||||||
<div className="flex items-start justify-between">
|
|
||||||
<div className="space-y-1 flex-1">
|
|
||||||
<p className="text-xs font-medium text-muted-foreground">Success Rate</p>
|
|
||||||
<p className="text-2xl font-bold">{successRate}%</p>
|
|
||||||
<div className="h-1.5 mt-2 bg-muted/50 rounded-full overflow-hidden">
|
|
||||||
<div
|
|
||||||
className={cn(
|
|
||||||
'h-full rounded-full transition-all',
|
|
||||||
successRate >= 90 ? 'bg-green-500' : 'bg-amber-500'
|
|
||||||
)}
|
|
||||||
style={{ width: `${successRate}%` }}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
className={cn(
|
|
||||||
'p-2 rounded-lg',
|
|
||||||
successRate >= 90
|
|
||||||
? 'bg-green-100 dark:bg-green-900/20'
|
|
||||||
: 'bg-amber-100 dark:bg-amber-900/20'
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
{successRate >= 90 ? (
|
|
||||||
<CheckCircle2 className="h-4 w-4 text-green-600" />
|
|
||||||
) : (
|
|
||||||
<XCircle className="h-4 w-4 text-amber-600" />
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
|
|
||||||
{/* Tokens Card */}
|
|
||||||
<Card className="hover:shadow-md transition-shadow">
|
|
||||||
<CardContent className="p-4">
|
|
||||||
<div className="flex items-start justify-between">
|
|
||||||
<div className="space-y-1">
|
|
||||||
<p className="text-xs font-medium text-muted-foreground">Total Tokens</p>
|
|
||||||
<p className={cn('text-2xl font-bold', privacyMode && PRIVACY_BLUR_CLASS)}>
|
|
||||||
{formatNumber(totalTokens)}
|
|
||||||
</p>
|
|
||||||
<p
|
|
||||||
className={cn(
|
|
||||||
'text-[10px] text-muted-foreground',
|
|
||||||
privacyMode && PRIVACY_BLUR_CLASS
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
~${estimateCost(totalTokens).toFixed(2)} estimated
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<div className="p-2 rounded-lg bg-purple-100 dark:bg-purple-900/20">
|
|
||||||
<Coins className="h-4 w-4 text-purple-600" />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
|
|
||||||
{/* Models Card */}
|
|
||||||
<Card className="hover:shadow-md transition-shadow">
|
|
||||||
<CardContent className="p-4">
|
|
||||||
<div className="flex items-start justify-between">
|
|
||||||
<div className="space-y-1">
|
|
||||||
<p className="text-xs font-medium text-muted-foreground">Models Used</p>
|
|
||||||
<p className="text-2xl font-bold">{models.length}</p>
|
|
||||||
<p className="text-[10px] text-muted-foreground">
|
|
||||||
{models.length > 0 ? formatModelName(models[0][0]) : 'None'}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<div className="p-2 rounded-lg bg-cyan-100 dark:bg-cyan-900/20">
|
|
||||||
<Cpu className="h-4 w-4 text-cyan-600" />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Model Breakdown */}
|
|
||||||
{models.length > 0 && (
|
|
||||||
<Card>
|
|
||||||
<CardHeader className="pb-3">
|
|
||||||
<CardTitle className="text-sm font-medium flex items-center gap-2">
|
|
||||||
<Cpu className="h-4 w-4" />
|
|
||||||
Model Usage Distribution
|
|
||||||
</CardTitle>
|
|
||||||
</CardHeader>
|
|
||||||
<CardContent className="pt-0">
|
|
||||||
<div className="space-y-3">
|
|
||||||
{models.map(([model, count], index) => {
|
|
||||||
const percentage = Math.round((count / totalRequests) * 100);
|
|
||||||
const barPercentage = Math.round((count / maxModelRequests) * 100);
|
|
||||||
const displayName = formatModelName(model);
|
|
||||||
const colorClass = modelColors[index % modelColors.length];
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div key={model} className="group">
|
|
||||||
<div className="flex items-center justify-between text-sm mb-1.5">
|
|
||||||
<div className="flex items-center gap-2 min-w-0">
|
|
||||||
<div className={cn('w-2 h-2 rounded-full shrink-0', colorClass)} />
|
|
||||||
<span className="font-medium truncate" title={model}>
|
|
||||||
{displayName}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<div className="flex items-center gap-3 text-muted-foreground shrink-0">
|
|
||||||
<span>{count} requests</span>
|
|
||||||
<span className="text-xs font-medium w-10 text-right">{percentage}%</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div className="h-2 bg-muted/50 rounded-full overflow-hidden">
|
|
||||||
<div
|
|
||||||
className={cn(
|
|
||||||
'h-full rounded-full transition-all duration-500',
|
|
||||||
colorClass
|
|
||||||
)}
|
|
||||||
style={{ width: `${barPercentage}%` }}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</div>
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Format large numbers with K/M suffix */
|
|
||||||
function formatNumber(num: number): string {
|
|
||||||
if (num >= 1000000) {
|
|
||||||
return `${(num / 1000000).toFixed(1)}M`;
|
|
||||||
}
|
|
||||||
if (num >= 1000) {
|
|
||||||
return `${(num / 1000).toFixed(1)}K`;
|
|
||||||
}
|
|
||||||
return num.toLocaleString();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Format model names for display */
|
|
||||||
function formatModelName(model: string): string {
|
|
||||||
let name = model
|
|
||||||
.replace(/^gemini-claude-/, '')
|
|
||||||
.replace(/^gemini-/, '')
|
|
||||||
.replace(/^claude-/, '')
|
|
||||||
.replace(/^anthropic\./, '')
|
|
||||||
.replace(/-thinking$/, ' Thinking');
|
|
||||||
|
|
||||||
name = name
|
|
||||||
.split(/[-_]/)
|
|
||||||
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
|
|
||||||
.join(' ');
|
|
||||||
|
|
||||||
if (name.length > 25) {
|
|
||||||
name = name.slice(0, 23) + '...';
|
|
||||||
}
|
|
||||||
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Estimate cost based on token count (rough average) */
|
|
||||||
function estimateCost(tokens: number): number {
|
|
||||||
// Average cost per 1M tokens across models (~$3 for input, ~$15 for output)
|
|
||||||
// Assuming 30% input, 70% output ratio
|
|
||||||
const avgCostPerMillion = 3 * 0.3 + 15 * 0.7;
|
|
||||||
return (tokens / 1000000) * avgCostPerMillion;
|
|
||||||
}
|
|
||||||
@@ -1,154 +0,0 @@
|
|||||||
/**
|
|
||||||
* CLIProxy Variants Table Component
|
|
||||||
* Phase 03: REST API Routes & CRUD
|
|
||||||
* Phase 06: Multi-Account Support
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { useReactTable, getCoreRowModel, flexRender, type ColumnDef } from '@tanstack/react-table';
|
|
||||||
import {
|
|
||||||
Table,
|
|
||||||
TableBody,
|
|
||||||
TableCell,
|
|
||||||
TableHead,
|
|
||||||
TableHeader,
|
|
||||||
TableRow,
|
|
||||||
} from '@/components/ui/table';
|
|
||||||
import { Button } from '@/components/ui/button';
|
|
||||||
import { Badge } from '@/components/ui/badge';
|
|
||||||
import {
|
|
||||||
DropdownMenu,
|
|
||||||
DropdownMenuContent,
|
|
||||||
DropdownMenuItem,
|
|
||||||
DropdownMenuTrigger,
|
|
||||||
} from '@/components/ui/dropdown-menu';
|
|
||||||
import { MoreHorizontal, Trash2, User } from 'lucide-react';
|
|
||||||
import { useDeleteVariant } from '@/hooks/use-cliproxy';
|
|
||||||
import type { Variant } from '@/lib/api-client';
|
|
||||||
|
|
||||||
interface CliproxyTableProps {
|
|
||||||
data: Variant[];
|
|
||||||
}
|
|
||||||
|
|
||||||
const providerLabels: Record<string, string> = {
|
|
||||||
gemini: 'Google Gemini',
|
|
||||||
codex: 'OpenAI Codex',
|
|
||||||
agy: 'Antigravity',
|
|
||||||
qwen: 'Alibaba Qwen',
|
|
||||||
iflow: 'iFlow',
|
|
||||||
};
|
|
||||||
|
|
||||||
export function CliproxyTable({ data }: CliproxyTableProps) {
|
|
||||||
const deleteMutation = useDeleteVariant();
|
|
||||||
|
|
||||||
const columns: ColumnDef<Variant>[] = [
|
|
||||||
{
|
|
||||||
accessorKey: 'name',
|
|
||||||
header: 'Name',
|
|
||||||
cell: ({ row }) => <span className="font-medium">{row.original.name}</span>,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
accessorKey: 'provider',
|
|
||||||
header: 'Provider',
|
|
||||||
cell: ({ row }) => providerLabels[row.original.provider] || row.original.provider,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
accessorKey: 'account',
|
|
||||||
header: 'Account',
|
|
||||||
cell: ({ row }) => {
|
|
||||||
const account = row.original.account;
|
|
||||||
if (!account) {
|
|
||||||
return <span className="text-muted-foreground text-xs italic">default</span>;
|
|
||||||
}
|
|
||||||
return (
|
|
||||||
<Badge variant="secondary" className="text-xs font-normal">
|
|
||||||
<User className="w-3 h-3 mr-1 opacity-70" />
|
|
||||||
{account}
|
|
||||||
</Badge>
|
|
||||||
);
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
accessorKey: 'settings',
|
|
||||||
header: 'Settings Path',
|
|
||||||
cell: ({ row }) => (
|
|
||||||
<code className="text-[10px] bg-muted px-1.5 py-0.5 rounded text-muted-foreground">
|
|
||||||
{row.original.settings || `config.cliproxy.${row.original.name}`}
|
|
||||||
</code>
|
|
||||||
),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 'actions',
|
|
||||||
header: 'Actions',
|
|
||||||
cell: ({ row }) => (
|
|
||||||
<div className="flex justify-end">
|
|
||||||
<DropdownMenu>
|
|
||||||
<DropdownMenuTrigger asChild>
|
|
||||||
<Button variant="ghost" size="sm" className="h-8 w-8 p-0">
|
|
||||||
<span className="sr-only">Open menu</span>
|
|
||||||
<MoreHorizontal className="w-4 h-4" />
|
|
||||||
</Button>
|
|
||||||
</DropdownMenuTrigger>
|
|
||||||
<DropdownMenuContent align="end" className="bg-white dark:bg-zinc-950">
|
|
||||||
<DropdownMenuItem
|
|
||||||
className="text-red-600 focus:text-red-600 focus:bg-red-50 dark:focus:bg-red-950/30"
|
|
||||||
onClick={() => deleteMutation.mutate(row.original.name)}
|
|
||||||
>
|
|
||||||
<Trash2 className="w-4 h-4 mr-2" />
|
|
||||||
Delete
|
|
||||||
</DropdownMenuItem>
|
|
||||||
</DropdownMenuContent>
|
|
||||||
</DropdownMenu>
|
|
||||||
</div>
|
|
||||||
),
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
// eslint-disable-next-line react-hooks/incompatible-library
|
|
||||||
const table = useReactTable({
|
|
||||||
data,
|
|
||||||
columns,
|
|
||||||
getCoreRowModel: getCoreRowModel(),
|
|
||||||
});
|
|
||||||
|
|
||||||
if (data.length === 0) {
|
|
||||||
return (
|
|
||||||
<div className="text-center py-12 border rounded-lg bg-muted/5 border-dashed">
|
|
||||||
<div className="text-muted-foreground text-sm">No CLIProxy variants found.</div>
|
|
||||||
<div className="text-xs text-muted-foreground mt-1">
|
|
||||||
Create one to use OAuth-based providers with specific account configurations.
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="border rounded-md overflow-hidden bg-card">
|
|
||||||
<Table>
|
|
||||||
<TableHeader className="bg-muted/50">
|
|
||||||
{table.getHeaderGroups().map((headerGroup) => (
|
|
||||||
<TableRow key={headerGroup.id}>
|
|
||||||
{headerGroup.headers.map((header) => (
|
|
||||||
<TableHead key={header.id}>
|
|
||||||
{header.isPlaceholder
|
|
||||||
? null
|
|
||||||
: flexRender(header.column.columnDef.header, header.getContext())}
|
|
||||||
</TableHead>
|
|
||||||
))}
|
|
||||||
</TableRow>
|
|
||||||
))}
|
|
||||||
</TableHeader>
|
|
||||||
<TableBody>
|
|
||||||
{table.getRowModel().rows.map((row) => (
|
|
||||||
<TableRow key={row.id}>
|
|
||||||
{row.getVisibleCells().map((cell) => (
|
|
||||||
<TableCell key={cell.id}>
|
|
||||||
{flexRender(cell.column.columnDef.cell, cell.getContext())}
|
|
||||||
</TableCell>
|
|
||||||
))}
|
|
||||||
</TableRow>
|
|
||||||
))}
|
|
||||||
</TableBody>
|
|
||||||
</Table>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,221 +0,0 @@
|
|||||||
/**
|
|
||||||
* Code Editor Component
|
|
||||||
* Lightweight JSON editor with syntax highlighting, line numbers, and validation
|
|
||||||
* Uses react-simple-code-editor + prism-react-renderer for minimal bundle size (~18KB)
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { useState, useCallback, useMemo } from 'react';
|
|
||||||
import Editor from 'react-simple-code-editor';
|
|
||||||
import { Highlight, themes } from 'prism-react-renderer';
|
|
||||||
import { useTheme } from '@/hooks/use-theme';
|
|
||||||
import { cn } from '@/lib/utils';
|
|
||||||
import { isSensitiveKey } from '@/lib/sensitive-keys';
|
|
||||||
import { AlertCircle, CheckCircle2, Eye, EyeOff } from 'lucide-react';
|
|
||||||
import { Button } from '@/components/ui/button';
|
|
||||||
|
|
||||||
interface CodeEditorProps {
|
|
||||||
value: string;
|
|
||||||
onChange: (value: string) => void;
|
|
||||||
language?: 'json' | 'yaml';
|
|
||||||
readonly?: boolean;
|
|
||||||
className?: string;
|
|
||||||
minHeight?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface ValidationResult {
|
|
||||||
valid: boolean;
|
|
||||||
error?: string;
|
|
||||||
line?: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Validate JSON and extract error location
|
|
||||||
*/
|
|
||||||
function validateJson(code: string): ValidationResult {
|
|
||||||
if (!code.trim()) {
|
|
||||||
return { valid: true };
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
JSON.parse(code);
|
|
||||||
return { valid: true };
|
|
||||||
} catch (e) {
|
|
||||||
const error = e as SyntaxError;
|
|
||||||
const message = error.message;
|
|
||||||
|
|
||||||
// Try to extract line number from error message
|
|
||||||
// Format: "... at position X" or "... at line Y column Z"
|
|
||||||
const posMatch = message.match(/position (\d+)/);
|
|
||||||
if (posMatch) {
|
|
||||||
const pos = parseInt(posMatch[1], 10);
|
|
||||||
const lines = code.substring(0, pos).split('\n');
|
|
||||||
return {
|
|
||||||
valid: false,
|
|
||||||
error: message,
|
|
||||||
line: lines.length,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
valid: false,
|
|
||||||
error: message,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function CodeEditor({
|
|
||||||
value,
|
|
||||||
onChange,
|
|
||||||
language = 'json',
|
|
||||||
readonly = false,
|
|
||||||
className,
|
|
||||||
minHeight = '300px',
|
|
||||||
}: CodeEditorProps) {
|
|
||||||
const { isDark } = useTheme();
|
|
||||||
const [isFocused, setIsFocused] = useState(false);
|
|
||||||
const [isMasked, setIsMasked] = useState(true);
|
|
||||||
|
|
||||||
// Validate on every change for JSON
|
|
||||||
const validation = useMemo(() => {
|
|
||||||
if (language === 'json') {
|
|
||||||
return validateJson(value);
|
|
||||||
}
|
|
||||||
return { valid: true };
|
|
||||||
}, [value, language]);
|
|
||||||
|
|
||||||
// Highlight function using prism-react-renderer
|
|
||||||
// Note: Line numbers removed - they break textarea/pre alignment in react-simple-code-editor
|
|
||||||
const highlightCode = useCallback(
|
|
||||||
(code: string) => (
|
|
||||||
<Highlight theme={isDark ? themes.nightOwl : themes.github} code={code} language={language}>
|
|
||||||
{({ tokens, getLineProps, getTokenProps }) => {
|
|
||||||
let nextValueIsSensitive = false;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
{tokens.map((line, i) => (
|
|
||||||
<div
|
|
||||||
key={i}
|
|
||||||
{...getLineProps({ line })}
|
|
||||||
className={cn(validation.line === i + 1 && 'bg-destructive/20')}
|
|
||||||
>
|
|
||||||
{line.map((token, key) => {
|
|
||||||
let isSensitive = false;
|
|
||||||
|
|
||||||
// Check for sensitive keys
|
|
||||||
if (token.types.includes('property')) {
|
|
||||||
const content = token.content.replace(/['"]/g, '');
|
|
||||||
// Use shared sensitive key detection utility
|
|
||||||
if (isSensitiveKey(content)) {
|
|
||||||
nextValueIsSensitive = true;
|
|
||||||
} else {
|
|
||||||
nextValueIsSensitive = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Apply masking to values following sensitive keys
|
|
||||||
else if (
|
|
||||||
(token.types.includes('string') ||
|
|
||||||
token.types.includes('number') ||
|
|
||||||
token.types.includes('boolean')) &&
|
|
||||||
nextValueIsSensitive
|
|
||||||
) {
|
|
||||||
isSensitive = true;
|
|
||||||
// Consumes the flag for this value
|
|
||||||
nextValueIsSensitive = false;
|
|
||||||
}
|
|
||||||
// Reset flag on commas or new keys (handled by property check),
|
|
||||||
// but persist through colons and whitespace
|
|
||||||
else if (token.types.includes('punctuation')) {
|
|
||||||
if (token.content !== ':' && token.content !== '[' && token.content !== '{') {
|
|
||||||
nextValueIsSensitive = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const tokenProps = getTokenProps({ token });
|
|
||||||
|
|
||||||
if (isSensitive && isMasked) {
|
|
||||||
tokenProps.className = cn(
|
|
||||||
tokenProps.className,
|
|
||||||
'blur-[3px] select-none opacity-70 transition-all duration-200'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return <span key={key} {...tokenProps} />;
|
|
||||||
})}
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
}}
|
|
||||||
</Highlight>
|
|
||||||
),
|
|
||||||
[isDark, language, validation.line, isMasked]
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className={cn('flex flex-col', className)}>
|
|
||||||
{/* Editor container */}
|
|
||||||
<div
|
|
||||||
className={cn(
|
|
||||||
'relative rounded-md border overflow-hidden',
|
|
||||||
'bg-muted/30',
|
|
||||||
isFocused && 'ring-2 ring-ring ring-offset-2 ring-offset-background',
|
|
||||||
readonly && 'opacity-70 cursor-not-allowed',
|
|
||||||
!validation.valid && 'border-destructive'
|
|
||||||
)}
|
|
||||||
style={{ minHeight }}
|
|
||||||
>
|
|
||||||
<Editor
|
|
||||||
value={value}
|
|
||||||
onValueChange={readonly ? () => {} : onChange}
|
|
||||||
highlight={highlightCode}
|
|
||||||
key={isDark ? 'dark-editor' : 'light-editor'}
|
|
||||||
padding={12}
|
|
||||||
disabled={readonly}
|
|
||||||
onFocus={() => setIsFocused(true)}
|
|
||||||
onBlur={() => setIsFocused(false)}
|
|
||||||
textareaClassName={cn(
|
|
||||||
'focus:outline-none font-mono text-sm',
|
|
||||||
readonly && 'cursor-not-allowed'
|
|
||||||
)}
|
|
||||||
preClassName="font-mono text-sm"
|
|
||||||
style={{
|
|
||||||
fontFamily: 'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace',
|
|
||||||
fontSize: '0.875rem',
|
|
||||||
minHeight,
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
|
|
||||||
{/* Secrets Toggle Overlay */}
|
|
||||||
<div className="absolute top-2 right-2 z-10 opacity-50 hover:opacity-100 transition-opacity">
|
|
||||||
<Button
|
|
||||||
variant="ghost"
|
|
||||||
size="icon"
|
|
||||||
className="h-6 w-6 bg-background/50 hover:bg-background border shadow-sm rounded-full"
|
|
||||||
onClick={() => setIsMasked(!isMasked)}
|
|
||||||
title={isMasked ? 'Reveal sensitive values' : 'Mask sensitive values'}
|
|
||||||
>
|
|
||||||
{isMasked ? <Eye className="h-3 w-3" /> : <EyeOff className="h-3 w-3" />}
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Validation status */}
|
|
||||||
<div className="flex items-center gap-2 mt-2 text-xs">
|
|
||||||
{validation.valid ? (
|
|
||||||
<span className="flex items-center gap-1 text-muted-foreground">
|
|
||||||
<CheckCircle2 className="w-3 h-3 text-green-500" />
|
|
||||||
Valid {language.toUpperCase()}
|
|
||||||
</span>
|
|
||||||
) : (
|
|
||||||
<span className="flex items-center gap-1 text-destructive">
|
|
||||||
<AlertCircle className="w-3 h-3" />
|
|
||||||
{validation.error}
|
|
||||||
{validation.line && ` (line ${validation.line})`}
|
|
||||||
</span>
|
|
||||||
)}
|
|
||||||
{readonly && <span className="ml-auto text-muted-foreground">(Read-only)</span>}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,148 +0,0 @@
|
|||||||
import { useState } from 'react';
|
|
||||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
|
||||||
import { Input } from '@/components/ui/input';
|
|
||||||
import { Button } from '@/components/ui/button';
|
|
||||||
import { Badge } from '@/components/ui/badge';
|
|
||||||
import { ScrollArea } from '@/components/ui/scroll-area';
|
|
||||||
import { CopyIcon, PlayIcon, TerminalIcon } from 'lucide-react';
|
|
||||||
|
|
||||||
interface Command {
|
|
||||||
id: string;
|
|
||||||
command: string;
|
|
||||||
description: string;
|
|
||||||
category: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
const commonCommands: Command[] = [
|
|
||||||
{
|
|
||||||
id: '1',
|
|
||||||
command: 'ccs config',
|
|
||||||
description: 'Open configuration interface',
|
|
||||||
category: 'Config',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: '2',
|
|
||||||
command: 'ccs profile create --name my-profile',
|
|
||||||
description: 'Create a new profile',
|
|
||||||
category: 'Profile',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: '3',
|
|
||||||
command: 'ccs profile switch --name my-profile',
|
|
||||||
description: 'Switch to a profile',
|
|
||||||
category: 'Profile',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: '4',
|
|
||||||
command: 'ccs doctor',
|
|
||||||
description: 'Check system health',
|
|
||||||
category: 'Diagnostics',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: '5',
|
|
||||||
command: 'ccs cliproxy list',
|
|
||||||
description: 'List available CLIProxy providers',
|
|
||||||
category: 'CLIProxy',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: '6',
|
|
||||||
command: 'ccs cliproxy add --provider gemini --token YOUR_TOKEN',
|
|
||||||
description: 'Add CLIProxy provider',
|
|
||||||
category: 'CLIProxy',
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
export function CommandBuilder() {
|
|
||||||
const [command, setCommand] = useState('');
|
|
||||||
const [filteredCommands, setFilteredCommands] = useState(commonCommands);
|
|
||||||
|
|
||||||
const handleCommandChange = (value: string) => {
|
|
||||||
setCommand(value);
|
|
||||||
const filtered = commonCommands.filter(
|
|
||||||
(cmd) =>
|
|
||||||
cmd.command.toLowerCase().includes(value.toLowerCase()) ||
|
|
||||||
cmd.description.toLowerCase().includes(value.toLowerCase())
|
|
||||||
);
|
|
||||||
setFilteredCommands(filtered);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleCommandSelect = (cmd: string) => {
|
|
||||||
setCommand(cmd);
|
|
||||||
setFilteredCommands(commonCommands);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleCopy = () => {
|
|
||||||
navigator.clipboard.writeText(command);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleRun = () => {
|
|
||||||
console.log('Running command:', command);
|
|
||||||
};
|
|
||||||
|
|
||||||
const categories = Array.from(new Set(commonCommands.map((cmd) => cmd.category)));
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Card className="h-[400px] flex flex-col">
|
|
||||||
<CardHeader>
|
|
||||||
<CardTitle className="flex items-center gap-2">
|
|
||||||
<TerminalIcon className="w-5 h-5" />
|
|
||||||
Command Builder
|
|
||||||
</CardTitle>
|
|
||||||
</CardHeader>
|
|
||||||
<CardContent className="flex-1 flex flex-col space-y-4">
|
|
||||||
<div className="space-y-2">
|
|
||||||
<Input
|
|
||||||
placeholder="Type or select a command..."
|
|
||||||
value={command}
|
|
||||||
onChange={(e) => handleCommandChange(e.target.value)}
|
|
||||||
className="font-mono"
|
|
||||||
/>
|
|
||||||
<div className="flex gap-2">
|
|
||||||
<Button variant="outline" size="sm" onClick={handleCopy} disabled={!command}>
|
|
||||||
<CopyIcon className="w-4 h-4 mr-1" />
|
|
||||||
Copy
|
|
||||||
</Button>
|
|
||||||
<Button size="sm" onClick={handleRun} disabled={!command}>
|
|
||||||
<PlayIcon className="w-4 h-4 mr-1" />
|
|
||||||
Run
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="flex gap-2 flex-wrap">
|
|
||||||
{categories.map((category) => (
|
|
||||||
<Badge
|
|
||||||
key={category}
|
|
||||||
variant="secondary"
|
|
||||||
className="text-xs cursor-pointer hover:bg-secondary/80"
|
|
||||||
onClick={() => {
|
|
||||||
const categoryCommands = commonCommands.filter((cmd) => cmd.category === category);
|
|
||||||
console.log(`${category} commands:`, categoryCommands);
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{category}
|
|
||||||
</Badge>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<ScrollArea className="flex-1">
|
|
||||||
<div className="space-y-2">
|
|
||||||
{filteredCommands.map((cmd) => (
|
|
||||||
<div
|
|
||||||
key={cmd.id}
|
|
||||||
className="p-3 rounded-lg border cursor-pointer hover:bg-accent/50 transition-colors"
|
|
||||||
onClick={() => handleCommandSelect(cmd.command)}
|
|
||||||
>
|
|
||||||
<div className="font-mono text-sm">{cmd.command}</div>
|
|
||||||
<div className="text-xs text-muted-foreground mt-1">{cmd.description}</div>
|
|
||||||
<Badge variant="outline" className="mt-2 text-xs">
|
|
||||||
{cmd.category}
|
|
||||||
</Badge>
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
</ScrollArea>
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,50 +0,0 @@
|
|||||||
import {
|
|
||||||
AlertDialog,
|
|
||||||
AlertDialogAction,
|
|
||||||
AlertDialogCancel,
|
|
||||||
AlertDialogContent,
|
|
||||||
AlertDialogDescription,
|
|
||||||
AlertDialogFooter,
|
|
||||||
AlertDialogHeader,
|
|
||||||
AlertDialogTitle,
|
|
||||||
} from '@/components/ui/alert-dialog';
|
|
||||||
|
|
||||||
interface ConfirmDialogProps {
|
|
||||||
open: boolean;
|
|
||||||
onConfirm: () => void;
|
|
||||||
onCancel: () => void;
|
|
||||||
title: string;
|
|
||||||
description: string;
|
|
||||||
confirmText?: string;
|
|
||||||
variant?: 'default' | 'destructive';
|
|
||||||
}
|
|
||||||
|
|
||||||
export function ConfirmDialog({
|
|
||||||
open,
|
|
||||||
onConfirm,
|
|
||||||
onCancel,
|
|
||||||
title,
|
|
||||||
description,
|
|
||||||
confirmText = 'Confirm',
|
|
||||||
variant = 'default',
|
|
||||||
}: ConfirmDialogProps) {
|
|
||||||
return (
|
|
||||||
<AlertDialog open={open} onOpenChange={(isOpen) => !isOpen && onCancel()}>
|
|
||||||
<AlertDialogContent>
|
|
||||||
<AlertDialogHeader>
|
|
||||||
<AlertDialogTitle>{title}</AlertDialogTitle>
|
|
||||||
<AlertDialogDescription>{description}</AlertDialogDescription>
|
|
||||||
</AlertDialogHeader>
|
|
||||||
<AlertDialogFooter>
|
|
||||||
<AlertDialogCancel onClick={onCancel}>Cancel</AlertDialogCancel>
|
|
||||||
<AlertDialogAction
|
|
||||||
onClick={onConfirm}
|
|
||||||
className={variant === 'destructive' ? 'bg-red-600 hover:bg-red-700' : ''}
|
|
||||||
>
|
|
||||||
{confirmText}
|
|
||||||
</AlertDialogAction>
|
|
||||||
</AlertDialogFooter>
|
|
||||||
</AlertDialogContent>
|
|
||||||
</AlertDialog>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
/**
|
|
||||||
* Connection Indicator (Phase 04)
|
|
||||||
*
|
|
||||||
* Shows WebSocket connection status in the header.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { Wifi, WifiOff } from 'lucide-react';
|
|
||||||
import { useWebSocket } from '@/hooks/use-websocket';
|
|
||||||
|
|
||||||
export function ConnectionIndicator() {
|
|
||||||
const { status } = useWebSocket();
|
|
||||||
|
|
||||||
const statusConfig = {
|
|
||||||
connected: { icon: Wifi, color: 'text-green-600', label: 'Connected' },
|
|
||||||
connecting: { icon: Wifi, color: 'text-yellow-500', label: 'Connecting...' },
|
|
||||||
disconnected: { icon: WifiOff, color: 'text-red-500', label: 'Disconnected' },
|
|
||||||
};
|
|
||||||
|
|
||||||
const config = statusConfig[status];
|
|
||||||
const Icon = config.icon;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className={`flex items-center gap-1 text-sm ${config.color}`}>
|
|
||||||
<Icon className="w-4 h-4" />
|
|
||||||
<span className="hidden sm:inline">{config.label}</span>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
/**
|
|
||||||
* Docs Link Button
|
|
||||||
*
|
|
||||||
* Links to CCS documentation site for guides and reference.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { BookOpen } from 'lucide-react';
|
|
||||||
import { Button } from '@/components/ui/button';
|
|
||||||
|
|
||||||
const DOCS_URL = 'https://docs.ccs.kaitran.ca';
|
|
||||||
|
|
||||||
export function DocsLink() {
|
|
||||||
return (
|
|
||||||
<Button variant="ghost" size="icon" asChild title="View documentation">
|
|
||||||
<a href={DOCS_URL} target="_blank" rel="noopener noreferrer">
|
|
||||||
<BookOpen className="w-4 h-4" />
|
|
||||||
</a>
|
|
||||||
</Button>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
/**
|
|
||||||
* GitHub Link Button
|
|
||||||
*
|
|
||||||
* Links to CCS GitHub issues page for bug reports and feature requests.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { Github } from 'lucide-react';
|
|
||||||
import { Button } from '@/components/ui/button';
|
|
||||||
|
|
||||||
const GITHUB_REPO_URL = 'https://github.com/kaitranntt/ccs/issues';
|
|
||||||
|
|
||||||
export function GitHubLink() {
|
|
||||||
return (
|
|
||||||
<Button variant="ghost" size="icon" asChild title="Report an issue on GitHub">
|
|
||||||
<a href={GITHUB_REPO_URL} target="_blank" rel="noopener noreferrer">
|
|
||||||
<Github className="w-4 h-4" />
|
|
||||||
</a>
|
|
||||||
</Button>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,132 +0,0 @@
|
|||||||
/**
|
|
||||||
* Global Environment Variables Indicator
|
|
||||||
*
|
|
||||||
* Shows which env vars from global_env will be injected at runtime.
|
|
||||||
* Displayed below the Raw Configuration (JSON) section in profile editors.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { useState, useEffect } from 'react';
|
|
||||||
import { Link } from 'react-router-dom';
|
|
||||||
import { Settings2, ChevronDown, ChevronUp, ExternalLink, Info } from 'lucide-react';
|
|
||||||
import { Button } from '@/components/ui/button';
|
|
||||||
|
|
||||||
interface GlobalEnvConfig {
|
|
||||||
enabled: boolean;
|
|
||||||
env: Record<string, string>;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface GlobalEnvIndicatorProps {
|
|
||||||
/** Current profile's env vars (to show which are overridden) */
|
|
||||||
profileEnv?: Record<string, string>;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function GlobalEnvIndicator({ profileEnv = {} }: GlobalEnvIndicatorProps) {
|
|
||||||
const [config, setConfig] = useState<GlobalEnvConfig | null>(null);
|
|
||||||
const [loading, setLoading] = useState(true);
|
|
||||||
const [expanded, setExpanded] = useState(false);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
fetchConfig();
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const fetchConfig = async () => {
|
|
||||||
try {
|
|
||||||
setLoading(true);
|
|
||||||
const res = await fetch('/api/global-env');
|
|
||||||
if (!res.ok) throw new Error('Failed to load');
|
|
||||||
const data = await res.json();
|
|
||||||
setConfig(data);
|
|
||||||
} catch {
|
|
||||||
setConfig(null);
|
|
||||||
} finally {
|
|
||||||
setLoading(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Don't render if loading or disabled or no vars
|
|
||||||
if (loading) return null;
|
|
||||||
if (!config?.enabled) return null;
|
|
||||||
|
|
||||||
const envVars = config.env || {};
|
|
||||||
const envKeys = Object.keys(envVars);
|
|
||||||
if (envKeys.length === 0) return null;
|
|
||||||
|
|
||||||
// Check which keys are already in profile (won't be overridden)
|
|
||||||
const injectedKeys = envKeys.filter((key) => !(key in profileEnv));
|
|
||||||
const overriddenKeys = envKeys.filter((key) => key in profileEnv);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="border-t bg-muted/20">
|
|
||||||
{/* Header - clickable to expand */}
|
|
||||||
<button
|
|
||||||
onClick={() => setExpanded(!expanded)}
|
|
||||||
className="w-full px-4 py-2 flex items-center gap-2 hover:bg-muted/30 transition-colors"
|
|
||||||
>
|
|
||||||
<Info className="w-4 h-4 text-blue-500" />
|
|
||||||
<span className="text-xs text-muted-foreground flex-1 text-left">
|
|
||||||
<span className="font-medium text-foreground">{injectedKeys.length}</span> global env var
|
|
||||||
{injectedKeys.length !== 1 ? 's' : ''} will be injected at runtime
|
|
||||||
{overriddenKeys.length > 0 && (
|
|
||||||
<span className="text-amber-600 dark:text-amber-400 ml-1">
|
|
||||||
({overriddenKeys.length} overridden by profile)
|
|
||||||
</span>
|
|
||||||
)}
|
|
||||||
</span>
|
|
||||||
{expanded ? (
|
|
||||||
<ChevronUp className="w-4 h-4 text-muted-foreground" />
|
|
||||||
) : (
|
|
||||||
<ChevronDown className="w-4 h-4 text-muted-foreground" />
|
|
||||||
)}
|
|
||||||
</button>
|
|
||||||
|
|
||||||
{/* Expanded content */}
|
|
||||||
{expanded && (
|
|
||||||
<div className="px-4 pb-3 space-y-2">
|
|
||||||
{/* Injected vars */}
|
|
||||||
{injectedKeys.length > 0 && (
|
|
||||||
<div className="space-y-1">
|
|
||||||
{injectedKeys.map((key) => (
|
|
||||||
<div
|
|
||||||
key={key}
|
|
||||||
className="flex items-center gap-2 text-xs font-mono bg-green-500/10 text-green-700 dark:text-green-400 px-2 py-1 rounded"
|
|
||||||
>
|
|
||||||
<span className="text-green-500">+</span>
|
|
||||||
<span className="truncate">
|
|
||||||
{key}={envVars[key]}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{/* Overridden vars (profile takes precedence) */}
|
|
||||||
{overriddenKeys.length > 0 && (
|
|
||||||
<div className="space-y-1">
|
|
||||||
<p className="text-xs text-muted-foreground">Skipped (profile already defines):</p>
|
|
||||||
{overriddenKeys.map((key) => (
|
|
||||||
<div
|
|
||||||
key={key}
|
|
||||||
className="flex items-center gap-2 text-xs font-mono bg-amber-500/10 text-amber-700 dark:text-amber-400 px-2 py-1 rounded"
|
|
||||||
>
|
|
||||||
<span className="text-amber-500">~</span>
|
|
||||||
<span className="truncate">{key}</span>
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{/* Link to settings */}
|
|
||||||
<div className="pt-2 border-t border-border/50">
|
|
||||||
<Button variant="ghost" size="sm" asChild className="h-7 text-xs gap-1.5 -ml-2">
|
|
||||||
<Link to="/settings?tab=globalenv">
|
|
||||||
<Settings2 className="w-3.5 h-3.5" />
|
|
||||||
Configure in Settings
|
|
||||||
<ExternalLink className="w-3 h-3 opacity-50" />
|
|
||||||
</Link>
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,68 +0,0 @@
|
|||||||
import { Card, CardContent } from '@/components/ui/card';
|
|
||||||
import { Button } from '@/components/ui/button';
|
|
||||||
import { CheckCircle, AlertTriangle, XCircle, Wrench } from 'lucide-react';
|
|
||||||
import { useFixHealth } from '@/hooks/use-health';
|
|
||||||
|
|
||||||
interface HealthCheck {
|
|
||||||
id: string;
|
|
||||||
name: string;
|
|
||||||
status: 'ok' | 'warning' | 'error';
|
|
||||||
message: string;
|
|
||||||
details?: string;
|
|
||||||
fixable?: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
const statusConfig = {
|
|
||||||
ok: {
|
|
||||||
icon: CheckCircle,
|
|
||||||
color: 'text-green-600',
|
|
||||||
bg: 'bg-green-50 dark:bg-green-900/20',
|
|
||||||
border: 'border-green-200 dark:border-green-800',
|
|
||||||
},
|
|
||||||
warning: {
|
|
||||||
icon: AlertTriangle,
|
|
||||||
color: 'text-yellow-500',
|
|
||||||
bg: 'bg-yellow-50 dark:bg-yellow-900/20',
|
|
||||||
border: 'border-yellow-200 dark:border-yellow-800',
|
|
||||||
},
|
|
||||||
error: {
|
|
||||||
icon: XCircle,
|
|
||||||
color: 'text-red-500',
|
|
||||||
bg: 'bg-red-50 dark:bg-red-900/20',
|
|
||||||
border: 'border-red-200 dark:border-red-800',
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
export function HealthCard({ check }: { check: HealthCheck }) {
|
|
||||||
const fixMutation = useFixHealth();
|
|
||||||
const config = statusConfig[check.status];
|
|
||||||
const Icon = config.icon;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Card className={`${config.bg} ${config.border} border`}>
|
|
||||||
<CardContent className="pt-4">
|
|
||||||
<div className="flex items-start justify-between">
|
|
||||||
<div className="flex items-center gap-2">
|
|
||||||
<Icon className={`w-5 h-5 ${config.color}`} />
|
|
||||||
<span className="font-medium">{check.name}</span>
|
|
||||||
</div>
|
|
||||||
{check.fixable && check.status !== 'ok' && (
|
|
||||||
<Button
|
|
||||||
size="sm"
|
|
||||||
variant="outline"
|
|
||||||
onClick={() => fixMutation.mutate(check.id)}
|
|
||||||
disabled={fixMutation.isPending}
|
|
||||||
>
|
|
||||||
<Wrench className="w-3 h-3 mr-1" />
|
|
||||||
Fix
|
|
||||||
</Button>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
<p className="text-sm text-muted-foreground mt-2">{check.message}</p>
|
|
||||||
{check.details && (
|
|
||||||
<p className="text-xs text-muted-foreground mt-1 font-mono truncate">{check.details}</p>
|
|
||||||
)}
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,162 +0,0 @@
|
|||||||
import { ChevronRight, Copy, Terminal, Wrench } from 'lucide-react';
|
|
||||||
import { Button } from '@/components/ui/button';
|
|
||||||
import { Collapsible, CollapsibleContent, CollapsibleTrigger } from '@/components/ui/collapsible';
|
|
||||||
import { useFixHealth, type HealthCheck } from '@/hooks/use-health';
|
|
||||||
import { cn } from '@/lib/utils';
|
|
||||||
import { useState } from 'react';
|
|
||||||
import { toast } from 'sonner';
|
|
||||||
|
|
||||||
const statusConfig = {
|
|
||||||
ok: { dot: 'bg-green-500', label: 'OK', labelColor: 'text-green-500' },
|
|
||||||
warning: { dot: 'bg-yellow-500', label: 'WARN', labelColor: 'text-yellow-500' },
|
|
||||||
error: { dot: 'bg-red-500', label: 'ERR', labelColor: 'text-red-500' },
|
|
||||||
info: { dot: 'bg-blue-500', label: 'INFO', labelColor: 'text-blue-500' },
|
|
||||||
};
|
|
||||||
|
|
||||||
export function HealthCheckItem({ check }: { check: HealthCheck }) {
|
|
||||||
const fixMutation = useFixHealth();
|
|
||||||
const config = statusConfig[check.status];
|
|
||||||
const [isOpen, setIsOpen] = useState(false);
|
|
||||||
const hasExpandableContent = check.details || check.fix;
|
|
||||||
|
|
||||||
const copyToClipboard = (text: string) => {
|
|
||||||
navigator.clipboard.writeText(text);
|
|
||||||
toast.success('Copied to clipboard');
|
|
||||||
};
|
|
||||||
|
|
||||||
// Compact single-line display for items without expandable content
|
|
||||||
if (!hasExpandableContent) {
|
|
||||||
return (
|
|
||||||
<div
|
|
||||||
className={cn(
|
|
||||||
'group flex items-center gap-3 px-3 py-2 rounded-lg',
|
|
||||||
'hover:bg-muted/50 transition-colors duration-150',
|
|
||||||
'border border-transparent hover:border-border/50'
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
{/* Status dot with pulse animation */}
|
|
||||||
<div className="relative flex items-center justify-center w-4 h-4">
|
|
||||||
<div className={cn('w-2 h-2 rounded-full', config.dot)} />
|
|
||||||
{check.status !== 'ok' && (
|
|
||||||
<div
|
|
||||||
className={cn('absolute w-2 h-2 rounded-full animate-ping opacity-75', config.dot)}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Check name */}
|
|
||||||
<span className="flex-1 text-sm font-medium truncate">{check.name}</span>
|
|
||||||
|
|
||||||
{/* Status label */}
|
|
||||||
<span className={cn('font-mono text-xs font-semibold', config.labelColor)}>
|
|
||||||
[{config.label}]
|
|
||||||
</span>
|
|
||||||
|
|
||||||
{/* Fix button for fixable non-ok items */}
|
|
||||||
{check.fixable && check.status !== 'ok' && (
|
|
||||||
<Button
|
|
||||||
size="sm"
|
|
||||||
variant="ghost"
|
|
||||||
onClick={() => fixMutation.mutate(check.id)}
|
|
||||||
disabled={fixMutation.isPending}
|
|
||||||
className="h-6 px-2 text-xs opacity-0 group-hover:opacity-100 transition-opacity"
|
|
||||||
>
|
|
||||||
<Wrench className="w-3 h-3 mr-1" />
|
|
||||||
Fix
|
|
||||||
</Button>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Expandable display for items with details or fix commands
|
|
||||||
return (
|
|
||||||
<Collapsible open={isOpen} onOpenChange={setIsOpen}>
|
|
||||||
<div
|
|
||||||
className={cn(
|
|
||||||
'group rounded-lg border transition-all duration-150',
|
|
||||||
isOpen
|
|
||||||
? 'border-border bg-muted/30'
|
|
||||||
: 'border-transparent hover:border-border/50 hover:bg-muted/50'
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
<CollapsibleTrigger asChild>
|
|
||||||
<button className="w-full flex items-center gap-3 px-3 py-2 text-left">
|
|
||||||
{/* Status dot */}
|
|
||||||
<div className="relative flex items-center justify-center w-4 h-4">
|
|
||||||
<div className={cn('w-2 h-2 rounded-full', config.dot)} />
|
|
||||||
{check.status !== 'ok' && (
|
|
||||||
<div
|
|
||||||
className={cn(
|
|
||||||
'absolute w-2 h-2 rounded-full animate-ping opacity-75',
|
|
||||||
config.dot
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Check name */}
|
|
||||||
<span className="flex-1 text-sm font-medium truncate">{check.name}</span>
|
|
||||||
|
|
||||||
{/* Status label */}
|
|
||||||
<span className={cn('font-mono text-xs font-semibold', config.labelColor)}>
|
|
||||||
[{config.label}]
|
|
||||||
</span>
|
|
||||||
|
|
||||||
{/* Chevron indicator */}
|
|
||||||
<ChevronRight
|
|
||||||
className={cn(
|
|
||||||
'w-4 h-4 text-muted-foreground transition-transform duration-200',
|
|
||||||
isOpen && 'rotate-90'
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
</button>
|
|
||||||
</CollapsibleTrigger>
|
|
||||||
|
|
||||||
<CollapsibleContent>
|
|
||||||
<div className="px-3 pb-3 pt-1 space-y-2 ml-7">
|
|
||||||
{/* Message */}
|
|
||||||
<p className="text-xs text-muted-foreground">{check.message}</p>
|
|
||||||
|
|
||||||
{/* Details block */}
|
|
||||||
{check.details && (
|
|
||||||
<pre className="text-xs font-mono text-muted-foreground bg-background/50 rounded p-2 overflow-x-auto border border-border/50">
|
|
||||||
{check.details}
|
|
||||||
</pre>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{/* Fix command block */}
|
|
||||||
{check.fix && (
|
|
||||||
<div className="flex items-center gap-2">
|
|
||||||
<div className="flex-1 flex items-center gap-2 bg-background/50 rounded px-2 py-1.5 border border-border/50">
|
|
||||||
<Terminal className="w-3 h-3 text-muted-foreground shrink-0" />
|
|
||||||
<code className="text-xs font-mono flex-1 truncate">{check.fix}</code>
|
|
||||||
<Button
|
|
||||||
variant="ghost"
|
|
||||||
size="sm"
|
|
||||||
onClick={() => check.fix && copyToClipboard(check.fix)}
|
|
||||||
className="h-5 w-5 p-0"
|
|
||||||
>
|
|
||||||
<Copy className="w-3 h-3" />
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{check.fixable && check.status !== 'ok' && (
|
|
||||||
<Button
|
|
||||||
size="sm"
|
|
||||||
onClick={() => fixMutation.mutate(check.id)}
|
|
||||||
disabled={fixMutation.isPending}
|
|
||||||
className="h-7 px-3 text-xs"
|
|
||||||
>
|
|
||||||
<Wrench className="w-3 h-3 mr-1" />
|
|
||||||
Apply Fix
|
|
||||||
</Button>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</CollapsibleContent>
|
|
||||||
</div>
|
|
||||||
</Collapsible>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,91 +0,0 @@
|
|||||||
import { cn } from '@/lib/utils';
|
|
||||||
|
|
||||||
interface HealthGaugeProps {
|
|
||||||
passed: number;
|
|
||||||
total: number;
|
|
||||||
status: 'ok' | 'warning' | 'error';
|
|
||||||
size?: 'sm' | 'md' | 'lg';
|
|
||||||
}
|
|
||||||
|
|
||||||
const sizeConfig = {
|
|
||||||
sm: { dimension: 80, strokeWidth: 6, fontSize: 'text-lg', labelSize: 'text-[10px]' },
|
|
||||||
md: { dimension: 120, strokeWidth: 8, fontSize: 'text-3xl', labelSize: 'text-xs' },
|
|
||||||
lg: { dimension: 160, strokeWidth: 10, fontSize: 'text-4xl', labelSize: 'text-sm' },
|
|
||||||
};
|
|
||||||
|
|
||||||
const statusColors = {
|
|
||||||
ok: { stroke: '#22C55E', glow: 'rgba(34, 197, 94, 0.4)' },
|
|
||||||
warning: { stroke: '#EAB308', glow: 'rgba(234, 179, 8, 0.4)' },
|
|
||||||
error: { stroke: '#EF4444', glow: 'rgba(239, 68, 68, 0.4)' },
|
|
||||||
};
|
|
||||||
|
|
||||||
export function HealthGauge({ passed, total, status, size = 'md' }: HealthGaugeProps) {
|
|
||||||
const config = sizeConfig[size];
|
|
||||||
const colors = statusColors[status];
|
|
||||||
const percentage = total > 0 ? Math.round((passed / total) * 100) : 0;
|
|
||||||
|
|
||||||
const radius = (config.dimension - config.strokeWidth) / 2;
|
|
||||||
const circumference = 2 * Math.PI * radius;
|
|
||||||
const strokeDashoffset = circumference - (percentage / 100) * circumference;
|
|
||||||
const center = config.dimension / 2;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="relative inline-flex items-center justify-center">
|
|
||||||
<svg
|
|
||||||
width={config.dimension}
|
|
||||||
height={config.dimension}
|
|
||||||
className="transform -rotate-90"
|
|
||||||
style={{ filter: `drop-shadow(0 0 8px ${colors.glow})` }}
|
|
||||||
>
|
|
||||||
{/* Background track */}
|
|
||||||
<circle
|
|
||||||
cx={center}
|
|
||||||
cy={center}
|
|
||||||
r={radius}
|
|
||||||
fill="none"
|
|
||||||
stroke="currentColor"
|
|
||||||
strokeWidth={config.strokeWidth}
|
|
||||||
className="text-muted/30"
|
|
||||||
/>
|
|
||||||
{/* Progress arc */}
|
|
||||||
<circle
|
|
||||||
cx={center}
|
|
||||||
cy={center}
|
|
||||||
r={radius}
|
|
||||||
fill="none"
|
|
||||||
stroke={colors.stroke}
|
|
||||||
strokeWidth={config.strokeWidth}
|
|
||||||
strokeLinecap="round"
|
|
||||||
strokeDasharray={circumference}
|
|
||||||
strokeDashoffset={strokeDashoffset}
|
|
||||||
className="transition-all duration-1000 ease-out"
|
|
||||||
/>
|
|
||||||
{/* Animated glow dot at end of arc */}
|
|
||||||
{percentage > 0 && (
|
|
||||||
<circle
|
|
||||||
cx={center + radius * Math.cos((percentage / 100) * 2 * Math.PI - Math.PI / 2)}
|
|
||||||
cy={center + radius * Math.sin((percentage / 100) * 2 * Math.PI - Math.PI / 2)}
|
|
||||||
r={config.strokeWidth / 2}
|
|
||||||
fill={colors.stroke}
|
|
||||||
className="animate-pulse"
|
|
||||||
style={{ filter: `drop-shadow(0 0 4px ${colors.glow})` }}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</svg>
|
|
||||||
{/* Center content */}
|
|
||||||
<div className="absolute inset-0 flex flex-col items-center justify-center">
|
|
||||||
<span className={cn('font-mono font-bold tracking-tight', config.fontSize)}>
|
|
||||||
{percentage}
|
|
||||||
</span>
|
|
||||||
<span
|
|
||||||
className={cn(
|
|
||||||
'font-mono uppercase tracking-widest text-muted-foreground',
|
|
||||||
config.labelSize
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
health
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,111 +0,0 @@
|
|||||||
import { ChevronDown, Monitor, Settings, Users, Shield, Zap } from 'lucide-react';
|
|
||||||
import { Collapsible, CollapsibleContent, CollapsibleTrigger } from '@/components/ui/collapsible';
|
|
||||||
import { HealthCheckItem } from '@/components/health-check-item';
|
|
||||||
import { type HealthGroup } from '@/hooks/use-health';
|
|
||||||
import { cn } from '@/lib/utils';
|
|
||||||
import { useState } from 'react';
|
|
||||||
|
|
||||||
const groupIcons: Record<string, typeof Monitor> = {
|
|
||||||
Monitor,
|
|
||||||
Settings,
|
|
||||||
Users,
|
|
||||||
Shield,
|
|
||||||
Zap,
|
|
||||||
};
|
|
||||||
|
|
||||||
interface HealthGroupSectionProps {
|
|
||||||
group: HealthGroup;
|
|
||||||
defaultOpen?: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function HealthGroupSection({ group, defaultOpen = true }: HealthGroupSectionProps) {
|
|
||||||
const [isOpen, setIsOpen] = useState(defaultOpen);
|
|
||||||
const Icon = groupIcons[group.icon] || Monitor;
|
|
||||||
|
|
||||||
const passed = group.checks.filter((c) => c.status === 'ok').length;
|
|
||||||
const total = group.checks.length;
|
|
||||||
const hasErrors = group.checks.some((c) => c.status === 'error');
|
|
||||||
const hasWarnings = group.checks.some((c) => c.status === 'warning');
|
|
||||||
const percentage = Math.round((passed / total) * 100);
|
|
||||||
|
|
||||||
// Determine status color
|
|
||||||
const statusColor = hasErrors
|
|
||||||
? 'text-red-500'
|
|
||||||
: hasWarnings
|
|
||||||
? 'text-yellow-500'
|
|
||||||
: 'text-green-500';
|
|
||||||
const progressColor = hasErrors ? 'bg-red-500' : hasWarnings ? 'bg-yellow-500' : 'bg-green-500';
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Collapsible open={isOpen} onOpenChange={setIsOpen}>
|
|
||||||
<div
|
|
||||||
className={cn(
|
|
||||||
'rounded-lg border transition-all duration-200',
|
|
||||||
hasErrors ? 'border-red-500/30' : hasWarnings ? 'border-yellow-500/30' : 'border-border'
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
{/* Group header */}
|
|
||||||
<CollapsibleTrigger asChild>
|
|
||||||
<button
|
|
||||||
className={cn(
|
|
||||||
'w-full flex items-center gap-3 p-3 text-left rounded-lg',
|
|
||||||
'hover:bg-muted/50 transition-colors duration-150',
|
|
||||||
isOpen && 'rounded-b-none border-b border-border/50'
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
{/* Group icon */}
|
|
||||||
<div
|
|
||||||
className={cn(
|
|
||||||
'p-1.5 rounded-md',
|
|
||||||
hasErrors
|
|
||||||
? 'bg-red-500/10 text-red-500'
|
|
||||||
: hasWarnings
|
|
||||||
? 'bg-yellow-500/10 text-yellow-500'
|
|
||||||
: 'bg-muted text-muted-foreground'
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
<Icon className="w-4 h-4" />
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Group name */}
|
|
||||||
<span className="flex-1 text-sm font-semibold">{group.name}</span>
|
|
||||||
|
|
||||||
{/* Progress indicator (collapsed view) */}
|
|
||||||
{!isOpen && (
|
|
||||||
<div className="flex items-center gap-2">
|
|
||||||
<div className="w-16 h-1.5 rounded-full bg-muted overflow-hidden">
|
|
||||||
<div
|
|
||||||
className={cn('h-full transition-all duration-500', progressColor)}
|
|
||||||
style={{ width: `${percentage}%` }}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{/* Count badge */}
|
|
||||||
<span className={cn('font-mono text-xs font-semibold', statusColor)}>
|
|
||||||
{passed}/{total}
|
|
||||||
</span>
|
|
||||||
|
|
||||||
{/* Chevron */}
|
|
||||||
<ChevronDown
|
|
||||||
className={cn(
|
|
||||||
'w-4 h-4 text-muted-foreground transition-transform duration-200',
|
|
||||||
isOpen && 'rotate-180'
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
</button>
|
|
||||||
</CollapsibleTrigger>
|
|
||||||
|
|
||||||
{/* Checks list */}
|
|
||||||
<CollapsibleContent>
|
|
||||||
<div className="p-2 space-y-0.5">
|
|
||||||
{group.checks.map((check) => (
|
|
||||||
<HealthCheckItem key={check.id} check={check} />
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
</CollapsibleContent>
|
|
||||||
</div>
|
|
||||||
</Collapsible>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,85 +0,0 @@
|
|||||||
import { cn } from '@/lib/utils';
|
|
||||||
|
|
||||||
interface HealthStatsBarProps {
|
|
||||||
total: number;
|
|
||||||
passed: number;
|
|
||||||
warnings: number;
|
|
||||||
errors: number;
|
|
||||||
info: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface StatItemProps {
|
|
||||||
label: string;
|
|
||||||
value: number;
|
|
||||||
color: string;
|
|
||||||
bgColor: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
function StatItem({ label, value, color, bgColor }: StatItemProps) {
|
|
||||||
return (
|
|
||||||
<div className="flex items-center gap-2">
|
|
||||||
<div className={cn('w-2 h-2 rounded-full animate-pulse', bgColor)} />
|
|
||||||
<span className="text-xs font-medium text-muted-foreground uppercase tracking-wider">
|
|
||||||
{label}
|
|
||||||
</span>
|
|
||||||
<span className={cn('font-mono font-bold text-sm', color)}>{value}</span>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function HealthStatsBar({ total, passed, warnings, errors, info }: HealthStatsBarProps) {
|
|
||||||
// Calculate percentages for the progress bar
|
|
||||||
const passedPct = (passed / total) * 100;
|
|
||||||
const warningPct = (warnings / total) * 100;
|
|
||||||
const errorPct = (errors / total) * 100;
|
|
||||||
const infoPct = (info / total) * 100;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="space-y-3">
|
|
||||||
{/* Progress bar visualization */}
|
|
||||||
<div className="h-2 rounded-full overflow-hidden bg-muted/50 flex">
|
|
||||||
{errorPct > 0 && (
|
|
||||||
<div
|
|
||||||
className="h-full bg-red-500 transition-all duration-500"
|
|
||||||
style={{ width: `${errorPct}%` }}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
{warningPct > 0 && (
|
|
||||||
<div
|
|
||||||
className="h-full bg-yellow-500 transition-all duration-500"
|
|
||||||
style={{ width: `${warningPct}%` }}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
{infoPct > 0 && (
|
|
||||||
<div
|
|
||||||
className="h-full bg-blue-500 transition-all duration-500"
|
|
||||||
style={{ width: `${infoPct}%` }}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
{passedPct > 0 && (
|
|
||||||
<div
|
|
||||||
className="h-full bg-green-500 transition-all duration-500"
|
|
||||||
style={{ width: `${passedPct}%` }}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Stats row */}
|
|
||||||
<div className="flex items-center justify-between gap-4 flex-wrap">
|
|
||||||
<div className="flex items-center gap-1">
|
|
||||||
<span className="text-xs font-medium text-muted-foreground uppercase tracking-wider">
|
|
||||||
Checks
|
|
||||||
</span>
|
|
||||||
<span className="font-mono font-bold text-lg">{total}</span>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="flex items-center gap-4 flex-wrap">
|
|
||||||
<StatItem label="OK" value={passed} color="text-green-500" bgColor="bg-green-500" />
|
|
||||||
<StatItem label="WARN" value={warnings} color="text-yellow-500" bgColor="bg-yellow-500" />
|
|
||||||
<StatItem label="ERR" value={errors} color="text-red-500" bgColor="bg-red-500" />
|
|
||||||
<StatItem label="INFO" value={info} color="text-blue-500" bgColor="bg-blue-500" />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
import { Badge } from '@/components/ui/badge';
|
|
||||||
import { CcsLogo } from '@/components/ccs-logo';
|
|
||||||
|
|
||||||
interface HeroSectionProps {
|
|
||||||
version?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function HeroSection({ version = '5.0.0' }: HeroSectionProps) {
|
|
||||||
return (
|
|
||||||
<div className="flex items-center gap-4">
|
|
||||||
<CcsLogo size="lg" showText={false} />
|
|
||||||
<div>
|
|
||||||
<div className="flex items-center gap-3">
|
|
||||||
<h1 className="text-2xl font-bold">CCS Config</h1>
|
|
||||||
<Badge variant="outline" className="font-mono text-xs">
|
|
||||||
v{version}
|
|
||||||
</Badge>
|
|
||||||
</div>
|
|
||||||
<p className="text-muted-foreground text-sm mt-1">Claude Code Switch Dashboard</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,71 +0,0 @@
|
|||||||
import { Separator } from '@/components/ui/separator';
|
|
||||||
import { Button } from '@/components/ui/button';
|
|
||||||
import { FileTextIcon, SettingsIcon, GithubIcon, ExternalLinkIcon } from 'lucide-react';
|
|
||||||
|
|
||||||
export function HubFooter() {
|
|
||||||
const currentYear = new Date().getFullYear();
|
|
||||||
|
|
||||||
const footerLinks = [
|
|
||||||
{
|
|
||||||
icon: <FileTextIcon className="w-4 h-4" />,
|
|
||||||
label: 'Logs',
|
|
||||||
href: '#logs',
|
|
||||||
onClick: () => console.log('Navigate to Logs'),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
icon: <SettingsIcon className="w-4 h-4" />,
|
|
||||||
label: 'Settings',
|
|
||||||
href: '#settings',
|
|
||||||
onClick: () => console.log('Navigate to Settings'),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
icon: <GithubIcon className="w-4 h-4" />,
|
|
||||||
label: 'GitHub',
|
|
||||||
href: 'https://github.com/kaitranntt/ccs',
|
|
||||||
external: true,
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
return (
|
|
||||||
<footer className="mt-auto border-t bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/60">
|
|
||||||
<div className="container flex h-14 items-center">
|
|
||||||
<div className="flex items-center space-x-2 text-sm text-muted-foreground">
|
|
||||||
<span>CCS v0.0.0</span>
|
|
||||||
<Separator orientation="vertical" className="h-4" />
|
|
||||||
<span>© {currentYear} kaitranntt</span>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="ml-auto flex items-center space-x-2">
|
|
||||||
{footerLinks.map((link) => (
|
|
||||||
<Button
|
|
||||||
key={link.label}
|
|
||||||
variant="ghost"
|
|
||||||
size="sm"
|
|
||||||
asChild={link.external}
|
|
||||||
onClick={link.onClick}
|
|
||||||
className="h-8 px-2"
|
|
||||||
>
|
|
||||||
{link.external ? (
|
|
||||||
<a
|
|
||||||
href={link.href}
|
|
||||||
target="_blank"
|
|
||||||
rel="noopener noreferrer"
|
|
||||||
className="flex items-center gap-1"
|
|
||||||
>
|
|
||||||
{link.icon}
|
|
||||||
<span className="hidden sm:inline">{link.label}</span>
|
|
||||||
<ExternalLinkIcon className="w-3 h-3" />
|
|
||||||
</a>
|
|
||||||
) : (
|
|
||||||
<div className="flex items-center gap-1">
|
|
||||||
{link.icon}
|
|
||||||
<span className="hidden sm:inline">{link.label}</span>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</Button>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</footer>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,69 +0,0 @@
|
|||||||
import { Suspense } from 'react';
|
|
||||||
import { Outlet } from 'react-router-dom';
|
|
||||||
import { SidebarProvider } from '@/components/ui/sidebar';
|
|
||||||
import { AppSidebar } from '@/components/app-sidebar';
|
|
||||||
import { ThemeToggle } from '@/components/theme-toggle';
|
|
||||||
import { PrivacyToggle } from '@/components/privacy-toggle';
|
|
||||||
import { GitHubLink } from '@/components/github-link';
|
|
||||||
import { DocsLink } from '@/components/docs-link';
|
|
||||||
import { ConnectionIndicator } from '@/components/connection-indicator';
|
|
||||||
import { LocalhostDisclaimer } from '@/components/localhost-disclaimer';
|
|
||||||
import { Skeleton } from '@/components/ui/skeleton';
|
|
||||||
import { ClaudeKitBadge } from '@/components/claudekit-badge';
|
|
||||||
import { SponsorButton } from '@/components/sponsor-button';
|
|
||||||
import { ProjectSelectionDialog } from '@/components/project-selection-dialog';
|
|
||||||
import { useProjectSelection } from '@/hooks/use-project-selection';
|
|
||||||
|
|
||||||
function PageLoader() {
|
|
||||||
return (
|
|
||||||
<div className="p-6 space-y-4">
|
|
||||||
<Skeleton className="h-8 w-48" />
|
|
||||||
<Skeleton className="h-64 w-full" />
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function Layout() {
|
|
||||||
const { isOpen, prompt, onSelect, onClose } = useProjectSelection();
|
|
||||||
|
|
||||||
return (
|
|
||||||
<SidebarProvider>
|
|
||||||
<AppSidebar />
|
|
||||||
<main className="flex-1 flex flex-col min-h-0 overflow-hidden bg-background">
|
|
||||||
<header className="flex h-14 items-center justify-between px-6 border-b shrink-0 bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/60">
|
|
||||||
<div className="flex items-center gap-3">
|
|
||||||
<ClaudeKitBadge />
|
|
||||||
<SponsorButton />
|
|
||||||
</div>
|
|
||||||
<div className="flex items-center gap-2">
|
|
||||||
<ConnectionIndicator />
|
|
||||||
<DocsLink />
|
|
||||||
<GitHubLink />
|
|
||||||
<PrivacyToggle />
|
|
||||||
<ThemeToggle />
|
|
||||||
</div>
|
|
||||||
</header>
|
|
||||||
<div className="flex-1 overflow-auto min-h-0">
|
|
||||||
<Suspense fallback={<PageLoader />}>
|
|
||||||
<Outlet />
|
|
||||||
</Suspense>
|
|
||||||
</div>
|
|
||||||
<LocalhostDisclaimer />
|
|
||||||
</main>
|
|
||||||
|
|
||||||
{/* Global project selection dialog for OAuth flows */}
|
|
||||||
{prompt && (
|
|
||||||
<ProjectSelectionDialog
|
|
||||||
open={isOpen}
|
|
||||||
onClose={onClose}
|
|
||||||
sessionId={prompt.sessionId}
|
|
||||||
provider={prompt.provider}
|
|
||||||
projects={prompt.projects}
|
|
||||||
defaultProjectId={prompt.defaultProjectId}
|
|
||||||
supportsAll={prompt.supportsAll}
|
|
||||||
onSelect={onSelect}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</SidebarProvider>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
import { Shield, X } from 'lucide-react';
|
|
||||||
import { useState } from 'react';
|
|
||||||
|
|
||||||
export function LocalhostDisclaimer() {
|
|
||||||
const [dismissed, setDismissed] = useState(false);
|
|
||||||
|
|
||||||
if (dismissed) return null;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="w-full bg-yellow-50 dark:bg-yellow-900/20 border-t border-yellow-200 dark:border-yellow-800 px-4 py-2 transition-colors duration-200">
|
|
||||||
<div className="flex items-center justify-center gap-4">
|
|
||||||
<div className="flex items-center gap-2 text-sm text-yellow-800 dark:text-yellow-200">
|
|
||||||
<Shield className="w-4 h-4 flex-shrink-0" />
|
|
||||||
<span className="hidden sm:inline">
|
|
||||||
This dashboard runs locally. All data stays on your machine.
|
|
||||||
</span>
|
|
||||||
<span className="sm:hidden">Local dashboard - data stays on your device.</span>
|
|
||||||
</div>
|
|
||||||
<button
|
|
||||||
onClick={() => setDismissed(true)}
|
|
||||||
className="text-yellow-600 hover:text-yellow-800 dark:text-yellow-400 flex-shrink-0 p-1 rounded hover:bg-yellow-100 dark:hover:bg-yellow-800/30 transition-colors"
|
|
||||||
aria-label="Dismiss disclaimer"
|
|
||||||
>
|
|
||||||
<X className="w-4 h-4" />
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
/**
|
|
||||||
* Privacy Toggle Button
|
|
||||||
* Toggles demo mode to blur personal information (emails, account IDs)
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { Button } from '@/components/ui/button';
|
|
||||||
import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip';
|
|
||||||
import { usePrivacy } from '@/contexts/privacy-context';
|
|
||||||
import { Eye, EyeOff } from 'lucide-react';
|
|
||||||
import { cn } from '@/lib/utils';
|
|
||||||
|
|
||||||
export function PrivacyToggle() {
|
|
||||||
const { privacyMode, togglePrivacyMode } = usePrivacy();
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Tooltip>
|
|
||||||
<TooltipTrigger asChild>
|
|
||||||
<Button
|
|
||||||
variant="ghost"
|
|
||||||
size="icon"
|
|
||||||
onClick={togglePrivacyMode}
|
|
||||||
className={cn(
|
|
||||||
'h-8 w-8 transition-colors',
|
|
||||||
privacyMode && 'text-amber-600 hover:text-amber-700 dark:text-amber-400'
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
{privacyMode ? <EyeOff className="h-4 w-4" /> : <Eye className="h-4 w-4" />}
|
|
||||||
</Button>
|
|
||||||
</TooltipTrigger>
|
|
||||||
<TooltipContent>
|
|
||||||
<p>
|
|
||||||
{privacyMode
|
|
||||||
? 'Privacy mode ON - Click to show data'
|
|
||||||
: 'Privacy mode OFF - Click to hide data'}
|
|
||||||
</p>
|
|
||||||
</TooltipContent>
|
|
||||||
</Tooltip>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,58 +0,0 @@
|
|||||||
import { Card, CardContent, CardHeader } from '@/components/ui/card';
|
|
||||||
import { Button } from '@/components/ui/button';
|
|
||||||
import { Badge } from '@/components/ui/badge';
|
|
||||||
import { SettingsIcon, PlayIcon } from 'lucide-react';
|
|
||||||
|
|
||||||
interface ProfileCardProps {
|
|
||||||
profile: {
|
|
||||||
name: string;
|
|
||||||
settingsPath: string;
|
|
||||||
configured: boolean;
|
|
||||||
isActive?: boolean;
|
|
||||||
lastUsed?: string;
|
|
||||||
model?: string;
|
|
||||||
};
|
|
||||||
onSwitch?: () => void;
|
|
||||||
onConfig?: () => void;
|
|
||||||
onTest?: () => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function ProfileCard({ profile, onSwitch, onConfig, onTest }: ProfileCardProps) {
|
|
||||||
return (
|
|
||||||
<Card className={profile.isActive ? 'border-primary' : ''}>
|
|
||||||
<CardHeader className="pb-3">
|
|
||||||
<div className="flex items-center justify-between">
|
|
||||||
<div className="flex items-center gap-2">
|
|
||||||
<h3 className="font-semibold">{profile.name}</h3>
|
|
||||||
{profile.isActive && (
|
|
||||||
<Badge variant="default" className="text-xs">
|
|
||||||
Active
|
|
||||||
</Badge>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
<Button variant="ghost" size="sm" onClick={onSwitch} disabled={profile.isActive}>
|
|
||||||
{profile.isActive ? 'Active' : 'Switch'}
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</CardHeader>
|
|
||||||
<CardContent className="space-y-3">
|
|
||||||
{profile.model && (
|
|
||||||
<div className="text-sm text-muted-foreground">Model: {profile.model}</div>
|
|
||||||
)}
|
|
||||||
{profile.lastUsed && (
|
|
||||||
<div className="text-sm text-muted-foreground">Last used: {profile.lastUsed}</div>
|
|
||||||
)}
|
|
||||||
<div className="flex gap-2">
|
|
||||||
<Button variant="outline" size="sm" onClick={onConfig} className="flex-1">
|
|
||||||
<SettingsIcon className="w-4 h-4 mr-1" />
|
|
||||||
Config
|
|
||||||
</Button>
|
|
||||||
<Button variant="outline" size="sm" onClick={onTest} className="flex-1">
|
|
||||||
<PlayIcon className="w-4 h-4 mr-1" />
|
|
||||||
Test
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,344 +0,0 @@
|
|||||||
/**
|
|
||||||
* Profile Create Dialog Component
|
|
||||||
* Modal dialog with tabbed interface for creating new API profiles
|
|
||||||
* Includes Quick Start templates and advanced model configuration
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { useState, useEffect } from 'react';
|
|
||||||
import { useForm } from 'react-hook-form';
|
|
||||||
import { zodResolver } from '@hookform/resolvers/zod';
|
|
||||||
import * as z from 'zod';
|
|
||||||
import { Button } from '@/components/ui/button';
|
|
||||||
import { Input } from '@/components/ui/input';
|
|
||||||
import { Label } from '@/components/ui/label';
|
|
||||||
import {
|
|
||||||
Dialog,
|
|
||||||
DialogContent,
|
|
||||||
DialogDescription,
|
|
||||||
DialogFooter,
|
|
||||||
DialogHeader,
|
|
||||||
DialogTitle,
|
|
||||||
} from '@/components/ui/dialog';
|
|
||||||
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs';
|
|
||||||
import { Badge } from '@/components/ui/badge';
|
|
||||||
import { useCreateProfile } from '@/hooks/use-profiles';
|
|
||||||
import { Loader2, Plus, AlertTriangle, Info, Eye, EyeOff } from 'lucide-react';
|
|
||||||
import { toast } from 'sonner';
|
|
||||||
import { cn } from '@/lib/utils';
|
|
||||||
|
|
||||||
const DEFAULT_MODEL = 'claude-sonnet-4-5-20250929';
|
|
||||||
|
|
||||||
const schema = z.object({
|
|
||||||
name: z
|
|
||||||
.string()
|
|
||||||
.min(1, 'Name is required')
|
|
||||||
.regex(/^[a-zA-Z][a-zA-Z0-9._-]*$/, 'Must start with letter, only letters/numbers/.-_'),
|
|
||||||
baseUrl: z.string().url('Invalid URL format'),
|
|
||||||
apiKey: z.string().min(1, 'API key is required'),
|
|
||||||
model: z.string().optional(),
|
|
||||||
opusModel: z.string().optional(),
|
|
||||||
sonnetModel: z.string().optional(),
|
|
||||||
haikuModel: z.string().optional(),
|
|
||||||
});
|
|
||||||
|
|
||||||
type FormData = z.infer<typeof schema>;
|
|
||||||
|
|
||||||
interface ProfileCreateDialogProps {
|
|
||||||
open: boolean;
|
|
||||||
onOpenChange: (open: boolean) => void;
|
|
||||||
onSuccess: (name: string) => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Common URL mistakes to warn about
|
|
||||||
const PROBLEMATIC_PATHS = ['/chat/completions', '/v1/messages', '/messages', '/completions'];
|
|
||||||
|
|
||||||
export function ProfileCreateDialog({ open, onOpenChange, onSuccess }: ProfileCreateDialogProps) {
|
|
||||||
const createMutation = useCreateProfile();
|
|
||||||
const [activeTab, setActiveTab] = useState('basic');
|
|
||||||
const [urlWarning, setUrlWarning] = useState<string | null>(null);
|
|
||||||
const [showApiKey, setShowApiKey] = useState(false);
|
|
||||||
|
|
||||||
const {
|
|
||||||
register,
|
|
||||||
handleSubmit,
|
|
||||||
formState: { errors },
|
|
||||||
watch,
|
|
||||||
reset,
|
|
||||||
} = useForm<FormData>({
|
|
||||||
resolver: zodResolver(schema),
|
|
||||||
defaultValues: {
|
|
||||||
name: '',
|
|
||||||
baseUrl: '',
|
|
||||||
apiKey: '',
|
|
||||||
model: '',
|
|
||||||
opusModel: '',
|
|
||||||
sonnetModel: '',
|
|
||||||
haikuModel: '',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const baseUrlValue = watch('baseUrl');
|
|
||||||
|
|
||||||
// Reset form when dialog opens
|
|
||||||
useEffect(() => {
|
|
||||||
if (open) {
|
|
||||||
reset();
|
|
||||||
setActiveTab('basic');
|
|
||||||
setUrlWarning(null);
|
|
||||||
setShowApiKey(false);
|
|
||||||
}
|
|
||||||
}, [open, reset]);
|
|
||||||
|
|
||||||
// Check for common URL mistakes
|
|
||||||
useEffect(() => {
|
|
||||||
if (baseUrlValue) {
|
|
||||||
const lowerUrl = baseUrlValue.toLowerCase();
|
|
||||||
for (const path of PROBLEMATIC_PATHS) {
|
|
||||||
if (lowerUrl.endsWith(path)) {
|
|
||||||
const suggestedUrl = baseUrlValue.replace(new RegExp(path + '$', 'i'), '');
|
|
||||||
setUrlWarning(
|
|
||||||
`URL ends with "${path}" - Claude appends this automatically. You likely want: ${suggestedUrl}`
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
setUrlWarning(null);
|
|
||||||
}, [baseUrlValue]);
|
|
||||||
|
|
||||||
const onSubmit = async (data: FormData) => {
|
|
||||||
try {
|
|
||||||
await createMutation.mutateAsync(data);
|
|
||||||
toast.success(`Profile "${data.name}" created`);
|
|
||||||
onSuccess(data.name);
|
|
||||||
onOpenChange(false);
|
|
||||||
} catch (error) {
|
|
||||||
toast.error((error as Error).message || 'Failed to create profile');
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const hasBasicErrors = !!errors.name || !!errors.baseUrl || !!errors.apiKey;
|
|
||||||
const hasModelErrors =
|
|
||||||
!!errors.model || !!errors.opusModel || !!errors.sonnetModel || !!errors.haikuModel;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
|
||||||
<DialogContent className="sm:max-w-[600px] p-0 gap-0 overflow-hidden">
|
|
||||||
<DialogHeader className="p-6 pb-4 border-b">
|
|
||||||
<DialogTitle className="flex items-center gap-2">
|
|
||||||
<Plus className="w-5 h-5 text-primary" />
|
|
||||||
Create API Profile
|
|
||||||
</DialogTitle>
|
|
||||||
<DialogDescription>Configure a custom API endpoint for Claude Code.</DialogDescription>
|
|
||||||
</DialogHeader>
|
|
||||||
|
|
||||||
<form onSubmit={handleSubmit(onSubmit)}>
|
|
||||||
<Tabs value={activeTab} onValueChange={setActiveTab} className="flex flex-col">
|
|
||||||
<div className="px-6 pt-4">
|
|
||||||
<TabsList className="grid w-full grid-cols-2">
|
|
||||||
<TabsTrigger value="basic" className="relative">
|
|
||||||
Basic Information
|
|
||||||
{hasBasicErrors && (
|
|
||||||
<span className="absolute top-1 right-2 w-2 h-2 rounded-full bg-destructive animate-pulse" />
|
|
||||||
)}
|
|
||||||
</TabsTrigger>
|
|
||||||
<TabsTrigger value="models" className="relative">
|
|
||||||
Model Configuration
|
|
||||||
{hasModelErrors && (
|
|
||||||
<span className="absolute top-1 right-2 w-2 h-2 rounded-full bg-destructive animate-pulse" />
|
|
||||||
)}
|
|
||||||
</TabsTrigger>
|
|
||||||
</TabsList>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="flex-1 overflow-y-auto max-h-[60vh]">
|
|
||||||
<TabsContent value="basic" className="p-6 space-y-6 mt-0">
|
|
||||||
<div className="space-y-4">
|
|
||||||
{/* Name */}
|
|
||||||
<div className="space-y-1.5">
|
|
||||||
<Label htmlFor="name">
|
|
||||||
Profile Name <span className="text-destructive">*</span>
|
|
||||||
</Label>
|
|
||||||
<Input
|
|
||||||
id="name"
|
|
||||||
{...register('name')}
|
|
||||||
placeholder="my-api"
|
|
||||||
className="font-mono"
|
|
||||||
/>
|
|
||||||
{errors.name ? (
|
|
||||||
<p className="text-xs text-destructive">{errors.name.message}</p>
|
|
||||||
) : (
|
|
||||||
<p className="text-xs text-muted-foreground">
|
|
||||||
Used in CLI:{' '}
|
|
||||||
<code className="bg-muted px-1 rounded text-[10px]">
|
|
||||||
ccs my-api "prompt"
|
|
||||||
</code>
|
|
||||||
</p>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Base URL */}
|
|
||||||
<div className="space-y-1.5">
|
|
||||||
<Label htmlFor="baseUrl">
|
|
||||||
API Base URL <span className="text-destructive">*</span>
|
|
||||||
</Label>
|
|
||||||
<Input
|
|
||||||
id="baseUrl"
|
|
||||||
{...register('baseUrl')}
|
|
||||||
placeholder="https://api.example.com/v1"
|
|
||||||
/>
|
|
||||||
{errors.baseUrl ? (
|
|
||||||
<p className="text-xs text-destructive">{errors.baseUrl.message}</p>
|
|
||||||
) : urlWarning ? (
|
|
||||||
<div className="flex items-start gap-2 text-xs text-yellow-600 bg-yellow-50 dark:bg-yellow-900/20 p-2 rounded">
|
|
||||||
<AlertTriangle className="w-4 h-4 shrink-0 mt-0.5" />
|
|
||||||
<span>{urlWarning}</span>
|
|
||||||
</div>
|
|
||||||
) : (
|
|
||||||
<p className="text-xs text-muted-foreground">
|
|
||||||
The endpoint that accepts OpenAI-compatible and Anthropic requests
|
|
||||||
</p>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* API Key */}
|
|
||||||
<div className="space-y-1.5">
|
|
||||||
<Label htmlFor="apiKey">
|
|
||||||
API Key <span className="text-destructive">*</span>
|
|
||||||
</Label>
|
|
||||||
<div className="relative">
|
|
||||||
<Input
|
|
||||||
id="apiKey"
|
|
||||||
type={showApiKey ? 'text' : 'password'}
|
|
||||||
{...register('apiKey')}
|
|
||||||
placeholder="sk-..."
|
|
||||||
className="pr-10"
|
|
||||||
/>
|
|
||||||
<Button
|
|
||||||
type="button"
|
|
||||||
variant="ghost"
|
|
||||||
size="icon"
|
|
||||||
className="absolute right-0 top-0 h-9 w-9 text-muted-foreground hover:text-foreground"
|
|
||||||
onClick={() => setShowApiKey(!showApiKey)}
|
|
||||||
tabIndex={-1}
|
|
||||||
>
|
|
||||||
{showApiKey ? <EyeOff className="h-4 w-4" /> : <Eye className="h-4 w-4" />}
|
|
||||||
<span className="sr-only">Toggle API key visibility</span>
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
{errors.apiKey && (
|
|
||||||
<p className="text-xs text-destructive">{errors.apiKey.message}</p>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</TabsContent>
|
|
||||||
|
|
||||||
<TabsContent value="models" className="p-6 mt-0 space-y-6">
|
|
||||||
<div className="flex items-start gap-3 p-4 bg-blue-50 dark:bg-blue-950/20 text-blue-800 dark:text-blue-300 rounded-md text-sm border border-blue-100 dark:border-blue-900/30">
|
|
||||||
<Info className="w-5 h-5 shrink-0 mt-0.5" />
|
|
||||||
<div>
|
|
||||||
<p className="font-medium mb-1">Model Mapping</p>
|
|
||||||
<p className="text-xs opacity-90">
|
|
||||||
Claude Code requests specific model tiers (Opus/Sonnet/Haiku). Map these tiers
|
|
||||||
to the specific models supported by your API provider.
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="space-y-5">
|
|
||||||
<div className="space-y-1.5">
|
|
||||||
<Label htmlFor="model">
|
|
||||||
Default Model
|
|
||||||
<Badge variant="outline" className="ml-2 text-[10px] font-mono">
|
|
||||||
ANTHROPIC_MODEL
|
|
||||||
</Badge>
|
|
||||||
</Label>
|
|
||||||
<Input
|
|
||||||
id="model"
|
|
||||||
{...register('model')}
|
|
||||||
placeholder={DEFAULT_MODEL}
|
|
||||||
className="font-mono text-sm"
|
|
||||||
/>
|
|
||||||
<p className="text-xs text-muted-foreground">
|
|
||||||
Fallback model if no specific tier is requested
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="grid gap-4 pt-2 border-t">
|
|
||||||
<div className="space-y-1.5">
|
|
||||||
<Label htmlFor="sonnetModel" className="text-sm">
|
|
||||||
Sonnet Mapping (Primary)
|
|
||||||
<Badge variant="outline" className="ml-2 text-[10px] font-mono">
|
|
||||||
DEFAULT_SONNET
|
|
||||||
</Badge>
|
|
||||||
</Label>
|
|
||||||
<Input
|
|
||||||
id="sonnetModel"
|
|
||||||
{...register('sonnetModel')}
|
|
||||||
placeholder="e.g. gpt-4o, claude-3-5-sonnet"
|
|
||||||
className="font-mono text-sm h-9"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="space-y-1.5">
|
|
||||||
<Label htmlFor="opusModel" className="text-sm">
|
|
||||||
Opus Mapping (Complex Tasks)
|
|
||||||
<Badge variant="outline" className="ml-2 text-[10px] font-mono">
|
|
||||||
DEFAULT_OPUS
|
|
||||||
</Badge>
|
|
||||||
</Label>
|
|
||||||
<Input
|
|
||||||
id="opusModel"
|
|
||||||
{...register('opusModel')}
|
|
||||||
placeholder="e.g. o1-preview, claude-3-opus"
|
|
||||||
className="font-mono text-sm h-9"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="space-y-1.5">
|
|
||||||
<Label htmlFor="haikuModel" className="text-sm">
|
|
||||||
Haiku Mapping (Fast Tasks)
|
|
||||||
<Badge variant="outline" className="ml-2 text-[10px] font-mono">
|
|
||||||
DEFAULT_HAIKU
|
|
||||||
</Badge>
|
|
||||||
</Label>
|
|
||||||
<Input
|
|
||||||
id="haikuModel"
|
|
||||||
{...register('haikuModel')}
|
|
||||||
placeholder="e.g. gpt-4o-mini, claude-3-haiku"
|
|
||||||
className="font-mono text-sm h-9"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</TabsContent>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<DialogFooter className="p-6 pt-2 border-t bg-muted/10">
|
|
||||||
<Button type="button" variant="outline" onClick={() => onOpenChange(false)}>
|
|
||||||
Cancel
|
|
||||||
</Button>
|
|
||||||
<Button
|
|
||||||
type="submit"
|
|
||||||
disabled={createMutation.isPending}
|
|
||||||
className={cn(createMutation.isPending && 'opacity-80')}
|
|
||||||
>
|
|
||||||
{createMutation.isPending ? (
|
|
||||||
<>
|
|
||||||
<Loader2 className="w-4 h-4 mr-2 animate-spin" />
|
|
||||||
Creating...
|
|
||||||
</>
|
|
||||||
) : (
|
|
||||||
<>
|
|
||||||
<Plus className="w-4 h-4 mr-2" />
|
|
||||||
Create Profile
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</Button>
|
|
||||||
</DialogFooter>
|
|
||||||
</Tabs>
|
|
||||||
</form>
|
|
||||||
</DialogContent>
|
|
||||||
</Dialog>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,56 +0,0 @@
|
|||||||
import { useProfiles } from '@/hooks/use-profiles';
|
|
||||||
import { ProfileCard } from './profile-card';
|
|
||||||
import { Skeleton } from '@/components/ui/skeleton';
|
|
||||||
|
|
||||||
export function ProfileDeck() {
|
|
||||||
const { data: response, isLoading, error } = useProfiles();
|
|
||||||
|
|
||||||
if (isLoading) {
|
|
||||||
return (
|
|
||||||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
|
|
||||||
{[...Array(6)].map((_, i) => (
|
|
||||||
<div key={i} className="space-y-3">
|
|
||||||
<Skeleton className="h-32 w-full" />
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (error) {
|
|
||||||
return <div className="text-destructive text-sm">Failed to load profiles: {error.message}</div>;
|
|
||||||
}
|
|
||||||
|
|
||||||
const profiles = response?.profiles || [];
|
|
||||||
|
|
||||||
if (!profiles || profiles.length === 0) {
|
|
||||||
return (
|
|
||||||
<div className="text-muted-foreground text-center py-8">
|
|
||||||
No profiles configured. Create your first profile to get started.
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Use real profile data directly
|
|
||||||
const normalizedProfiles = profiles.map((profile) => ({
|
|
||||||
...profile,
|
|
||||||
configured: profile.configured ?? false, // Ensure configured is always boolean
|
|
||||||
}));
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="space-y-4">
|
|
||||||
<h2 className="text-lg font-semibold">Profiles</h2>
|
|
||||||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
|
|
||||||
{normalizedProfiles.map((profile) => (
|
|
||||||
<ProfileCard
|
|
||||||
key={profile.name}
|
|
||||||
profile={profile}
|
|
||||||
onSwitch={() => console.log('Switch to', profile.name)}
|
|
||||||
onConfig={() => console.log('Config', profile.name)}
|
|
||||||
onTest={() => console.log('Test', profile.name)}
|
|
||||||
/>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,224 +0,0 @@
|
|||||||
/**
|
|
||||||
* Profile Dialog Component
|
|
||||||
* Phase 03: REST API Routes & CRUD
|
|
||||||
* Updated: Added model mapping fields for Opus/Sonnet/Haiku
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { useState, useEffect } from 'react';
|
|
||||||
import { useForm } from 'react-hook-form';
|
|
||||||
import { zodResolver } from '@hookform/resolvers/zod';
|
|
||||||
import * as z from 'zod';
|
|
||||||
import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/components/ui/dialog';
|
|
||||||
import { Button } from '@/components/ui/button';
|
|
||||||
import { Input } from '@/components/ui/input';
|
|
||||||
import { Label } from '@/components/ui/label';
|
|
||||||
import { useCreateProfile, useUpdateProfile } from '@/hooks/use-profiles';
|
|
||||||
import type { Profile } from '@/lib/api-client';
|
|
||||||
import { ChevronDown, ChevronRight } from 'lucide-react';
|
|
||||||
|
|
||||||
const DEFAULT_MODEL = 'claude-sonnet-4-5-20250929';
|
|
||||||
|
|
||||||
const schema = z.object({
|
|
||||||
name: z
|
|
||||||
.string()
|
|
||||||
.min(1, 'Name is required')
|
|
||||||
.regex(/^[a-zA-Z][a-zA-Z0-9._-]*$/, 'Invalid profile name'),
|
|
||||||
baseUrl: z.string().url('Invalid URL'),
|
|
||||||
apiKey: z.string().min(10, 'API key must be at least 10 characters'),
|
|
||||||
model: z.string().optional(),
|
|
||||||
opusModel: z.string().optional(),
|
|
||||||
sonnetModel: z.string().optional(),
|
|
||||||
haikuModel: z.string().optional(),
|
|
||||||
});
|
|
||||||
|
|
||||||
type FormData = z.infer<typeof schema>;
|
|
||||||
|
|
||||||
interface ProfileDialogProps {
|
|
||||||
open: boolean;
|
|
||||||
onClose: () => void;
|
|
||||||
profile?: Profile | null;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function ProfileDialog({ open, onClose, profile }: ProfileDialogProps) {
|
|
||||||
const createMutation = useCreateProfile();
|
|
||||||
const updateMutation = useUpdateProfile();
|
|
||||||
const [showModelMapping, setShowModelMapping] = useState(false);
|
|
||||||
|
|
||||||
const {
|
|
||||||
register,
|
|
||||||
handleSubmit,
|
|
||||||
formState: { errors },
|
|
||||||
reset,
|
|
||||||
watch,
|
|
||||||
} = useForm<FormData>({
|
|
||||||
resolver: zodResolver(schema),
|
|
||||||
defaultValues: profile
|
|
||||||
? {
|
|
||||||
name: profile.name,
|
|
||||||
baseUrl: '',
|
|
||||||
apiKey: '',
|
|
||||||
model: '',
|
|
||||||
opusModel: '',
|
|
||||||
sonnetModel: '',
|
|
||||||
haikuModel: '',
|
|
||||||
}
|
|
||||||
: undefined,
|
|
||||||
});
|
|
||||||
|
|
||||||
// Watch model field to auto-expand model mapping when custom model is entered
|
|
||||||
const modelValue = watch('model');
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
// Auto-show model mapping if user enters a custom model (not default)
|
|
||||||
if (modelValue && modelValue !== DEFAULT_MODEL && modelValue.trim() !== '') {
|
|
||||||
setShowModelMapping(true);
|
|
||||||
}
|
|
||||||
}, [modelValue]);
|
|
||||||
|
|
||||||
// Reset state when dialog opens/closes
|
|
||||||
useEffect(() => {
|
|
||||||
if (!open) {
|
|
||||||
setShowModelMapping(false);
|
|
||||||
}
|
|
||||||
}, [open]);
|
|
||||||
|
|
||||||
const onSubmit = async (data: FormData) => {
|
|
||||||
try {
|
|
||||||
if (profile) {
|
|
||||||
// Update mode
|
|
||||||
await updateMutation.mutateAsync({
|
|
||||||
name: profile.name,
|
|
||||||
data: {
|
|
||||||
baseUrl: data.baseUrl,
|
|
||||||
apiKey: data.apiKey,
|
|
||||||
model: data.model,
|
|
||||||
opusModel: data.opusModel,
|
|
||||||
sonnetModel: data.sonnetModel,
|
|
||||||
haikuModel: data.haikuModel,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
// Create mode
|
|
||||||
await createMutation.mutateAsync(data);
|
|
||||||
}
|
|
||||||
reset();
|
|
||||||
onClose();
|
|
||||||
} catch (error) {
|
|
||||||
// Error is handled by the mutation hooks
|
|
||||||
console.error('Failed to save profile:', error);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Dialog open={open} onOpenChange={onClose}>
|
|
||||||
<DialogContent className="max-w-md">
|
|
||||||
<DialogHeader>
|
|
||||||
<DialogTitle>{profile ? 'Edit Profile' : 'Create API Profile'}</DialogTitle>
|
|
||||||
</DialogHeader>
|
|
||||||
<form onSubmit={handleSubmit(onSubmit)} className="space-y-4">
|
|
||||||
<div>
|
|
||||||
<Label htmlFor="name">Name</Label>
|
|
||||||
<Input id="name" {...register('name')} placeholder="my-api" disabled={!!profile} />
|
|
||||||
{errors.name && <span className="text-xs text-red-500">{errors.name.message}</span>}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<Label htmlFor="baseUrl">Base URL</Label>
|
|
||||||
<Input id="baseUrl" {...register('baseUrl')} placeholder="https://api.example.com" />
|
|
||||||
{errors.baseUrl && (
|
|
||||||
<span className="text-xs text-red-500">{errors.baseUrl.message}</span>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<Label htmlFor="apiKey">API Key</Label>
|
|
||||||
<Input id="apiKey" type="password" {...register('apiKey')} />
|
|
||||||
{errors.apiKey && <span className="text-xs text-red-500">{errors.apiKey.message}</span>}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<Label htmlFor="model">Default Model (ANTHROPIC_MODEL)</Label>
|
|
||||||
<Input id="model" {...register('model')} placeholder={DEFAULT_MODEL} />
|
|
||||||
<p className="text-xs text-muted-foreground mt-1">
|
|
||||||
Leave blank to use: {DEFAULT_MODEL}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Model Mapping Section */}
|
|
||||||
<div className="border rounded-md">
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
className="w-full flex items-center justify-between p-3 text-sm font-medium hover:bg-muted/50 transition-colors"
|
|
||||||
onClick={() => setShowModelMapping(!showModelMapping)}
|
|
||||||
>
|
|
||||||
<span>Model Mapping (Opus/Sonnet/Haiku)</span>
|
|
||||||
{showModelMapping ? (
|
|
||||||
<ChevronDown className="w-4 h-4" />
|
|
||||||
) : (
|
|
||||||
<ChevronRight className="w-4 h-4" />
|
|
||||||
)}
|
|
||||||
</button>
|
|
||||||
|
|
||||||
{showModelMapping && (
|
|
||||||
<div className="p-3 pt-0 space-y-3 border-t">
|
|
||||||
<p className="text-xs text-muted-foreground">
|
|
||||||
Configure different model IDs for each tier. Useful for API proxies that route
|
|
||||||
different model types to different backends.
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<Label htmlFor="opusModel" className="text-xs">
|
|
||||||
Opus Model (ANTHROPIC_DEFAULT_OPUS_MODEL)
|
|
||||||
</Label>
|
|
||||||
<Input
|
|
||||||
id="opusModel"
|
|
||||||
{...register('opusModel')}
|
|
||||||
placeholder={modelValue || DEFAULT_MODEL}
|
|
||||||
className="h-8 text-sm"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<Label htmlFor="sonnetModel" className="text-xs">
|
|
||||||
Sonnet Model (ANTHROPIC_DEFAULT_SONNET_MODEL)
|
|
||||||
</Label>
|
|
||||||
<Input
|
|
||||||
id="sonnetModel"
|
|
||||||
{...register('sonnetModel')}
|
|
||||||
placeholder={modelValue || DEFAULT_MODEL}
|
|
||||||
className="h-8 text-sm"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<Label htmlFor="haikuModel" className="text-xs">
|
|
||||||
Haiku Model (ANTHROPIC_DEFAULT_HAIKU_MODEL)
|
|
||||||
</Label>
|
|
||||||
<Input
|
|
||||||
id="haikuModel"
|
|
||||||
{...register('haikuModel')}
|
|
||||||
placeholder={modelValue || DEFAULT_MODEL}
|
|
||||||
className="h-8 text-sm"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="flex justify-end gap-2 pt-2">
|
|
||||||
<Button type="button" variant="outline" onClick={onClose}>
|
|
||||||
Cancel
|
|
||||||
</Button>
|
|
||||||
<Button type="submit" disabled={createMutation.isPending || updateMutation.isPending}>
|
|
||||||
{createMutation.isPending || updateMutation.isPending
|
|
||||||
? 'Saving...'
|
|
||||||
: profile
|
|
||||||
? 'Update'
|
|
||||||
: 'Create'}
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</DialogContent>
|
|
||||||
</Dialog>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,149 +0,0 @@
|
|||||||
/**
|
|
||||||
* Profiles Table Component
|
|
||||||
* Phase 03: REST API Routes & CRUD
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { useReactTable, getCoreRowModel, flexRender, type ColumnDef } from '@tanstack/react-table';
|
|
||||||
import {
|
|
||||||
Table,
|
|
||||||
TableBody,
|
|
||||||
TableCell,
|
|
||||||
TableHead,
|
|
||||||
TableHeader,
|
|
||||||
TableRow,
|
|
||||||
} from '@/components/ui/table';
|
|
||||||
import { Button } from '@/components/ui/button';
|
|
||||||
import {
|
|
||||||
DropdownMenu,
|
|
||||||
DropdownMenuContent,
|
|
||||||
DropdownMenuItem,
|
|
||||||
DropdownMenuSeparator,
|
|
||||||
DropdownMenuTrigger,
|
|
||||||
} from '@/components/ui/dropdown-menu';
|
|
||||||
import { MoreHorizontal, Trash2, Edit } from 'lucide-react';
|
|
||||||
import { useDeleteProfile } from '@/hooks/use-profiles';
|
|
||||||
import type { Profile } from '@/lib/api-client';
|
|
||||||
|
|
||||||
interface ProfilesTableProps {
|
|
||||||
data: Profile[];
|
|
||||||
onEditSettings?: (profile: Profile) => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function ProfilesTable({ data, onEditSettings }: ProfilesTableProps) {
|
|
||||||
const deleteMutation = useDeleteProfile();
|
|
||||||
|
|
||||||
const columns: ColumnDef<Profile>[] = [
|
|
||||||
{
|
|
||||||
accessorKey: 'name',
|
|
||||||
header: 'Name',
|
|
||||||
size: 200,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
accessorKey: 'settingsPath',
|
|
||||||
header: 'Settings Path',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
accessorKey: 'configured',
|
|
||||||
header: 'Status',
|
|
||||||
size: 100,
|
|
||||||
cell: ({ row }) => (
|
|
||||||
<span className={row.original.configured ? 'text-green-600' : 'text-yellow-600'}>
|
|
||||||
{row.original.configured ? '[OK]' : '[!]'}
|
|
||||||
</span>
|
|
||||||
),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 'actions',
|
|
||||||
header: 'Actions',
|
|
||||||
size: 100,
|
|
||||||
cell: ({ row }) => (
|
|
||||||
<DropdownMenu>
|
|
||||||
<DropdownMenuTrigger asChild>
|
|
||||||
<Button variant="ghost" size="sm">
|
|
||||||
<MoreHorizontal className="w-4 h-4" />
|
|
||||||
</Button>
|
|
||||||
</DropdownMenuTrigger>
|
|
||||||
<DropdownMenuContent align="end" className="bg-white dark:bg-zinc-950 border shadow-md">
|
|
||||||
{onEditSettings && (
|
|
||||||
<DropdownMenuItem onClick={() => onEditSettings(row.original)}>
|
|
||||||
<Edit className="w-4 h-4 mr-2" />
|
|
||||||
Edit
|
|
||||||
</DropdownMenuItem>
|
|
||||||
)}
|
|
||||||
<DropdownMenuSeparator />
|
|
||||||
<DropdownMenuItem
|
|
||||||
className="text-red-600 focus:text-red-600 focus:bg-red-100/50"
|
|
||||||
onClick={() => deleteMutation.mutate(row.original.name)}
|
|
||||||
>
|
|
||||||
<Trash2 className="w-4 h-4 mr-2" />
|
|
||||||
Delete
|
|
||||||
</DropdownMenuItem>
|
|
||||||
</DropdownMenuContent>
|
|
||||||
</DropdownMenu>
|
|
||||||
),
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
// eslint-disable-next-line react-hooks/incompatible-library
|
|
||||||
const table = useReactTable({
|
|
||||||
data,
|
|
||||||
columns,
|
|
||||||
getCoreRowModel: getCoreRowModel(),
|
|
||||||
});
|
|
||||||
|
|
||||||
if (data.length === 0) {
|
|
||||||
return (
|
|
||||||
<div className="text-center py-8 text-muted-foreground">
|
|
||||||
No profiles found. Create one to get started.
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="border rounded-md">
|
|
||||||
<Table>
|
|
||||||
<TableHeader>
|
|
||||||
{table.getHeaderGroups().map((headerGroup) => (
|
|
||||||
<TableRow key={headerGroup.id}>
|
|
||||||
{headerGroup.headers.map((header) => {
|
|
||||||
const isAction = header.id === 'actions';
|
|
||||||
const isStatus = header.id === 'configured';
|
|
||||||
const isName = header.id === 'name';
|
|
||||||
|
|
||||||
return (
|
|
||||||
<TableHead
|
|
||||||
key={header.id}
|
|
||||||
className={
|
|
||||||
isAction
|
|
||||||
? 'w-[50px]'
|
|
||||||
: isStatus
|
|
||||||
? 'w-[100px]'
|
|
||||||
: isName
|
|
||||||
? 'w-[200px]'
|
|
||||||
: 'w-auto'
|
|
||||||
}
|
|
||||||
>
|
|
||||||
{header.isPlaceholder
|
|
||||||
? null
|
|
||||||
: flexRender(header.column.columnDef.header, header.getContext())}
|
|
||||||
</TableHead>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</TableRow>
|
|
||||||
))}
|
|
||||||
</TableHeader>
|
|
||||||
<TableBody>
|
|
||||||
{table.getRowModel().rows.map((row) => (
|
|
||||||
<TableRow key={row.id}>
|
|
||||||
{row.getVisibleCells().map((cell) => (
|
|
||||||
<TableCell key={cell.id}>
|
|
||||||
{flexRender(cell.column.columnDef.cell, cell.getContext())}
|
|
||||||
</TableCell>
|
|
||||||
))}
|
|
||||||
</TableRow>
|
|
||||||
))}
|
|
||||||
</TableBody>
|
|
||||||
</Table>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,203 +0,0 @@
|
|||||||
/**
|
|
||||||
* Project Selection Dialog Component
|
|
||||||
*
|
|
||||||
* Displays during OAuth flow when CLIProxyAPI requires user to select
|
|
||||||
* a Google Cloud project. Shows list of available projects with option
|
|
||||||
* to select one or ALL.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { useState, useEffect } from 'react';
|
|
||||||
import {
|
|
||||||
Dialog,
|
|
||||||
DialogContent,
|
|
||||||
DialogHeader,
|
|
||||||
DialogTitle,
|
|
||||||
DialogDescription,
|
|
||||||
} from '@/components/ui/dialog';
|
|
||||||
import { Button } from '@/components/ui/button';
|
|
||||||
import { Loader2, FolderOpen, Check, Circle, CheckCircle } from 'lucide-react';
|
|
||||||
|
|
||||||
interface GCloudProject {
|
|
||||||
id: string;
|
|
||||||
name: string;
|
|
||||||
index: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface ProjectSelectionDialogProps {
|
|
||||||
open: boolean;
|
|
||||||
onClose: () => void;
|
|
||||||
sessionId: string;
|
|
||||||
provider: string;
|
|
||||||
projects: GCloudProject[];
|
|
||||||
defaultProjectId: string;
|
|
||||||
supportsAll: boolean;
|
|
||||||
onSelect: (selectedId: string) => Promise<void>;
|
|
||||||
/** Timeout in seconds before auto-selecting default */
|
|
||||||
timeoutSeconds?: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function ProjectSelectionDialog({
|
|
||||||
open,
|
|
||||||
onClose,
|
|
||||||
sessionId,
|
|
||||||
provider,
|
|
||||||
projects,
|
|
||||||
defaultProjectId,
|
|
||||||
supportsAll,
|
|
||||||
onSelect,
|
|
||||||
timeoutSeconds = 30,
|
|
||||||
}: ProjectSelectionDialogProps) {
|
|
||||||
const [selectedId, setSelectedId] = useState(defaultProjectId);
|
|
||||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
|
||||||
const [countdown, setCountdown] = useState(timeoutSeconds);
|
|
||||||
|
|
||||||
// Countdown timer for auto-selection
|
|
||||||
useEffect(() => {
|
|
||||||
if (!open) {
|
|
||||||
setCountdown(timeoutSeconds);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const timer = setInterval(() => {
|
|
||||||
setCountdown((prev) => {
|
|
||||||
if (prev <= 1) {
|
|
||||||
clearInterval(timer);
|
|
||||||
// Auto-submit on timeout
|
|
||||||
handleSubmit(true);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return prev - 1;
|
|
||||||
});
|
|
||||||
}, 1000);
|
|
||||||
|
|
||||||
return () => clearInterval(timer);
|
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
||||||
}, [open, timeoutSeconds]);
|
|
||||||
|
|
||||||
// Reset state when dialog opens
|
|
||||||
useEffect(() => {
|
|
||||||
if (open) {
|
|
||||||
setSelectedId(defaultProjectId);
|
|
||||||
setIsSubmitting(false);
|
|
||||||
setCountdown(timeoutSeconds);
|
|
||||||
}
|
|
||||||
}, [open, defaultProjectId, timeoutSeconds]);
|
|
||||||
|
|
||||||
const handleSubmit = async (isTimeout = false) => {
|
|
||||||
if (isSubmitting) return;
|
|
||||||
setIsSubmitting(true);
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Empty string means use default (press Enter behavior)
|
|
||||||
const submitId = isTimeout ? '' : selectedId;
|
|
||||||
await onSelect(submitId);
|
|
||||||
onClose();
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Failed to submit project selection:', error);
|
|
||||||
// On error, submit empty to use default
|
|
||||||
try {
|
|
||||||
await onSelect('');
|
|
||||||
} catch {
|
|
||||||
// Ignore double-error
|
|
||||||
}
|
|
||||||
onClose();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const providerDisplay = provider.charAt(0).toUpperCase() + provider.slice(1);
|
|
||||||
|
|
||||||
// Suppress unused variable warning - sessionId used for identification
|
|
||||||
void sessionId;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Dialog open={open} onOpenChange={(isOpen) => !isOpen && !isSubmitting && onClose()}>
|
|
||||||
<DialogContent className="sm:max-w-lg">
|
|
||||||
<DialogHeader>
|
|
||||||
<DialogTitle className="flex items-center gap-2">
|
|
||||||
<FolderOpen className="w-5 h-5" />
|
|
||||||
Select Google Cloud Project
|
|
||||||
</DialogTitle>
|
|
||||||
<DialogDescription>
|
|
||||||
Choose which project to use for {providerDisplay} authentication.
|
|
||||||
{countdown > 0 && (
|
|
||||||
<span className="text-muted-foreground ml-1">
|
|
||||||
(Auto-selecting default in {countdown}s)
|
|
||||||
</span>
|
|
||||||
)}
|
|
||||||
</DialogDescription>
|
|
||||||
</DialogHeader>
|
|
||||||
|
|
||||||
<div className="space-y-4 py-4">
|
|
||||||
<div className="space-y-2">
|
|
||||||
{projects.map((project) => (
|
|
||||||
<div
|
|
||||||
key={project.id}
|
|
||||||
className={`flex items-center space-x-3 p-3 rounded-lg border cursor-pointer transition-colors ${
|
|
||||||
selectedId === project.id
|
|
||||||
? 'border-primary bg-primary/5'
|
|
||||||
: 'border-border hover:border-primary/50'
|
|
||||||
}`}
|
|
||||||
onClick={() => !isSubmitting && setSelectedId(project.id)}
|
|
||||||
>
|
|
||||||
{selectedId === project.id ? (
|
|
||||||
<CheckCircle className="w-5 h-5 text-primary" />
|
|
||||||
) : (
|
|
||||||
<Circle className="w-5 h-5 text-muted-foreground" />
|
|
||||||
)}
|
|
||||||
<div className="flex-1">
|
|
||||||
<div className="font-medium">{project.name}</div>
|
|
||||||
<div className="text-sm text-muted-foreground font-mono">{project.id}</div>
|
|
||||||
</div>
|
|
||||||
{project.id === defaultProjectId && (
|
|
||||||
<span className="text-xs px-2 py-1 bg-secondary rounded">Default</span>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
|
|
||||||
{supportsAll && (
|
|
||||||
<div
|
|
||||||
className={`flex items-center space-x-3 p-3 rounded-lg border cursor-pointer transition-colors ${
|
|
||||||
selectedId === 'ALL'
|
|
||||||
? 'border-primary bg-primary/5'
|
|
||||||
: 'border-border hover:border-primary/50'
|
|
||||||
}`}
|
|
||||||
onClick={() => !isSubmitting && setSelectedId('ALL')}
|
|
||||||
>
|
|
||||||
{selectedId === 'ALL' ? (
|
|
||||||
<CheckCircle className="w-5 h-5 text-primary" />
|
|
||||||
) : (
|
|
||||||
<Circle className="w-5 h-5 text-muted-foreground" />
|
|
||||||
)}
|
|
||||||
<div className="flex-1">
|
|
||||||
<div className="font-medium">All Projects</div>
|
|
||||||
<div className="text-sm text-muted-foreground">
|
|
||||||
Onboard all {projects.length} listed projects
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="flex items-center justify-end gap-2 pt-2">
|
|
||||||
<Button variant="ghost" onClick={() => handleSubmit(true)} disabled={isSubmitting}>
|
|
||||||
Use Default
|
|
||||||
</Button>
|
|
||||||
<Button onClick={() => handleSubmit(false)} disabled={isSubmitting}>
|
|
||||||
{isSubmitting ? (
|
|
||||||
<>
|
|
||||||
<Loader2 className="w-4 h-4 mr-2 animate-spin" />
|
|
||||||
Selecting...
|
|
||||||
</>
|
|
||||||
) : (
|
|
||||||
<>
|
|
||||||
<Check className="w-4 h-4 mr-2" />
|
|
||||||
Confirm Selection
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</DialogContent>
|
|
||||||
</Dialog>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,95 +0,0 @@
|
|||||||
/**
|
|
||||||
* Provider Icon Component
|
|
||||||
* Renders provider logos from /assets/providers/
|
|
||||||
* Supports white background circle variant for dark themes
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { cn } from '@/lib/utils';
|
|
||||||
import { PROVIDER_ASSETS, PROVIDER_COLORS } from '@/lib/provider-config';
|
|
||||||
|
|
||||||
interface ProviderIconProps {
|
|
||||||
provider: string;
|
|
||||||
className?: string;
|
|
||||||
size?: number;
|
|
||||||
/** White background circle variant for better visibility */
|
|
||||||
withBackground?: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function ProviderIcon({
|
|
||||||
provider,
|
|
||||||
className,
|
|
||||||
size = 18,
|
|
||||||
withBackground = false,
|
|
||||||
}: ProviderIconProps) {
|
|
||||||
const normalized = provider.toLowerCase();
|
|
||||||
const assetPath = PROVIDER_ASSETS[normalized];
|
|
||||||
|
|
||||||
// Icon size is smaller when inside background circle
|
|
||||||
const iconSize = withBackground ? Math.floor(size * 0.65) : size;
|
|
||||||
|
|
||||||
const iconElement = assetPath ? (
|
|
||||||
<img
|
|
||||||
src={assetPath}
|
|
||||||
alt={`${provider} icon`}
|
|
||||||
width={iconSize}
|
|
||||||
height={iconSize}
|
|
||||||
className="shrink-0 object-contain"
|
|
||||||
/>
|
|
||||||
) : (
|
|
||||||
// Fallback: colored text letter
|
|
||||||
<span
|
|
||||||
className="font-bold"
|
|
||||||
style={{
|
|
||||||
color: PROVIDER_COLORS[normalized] || '#6b7280',
|
|
||||||
fontSize: iconSize * 0.6,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{provider.charAt(0).toUpperCase()}
|
|
||||||
</span>
|
|
||||||
);
|
|
||||||
|
|
||||||
if (withBackground) {
|
|
||||||
return (
|
|
||||||
<div
|
|
||||||
className={cn(
|
|
||||||
'shrink-0 rounded-full bg-white border border-border flex items-center justify-center shadow-sm',
|
|
||||||
className
|
|
||||||
)}
|
|
||||||
style={{ width: size, height: size }}
|
|
||||||
>
|
|
||||||
{iconElement}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Without background - original behavior for logos, colored circle for fallback
|
|
||||||
if (assetPath) {
|
|
||||||
return (
|
|
||||||
<img
|
|
||||||
src={assetPath}
|
|
||||||
alt={`${provider} icon`}
|
|
||||||
width={size}
|
|
||||||
height={size}
|
|
||||||
className={cn('shrink-0 rounded-sm object-contain', className)}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const bgColor = PROVIDER_COLORS[normalized] || '#6b7280';
|
|
||||||
return (
|
|
||||||
<div
|
|
||||||
className={cn(
|
|
||||||
'shrink-0 rounded-full flex items-center justify-center text-white font-bold',
|
|
||||||
className
|
|
||||||
)}
|
|
||||||
style={{
|
|
||||||
width: size,
|
|
||||||
height: size,
|
|
||||||
backgroundColor: bgColor,
|
|
||||||
fontSize: size * 0.5,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{provider.charAt(0).toUpperCase()}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,196 +0,0 @@
|
|||||||
/**
|
|
||||||
* Proxy Status Widget
|
|
||||||
*
|
|
||||||
* Displays CLIProxy process status with start/stop/restart controls.
|
|
||||||
* Shows: running state, port, session count, uptime, update availability.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { Activity, Power, RefreshCw, Clock, Users, Square, RotateCw, ArrowUp } from 'lucide-react';
|
|
||||||
import { Button } from '@/components/ui/button';
|
|
||||||
import { Badge } from '@/components/ui/badge';
|
|
||||||
import {
|
|
||||||
useProxyStatus,
|
|
||||||
useStartProxy,
|
|
||||||
useStopProxy,
|
|
||||||
useCliproxyUpdateCheck,
|
|
||||||
} from '@/hooks/use-cliproxy';
|
|
||||||
import { cn } from '@/lib/utils';
|
|
||||||
|
|
||||||
function formatUptime(startedAt?: string): string {
|
|
||||||
if (!startedAt) return '';
|
|
||||||
const start = new Date(startedAt).getTime();
|
|
||||||
const now = Date.now();
|
|
||||||
const diff = now - start;
|
|
||||||
|
|
||||||
const hours = Math.floor(diff / (1000 * 60 * 60));
|
|
||||||
const minutes = Math.floor((diff % (1000 * 60 * 60)) / (1000 * 60));
|
|
||||||
|
|
||||||
if (hours > 0) {
|
|
||||||
return `${hours}h ${minutes}m`;
|
|
||||||
}
|
|
||||||
return `${minutes}m`;
|
|
||||||
}
|
|
||||||
|
|
||||||
function formatTimeAgo(timestamp?: number): string {
|
|
||||||
if (!timestamp) return '';
|
|
||||||
const diff = Date.now() - timestamp;
|
|
||||||
const minutes = Math.floor(diff / (1000 * 60));
|
|
||||||
const hours = Math.floor(diff / (1000 * 60 * 60));
|
|
||||||
|
|
||||||
if (minutes < 1) return 'just now';
|
|
||||||
if (minutes < 60) return `${minutes}m ago`;
|
|
||||||
return `${hours}h ago`;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function ProxyStatusWidget() {
|
|
||||||
const { data: status, isLoading } = useProxyStatus();
|
|
||||||
const { data: updateCheck } = useCliproxyUpdateCheck();
|
|
||||||
const startProxy = useStartProxy();
|
|
||||||
const stopProxy = useStopProxy();
|
|
||||||
|
|
||||||
const isRunning = status?.running ?? false;
|
|
||||||
const isActioning = startProxy.isPending || stopProxy.isPending;
|
|
||||||
const hasUpdate = updateCheck?.hasUpdate ?? false;
|
|
||||||
|
|
||||||
// Restart = stop then start
|
|
||||||
const handleRestart = async () => {
|
|
||||||
await stopProxy.mutateAsync();
|
|
||||||
// Small delay to ensure port is released
|
|
||||||
await new Promise((r) => setTimeout(r, 500));
|
|
||||||
startProxy.mutate();
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div
|
|
||||||
className={cn(
|
|
||||||
'rounded-lg border p-3 transition-colors',
|
|
||||||
isRunning ? 'border-green-500/30 bg-green-500/5' : 'border-muted bg-muted/30'
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
<div className="flex items-center justify-between">
|
|
||||||
<div className="flex items-center gap-2">
|
|
||||||
<div
|
|
||||||
className={cn(
|
|
||||||
'w-2 h-2 rounded-full',
|
|
||||||
isRunning ? 'bg-green-500 animate-pulse' : 'bg-muted-foreground/30'
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
<span className="text-sm font-medium">CLIProxy Service</span>
|
|
||||||
{hasUpdate && (
|
|
||||||
<Badge
|
|
||||||
variant="secondary"
|
|
||||||
className="text-[10px] h-4 px-1.5 gap-0.5 bg-amber-100 text-amber-700 dark:bg-amber-900/30 dark:text-amber-400"
|
|
||||||
title={`Update: v${updateCheck?.currentVersion} -> v${updateCheck?.latestVersion}`}
|
|
||||||
>
|
|
||||||
<ArrowUp className="w-2.5 h-2.5" />
|
|
||||||
Update
|
|
||||||
</Badge>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="flex items-center gap-1">
|
|
||||||
{isLoading ? (
|
|
||||||
<RefreshCw className="w-3 h-3 animate-spin text-muted-foreground" />
|
|
||||||
) : isRunning ? (
|
|
||||||
<Activity className="w-3 h-3 text-green-600" />
|
|
||||||
) : (
|
|
||||||
<Power className="w-3 h-3 text-muted-foreground" />
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{isRunning && status ? (
|
|
||||||
<>
|
|
||||||
<div className="mt-2 flex items-center gap-4 text-xs text-muted-foreground">
|
|
||||||
<span className="flex items-center gap-1">Port {status.port}</span>
|
|
||||||
{status.sessionCount !== undefined && status.sessionCount > 0 && (
|
|
||||||
<span className="flex items-center gap-1">
|
|
||||||
<Users className="w-3 h-3" />
|
|
||||||
{status.sessionCount} session{status.sessionCount !== 1 ? 's' : ''}
|
|
||||||
</span>
|
|
||||||
)}
|
|
||||||
{status.startedAt && (
|
|
||||||
<span className="flex items-center gap-1">
|
|
||||||
<Clock className="w-3 h-3" />
|
|
||||||
{formatUptime(status.startedAt)}
|
|
||||||
</span>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
{/* Control buttons when running */}
|
|
||||||
<div className="mt-2 flex items-center gap-2">
|
|
||||||
<Button
|
|
||||||
variant={hasUpdate ? 'default' : 'outline'}
|
|
||||||
size="sm"
|
|
||||||
className={cn(
|
|
||||||
'h-7 text-xs gap-1 flex-1',
|
|
||||||
hasUpdate &&
|
|
||||||
'bg-sidebar-accent hover:bg-sidebar-accent/90 text-sidebar-accent-foreground'
|
|
||||||
)}
|
|
||||||
onClick={handleRestart}
|
|
||||||
disabled={isActioning}
|
|
||||||
title={
|
|
||||||
hasUpdate
|
|
||||||
? `Restart to update: v${updateCheck?.currentVersion} -> v${updateCheck?.latestVersion}`
|
|
||||||
: 'Restart CLIProxy service'
|
|
||||||
}
|
|
||||||
>
|
|
||||||
{isActioning ? (
|
|
||||||
<RefreshCw className="w-3 h-3 animate-spin" />
|
|
||||||
) : hasUpdate ? (
|
|
||||||
<ArrowUp className="w-3 h-3" />
|
|
||||||
) : (
|
|
||||||
<RotateCw className="w-3 h-3" />
|
|
||||||
)}
|
|
||||||
{hasUpdate ? 'Update' : 'Restart'}
|
|
||||||
</Button>
|
|
||||||
<Button
|
|
||||||
variant="outline"
|
|
||||||
size="sm"
|
|
||||||
className="h-7 text-xs gap-1 hover:bg-destructive/10 hover:text-destructive hover:border-destructive/30"
|
|
||||||
onClick={() => stopProxy.mutate()}
|
|
||||||
disabled={isActioning}
|
|
||||||
title="Stop CLIProxy service"
|
|
||||||
>
|
|
||||||
{stopProxy.isPending ? (
|
|
||||||
<RefreshCw className="w-3 h-3 animate-spin" />
|
|
||||||
) : (
|
|
||||||
<Square className="w-3 h-3" />
|
|
||||||
)}
|
|
||||||
Stop
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</>
|
|
||||||
) : (
|
|
||||||
<div className="mt-2 flex items-center justify-between">
|
|
||||||
<span className="text-xs text-muted-foreground">Not running</span>
|
|
||||||
<Button
|
|
||||||
variant="outline"
|
|
||||||
size="sm"
|
|
||||||
className="h-7 text-xs gap-1"
|
|
||||||
onClick={() => startProxy.mutate()}
|
|
||||||
disabled={startProxy.isPending}
|
|
||||||
>
|
|
||||||
{startProxy.isPending ? (
|
|
||||||
<RefreshCw className="w-3 h-3 animate-spin" />
|
|
||||||
) : (
|
|
||||||
<Power className="w-3 h-3" />
|
|
||||||
)}
|
|
||||||
Start
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{/* Version sync indicator */}
|
|
||||||
{updateCheck?.currentVersion && (
|
|
||||||
<div className="mt-2 pt-2 border-t border-muted flex items-center justify-between text-[10px] text-muted-foreground/70">
|
|
||||||
<span>v{updateCheck.currentVersion}</span>
|
|
||||||
{updateCheck.checkedAt && (
|
|
||||||
<span title={new Date(updateCheck.checkedAt).toLocaleString()}>
|
|
||||||
Synced {formatTimeAgo(updateCheck.checkedAt)}
|
|
||||||
</span>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,92 +0,0 @@
|
|||||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
|
||||||
import { Button } from '@/components/ui/button';
|
|
||||||
import { Copy, Check, Terminal } from 'lucide-react';
|
|
||||||
import { useState } from 'react';
|
|
||||||
import { cn } from '@/lib/utils';
|
|
||||||
|
|
||||||
interface CommandSnippet {
|
|
||||||
label: string;
|
|
||||||
command: string;
|
|
||||||
description: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
const defaultSnippets: CommandSnippet[] = [
|
|
||||||
{
|
|
||||||
label: 'Start Default',
|
|
||||||
command: 'ccs',
|
|
||||||
description: 'Launch Claude with default profile',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: 'GLM Profile',
|
|
||||||
command: 'ccs glm',
|
|
||||||
description: 'Switch to GLM model',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: 'Health Check',
|
|
||||||
command: 'ccs doctor',
|
|
||||||
description: 'Run system diagnostics',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: 'Delegate Task',
|
|
||||||
command: 'ccs glm -p "your task"',
|
|
||||||
description: 'Delegate to GLM profile',
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
interface QuickCommandsProps {
|
|
||||||
snippets?: CommandSnippet[];
|
|
||||||
}
|
|
||||||
|
|
||||||
export function QuickCommands({ snippets = defaultSnippets }: QuickCommandsProps) {
|
|
||||||
const [copiedIndex, setCopiedIndex] = useState<number | null>(null);
|
|
||||||
|
|
||||||
const copyToClipboard = async (text: string, index: number) => {
|
|
||||||
await navigator.clipboard.writeText(text);
|
|
||||||
setCopiedIndex(index);
|
|
||||||
setTimeout(() => setCopiedIndex(null), 2000);
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Card>
|
|
||||||
<CardHeader className="pb-3">
|
|
||||||
<CardTitle className="text-lg flex items-center gap-2">
|
|
||||||
<Terminal className="w-5 h-5 text-muted-foreground" />
|
|
||||||
Quick Commands
|
|
||||||
</CardTitle>
|
|
||||||
</CardHeader>
|
|
||||||
<CardContent>
|
|
||||||
<div className="grid grid-cols-1 sm:grid-cols-2 gap-2">
|
|
||||||
{snippets.map((snippet, index) => (
|
|
||||||
<div
|
|
||||||
key={index}
|
|
||||||
className={cn(
|
|
||||||
'group flex items-center justify-between gap-2 px-3 py-2',
|
|
||||||
'rounded-lg border bg-muted/30 hover:bg-muted/50 transition-colors'
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
<div className="flex-1 min-w-0">
|
|
||||||
<p className="text-xs text-muted-foreground">{snippet.label}</p>
|
|
||||||
<code className="text-sm font-mono font-medium truncate block">
|
|
||||||
{snippet.command}
|
|
||||||
</code>
|
|
||||||
</div>
|
|
||||||
<Button
|
|
||||||
variant="ghost"
|
|
||||||
size="sm"
|
|
||||||
className="h-8 w-8 p-0 opacity-0 group-hover:opacity-100 transition-opacity"
|
|
||||||
onClick={() => copyToClipboard(snippet.command, index)}
|
|
||||||
title={snippet.description}
|
|
||||||
>
|
|
||||||
{copiedIndex === index ? (
|
|
||||||
<Check className="h-4 w-4 text-green-600" />
|
|
||||||
) : (
|
|
||||||
<Copy className="h-4 w-4" />
|
|
||||||
)}
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,387 +0,0 @@
|
|||||||
/**
|
|
||||||
* Settings Dialog Component
|
|
||||||
* Reusable dialog for editing profile environment variables
|
|
||||||
* Features: masked inputs for sensitive keys, conflict detection, save/cancel, raw JSON editor
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { useState, useMemo, useCallback, lazy, Suspense } from 'react';
|
|
||||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
|
|
||||||
import {
|
|
||||||
Dialog,
|
|
||||||
DialogContent,
|
|
||||||
DialogHeader,
|
|
||||||
DialogTitle,
|
|
||||||
DialogDescription,
|
|
||||||
} from '@/components/ui/dialog';
|
|
||||||
import { Button } from '@/components/ui/button';
|
|
||||||
import { Input } from '@/components/ui/input';
|
|
||||||
import { Label } from '@/components/ui/label';
|
|
||||||
import { MaskedInput } from '@/components/ui/masked-input';
|
|
||||||
import { ConfirmDialog } from '@/components/confirm-dialog';
|
|
||||||
import { Save, X, Loader2, Code2 } from 'lucide-react';
|
|
||||||
import { toast } from 'sonner';
|
|
||||||
|
|
||||||
// Lazy load CodeEditor to reduce initial bundle size
|
|
||||||
const CodeEditor = lazy(() =>
|
|
||||||
import('@/components/code-editor').then((m) => ({ default: m.CodeEditor }))
|
|
||||||
);
|
|
||||||
|
|
||||||
interface Settings {
|
|
||||||
env?: Record<string, string>;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface SettingsResponse {
|
|
||||||
profile: string;
|
|
||||||
settings: Settings;
|
|
||||||
mtime: number;
|
|
||||||
path: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface SettingsDialogProps {
|
|
||||||
open: boolean;
|
|
||||||
onClose: () => void;
|
|
||||||
profileName: string | null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Inner component that manages local edits state
|
|
||||||
* Gets unmounted/remounted via key prop when dialog closes/opens
|
|
||||||
*/
|
|
||||||
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs';
|
|
||||||
import { ScrollArea } from '@/components/ui/scroll-area';
|
|
||||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
|
||||||
|
|
||||||
function SettingsDialogContent({
|
|
||||||
profileName,
|
|
||||||
onClose,
|
|
||||||
}: {
|
|
||||||
profileName: string;
|
|
||||||
onClose: () => void;
|
|
||||||
}) {
|
|
||||||
const [localEdits, setLocalEdits] = useState<Record<string, string>>({});
|
|
||||||
const [conflictDialog, setConflictDialog] = useState(false);
|
|
||||||
const [rawJsonEdits, setRawJsonEdits] = useState<string | null>(null);
|
|
||||||
const [activeTab, setActiveTab] = useState('env');
|
|
||||||
const queryClient = useQueryClient();
|
|
||||||
|
|
||||||
// Fetch settings for selected profile
|
|
||||||
const { data, isLoading, refetch } = useQuery<SettingsResponse>({
|
|
||||||
queryKey: ['settings', profileName],
|
|
||||||
queryFn: () => fetch(`/api/settings/${profileName}/raw`).then((r) => r.json()),
|
|
||||||
});
|
|
||||||
|
|
||||||
// Derive raw JSON content: use edits if available, otherwise serialize from data
|
|
||||||
const settings = data?.settings;
|
|
||||||
const rawJsonContent = useMemo(() => {
|
|
||||||
if (rawJsonEdits !== null) {
|
|
||||||
return rawJsonEdits;
|
|
||||||
}
|
|
||||||
if (settings) {
|
|
||||||
return JSON.stringify(settings, null, 2);
|
|
||||||
}
|
|
||||||
return '';
|
|
||||||
}, [rawJsonEdits, settings]);
|
|
||||||
|
|
||||||
// Update raw JSON when user edits
|
|
||||||
const handleRawJsonChange = useCallback((value: string) => {
|
|
||||||
setRawJsonEdits(value);
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
// Derive current settings by merging original data with local edits
|
|
||||||
const currentSettings = useMemo((): Settings | undefined => {
|
|
||||||
const settings = data?.settings;
|
|
||||||
if (!settings) return undefined;
|
|
||||||
return {
|
|
||||||
...settings,
|
|
||||||
env: {
|
|
||||||
...settings.env,
|
|
||||||
...localEdits,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}, [data?.settings, localEdits]);
|
|
||||||
|
|
||||||
// Check if raw JSON is valid
|
|
||||||
const isRawJsonValid = useMemo(() => {
|
|
||||||
try {
|
|
||||||
JSON.parse(rawJsonContent);
|
|
||||||
return true;
|
|
||||||
} catch {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}, [rawJsonContent]);
|
|
||||||
|
|
||||||
// Save mutation
|
|
||||||
const saveMutation = useMutation({
|
|
||||||
mutationFn: async () => {
|
|
||||||
let settingsToSave: Settings;
|
|
||||||
|
|
||||||
// Determine what to save based on active tab
|
|
||||||
if (activeTab === 'raw') {
|
|
||||||
// Parse raw JSON content
|
|
||||||
try {
|
|
||||||
settingsToSave = JSON.parse(rawJsonContent);
|
|
||||||
} catch {
|
|
||||||
throw new Error('Invalid JSON');
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Use form-based edits
|
|
||||||
settingsToSave = {
|
|
||||||
...data?.settings,
|
|
||||||
env: {
|
|
||||||
...data?.settings?.env,
|
|
||||||
...localEdits,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const res = await fetch(`/api/settings/${profileName}`, {
|
|
||||||
method: 'PUT',
|
|
||||||
headers: { 'Content-Type': 'application/json' },
|
|
||||||
body: JSON.stringify({
|
|
||||||
settings: settingsToSave,
|
|
||||||
expectedMtime: data?.mtime,
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
|
|
||||||
if (res.status === 409) {
|
|
||||||
throw new Error('CONFLICT');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!res.ok) {
|
|
||||||
throw new Error('Failed to save');
|
|
||||||
}
|
|
||||||
|
|
||||||
return res.json();
|
|
||||||
},
|
|
||||||
onSuccess: () => {
|
|
||||||
queryClient.invalidateQueries({ queryKey: ['settings', profileName] });
|
|
||||||
queryClient.invalidateQueries({ queryKey: ['profiles'] });
|
|
||||||
toast.success('Settings saved');
|
|
||||||
onClose();
|
|
||||||
},
|
|
||||||
onError: (error: Error) => {
|
|
||||||
if (error.message === 'CONFLICT') {
|
|
||||||
setConflictDialog(true);
|
|
||||||
} else {
|
|
||||||
toast.error(error.message);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const handleSave = () => {
|
|
||||||
saveMutation.mutate();
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleConflictResolve = async (overwrite: boolean) => {
|
|
||||||
setConflictDialog(false);
|
|
||||||
if (overwrite) {
|
|
||||||
// Refetch to get new mtime, then save
|
|
||||||
await refetch();
|
|
||||||
saveMutation.mutate();
|
|
||||||
} else {
|
|
||||||
// Discard local changes and close
|
|
||||||
onClose();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const updateEnvValue = (key: string, value: string) => {
|
|
||||||
setLocalEdits((prev) => ({
|
|
||||||
...prev,
|
|
||||||
[key]: value,
|
|
||||||
}));
|
|
||||||
};
|
|
||||||
|
|
||||||
const isSensitiveKey = (key: string): boolean => {
|
|
||||||
// Pattern-based matching for sensitive keys (same as backend)
|
|
||||||
const sensitivePatterns = [
|
|
||||||
/^ANTHROPIC_AUTH_TOKEN$/, // Exact match for Anthropic auth token
|
|
||||||
/_API_KEY$/, // Keys ending with _API_KEY
|
|
||||||
/_AUTH_TOKEN$/, // Keys ending with _AUTH_TOKEN
|
|
||||||
/^API_KEY$/, // Exact match for API_KEY
|
|
||||||
/^AUTH_TOKEN$/, // Exact match for AUTH_TOKEN
|
|
||||||
/_SECRET$/, // Keys ending with _SECRET
|
|
||||||
/^SECRET$/, // Exact match for SECRET
|
|
||||||
];
|
|
||||||
return sensitivePatterns.some((pattern) => pattern.test(key));
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<DialogHeader>
|
|
||||||
<DialogTitle>Edit Profile: {profileName}</DialogTitle>
|
|
||||||
<DialogDescription>
|
|
||||||
Configure environment variables and settings for this profile.
|
|
||||||
</DialogDescription>
|
|
||||||
</DialogHeader>
|
|
||||||
|
|
||||||
{isLoading ? (
|
|
||||||
<div className="flex items-center justify-center py-12">
|
|
||||||
<Loader2 className="w-8 h-8 animate-spin text-muted-foreground" />
|
|
||||||
<span className="ml-3 text-muted-foreground">Loading settings...</span>
|
|
||||||
</div>
|
|
||||||
) : (
|
|
||||||
<div className="flex flex-col h-[60vh]">
|
|
||||||
<Tabs
|
|
||||||
value={activeTab}
|
|
||||||
onValueChange={setActiveTab}
|
|
||||||
className="flex-1 flex flex-col overflow-hidden"
|
|
||||||
>
|
|
||||||
<TabsList className="w-full justify-start border-b rounded-none p-0 h-auto bg-transparent">
|
|
||||||
<TabsTrigger
|
|
||||||
value="env"
|
|
||||||
className="rounded-none border-b-2 border-transparent data-[state=active]:border-primary data-[state=active]:bg-transparent px-4 py-2"
|
|
||||||
>
|
|
||||||
Environment
|
|
||||||
</TabsTrigger>
|
|
||||||
<TabsTrigger
|
|
||||||
value="raw"
|
|
||||||
className="rounded-none border-b-2 border-transparent data-[state=active]:border-primary data-[state=active]:bg-transparent px-4 py-2"
|
|
||||||
>
|
|
||||||
<Code2 className="w-4 h-4 mr-1" />
|
|
||||||
Raw JSON
|
|
||||||
</TabsTrigger>
|
|
||||||
<TabsTrigger
|
|
||||||
value="general"
|
|
||||||
className="rounded-none border-b-2 border-transparent data-[state=active]:border-primary data-[state=active]:bg-transparent px-4 py-2"
|
|
||||||
>
|
|
||||||
General
|
|
||||||
</TabsTrigger>
|
|
||||||
</TabsList>
|
|
||||||
|
|
||||||
<TabsContent value="env" className="flex-1 overflow-hidden p-4 pt-4 m-0">
|
|
||||||
<ScrollArea className="h-full pr-4">
|
|
||||||
{currentSettings?.env && Object.keys(currentSettings.env).length > 0 ? (
|
|
||||||
<div className="space-y-6">
|
|
||||||
{Object.entries(currentSettings.env).map(([key, value]) => (
|
|
||||||
<div key={key} className="space-y-2">
|
|
||||||
<Label className="text-sm font-medium text-foreground">{key}</Label>
|
|
||||||
{isSensitiveKey(key) ? (
|
|
||||||
<MaskedInput
|
|
||||||
value={value}
|
|
||||||
onChange={(e) => updateEnvValue(key, e.target.value)}
|
|
||||||
className="font-mono text-sm"
|
|
||||||
/>
|
|
||||||
) : (
|
|
||||||
<Input
|
|
||||||
value={value}
|
|
||||||
onChange={(e) => updateEnvValue(key, e.target.value)}
|
|
||||||
className="font-mono text-sm"
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
) : (
|
|
||||||
<div className="py-12 text-center text-muted-foreground bg-muted/30 rounded-lg border border-dashed">
|
|
||||||
<p>No environment variables configured.</p>
|
|
||||||
<p className="text-xs mt-1">Add variables in your settings.json file.</p>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</ScrollArea>
|
|
||||||
</TabsContent>
|
|
||||||
|
|
||||||
<TabsContent value="raw" className="flex-1 overflow-hidden p-4 pt-4 m-0">
|
|
||||||
<Suspense
|
|
||||||
fallback={
|
|
||||||
<div className="flex items-center justify-center h-full">
|
|
||||||
<Loader2 className="w-6 h-6 animate-spin text-muted-foreground" />
|
|
||||||
<span className="ml-2 text-muted-foreground">Loading editor...</span>
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
>
|
|
||||||
<CodeEditor
|
|
||||||
value={rawJsonContent}
|
|
||||||
onChange={handleRawJsonChange}
|
|
||||||
language="json"
|
|
||||||
minHeight="calc(60vh - 120px)"
|
|
||||||
/>
|
|
||||||
</Suspense>
|
|
||||||
</TabsContent>
|
|
||||||
|
|
||||||
<TabsContent value="general" className="p-4 m-0">
|
|
||||||
<Card>
|
|
||||||
<CardHeader>
|
|
||||||
<CardTitle className="text-base">Profile Information</CardTitle>
|
|
||||||
<CardDescription>Details about this configuration file.</CardDescription>
|
|
||||||
</CardHeader>
|
|
||||||
<CardContent className="space-y-4">
|
|
||||||
{data && (
|
|
||||||
<>
|
|
||||||
<div className="grid grid-cols-3 gap-2 text-sm">
|
|
||||||
<span className="font-medium text-muted-foreground">Path</span>
|
|
||||||
<code className="col-span-2 bg-muted p-1 rounded text-xs break-all">
|
|
||||||
{data.path}
|
|
||||||
</code>
|
|
||||||
</div>
|
|
||||||
<div className="grid grid-cols-3 gap-2 text-sm">
|
|
||||||
<span className="font-medium text-muted-foreground">Last Modified</span>
|
|
||||||
<span className="col-span-2">{new Date(data.mtime).toLocaleString()}</span>
|
|
||||||
</div>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
</TabsContent>
|
|
||||||
</Tabs>
|
|
||||||
|
|
||||||
<div className="pt-4 mt-auto border-t flex justify-end gap-2">
|
|
||||||
<Button type="button" variant="outline" onClick={onClose}>
|
|
||||||
<X className="w-4 h-4 mr-2" /> Cancel
|
|
||||||
</Button>
|
|
||||||
<Button
|
|
||||||
onClick={handleSave}
|
|
||||||
disabled={saveMutation.isPending || (activeTab === 'raw' && !isRawJsonValid)}
|
|
||||||
>
|
|
||||||
{saveMutation.isPending ? (
|
|
||||||
<>
|
|
||||||
<Loader2 className="w-4 h-4 mr-2 animate-spin" /> Saving...
|
|
||||||
</>
|
|
||||||
) : (
|
|
||||||
<>
|
|
||||||
<Save className="w-4 h-4 mr-2" /> Save Changes
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<ConfirmDialog
|
|
||||||
open={conflictDialog}
|
|
||||||
title="File Modified Externally"
|
|
||||||
description="This settings file was modified by another process. Overwrite with your changes or discard?"
|
|
||||||
confirmText="Overwrite"
|
|
||||||
variant="destructive"
|
|
||||||
onConfirm={() => handleConflictResolve(true)}
|
|
||||||
onCancel={() => handleConflictResolve(false)}
|
|
||||||
/>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function SettingsDialog({ open, onClose, profileName }: SettingsDialogProps) {
|
|
||||||
// Handle dialog open/close state changes
|
|
||||||
const handleOpenChange = useCallback(
|
|
||||||
(isOpen: boolean) => {
|
|
||||||
if (!isOpen) {
|
|
||||||
onClose();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
[onClose]
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Dialog open={open} onOpenChange={handleOpenChange}>
|
|
||||||
<DialogContent className="sm:max-w-3xl max-h-[80vh] overflow-y-auto">
|
|
||||||
{/* Key prop ensures fresh state on each open */}
|
|
||||||
{open && profileName && (
|
|
||||||
<SettingsDialogContent
|
|
||||||
key={`${profileName}-${open}`}
|
|
||||||
profileName={profileName}
|
|
||||||
onClose={onClose}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</DialogContent>
|
|
||||||
</Dialog>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
/**
|
|
||||||
* Sponsor Button
|
|
||||||
*
|
|
||||||
* GitHub Sponsors button for navbar.
|
|
||||||
* Heart icon with hover animation.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { Heart } from 'lucide-react';
|
|
||||||
import { cn } from '@/lib/utils';
|
|
||||||
|
|
||||||
const SPONSOR_URL = 'https://github.com/sponsors/kaitranntt';
|
|
||||||
|
|
||||||
export function SponsorButton() {
|
|
||||||
return (
|
|
||||||
<a
|
|
||||||
href={SPONSOR_URL}
|
|
||||||
target="_blank"
|
|
||||||
rel="noopener noreferrer"
|
|
||||||
className={cn(
|
|
||||||
'group inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg',
|
|
||||||
'bg-pink-500/10 border-2 border-pink-500/40',
|
|
||||||
'hover:bg-pink-400 hover:border-pink-400',
|
|
||||||
'transition-all duration-200 shadow-sm hover:shadow-md'
|
|
||||||
)}
|
|
||||||
title="Sponsor this project on GitHub"
|
|
||||||
>
|
|
||||||
<Heart
|
|
||||||
className={cn(
|
|
||||||
'w-4 h-4 text-pink-500',
|
|
||||||
'group-hover:text-white group-hover:fill-white',
|
|
||||||
'group-hover:animate-pulse',
|
|
||||||
'transition-colors'
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
<span
|
|
||||||
className={cn(
|
|
||||||
'text-xs font-bold text-pink-600 dark:text-pink-300',
|
|
||||||
'group-hover:text-white dark:group-hover:text-white',
|
|
||||||
'transition-colors'
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
Sponsor
|
|
||||||
</span>
|
|
||||||
</a>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,88 +0,0 @@
|
|||||||
import { Card, CardContent } from '@/components/ui/card';
|
|
||||||
import type { LucideIcon } from 'lucide-react';
|
|
||||||
import { cn } from '@/lib/utils';
|
|
||||||
|
|
||||||
interface StatCardProps {
|
|
||||||
title: string;
|
|
||||||
value: number | string;
|
|
||||||
icon: LucideIcon;
|
|
||||||
color?: string;
|
|
||||||
variant?: 'default' | 'success' | 'warning' | 'error' | 'accent';
|
|
||||||
subtitle?: string;
|
|
||||||
onClick?: () => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
const variantStyles = {
|
|
||||||
default: {
|
|
||||||
iconBg: 'bg-muted',
|
|
||||||
iconColor: 'text-muted-foreground',
|
|
||||||
borderHover: 'hover:border-primary',
|
|
||||||
},
|
|
||||||
success: {
|
|
||||||
iconBg: 'bg-green-500/10',
|
|
||||||
iconColor: 'text-green-600',
|
|
||||||
borderHover: 'hover:border-green-500/50',
|
|
||||||
},
|
|
||||||
warning: {
|
|
||||||
iconBg: 'bg-yellow-500/10',
|
|
||||||
iconColor: 'text-yellow-500',
|
|
||||||
borderHover: 'hover:border-yellow-500/50',
|
|
||||||
},
|
|
||||||
error: {
|
|
||||||
iconBg: 'bg-red-500/10',
|
|
||||||
iconColor: 'text-red-500',
|
|
||||||
borderHover: 'hover:border-red-500/50',
|
|
||||||
},
|
|
||||||
accent: {
|
|
||||||
iconBg: 'bg-accent/10',
|
|
||||||
iconColor: 'text-accent',
|
|
||||||
borderHover: 'hover:border-accent/50',
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
export function StatCard({
|
|
||||||
title,
|
|
||||||
value,
|
|
||||||
icon: Icon,
|
|
||||||
color,
|
|
||||||
variant = 'default',
|
|
||||||
subtitle,
|
|
||||||
onClick,
|
|
||||||
}: StatCardProps) {
|
|
||||||
const styles = variantStyles[variant];
|
|
||||||
const iconColorClass = color || styles.iconColor;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Card
|
|
||||||
className={cn(
|
|
||||||
'cursor-pointer transition-all duration-200',
|
|
||||||
'hover:shadow-lg hover:-translate-y-0.5',
|
|
||||||
styles.borderHover,
|
|
||||||
onClick && 'active:scale-[0.98]'
|
|
||||||
)}
|
|
||||||
onClick={onClick}
|
|
||||||
>
|
|
||||||
<CardContent className="pt-4 pb-4">
|
|
||||||
<div className="flex items-center gap-4">
|
|
||||||
{/* Icon Container with background */}
|
|
||||||
<div
|
|
||||||
className={cn(
|
|
||||||
'flex items-center justify-center w-12 h-12 rounded-lg transition-transform duration-200',
|
|
||||||
styles.iconBg,
|
|
||||||
'group-hover:scale-105'
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
<Icon className={cn('w-6 h-6', iconColorClass)} />
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Content */}
|
|
||||||
<div className="flex-1 min-w-0">
|
|
||||||
<p className="text-sm text-muted-foreground truncate">{title}</p>
|
|
||||||
<p className={cn('text-2xl font-bold font-mono', iconColorClass)}>{value}</p>
|
|
||||||
{subtitle && <p className="text-xs text-muted-foreground mt-0.5">{subtitle}</p>}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,61 +0,0 @@
|
|||||||
import { useEffect, useState } from 'react';
|
|
||||||
import { ThemeProviderContext } from '@/contexts/theme-context';
|
|
||||||
import type { Theme } from '@/contexts/theme-context';
|
|
||||||
|
|
||||||
type ThemeProviderProps = {
|
|
||||||
children: React.ReactNode;
|
|
||||||
defaultTheme?: Theme;
|
|
||||||
storageKey?: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
export function ThemeProvider({
|
|
||||||
children,
|
|
||||||
defaultTheme = 'system',
|
|
||||||
storageKey = 'vite-ui-theme',
|
|
||||||
}: ThemeProviderProps) {
|
|
||||||
const [theme, setTheme] = useState<Theme>(
|
|
||||||
() => (localStorage.getItem(storageKey) as Theme) || defaultTheme
|
|
||||||
);
|
|
||||||
|
|
||||||
// Track system preference separately
|
|
||||||
// Initialize with window.matchMedia value if available
|
|
||||||
const [systemIsDark, setSystemIsDark] = useState(() => {
|
|
||||||
if (typeof window !== 'undefined') {
|
|
||||||
return window.matchMedia('(prefers-color-scheme: dark)').matches;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
|
|
||||||
// Listen for system theme changes
|
|
||||||
useEffect(() => {
|
|
||||||
const media = window.matchMedia('(prefers-color-scheme: dark)');
|
|
||||||
|
|
||||||
const listener = (e: MediaQueryListEvent) => {
|
|
||||||
setSystemIsDark(e.matches);
|
|
||||||
};
|
|
||||||
|
|
||||||
media.addEventListener('change', listener);
|
|
||||||
return () => media.removeEventListener('change', listener);
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
// Derive effective theme
|
|
||||||
const isDark = theme === 'dark' || (theme === 'system' && systemIsDark);
|
|
||||||
|
|
||||||
// Update DOM when effective theme changes
|
|
||||||
useEffect(() => {
|
|
||||||
const root = window.document.documentElement;
|
|
||||||
root.classList.remove('light', 'dark');
|
|
||||||
root.classList.add(isDark ? 'dark' : 'light');
|
|
||||||
}, [isDark]);
|
|
||||||
|
|
||||||
const value = {
|
|
||||||
theme,
|
|
||||||
setTheme: (theme: Theme) => {
|
|
||||||
localStorage.setItem(storageKey, theme);
|
|
||||||
setTheme(theme);
|
|
||||||
},
|
|
||||||
isDark,
|
|
||||||
};
|
|
||||||
|
|
||||||
return <ThemeProviderContext.Provider value={value}>{children}</ThemeProviderContext.Provider>;
|
|
||||||
}
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
import { Moon, Sun } from 'lucide-react';
|
|
||||||
import { Button } from '@/components/ui/button';
|
|
||||||
import { useTheme } from '@/hooks/use-theme';
|
|
||||||
|
|
||||||
export function ThemeToggle() {
|
|
||||||
const { theme, setTheme } = useTheme();
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Button
|
|
||||||
variant="ghost"
|
|
||||||
size="icon"
|
|
||||||
onClick={() => setTheme(theme === 'dark' ? 'light' : 'dark')}
|
|
||||||
>
|
|
||||||
<Sun className="h-[1.2rem] w-[1.2rem] rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0" />
|
|
||||||
<Moon className="absolute h-[1.2rem] w-[1.2rem] rotate-90 scale-0 transition-all dark:rotate-0 dark:scale-100" />
|
|
||||||
<span className="sr-only">Toggle theme</span>
|
|
||||||
</Button>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,114 +0,0 @@
|
|||||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
|
||||||
import { Badge } from '@/components/ui/badge';
|
|
||||||
import { TrendingUpIcon, TrendingDownIcon, DollarSignIcon, ZapIcon } from 'lucide-react';
|
|
||||||
|
|
||||||
interface MetricCardProps {
|
|
||||||
title: string;
|
|
||||||
value: string | number;
|
|
||||||
change?: number;
|
|
||||||
changeLabel?: string;
|
|
||||||
icon: React.ReactNode;
|
|
||||||
trend?: 'up' | 'down' | 'neutral';
|
|
||||||
}
|
|
||||||
|
|
||||||
function MetricCard({ title, value, change, changeLabel, icon, trend }: MetricCardProps) {
|
|
||||||
const TrendIcon = trend === 'up' ? TrendingUpIcon : trend === 'down' ? TrendingDownIcon : null;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Card>
|
|
||||||
<CardContent className="p-6">
|
|
||||||
<div className="flex items-center justify-between">
|
|
||||||
<div className="flex items-center gap-2">
|
|
||||||
{icon}
|
|
||||||
<h3 className="font-medium text-sm text-muted-foreground">{title}</h3>
|
|
||||||
</div>
|
|
||||||
{trend && TrendIcon && (
|
|
||||||
<Badge variant={trend === 'up' ? 'default' : 'destructive'} className="text-xs">
|
|
||||||
<TrendIcon className="w-3 h-3 mr-1" />
|
|
||||||
{change && `${Math.abs(change)}%`}
|
|
||||||
</Badge>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
<div className="mt-2">
|
|
||||||
<div className="text-2xl font-bold">{value}</div>
|
|
||||||
{changeLabel && <div className="text-xs text-muted-foreground mt-1">{changeLabel}</div>}
|
|
||||||
</div>
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function ValueMetrics() {
|
|
||||||
// Mock data for demonstration
|
|
||||||
const metrics = [
|
|
||||||
{
|
|
||||||
title: 'API Cost Saved',
|
|
||||||
value: '$127.50',
|
|
||||||
change: 23,
|
|
||||||
changeLabel: 'vs last month',
|
|
||||||
icon: <DollarSignIcon className="w-4 h-4 text-green-600" />,
|
|
||||||
trend: 'up' as const,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: 'Tokens Saved',
|
|
||||||
value: '2.4M',
|
|
||||||
change: 18,
|
|
||||||
changeLabel: 'through caching',
|
|
||||||
icon: <ZapIcon className="w-4 h-4 text-blue-600" />,
|
|
||||||
trend: 'up' as const,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: 'Queries Faster',
|
|
||||||
value: '43%',
|
|
||||||
change: 12,
|
|
||||||
changeLabel: 'average speedup',
|
|
||||||
icon: <TrendingUpIcon className="w-4 h-4 text-purple-600" />,
|
|
||||||
trend: 'up' as const,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: 'Errors Reduced',
|
|
||||||
value: '-67%',
|
|
||||||
change: 67,
|
|
||||||
changeLabel: 'with retry logic',
|
|
||||||
icon: <TrendingDownIcon className="w-4 h-4 text-red-600" />,
|
|
||||||
trend: 'down' as const,
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="space-y-4">
|
|
||||||
<h2 className="text-lg font-semibold">Performance Metrics</h2>
|
|
||||||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4">
|
|
||||||
{metrics.map((metric, index) => (
|
|
||||||
<MetricCard key={index} {...metric} />
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<Card>
|
|
||||||
<CardHeader>
|
|
||||||
<CardTitle className="text-base">Monthly Summary</CardTitle>
|
|
||||||
</CardHeader>
|
|
||||||
<CardContent>
|
|
||||||
<div className="grid grid-cols-2 md:grid-cols-4 gap-4 text-center">
|
|
||||||
<div>
|
|
||||||
<div className="text-lg font-semibold">$342.10</div>
|
|
||||||
<div className="text-xs text-muted-foreground">Total Saved</div>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<div className="text-lg font-semibold">8.7M</div>
|
|
||||||
<div className="text-xs text-muted-foreground">Tokens Processed</div>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<div className="text-lg font-semibold">1,247</div>
|
|
||||||
<div className="text-xs text-muted-foreground">Queries Handled</div>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<div className="text-lg font-semibold">99.8%</div>
|
|
||||||
<div className="text-xs text-muted-foreground">Uptime</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user