// Minimal sanitized request logger for the TypeScript examples (mirrors scripts/live.py::log_request). // Appends one JSON line to reports/live-requests.jsonl; never writes keys (masks sk-… patterns defensively). import { appendFileSync, mkdirSync } from "node:fs"; import { dirname, resolve } from "node:path"; import { fileURLToPath } from "node:url"; const ROOT = resolve(dirname(fileURLToPath(import.meta.url)), "../../.."); const LOG = resolve(ROOT, "reports/live-requests.jsonl"); export function logRequest(provider: string, method: string, path: string, status: number, estCostUsd = 0, note = ""): void { mkdirSync(dirname(LOG), { recursive: true }); const safe = note.replace(/sk-(ant-)?[A-Za-z0-9_-]{8,}/g, "sk-***REDACTED***").slice(0, 300); appendFileSync(LOG, JSON.stringify({ ts: new Date().toISOString().replace(/\.\d+Z$/, "Z"), provider, method, path, status, est_cost_usd: estCostUsd, note: safe }) + "\n"); }