(filePath: string)
| 103 | } |
| 104 | |
| 105 | function getMaxMessageTimestampFromFile(filePath: string): number | null { |
| 106 | try { |
| 107 | let maxTs: number | null = null |
| 108 | const visitTimestamp = (value: unknown) => { |
| 109 | const ts = typeof value === 'string' && value.trim() !== '' ? Number(value) : value |
| 110 | if (typeof ts === 'number' && Number.isFinite(ts)) { |
| 111 | maxTs = maxTs === null ? ts : Math.max(maxTs, ts) |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | if (filePath.endsWith('.jsonl')) { |
| 116 | const content = fs.readFileSync(filePath, 'utf-8') |
| 117 | for (const line of content.split('\n')) { |
| 118 | const trimmed = line.trim() |
| 119 | if (!trimmed) continue |
| 120 | try { |
| 121 | const obj = JSON.parse(trimmed) |
| 122 | if (obj._type === 'message') visitTimestamp(obj.timestamp) |
| 123 | } catch { |
| 124 | continue |
| 125 | } |
| 126 | } |
| 127 | return maxTs |
| 128 | } |
| 129 | |
| 130 | const raw = fs.readFileSync(filePath, 'utf-8') |
| 131 | const parsed = JSON.parse(raw) |
| 132 | if (Array.isArray(parsed.messages)) { |
| 133 | for (const message of parsed.messages) { |
| 134 | visitTimestamp(message?.timestamp) |
| 135 | } |
| 136 | } |
| 137 | return maxTs |
| 138 | } catch { |
| 139 | return null |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | function cleanupTempFile(filePath: string): void { |
| 144 | try { |
no test coverage detected