import { Button } from "@/src/components/ui/button"; import { Switch } from "@/src/components/ui/switch"; import { api } from "@/src/utils/api"; import { useState } from "react"; import { Dialog, DialogBody, DialogContent, DialogFooter, DialogHeader, DialogTitle, } from "@/src/components/ui/dialog"; import Header from "@/src/components/layouts/header"; import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture"; import { useHasOrganizationAccess } from "@/src/features/rbac/utils/checkOrganizationAccess"; import { useLangfuseCloudRegion, useQueryOrganization, } from "@/src/features/organizations/hooks"; import { Card } from "@/src/components/ui/card"; import { LockIcon, ExternalLink } from "lucide-react"; import { useSession } from "next-auth/react"; import { useForm } from "react-hook-form"; import { zodResolver } from "@hookform/resolvers/zod"; import * as z from "zod/v4"; const aiFeaturesSchema = z.object({ aiFeaturesEnabled: z.boolean(), }); export default function AIFeatureSwitch() { const { update: updateSession } = useSession(); const { isLangfuseCloud } = useLangfuseCloudRegion(); const capture = usePostHogClientCapture(); const organization = useQueryOrganization(); const [isAIFeatureSwitchEnabled, setIsAIFeatureSwitchEnabled] = useState( organization?.aiFeaturesEnabled ?? false, ); const [confirmOpen, setConfirmOpen] = useState(false); const hasAccess = useHasOrganizationAccess({ organizationId: organization?.id, scope: "organization:update", }); const confirmForm = useForm>({ resolver: zodResolver(aiFeaturesSchema), defaultValues: { aiFeaturesEnabled: isAIFeatureSwitchEnabled, }, }); const updateAIFeatures = api.organizations.update.useMutation({ onSuccess: () => { void updateSession(); setConfirmOpen(false); }, onError: () => { setConfirmOpen(false); }, }); function handleSwitchChange(newValue: boolean) { if (!hasAccess) return; setIsAIFeatureSwitchEnabled(newValue); confirmForm.setValue("aiFeaturesEnabled", newValue); setConfirmOpen(true); } function handleCancel() { setIsAIFeatureSwitchEnabled(organization?.aiFeaturesEnabled ?? false); setConfirmOpen(false); } function handleConfirm() { if (!organization || !hasAccess) return; capture("organization_settings:ai_features_toggle"); updateAIFeatures.mutate({ orgId: organization.id, aiFeaturesEnabled: isAIFeatureSwitchEnabled, }); } if (!isLangfuseCloud) return null; return (

Enable AI powered features for your organization

This setting applies to all users and projects. Any data{" "} can be sent to AWS Bedrock within the Langfuse data region. Traces are sent to Langfuse Cloud in your data region. Your data will not be used for training models. Applicable HIPAA, SOC2, GDPR, and ISO 27001 compliance remains intact.{" "} More details in the docs here.

{!hasAccess && ( )}
{ if (!isOpen && !updateAIFeatures.isPending) { handleCancel(); } }} > Confirm AI Features Change You are about to{" "} {isAIFeatureSwitchEnabled ? "enable " : "disable"} {" "} AI features for your organization. When enabled, any data{" "} can be sent to AWS Bedrock in your data region for processing.

{" "} Learn more in the docs.

Are you sure you want to proceed?

); }