(content)
| 143 | } |
| 144 | |
| 145 | function parseUsageContent(content) { |
| 146 | const trimmed = content.trim(); |
| 147 | if (!trimmed) { |
| 148 | return []; |
| 149 | } |
| 150 | |
| 151 | if (trimmed.startsWith("[")) { |
| 152 | return [JSON.parse(trimmed)]; |
| 153 | } |
| 154 | |
| 155 | if (trimmed.startsWith("{")) { |
| 156 | try { |
| 157 | return [JSON.parse(trimmed)]; |
| 158 | } catch { |
| 159 | // Fall through to JSONL parsing when the file contains multiple JSON objects. |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | return trimmed |
| 164 | .split(/\r?\n/) |
| 165 | .map((line) => line.trim()) |
| 166 | .filter(Boolean) |
| 167 | .map((line) => JSON.parse(line)); |
| 168 | } |
| 169 | |
| 170 | async function loadSnapshotsFromFile(filePath) { |
| 171 | const resolvedPath = path.resolve(filePath); |
no test coverage detected