import { createId, appendJsonl, nowIso, readJsonl } from "../../shared/index.js";
import { contextMetricsPath } from "./store.js";
import { SEED_CONTEXT_METRIC_SCHEMA_VERSION } from "./types.js";
export async function appendContextMetric(store, runId, input) {
    if (!store.config.context_ledger.enabled || !store.config.context_ledger.metrics_enabled)
        return undefined;
    const metric = {
        schema_version: SEED_CONTEXT_METRIC_SCHEMA_VERSION,
        metric_id: createId("ctxmetric"),
        run_id: runId,
        created_at: nowIso(),
        ...input,
    };
    await appendJsonl(contextMetricsPath(store, runId), metric);
    return metric;
}
export async function readContextMetrics(store, runId, input = {}) {
    const metrics = await readJsonl(contextMetricsPath(store, runId));
    const limit = Math.max(1, Math.floor(input.limit ?? 50));
    return metrics.slice(-limit);
}
//# sourceMappingURL=telemetry.js.map