import "../chunk-NSBPE2FW.js";

// src/telemetry/sink-file.ts
import * as fs from "fs";
import * as path from "path";
var FileTelemetrySink = class {
  constructor(baseDir) {
    this.baseDir = baseDir;
    fs.mkdirSync(baseDir, { recursive: true });
  }
  baseDir;
  streams = /* @__PURE__ */ new Map();
  emit(envelope) {
    const date = envelope.timestamp.slice(0, 10);
    const repo = envelope.source.repo || "unknown";
    const key = `${repo}/${date}`;
    let stream = this.streams.get(key);
    if (!stream) {
      const dir = path.join(this.baseDir, repo);
      fs.mkdirSync(dir, { recursive: true });
      stream = fs.createWriteStream(path.join(dir, `${date}.jsonl`), {
        flags: "a",
        encoding: "utf-8"
      });
      this.streams.set(key, stream);
    }
    stream.write(`${JSON.stringify(envelope)}
`);
  }
  async close() {
    const closes = Array.from(this.streams.values()).map(
      (s) => new Promise((resolve) => s.end(() => resolve()))
    );
    this.streams.clear();
    await Promise.all(closes);
  }
};
function defaultTelemetryDir(homeDir, override) {
  return override || path.join(homeDir, ".agent-eval", "telemetry");
}
export {
  FileTelemetrySink,
  defaultTelemetryDir
};
//# sourceMappingURL=file.js.map