ai-memory-claw 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gitattributes +28 -0
- package/LICENSE +194 -0
- package/README.md +199 -0
- package/index.ts +167 -0
- package/openclaw.plugin.json +145 -0
- package/package.json +30 -0
- package/src/auto-capture.ts +211 -0
- package/src/auto-recall.ts +180 -0
- package/src/category.ts +149 -0
- package/src/config.ts +74 -0
- package/src/embedding.ts +149 -0
- package/src/forgetter.ts +129 -0
- package/src/integrator.ts +197 -0
- package/src/memory-system.ts +304 -0
- package/src/test.ts +116 -0
- package/src/triggers.ts +126 -0
- package/src/types.ts +191 -0
- package/tsconfig.json +20 -0
package/src/types.ts
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 类型定义模块
|
|
3
|
+
*
|
|
4
|
+
* 定义记忆系统的核心数据类型
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
8
|
+
|
|
9
|
+
// 重要性等级
|
|
10
|
+
export type ImportanceLevel = 'critical' | 'high' | 'medium' | 'low';
|
|
11
|
+
|
|
12
|
+
// 记忆差异
|
|
13
|
+
export interface MemoryDiff {
|
|
14
|
+
field: string;
|
|
15
|
+
oldValue: string;
|
|
16
|
+
newValue: string;
|
|
17
|
+
description: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// 记忆内容
|
|
21
|
+
export interface MemoryContent {
|
|
22
|
+
task: string;
|
|
23
|
+
process: string;
|
|
24
|
+
result: string;
|
|
25
|
+
insights: string[];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// 记忆
|
|
29
|
+
export interface Memory {
|
|
30
|
+
id: string;
|
|
31
|
+
taskDescription: string;
|
|
32
|
+
category: string;
|
|
33
|
+
subCategory: string;
|
|
34
|
+
cluster: string;
|
|
35
|
+
content: MemoryContent;
|
|
36
|
+
embedding: number[];
|
|
37
|
+
createdAt: Date;
|
|
38
|
+
updatedAt: Date;
|
|
39
|
+
lastAccessedAt: Date;
|
|
40
|
+
version: number;
|
|
41
|
+
diffs: MemoryDiff[];
|
|
42
|
+
mergedFrom: string[];
|
|
43
|
+
confidence: number;
|
|
44
|
+
usageCount: number;
|
|
45
|
+
importance: ImportanceLevel;
|
|
46
|
+
tags: string[];
|
|
47
|
+
encrypted: boolean;
|
|
48
|
+
encryptedContent?: string;
|
|
49
|
+
autoCleanup?: boolean;
|
|
50
|
+
cleanupAt?: Date;
|
|
51
|
+
summary?: string;
|
|
52
|
+
originalSize?: number;
|
|
53
|
+
compressedSize?: number;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// 记忆簇
|
|
57
|
+
export interface MemoryCluster {
|
|
58
|
+
id: string;
|
|
59
|
+
name: string;
|
|
60
|
+
category: string;
|
|
61
|
+
subCategory: string;
|
|
62
|
+
memories: string[];
|
|
63
|
+
summary: string;
|
|
64
|
+
createdAt: Date;
|
|
65
|
+
updatedAt: Date;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// 记忆分类
|
|
69
|
+
export interface MemoryCategory {
|
|
70
|
+
id: string;
|
|
71
|
+
name: string;
|
|
72
|
+
description: string;
|
|
73
|
+
subCategories: string[];
|
|
74
|
+
keywords: string[];
|
|
75
|
+
parentCategory?: string;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// 记忆统计
|
|
79
|
+
export interface MemoryStats {
|
|
80
|
+
total: number;
|
|
81
|
+
byCategory: Record<string, number>;
|
|
82
|
+
byImportance: Record<string, number>;
|
|
83
|
+
averageUsage: number;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// 记忆输入
|
|
87
|
+
export interface MemoryInput {
|
|
88
|
+
content: MemoryContent;
|
|
89
|
+
category: string;
|
|
90
|
+
subCategory: string;
|
|
91
|
+
importance: ImportanceLevel;
|
|
92
|
+
tags?: string[];
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// 搜索选项
|
|
96
|
+
export interface SearchOptions {
|
|
97
|
+
limit: number;
|
|
98
|
+
threshold: number;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// 搜索结果
|
|
102
|
+
export interface SearchResult {
|
|
103
|
+
memory: Memory;
|
|
104
|
+
score: number;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// 记忆存储
|
|
108
|
+
export interface MemoryStore {
|
|
109
|
+
memories: Map<string, Memory>;
|
|
110
|
+
clusters: Map<string, MemoryCluster>;
|
|
111
|
+
categories: Map<string, MemoryCategory>;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// 生成记忆ID
|
|
115
|
+
export function generateMemoryId(category: string, subCategory: string): string {
|
|
116
|
+
const now = new Date();
|
|
117
|
+
const date = now.toISOString().slice(0, 10).replace(/-/g, '');
|
|
118
|
+
const time = now.toTimeString().slice(0, 5).replace(/:/g, '');
|
|
119
|
+
const shortUuid = uuidv4().slice(0, 6);
|
|
120
|
+
const categoryCode = category.slice(0, 2);
|
|
121
|
+
const subCategoryCode = subCategory.slice(0, 2);
|
|
122
|
+
return `${categoryCode}-${subCategoryCode}-${date}-${time}-${shortUuid}`;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// 创建记忆
|
|
126
|
+
export function createMemory(
|
|
127
|
+
taskDescription: string,
|
|
128
|
+
category: string,
|
|
129
|
+
subCategory: string,
|
|
130
|
+
cluster: string,
|
|
131
|
+
content: MemoryContent,
|
|
132
|
+
embedding: number[] = [],
|
|
133
|
+
importance: ImportanceLevel = 'medium'
|
|
134
|
+
): Memory {
|
|
135
|
+
return {
|
|
136
|
+
id: generateMemoryId(category, subCategory),
|
|
137
|
+
taskDescription,
|
|
138
|
+
category,
|
|
139
|
+
subCategory,
|
|
140
|
+
cluster,
|
|
141
|
+
content,
|
|
142
|
+
embedding,
|
|
143
|
+
createdAt: new Date(),
|
|
144
|
+
updatedAt: new Date(),
|
|
145
|
+
lastAccessedAt: new Date(),
|
|
146
|
+
version: 1,
|
|
147
|
+
diffs: [],
|
|
148
|
+
mergedFrom: [],
|
|
149
|
+
confidence: 0.8,
|
|
150
|
+
usageCount: 0,
|
|
151
|
+
importance,
|
|
152
|
+
tags: [],
|
|
153
|
+
encrypted: false,
|
|
154
|
+
autoCleanup: false
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// 创建分类
|
|
159
|
+
export function createCategory(
|
|
160
|
+
name: string,
|
|
161
|
+
description: string,
|
|
162
|
+
keywords: string[],
|
|
163
|
+
parentCategory?: string
|
|
164
|
+
): MemoryCategory {
|
|
165
|
+
return {
|
|
166
|
+
id: uuidv4(),
|
|
167
|
+
name,
|
|
168
|
+
description,
|
|
169
|
+
subCategories: [],
|
|
170
|
+
keywords,
|
|
171
|
+
parentCategory
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// 创建簇
|
|
176
|
+
export function createCluster(
|
|
177
|
+
name: string,
|
|
178
|
+
category: string,
|
|
179
|
+
subCategory: string
|
|
180
|
+
): MemoryCluster {
|
|
181
|
+
return {
|
|
182
|
+
id: uuidv4(),
|
|
183
|
+
name,
|
|
184
|
+
category,
|
|
185
|
+
subCategory,
|
|
186
|
+
memories: [],
|
|
187
|
+
summary: '',
|
|
188
|
+
createdAt: new Date(),
|
|
189
|
+
updatedAt: new Date()
|
|
190
|
+
};
|
|
191
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"moduleResolution": "bundler",
|
|
6
|
+
"lib": ["ES2022", "DOM"],
|
|
7
|
+
"outDir": "./dist",
|
|
8
|
+
"rootDir": "./src",
|
|
9
|
+
"strict": true,
|
|
10
|
+
"esModuleInterop": true,
|
|
11
|
+
"skipLibCheck": true,
|
|
12
|
+
"forceConsistentCasingInFileNames": true,
|
|
13
|
+
"resolveJsonModule": true,
|
|
14
|
+
"declaration": true,
|
|
15
|
+
"declarationMap": true,
|
|
16
|
+
"sourceMap": true
|
|
17
|
+
},
|
|
18
|
+
"include": ["src/**/*"],
|
|
19
|
+
"exclude": ["node_modules", "dist", "tests"]
|
|
20
|
+
}
|