import { invoke } from "@tauri-apps/api/core";

/**
 * Best-effort lore ingestion. Every generated result gets indexed into the
 * local RAG store so future generations stay consistent with everything the
 * DM has already created. Errors are swallowed — lore is augmentation, never
 * a blocker on the generation UX.
 */
export async function addToLore(source: string, text: string): Promise<void> {
  if (!source.trim() || !text.trim()) return;
  try {
    await invoke("rag_add", { req: { source, text } });
  } catch (e) {
    console.warn("addToLore failed:", e);
  }
}