Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

2.2 KB
Raw Blame
// SPDX-License-Identifier: AGPL-3.0-only
// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0

import { authFetch } from "@/features/auth";
import { readFastApiError } from "@/lib/format-fastapi-error";
import type { ColorThemeId } from "../lib/color-themes";
import type { AppearanceCustomization } from "../stores/appearance-custom-store";

export type PersonalizationProfile = {
  displayName: string;
  nickname: string;
  avatarDataUrl: string | null;
  avatarShape: "circle" | "rounded";
  showGreetingSloth: boolean;
  greetingStyle: "text" | "image";
  greetingIcon: "sloth" | "custom" | "none";
  greetingIconDataUrl: string | null;
  greetingText: string;
  greetingImageDataUrl: string | null;
};

export type PersonalizationAppearance = {
  theme: "light" | "dark" | "system";
  palette: ColorThemeId;
  language: string | null;
  customization: AppearanceCustomization;
};

export type Personalization = {
  version: number;
  profile: PersonalizationProfile;
  appearance: PersonalizationAppearance;
  saved: boolean;
  // False for legacy records: the client keeps local values over server-filled defaults.
  customizationSaved: boolean;
  chatWidthSaved?: boolean;
  sentAttachmentsSaved?: boolean;
  paletteSaved: boolean;
  greetingSlothSaved: boolean;
  greetingCustomSaved?: boolean;
};

export async function loadPersonalization(): Promise<Personalization> {
  const res = await authFetch("/api/settings/personalization");
  if (!res.ok) {
    throw new Error(
      await readFastApiError(res, "Failed to load personalization"),
    );
  }
  return (await res.json()) as Personalization;
}

export async function savePersonalization(
  data: Omit<
    Personalization,
    | "saved"
    | "customizationSaved"
    | "chatWidthSaved"
    | "sentAttachmentsSaved"
    | "paletteSaved"
    | "greetingSlothSaved"
    | "greetingCustomSaved"
  >,
): Promise<void> {
  const res = await authFetch("/api/settings/personalization", {
    method: "PUT",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify(data),
  });
  if (!res.ok) {
    throw new Error(
      await readFastApiError(res, "Failed to save personalization"),
    );
  }
}