MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / readLogs

Function readLogs

graph-ui/src/projects/projects-model.ts:207–234  ·  view source on GitHub ↗
(raw: unknown)

Source from the content-addressed store, hash-verified

205}
206
207export function readLogs(raw: unknown): LogTail {
208 const record = isRecord(raw) ? raw : {};
209 const lines = strings(record['lines']);
210 const result: LogTail = { lines, total: optionalNumber(record['total']) ?? lines.length };
211 if (typeof record['query'] === 'string') result.query = record['query'];
212 if (Array.isArray(record['records'])) {
213 // A snapshot replaces the previous snapshot. Stable IDs also collapse a
214 // repeated row within one response; never append replayed records.
215 const rows = new Map<number, DaemonLogRecord>();
216 for (const entry of record['records']) {
217 if (!isRecord(entry)) continue;
218 const id = optionalNumber(entry['id']);
219 if (id === undefined || !Number.isSafeInteger(id) || id < 0 || typeof entry['message'] !== 'string') continue;
220 rows.set(id, { id, ts: text(entry['ts']), level: text(entry['level']), source: text(entry['source']), message: entry['message'], ...(typeof entry['project'] === 'string' || entry['project'] === null ? { project: entry['project'] } : {}) });
221 }
222 result.records = [...rows.values()].sort((left, right) => left.id - right.id);
223 }
224 if (['project', 'daemon', 'unattributed'].includes(String(record['scope']))) result.scope = record['scope'] as LogTail['scope'];
225 if (typeof record['project'] === 'string' || record['project'] === null) result.project = record['project'];
226 if (typeof record['persistent'] === 'boolean') result.persistent = record['persistent'];
227 if (typeof record['generation'] === 'string') result.generation = record['generation'];
228 if (typeof record['has_more'] === 'boolean') result.hasMore = record['has_more'];
229 for (const [input, output] of [['retention_limit', 'retentionLimit'], ['oldest_cursor', 'oldestCursor'], ['cursor', 'cursor']] as const) {
230 const value = optionalNumber(record[input]);
231 if (value !== undefined) result[output] = value;
232 }
233 return result;
234}
235
236// ------------------------------------------------------------- processes --
237

Callers 4

logsMethod · 0.90

Calls 4

stringsFunction · 0.85
optionalNumberFunction · 0.85
isRecordFunction · 0.70
textFunction · 0.70

Tested by

no test coverage detected