//#region src/session/parity/sessions-json-patch.ts
function buildSessionsJsonStatsPatch(messageCount, estimatedTokens) {
	return {
		messageCount,
		estimatedTokens,
		lastTurnAt: Date.now()
	};
}
/** Apply stats + timestamps to a single sessions.json entry (in-memory patch). */
function patchSessionsJsonEntryStats(entry, stats) {
	if (!entry.pluginExtensions?.xopc?.metadata) return;
	const meta = entry.pluginExtensions.xopc.metadata;
	meta.messageCount = stats.messageCount;
	meta.estimatedTokens = stats.estimatedTokens;
	meta.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
	meta.lastAccessedAt = meta.updatedAt;
	meta.stats = {
		messageCount: stats.messageCount,
		tokenCount: stats.estimatedTokens,
		lastTurnAt: stats.lastTurnAt
	};
	entry.updatedAt = stats.lastTurnAt;
}
function isAppendOnlyLlmTranscriptMessage(message) {
	if (!message || typeof message !== "object") return false;
	const role = message.role;
	return role === "user" || role === "assistant" || role === "tool" || role === "toolResult";
}
/** Increment stats for a single appended LLM row (hot path). */
function incrementSessionsJsonStatsForAppend(entry, opts) {
	if (!entry.pluginExtensions?.xopc?.metadata) return;
	const meta = entry.pluginExtensions.xopc.metadata;
	const nextCount = (meta.messageCount ?? 0) + 1;
	const tokenDelta = opts?.tokenDelta ?? 0;
	patchSessionsJsonEntryStats(entry, buildSessionsJsonStatsPatch(nextCount, (meta.estimatedTokens ?? 0) + tokenDelta));
}
//#endregion
export { buildSessionsJsonStatsPatch, incrementSessionsJsonStatsForAppend, isAppendOnlyLlmTranscriptMessage, patchSessionsJsonEntryStats };

//# sourceMappingURL=sessions-json-patch.js.map