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 { Button } from "@/components/ui/button";
import { useT } from "@/i18n";
import type { CopySupportDiagnosticsResult } from "@/lib/tauri-diagnostics";

import { useState } from "react";

/** Falls back to a selectable textarea when the clipboard refuses. */
export function DiagnosticsCopyActions({
  onCopyDiagnostics,
  children,
}: {
  onCopyDiagnostics: () => Promise<CopySupportDiagnosticsResult>;
  children: React.ReactNode;
}) {
  const t = useT();
  const [copying, setCopying] = useState(false);
  const [manualReport, setManualReport] = useState<string | null>(null);
  const [manualMessage, setManualMessage] = useState<string | null>(null);

  async function handleCopyDiagnostics() {
    setCopying(true);
    try {
      const result = await onCopyDiagnostics();
      if (result.ok) {
        setManualReport(null);
        setManualMessage(null);
      } else {
        setManualReport(result.report);
        setManualMessage(result.error ?? t("desktopStartup.diagnostics.clipboardFailed"));
      }
    } catch (error) {
      setManualReport(null);
      setManualMessage(t("desktopStartup.diagnostics.copyFailed", { error: String(error) }));
    } finally {
      setCopying(false);
    }
  }

  return (
    <div className="mt-4 flex w-full flex-col items-center gap-3">
      <div className="flex flex-wrap items-center justify-center gap-3">
        <Button
          variant="muted"
          size="hero"
          onClick={() => void handleCopyDiagnostics()}
        >
          {copying ? t("desktopStartup.diagnostics.copying") : t("desktopStartup.diagnostics.copy")}
        </Button>
        {children}
      </div>
      {manualMessage && (
        <p className="max-w-md text-center text-xs text-destructive">{manualMessage}</p>
      )}
      {manualReport && (
        <textarea
          readOnly
          value={manualReport}
          onFocus={(event) => event.currentTarget.select()}
          className="h-32 w-full max-w-md resize-none rounded-xl border border-border/50 bg-muted/30 p-2 text-left font-mono text-ui-10 text-muted-foreground"
        />
      )}
    </div>
  );
}