MCPcopy
hub / github.com/ValueCell-ai/ClawX / readSessionStoreEntry

Function readSessionStoreEntry

electron/services/cron-api.ts:148–174  ·  view source on GitHub ↗
(
  agentId: string,
  sessionKey: string,
)

Source from the content-addressed store, hash-verified

146}
147
148async function readSessionStoreEntry(
149 agentId: string,
150 sessionKey: string,
151): Promise<Record<string, unknown> | undefined> {
152 const storePath = join(getOpenClawConfigDir(), 'agents', agentId, 'sessions', 'sessions.json');
153 const raw = await readFile(storePath, 'utf8').catch(() => '');
154 if (!raw.trim()) return undefined;
155
156 try {
157 const store = JSON.parse(raw) as Record<string, unknown>;
158 const directEntry = store[sessionKey];
159 if (directEntry && typeof directEntry === 'object') return directEntry as Record<string, unknown>;
160
161 const sessions = (store as { sessions?: unknown }).sessions;
162 if (Array.isArray(sessions)) {
163 const arrayEntry = sessions.find((entry) => {
164 if (!entry || typeof entry !== 'object') return false;
165 const record = entry as Record<string, unknown>;
166 return record.key === sessionKey || record.sessionKey === sessionKey;
167 });
168 if (arrayEntry && typeof arrayEntry === 'object') return arrayEntry as Record<string, unknown>;
169 }
170 } catch {
171 return undefined;
172 }
173 return undefined;
174}
175
176function buildCronSessionFallbackMessages(params: {
177 sessionKey: string;

Callers 1

createCronApiFunction · 0.85

Calls 1

getOpenClawConfigDirFunction · 0.90

Tested by

no test coverage detected