forked from RooCodeInc/Roo-Code
-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathmemory.ts
More file actions
61 lines (54 loc) · 1.38 KB
/
memory.ts
File metadata and controls
61 lines (54 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import * as fs from "fs"
import * as path from "path"
import * as os from "os"
export interface Memory {
id: string
content: string
timestamp: string
}
export interface APIMemory {
id: string
memory: string
created_at: string
updated_at: string
total_memories: number
owner: string
organization: string
metadata: Record<string, any>
type: string
}
const MEMORIES_FILE = "pearai_memories.json"
function convertToAPIMemory(localMemory: Memory): APIMemory {
return {
id: localMemory.id,
memory: localMemory.content,
created_at: localMemory.timestamp,
updated_at: localMemory.timestamp,
total_memories: 1,
owner: "",
organization: "",
metadata: {},
type: "manual",
}
}
export function getMemoriesFilePath(): string {
const pearaiPath = process.env.CONTINUE_GLOBAL_DIR ?? path.join(os.homedir(), ".pearai")
return path.join(pearaiPath, MEMORIES_FILE)
}
export function initializeMemoriesFile(): void {
const filePath = getMemoriesFilePath()
if (!fs.existsSync(filePath)) {
fs.writeFileSync(filePath, JSON.stringify([], null, 2))
}
}
export function readMemories(): APIMemory[] {
try {
initializeMemoriesFile()
const content = fs.readFileSync(getMemoriesFilePath(), "utf8")
const localMemories = JSON.parse(content) as Memory[]
return localMemories.map(convertToAPIMemory)
} catch (error) {
console.error("Error reading memories:", error)
return []
}
}