const require_chunk = require("./chunk-DakpK96I.cjs");
let path = require("path");
path = require_chunk.__toESM(path, 1);
let fs = require("fs");
fs = require_chunk.__toESM(fs, 1);
//#region src/core/usage.ts
const DEFAULT_PRICING = {
	"claude-haiku-4-5": {
		input: 1,
		output: 5
	},
	default: {
		input: 1,
		output: 5
	}
};
function ledgerPath(dataDir) {
	return path.default.join(dataDir, ".agentic", "usage.ndjson");
}
function loadPricing(dataDir) {
	const p = path.default.join(dataDir, ".agentic", "llm-pricing.json");
	if (!fs.default.existsSync(p)) return DEFAULT_PRICING;
	try {
		const custom = JSON.parse(fs.default.readFileSync(p, "utf-8"));
		return {
			...DEFAULT_PRICING,
			...custom
		};
	} catch {
		return DEFAULT_PRICING;
	}
}
function computeCost(pricing, model, inputTokens, outputTokens) {
	const price = pricing[model] ?? pricing["default"];
	const cost = inputTokens / 1e6 * price.input + outputTokens / 1e6 * price.output;
	return Math.round(cost * 1e6) / 1e6;
}
function recordUsage(dataDir, u) {
	const entry = {
		timestamp: (/* @__PURE__ */ new Date()).toISOString(),
		...u.slug ? { slug: u.slug } : {},
		...u.tool ? { tool: u.tool } : {},
		model: u.model,
		inputTokens: u.inputTokens,
		outputTokens: u.outputTokens,
		costUsd: computeCost(loadPricing(dataDir), u.model, u.inputTokens, u.outputTokens)
	};
	const p = ledgerPath(dataDir);
	try {
		fs.default.mkdirSync(path.default.dirname(p), { recursive: true });
		fs.default.appendFileSync(p, JSON.stringify(entry) + "\n", "utf-8");
	} catch {}
}
//#endregion
exports.recordUsage = recordUsage;

//# sourceMappingURL=usage-CClTf5e6.cjs.map