import { type ReactNode } from 'react' import { Key, Trash2, User, Loader2, Shield, KeyRound, Bot } from 'lucide-react' import { useTranslation } from '../../i18n' import { useFormatDate } from '../../hooks/useDateFormat' import ConfirmDialog from '../shared/ConfirmDialog' import { Tooltip } from '../shared/Tooltip' import { fs } from '../shared/DialogShell' import { SETTINGS_ICON_BUTTON, SettingRows, SettingsCard, SettingsHint, StatusPill } from '../Settings/settingsKit' import { SCOPES_PREVIEW, useMcpTokensAdmin } from './useMcpTokensAdmin' const ROW = 'flex flex-wrap items-center gap-x-4 gap-y-2 px-3.5 py-3' const TILE = 'grid h-9 w-9 flex-none place-items-center rounded-[10px] bg-surface-tertiary text-content-secondary' const CHIP = 'inline-flex items-center rounded-full border border-edge-faint bg-surface-secondary px-2 py-[1px] font-geist text-content-muted' /** The spinner or the empty line a list shows in place of its rows. */ function ListState({ loading, icon, text }: { loading: boolean; icon: ReactNode; text: string }) { if (loading) { return (
) } return (
{icon} {text}
) } /** One fact on the right of a row: an eyebrow over its value. */ function Meta({ label, children }: { label: string; children: ReactNode }) { return (
{label}
{children}
) } /** The owner of a session or token, with the person glyph in front. */ function Owner({ name }: { name: string }) { return ( {name} ) } /** The trash button of a row, named by its tooltip. */ function DeleteAction({ label, onClick }: { label: string; onClick: () => void }) { return ( ) } export default function AdminMcpTokensPanel() { const { sessions, sessionsLoading, tokens, tokensLoading, expandedScopes, toggleScopes, revokeConfirmId, setRevokeConfirmId, deleteConfirmId, setDeleteConfirmId, handleRevoke, handleDelete, } = useMcpTokensAdmin() const { t } = useTranslation() const { formatDate } = useFormatDate() const date = (iso: string) => formatDate(new Date(iso)) return (
{/* OAuth Sessions. The tab's own subtitle sits in its band: the sidebar already names the tab, so a bare heading over the cards only repeated it. */} 0 ? {sessions.length} : undefined} > {sessionsLoading || sessions.length === 0 ? ( } text={t('admin.oauthSessions.empty')} /> ) : ( {sessions.map(session => { const expanded = expandedScopes.has(session.id) const visible = expanded ? session.scopes : session.scopes.slice(0, SCOPES_PREVIEW) const hidden = session.scopes.length - SCOPES_PREVIEW return (

{session.client_name}

{visible.map(scope => ( {scope} ))} {hidden > 0 && ( )}
{date(session.created_at)} setRevokeConfirmId(session.id)} />
) })}
)}
{/* MCP Tokens */} 0 ? {tokens.length} : undefined} > {tokensLoading || tokens.length === 0 ? ( } text={t('admin.mcpTokens.empty')} /> ) : ( {tokens.map(token => (

{token.name}

{token.token_prefix}...

{date(token.created_at)} {token.last_used_at ? date(token.last_used_at) : t('admin.mcpTokens.never')} setDeleteConfirmId(token.id)} />
))}
)}
{/* Revoke OAuth session */} setRevokeConfirmId(null)} onConfirm={() => { if (revokeConfirmId !== null) void handleRevoke(revokeConfirmId) }} title={t('admin.oauthSessions.revokeTitle')} message={t('admin.oauthSessions.revokeMessage')} confirmLabel={t('common.delete')} danger /> {/* Delete MCP token */} setDeleteConfirmId(null)} onConfirm={() => { if (deleteConfirmId !== null) void handleDelete(deleteConfirmId) }} title={t('admin.mcpTokens.deleteTitle')} message={t('admin.mcpTokens.deleteMessage')} confirmLabel={t('common.delete')} danger />
) }