(tag: string)
| 327 | } |
| 328 | |
| 329 | async loadCheckpoint(tag: string): Promise<Content[]> { |
| 330 | if (!this.initialized) { |
| 331 | console.error( |
| 332 | 'Logger not initialized or checkpoint file path not set. Cannot load checkpoint.', |
| 333 | ); |
| 334 | return []; |
| 335 | } |
| 336 | |
| 337 | const path = await this._getCheckpointPath(tag); |
| 338 | try { |
| 339 | const fileContent = await fs.readFile(path, 'utf-8'); |
| 340 | const parsedContent = JSON.parse(fileContent); |
| 341 | if (!Array.isArray(parsedContent)) { |
| 342 | console.warn( |
| 343 | `Checkpoint file at ${path} is not a valid JSON array. Returning empty checkpoint.`, |
| 344 | ); |
| 345 | return []; |
| 346 | } |
| 347 | return parsedContent as Content[]; |
| 348 | } catch (error) { |
| 349 | const nodeError = error as NodeJS.ErrnoException; |
| 350 | if (nodeError.code === 'ENOENT') { |
| 351 | // This is okay, it just means the checkpoint doesn't exist in either format. |
| 352 | return []; |
| 353 | } |
| 354 | console.error(`Failed to read or parse checkpoint file ${path}:`, error); |
| 355 | return []; |
| 356 | } |
| 357 | } |
| 358 | |
| 359 | async deleteCheckpoint(tag: string): Promise<boolean> { |
| 360 | if (!this.initialized || !this.anusDir) { |
no test coverage detected