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

/** A denied folder looks like an empty one, so the row must say which and where to fix it. */

export type ScanFolderStatus =
  | "ok"
  | "permission_denied"
  | "missing"
  | "unreadable"
  | "partial"
  | "slow";

export interface ScanFolderStatusCopy {
  title: string;
  hint: string;
}

function hostPlatform(userAgent: string): "mac" | "windows" | "other" {
  if (/Mac|iPhone|iPad/i.test(userAgent)) return "mac";
  if (/Win/i.test(userAgent)) return "windows";
  return "other";
}

function permissionHint(userAgent: string): string {
  switch (hostPlatform(userAgent)) {
    case "mac":
      return "Grant access in System Settings > Privacy & Security > Files and Folders, then refresh the list.";
    case "windows":
      return "Check the folder's security permissions, or allow Unsloth in Controlled Folder Access, then refresh the list.";
    default:
      return "Check the folder's permissions, then refresh the list.";
  }
}

export function scanFolderStatusCopy(
  status: ScanFolderStatus | undefined,
  userAgent: string = typeof navigator === "undefined" ? "" : navigator.userAgent,
): ScanFolderStatusCopy | null {
  switch (status) {
    case "permission_denied":
      return {
        title: "Unsloth is not allowed to read this folder",
        hint: permissionHint(userAgent),
      };
    case "partial":
      return {
        title: "Some models in this folder could not be read",
        hint: permissionHint(userAgent),
      };
    case "missing":
      return {
        title: "This folder is no longer there",
        hint: "It was moved, renamed, or is on a drive that is not connected.",
      };
    case "unreadable":
      return {
        title: "This folder could not be read",
        hint: "The drive may be disconnected or failing. Check it, then refresh the list.",
      };
    case "slow":
      return {
        title: "This folder is taking too long to scan",
        hint: "It may be on a slow or disconnected network drive. Its models are skipped until a scan finishes in time.",
      };
    default:
      return null;
  }
}