"use client"; import { useTranslations } from "next-intl"; import moment from "moment"; import { Button } from "@app/components/ui/button"; import CopyTextBox from "@app/components/CopyTextBox"; import CopyToClipboard from "@app/components/CopyToClipboard"; import { AiClientConfigSection } from "@app/components/ai-client-config/AiClientConfigSection"; import { SettingsContainer, SettingsFormCell, SettingsFormGrid, SettingsSection, SettingsSectionBody, SettingsSectionDescription, SettingsSectionHeader, SettingsSectionTitle as SectionTitle } from "@app/components/Settings"; import { useMyVirtualApiKeySecret } from "@app/hooks/useMyVirtualApiKeySecret"; import type { ListMyVirtualApiKeysResponse, VirtualApiKeyWithResources } from "@server/routers/virtualApiKey/types"; import { formatVirtualApiKeyPreview } from "@app/lib/virtualApiKeyFormat"; type UserVirtualApiKeysProps = { orgId: string; initialData: ListMyVirtualApiKeysResponse; /** The resource's niceId, when this page is scoped to a single resource. */ resourceNiceId?: string; /** The resource's real access URL, when known; falls back to a placeholder otherwise. */ endpoint?: string; }; function OwnedKeySecret({ orgId, virtualApiKeyId, lastChars }: { orgId: string; virtualApiKeyId: string; lastChars: string; }) { const t = useTranslations(); const preview = formatVirtualApiKeyPreview(virtualApiKeyId, lastChars); const { credential, revealed, loading, getCopyText, revealSecret } = useMyVirtualApiKeySecret(orgId, virtualApiKeyId); const displayValue = revealed && credential ? credential : preview; return (
{!revealed ? ( ) : null}
); } function IdentityKeyCenterpiece({ orgId, virtualApiKeyId, lastChars, resourceName }: { orgId: string; virtualApiKeyId: string; lastChars: string; resourceName?: string | null; }) { const t = useTranslations(); const preview = formatVirtualApiKeyPreview(virtualApiKeyId, lastChars); const { credential, revealed, loading, getCopyText, revealSecret } = useMyVirtualApiKeySecret(orgId, virtualApiKeyId); const displayValue = revealed && credential ? credential : preview; const headline = resourceName ? t("myVirtualApiKeysIdentityResourceHeadline", { resourceName }) : t("myVirtualApiKeysIdentityHeadline"); const description = resourceName ? t("myVirtualApiKeysIdentityResourceDescription", { resourceName }) : t("myVirtualApiKeysIdentityDescription"); return (

{headline}

{description}

{!revealed ? (
) : null}
); } function ManualKeyRow({ orgId, keyRow }: { orgId: string; keyRow: VirtualApiKeyWithResources; }) { const t = useTranslations(); return (

{keyRow.name || t("myVirtualApiKeysUnnamed")}

{keyRow.description ? (

{keyRow.description}

) : null}

{t("created")} {moment(keyRow.createdAt).format("lll")}

); } export default function UserVirtualApiKeys({ orgId, initialData, resourceNiceId, endpoint }: UserVirtualApiKeysProps) { const t = useTranslations(); const resourceName = initialData.resourceName; const { getCopyText: getKeyCopyText } = useMyVirtualApiKeySecret( orgId, initialData.userKey.virtualApiKeyId ); return ( <> {initialData.manualKeys.length > 0 ? ( {t("myVirtualApiKeysManualTitle")} {resourceName ? t( "myVirtualApiKeysManualResourceDescription", { resourceName } ) : t("myVirtualApiKeysManualDescription")} {initialData.manualKeys.map((keyRow) => ( ))} ) : null} ); }