import { g as resolveStateDir } from "./paths-VdmjGGyc.js";
import { l as normalizeKoiId, n as DEFAULT_KOI_ID } from "./session-key-B2OXLVi_.js";
import path from "node:path";
import os from "node:os";

//#region src/config/sessions/paths.ts
function resolveKoiSessionsDir(koiId, env = process.env, homedir = os.homedir) {
	const root = resolveStateDir(env, homedir);
	const id = normalizeKoiId(koiId ?? DEFAULT_KOI_ID);
	return path.join(root, "kois", id, "sessions");
}
function resolveSessionTranscriptsDir(env = process.env, homedir = os.homedir) {
	return resolveKoiSessionsDir(DEFAULT_KOI_ID, env, homedir);
}
function resolveSessionTranscriptsDirForKoi(koiId, env = process.env, homedir = os.homedir) {
	return resolveKoiSessionsDir(koiId, env, homedir);
}
function resolveDefaultSessionStorePath(koiId) {
	return path.join(resolveKoiSessionsDir(koiId), "sessions.json");
}
function resolveSessionTranscriptPath(sessionId, koiId, topicId) {
	const safeTopicId = typeof topicId === "string" ? encodeURIComponent(topicId) : typeof topicId === "number" ? String(topicId) : void 0;
	const fileName = safeTopicId !== void 0 ? `${sessionId}-topic-${safeTopicId}.jsonl` : `${sessionId}.jsonl`;
	return path.join(resolveKoiSessionsDir(koiId), fileName);
}
function resolveSessionFilePath(sessionId, entry, opts) {
	const candidate = entry?.sessionFile?.trim();
	return candidate ? candidate : resolveSessionTranscriptPath(sessionId, opts?.koiId);
}
function resolveStorePath(store, opts) {
	const koiId = normalizeKoiId(opts?.koiId ?? DEFAULT_KOI_ID);
	if (!store) return resolveDefaultSessionStorePath(koiId);
	if (store.includes("{koiId}")) {
		const expanded = store.replaceAll("{koiId}", koiId);
		if (expanded.startsWith("~")) return path.resolve(expanded.replace(/^~(?=$|[\\/])/, os.homedir()));
		return path.resolve(expanded);
	}
	if (store.startsWith("~")) return path.resolve(store.replace(/^~(?=$|[\\/])/, os.homedir()));
	return path.resolve(store);
}

//#endregion
export { resolveSessionTranscriptsDirForKoi as a, resolveSessionTranscriptsDir as i, resolveSessionFilePath as n, resolveStorePath as o, resolveSessionTranscriptPath as r, resolveDefaultSessionStorePath as t };