({
taskId,
globalStoragePath,
}: ReadTaskMessagesOptions)
| 15 | } |
| 16 | |
| 17 | export async function readTaskMessages({ |
| 18 | taskId, |
| 19 | globalStoragePath, |
| 20 | }: ReadTaskMessagesOptions): Promise<ClineMessage[]> { |
| 21 | const taskDir = await getTaskDirectoryPath(globalStoragePath, taskId) |
| 22 | const filePath = path.join(taskDir, GlobalFileNames.uiMessages) |
| 23 | const fileExists = await fileExistsAtPath(filePath) |
| 24 | |
| 25 | if (fileExists) { |
| 26 | try { |
| 27 | const parsedData = JSON.parse(await fs.readFile(filePath, "utf8")) |
| 28 | if (!Array.isArray(parsedData)) { |
| 29 | console.warn( |
| 30 | `[readTaskMessages] Parsed data is not an array (got ${typeof parsedData}), returning empty. TaskId: ${taskId}, Path: ${filePath}`, |
| 31 | ) |
| 32 | return [] |
| 33 | } |
| 34 | return parsedData |
| 35 | } catch (error) { |
| 36 | console.warn( |
| 37 | `[readTaskMessages] Failed to parse ${filePath} for task ${taskId}, returning empty: ${error instanceof Error ? error.message : String(error)}`, |
| 38 | ) |
| 39 | return [] |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | return [] |
| 44 | } |
| 45 | |
| 46 | export type SaveTaskMessagesOptions = { |
| 47 | messages: ClineMessage[] |
no test coverage detected