// frontend/lib/inbox/multimodal.ts — 멀티모달 캡처 (음성 STT / 이미지 Vision)
import type { TranscribeResult, CaptionResult } from "@/lib/types";

const BASE = process.env.NEXT_PUBLIC_API_BASE ?? "http://localhost:31800";

export async function transcribeAudio(blob: Blob, hint = ""): Promise<TranscribeResult> {
  const fd = new FormData();
  fd.append("audio", blob, "capture.webm");
  if (hint) fd.append("hint", hint);
  const res = await fetch(`${BASE}/api/inbox/transcribe`, { method: "POST", body: fd });
  if (!res.ok) throw new Error(`transcribe ${res.status}`);
  return res.json();
}

export async function captionImage(file: File, hint = ""): Promise<CaptionResult> {
  const fd = new FormData();
  fd.append("image", file, file.name || "capture.jpg");
  if (hint) fd.append("hint", hint);
  const res = await fetch(`${BASE}/api/inbox/caption`, { method: "POST", body: fd });
  if (!res.ok) throw new Error(`caption ${res.status}`);
  return res.json();
}
