import { Firestore } from "@google-cloud/firestore"; import { config } from "../config.js"; import type { RunRecord, ToolDef } from "../types.js"; const db = new Firestore({ projectId: config.projectId }); export async function saveRun(run: RunRecord): Promise { await db.collection(config.runsCollection).doc(run.run_id).set(run, { merge: true }); } export async function getRun(runId: string): Promise { const snap = await db.collection(config.runsCollection).doc(runId).get(); return snap.exists ? (snap.data() as RunRecord) : null; } export async function saveTool(tool: ToolDef): Promise { await db.collection(config.toolsCollection).doc(tool.name).set(tool, { merge: true }); } export async function listTools(): Promise { const snap = await db.collection(config.toolsCollection).get(); return snap.docs.map(d => d.data() as ToolDef); }