import { Button } from "@/components/ui/button"; import { Switch } from "@/components/ui/switch"; import { getErrorMessage, useGetCoreConfigQuery, useUpdateCoreConfigMutation } from "@/lib/store"; import { CompatConfig, DefaultCoreConfig } from "@/lib/types/config"; import { RbacOperation, RbacResource, useRbac } from "@enterprise/lib"; import { useCallback, useEffect, useMemo, useState } from "react"; import { toast } from "sonner"; export default function CompatibilityView() { const hasSettingsUpdateAccess = useRbac(RbacResource.Settings, RbacOperation.Update); const { data: bifrostConfig } = useGetCoreConfigQuery({ fromDB: true }); const config = bifrostConfig?.client_config?.compat; const [updateCoreConfig, { isLoading }] = useUpdateCoreConfigMutation(); const [localCompatConfig, setLocalCompatConfig] = useState(DefaultCoreConfig.compat); useEffect(() => { if (config) { setLocalCompatConfig(config); return; } setLocalCompatConfig(DefaultCoreConfig.compat); }, [config]); const hasChanges = useMemo(() => { const baseline = config ?? DefaultCoreConfig.compat; return ( localCompatConfig.convert_text_to_chat !== baseline.convert_text_to_chat || localCompatConfig.convert_chat_to_responses !== baseline.convert_chat_to_responses || localCompatConfig.should_drop_params !== baseline.should_drop_params || localCompatConfig.should_convert_params !== baseline.should_convert_params ); }, [config, localCompatConfig]); const handleCompatChange = useCallback((field: keyof CompatConfig, value: boolean) => { setLocalCompatConfig((prev) => ({ ...prev, [field]: value })); }, []); const handleSave = useCallback(async () => { if (!bifrostConfig) { toast.error("Configuration not loaded"); return; } try { await updateCoreConfig({ ...bifrostConfig, client_config: { ...(bifrostConfig.client_config ?? DefaultCoreConfig), compat: localCompatConfig, }, }).unwrap(); toast.success("Compatibility settings updated successfully."); } catch (error) { toast.error(getErrorMessage(error)); } }, [bifrostConfig, localCompatConfig, updateCoreConfig]); return (

Compatibility

Configure request conversions and compatibility fallbacks.{" "} Learn more

Convert text completion requests to chat for models that only support chat.

handleCompatChange("convert_text_to_chat", checked)} disabled={!hasSettingsUpdateAccess} />

Convert chat completion requests to responses for models that only support responses.

handleCompatChange("convert_chat_to_responses", checked)} disabled={!hasSettingsUpdateAccess} />

Drop unsupported parameters based on model catalog allowlist.

handleCompatChange("should_drop_params", checked)} disabled={!hasSettingsUpdateAccess} />

Converts model parameter values that are not supported by the model.

handleCompatChange("should_convert_params", checked)} disabled={!hasSettingsUpdateAccess} />
); }