MCPcopy Index your code
hub / github.com/simstudioai/sim / readMemory

Function readMemory

apps/sim/lib/table/events.ts:208–227  ·  view source on GitHub ↗
(tableId: string, afterEventId: number)

Source from the content-addressed store, hash-verified

206}
207
208function readMemory(tableId: string, afterEventId: number): TableEventsReadResult {
209 pruneExpiredMemoryStreams()
210 const stream = memoryTableStreams.get(tableId)
211 if (!stream) {
212 // Mirror the Redis path: a non-zero afterEventId with no buffer at all
213 // means TTL expired or the stream never existed; either way the caller's
214 // cursor is stale.
215 if (afterEventId > 0) return { status: 'pruned', earliestEventId: undefined }
216 return { status: 'ok', events: [] }
217 }
218 if (stream.earliestEventId !== undefined && afterEventId + 1 < stream.earliestEventId) {
219 return { status: 'pruned', earliestEventId: stream.earliestEventId }
220 }
221 return {
222 status: 'ok',
223 events: stream.events
224 .filter((entry) => entry.eventId > afterEventId)
225 .slice(0, TABLE_EVENT_READ_CHUNK),
226 }
227}
228
229/**
230 * Append an event to the table's buffer. Fire-and-forget from the caller —

Callers 1

readTableEventsSinceFunction · 0.85

Calls 2

getMethod · 0.65

Tested by

no test coverage detected