Skip to content

Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.

2.1 KB
Raw Blame
import { TFunction } from "i18next";
import { describeProviderError } from "./describeProviderError";

type RecordingError = {
  code?: string;
  title: string;
  description?: string;
  messageKey?: string;
  messageParams?: Record<string, string | number | boolean>;
  surface?: string;
  selectionEditFatal?: boolean;
  /** Toast variant; defaults to destructive for genuine failures. */
  variant?: "default" | "destructive";
};

export function getRecordingErrorTitle(error: RecordingError, t: TFunction): string {
  if (error.code === "ACCESSIBILITY_PERMISSION_REQUIRED") {
    return t("hooks.audioRecording.pastePermission.title");
  }
  if (error.code === "PASTE_FAILED") return t("hooks.audioRecording.pasteFailed.title");
  if (error.selectionEditFatal) {
    return t("hooks.audioRecording.selectionEditing.notAppliedTitle");
  }
  if (error.code === "NETWORK_ERROR") return t(error.title);
  if (error.code === "AUTH_EXPIRED" || error.code === "AUTH_REQUIRED") {
    return t("hooks.audioRecording.errorTitles.sessionExpired");
  }
  if (error.code === "OFFLINE") return t("hooks.audioRecording.errorTitles.offline");
  if (error.code === "AGENT_REASONING_FAILED") {
    return t("hooks.audioRecording.errorTitles.agentUnavailable");
  }
  if (error.code === "SCREEN_CONTEXT_SKIPPED") {
    return t("hooks.audioRecording.errorTitles.screenContextSkipped");
  }
  if (error.code === "LIMIT_REACHED")
    return t("hooks.audioRecording.errorTitles.cloudLimitReached");
  if (error.code === "PROVIDER_RATE_LIMITED")
    return t("hooks.audioRecording.errorTitles.providerRateLimited");
  if (error.code?.startsWith("PROVIDER_")) {
    return t(
      error.surface === "llm" ? "providerErrors.titles.llm" : "providerErrors.titles.transcription"
    );
  }
  return error.title;
}

export function getRecordingErrorDescription(error: RecordingError, t: TFunction): string {
  if (error.code === "ACCESSIBILITY_PERMISSION_REQUIRED") {
    return t("hooks.audioRecording.pastePermission.description");
  }
  if (error.messageKey) return describeProviderError(error, t).description;
  return error.description ?? "";
}