( agentId: string, sessionKey: string, )
| 146 | } |
| 147 | |
| 148 | async 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 | |
| 176 | function buildCronSessionFallbackMessages(params: { |
| 177 | sessionKey: string; |
no test coverage detected