openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
49 lines (48 loc) • 1.82 kB
JavaScript
import { o as resolveSessionStorePathCore } from "./paths-CXdaYWF_.js";
import "./session-accessor-YsytfDtG.js";
import { r as resolveSqliteTargetFromSessionStorePath } from "./session-sqlite-target-Dp-kgpcT.js";
import { l as readSessionStoreSummaryReadOnly } from "./session-accessor.entry-CQ2WPpfn.js";
//#region src/status/session-stores.ts
/** One collection owns each physical store's bounded snapshot, including its agent windows. */
function createStatusSessionStoreReader(agentIds, recentLimit, readSummary = readSessionStoreSummaryReadOnly) {
const stores = /* @__PURE__ */ new Map();
return {
stores,
read(storePath, agentId) {
const path = resolveSqliteTargetFromSessionStorePath(storePath, { agentId }).path;
let store = stores.get(path);
if (!store) {
store = readSummary({
...agentId ? { agentId } : {},
storePath
}, {
agentIds,
recentLimit
});
stores.set(path, store);
}
const summary = agentId ? store.byAgent.get(agentId) : store;
return {
path,
count: summary?.count ?? 0,
recent: summary?.recent ?? []
};
}
};
}
/** Reads each physical store once, retaining retired agent namespaces in the aggregate. */
function readStatusSessionStores(cfg, agents, recentLimit) {
const reader = createStatusSessionStoreReader(agents.map((agent) => agent.id), recentLimit);
const byAgent = agents.map((agent) => ({
agent,
...reader.read(resolveSessionStorePathCore(cfg.session?.store, { agentId: agent.id }), agent.id)
}));
return {
paths: [...reader.stores.keys()],
count: [...reader.stores.values()].reduce((count, store) => count + store.count, 0),
recent: [...reader.stores.values()].flatMap((store) => store.recent),
byAgent
};
}
//#endregion
export { readStatusSessionStores as n, createStatusSessionStoreReader as t };