mirror of
https://github.com/RooVetGit/Roo-Code.git
synced 2026-09-05 08:10:14 +00:00
Co-authored-by: Eric Wheeler <roo-code@z.ewheeler.org> Co-authored-by: Daniel Riccio <ricciodaniel98@gmail.com>
42 lines
1.2 KiB
TypeScript
42 lines
1.2 KiB
TypeScript
import { safeWriteJson } from "../../utils/safeWriteJson"
|
|
import * as path from "path"
|
|
import * as fs from "fs/promises"
|
|
|
|
import type { ClineMessage } from "@roo-code/types"
|
|
|
|
import { fileExistsAtPath } from "../../utils/fs"
|
|
|
|
import { GlobalFileNames } from "../../shared/globalFileNames"
|
|
import { getTaskDirectoryPath } from "../../utils/storage"
|
|
|
|
export type ReadTaskMessagesOptions = {
|
|
taskId: string
|
|
globalStoragePath: string
|
|
}
|
|
|
|
export async function readTaskMessages({
|
|
taskId,
|
|
globalStoragePath,
|
|
}: ReadTaskMessagesOptions): Promise<ClineMessage[]> {
|
|
const taskDir = await getTaskDirectoryPath(globalStoragePath, taskId)
|
|
const filePath = path.join(taskDir, GlobalFileNames.uiMessages)
|
|
const fileExists = await fileExistsAtPath(filePath)
|
|
|
|
if (fileExists) {
|
|
return JSON.parse(await fs.readFile(filePath, "utf8"))
|
|
}
|
|
|
|
return []
|
|
}
|
|
|
|
export type SaveTaskMessagesOptions = {
|
|
messages: ClineMessage[]
|
|
taskId: string
|
|
globalStoragePath: string
|
|
}
|
|
|
|
export async function saveTaskMessages({ messages, taskId, globalStoragePath }: SaveTaskMessagesOptions) {
|
|
const taskDir = await getTaskDirectoryPath(globalStoragePath, taskId)
|
|
const filePath = path.join(taskDir, GlobalFileNames.uiMessages)
|
|
await safeWriteJson(filePath, messages)
|
|
}
|