import { a as loadConfig } from "./io-B_JNqEVl.js";
import "./store-EVWz5v6d.js";
import { i as resolveMainSessionKey } from "./main-session-OD_gfnPE.js";
import { l as resolveStorePath } from "./paths-DRORteAV.js";
import "./reset-Bp37ohGw.js";
import "./session-key-Bo03tSQB.js";
import { t as loadSessionStore } from "./store-load-Cz0tEUuX.js";
import "./session-file-mvXd6aLE.js";
import { t as parseSessionThreadInfo } from "./thread-info-CjJMvSnB.js";
import "./transcript-CSZqp3ZV.js";
import "./targets-QAKJMvHi.js";
//#region src/config/sessions/main-session.runtime.ts
function resolveMainSessionKeyFromConfig() {
	return resolveMainSessionKey(loadConfig());
}
//#endregion
//#region src/config/sessions/delivery-info.ts
function extractDeliveryInfo(sessionKey) {
	const { baseSessionKey, threadId } = parseSessionThreadInfo(sessionKey);
	if (!sessionKey || !baseSessionKey) return {
		deliveryContext: void 0,
		threadId
	};
	let deliveryContext;
	try {
		const store = loadSessionStore(resolveStorePath(loadConfig().session?.store));
		let entry = store[sessionKey];
		if (!entry?.deliveryContext && baseSessionKey !== sessionKey) entry = store[baseSessionKey];
		if (entry?.deliveryContext) {
			const resolvedThreadId = entry.deliveryContext.threadId ?? entry.lastThreadId ?? entry.origin?.threadId;
			deliveryContext = {
				channel: entry.deliveryContext.channel,
				to: entry.deliveryContext.to,
				accountId: entry.deliveryContext.accountId,
				threadId: resolvedThreadId != null ? String(resolvedThreadId) : void 0
			};
		}
	} catch {}
	return {
		deliveryContext,
		threadId
	};
}
//#endregion
export { resolveMainSessionKeyFromConfig as n, extractDeliveryInfo as t };
