import "server-only"

import { isRecord } from "./payload-parser"

export const getAiErrorMessage = (v: unknown) => {
  if (v instanceof Error) return v.message
  if (!isRecord(v)) return "AI request failed"
  const message = String(v.message ?? "")
  return message.trim().length ? message : "AI request failed"
}
