import { n as normalizeAgentId, t as isValidAgentId } from "./agent-id-CeT3w4ap.js";
import "./agent-scope-CB42Y_8g.js";
import "./artifacts-FzMa6c2e.js";
import "./paths-DVAvlIOc.js";
import "./openclaw-state-db-Cb4e1jdd.js";
import "./internal-runtime-context-E3ku7Huk.js";
import "./config-D_ojUgx2.js";
import "./main-session-Bht8AmQz.js";
import "./transcript-events-Dh6dX7iG.js";
import "./session-accessor-Dwfzn6Ej.js";
import { M as readTranscriptStatsSync } from "./session-accessor.sqlite-transcript-store-BAnJbMnW.js";
import "./heartbeat-yX5WzsUn.js";
import "./input-provenance-CCQsDhUy.js";
import "./heartbeat-filter-C22Hsofi.js";
import "./session-store-runtime-DIDzjIoO.js";
import "./heartbeat-events-filter-DTPF6atP.js";
import path from "node:path";
//#region packages/memory-host-sdk/src/host/openclaw-runtime-session.ts
/** Returns an opaque revision that changes for every canonical transcript mutation. */
function readTranscriptContentRevisionSync(params) {
	const stats = readTranscriptStatsSync(params);
	return [
		"sqlite",
		stats.maxSeq,
		stats.sizeBytes,
		stats.eventCount,
		stats.lastMutationAtMs ?? "",
		stats.lastObservedMutationAtMs ?? ""
	].join(":");
}
/** Extracts the agent id from a canonical `agents/<id>/sessions` directory path. */
function extractAgentIdFromSessionsDir(sessionsDir) {
	const parts = path.normalize(path.resolve(sessionsDir)).split(path.sep).filter(Boolean);
	const sessionsSegment = parts.at(-1);
	const agentId = parts.at(-2);
	const agentsSegment = parts.at(-3);
	const isWindows = process.platform === "win32";
	if (!sessionsSegment || !agentId || !agentsSegment || (isWindows ? sessionsSegment.toLowerCase() : sessionsSegment) !== "sessions" || (isWindows ? agentsSegment.toLowerCase() : agentsSegment) !== "agents" || isWindows && (agentId !== agentId.trim() || !isValidAgentId(agentId))) return null;
	return isWindows ? normalizeAgentId(agentId) : agentId;
}
/** Finds the nearest canonical sessions owner without escaping its directory. */
function extractAgentIdFromSessionPath(absPath) {
	let currentDir = path.dirname(path.resolve(absPath));
	while (true) {
		const currentSegment = path.basename(currentDir);
		if ((process.platform === "win32" ? currentSegment.toLowerCase() : currentSegment) === "sessions") {
			const agentId = extractAgentIdFromSessionsDir(currentDir);
			if (agentId) return agentId;
		}
		const parentDir = path.dirname(currentDir);
		if (parentDir === currentDir) return null;
		currentDir = parentDir;
	}
}
/** Session-key prefix marking transcripts generated by memory dreaming runs. */
const DREAMING_NARRATIVE_RUN_PREFIX = "dreaming-narrative-";
/** True when a session-store key belongs to a dreaming narrative run. */
function isDreamingNarrativeSessionStoreKey(sessionKey) {
	const trimmed = sessionKey.trim();
	if (!trimmed) return false;
	const firstSeparator = trimmed.indexOf(":");
	if (firstSeparator < 0) return trimmed.startsWith(DREAMING_NARRATIVE_RUN_PREFIX);
	const secondSeparator = trimmed.indexOf(":", firstSeparator + 1);
	return (secondSeparator < 0 ? trimmed : trimmed.slice(secondSeparator + 1)).startsWith(DREAMING_NARRATIVE_RUN_PREFIX);
}
//#endregion
export { readTranscriptContentRevisionSync as a, isDreamingNarrativeSessionStoreKey as i, extractAgentIdFromSessionPath as n, extractAgentIdFromSessionsDir as r, DREAMING_NARRATIVE_RUN_PREFIX as t };
