memories-lite 0.10.1 → 0.99.1
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/dist/config/defaults.js +11 -4
- package/dist/config/manager.js +2 -4
- package/dist/memory/index.d.ts +11 -0
- package/dist/memory/index.js +62 -124
- package/dist/memory/memory.types.d.ts +1 -2
- package/dist/prompts/index.d.ts +53 -17
- package/dist/prompts/index.js +63 -23
- package/dist/types/index.d.ts +28 -137
- package/dist/types/index.js +2 -8
- package/memories-lite-a42ac5108869b599bcbac21069f63fb47f07452fcc4b87e89b3c06a945612d0b.db +0 -0
- package/memories-lite-a9137698d8d3fdbf27efcdc8cd372084b52d484e8db866c5455bbb3f85299b54.db +0 -0
- package/package.json +1 -1
- package/src/config/defaults.ts +11 -4
- package/src/config/manager.ts +2 -4
- package/src/memory/index.ts +76 -158
- package/src/memory/memory.types.ts +1 -2
- package/src/prompts/index.ts +69 -26
- package/src/types/index.ts +4 -11
- package/tests/lite.spec.ts +44 -34
- package/tests/memory.discussion.test.ts +279 -0
- package/tests/memory.update.test.ts +5 -1
- package/tests/memory.facts.test.ts +0 -175
- package/tests/memory.todo.test.ts +0 -126
package/dist/config/defaults.js
CHANGED
|
@@ -2,11 +2,18 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DEFAULT_MEMORY_CONFIG = void 0;
|
|
4
4
|
const DEFAULT_SCORING_CONFIG = {
|
|
5
|
-
//
|
|
6
|
-
|
|
7
|
-
factual: { alpha: 0.70, beta: 0.20, gamma: 0.10, halfLifeDays: 150 }, // ~150 days
|
|
5
|
+
//
|
|
6
|
+
// assistant_preference: préférences utilisateur avec l'assistant (style, langue, etc.)
|
|
8
7
|
assistant_preference: { alpha: 0.60, beta: 0.05, gamma: 0.35, halfLifeDays: Infinity },
|
|
9
|
-
|
|
8
|
+
//
|
|
9
|
+
// discussion: mémoires de discussions (synthèses opérationnelles)
|
|
10
|
+
// - alpha=0: pas de cosine dans le score final
|
|
11
|
+
// - beta=1: score basé sur recency (constant car halfLife=∞)
|
|
12
|
+
// - gamma=0: pas d'importance base
|
|
13
|
+
discussion: { alpha: 0, beta: 1, gamma: 0, halfLifeDays: Infinity },
|
|
14
|
+
//
|
|
15
|
+
// default: fallback si type manquant ou inconnu
|
|
16
|
+
default: { alpha: 0.5, beta: 0.3, gamma: 0.1, halfLifeDays: 30 }
|
|
10
17
|
};
|
|
11
18
|
exports.DEFAULT_MEMORY_CONFIG = {
|
|
12
19
|
disableHistory: true,
|
package/dist/config/manager.js
CHANGED
|
@@ -47,9 +47,8 @@ class ConfigManager {
|
|
|
47
47
|
dimension: userConf.dimension || defaultConf.dimension,
|
|
48
48
|
// Merge scoring deeply if present in userConf, otherwise use default
|
|
49
49
|
scoring: userConf.scoring ? {
|
|
50
|
-
todo: { ...defaultConf.scoring?.todo, ...userConf.scoring.todo },
|
|
51
|
-
factual: { ...defaultConf.scoring?.factual, ...userConf.scoring.factual },
|
|
52
50
|
assistant_preference: { ...defaultConf.scoring?.assistant_preference, ...userConf.scoring.assistant_preference },
|
|
51
|
+
discussion: { ...defaultConf.scoring?.discussion, ...userConf.scoring.discussion },
|
|
53
52
|
default: { ...defaultConf.scoring?.default, ...userConf.scoring.default },
|
|
54
53
|
} : defaultConf.scoring,
|
|
55
54
|
...userConf, // Include any other passthrough fields from user
|
|
@@ -63,9 +62,8 @@ class ConfigManager {
|
|
|
63
62
|
client: undefined,
|
|
64
63
|
// Merge scoring deeply if present in userConf, otherwise use default
|
|
65
64
|
scoring: userConf?.scoring ? {
|
|
66
|
-
todo: { ...defaultConf.scoring?.todo, ...userConf.scoring.todo },
|
|
67
|
-
factual: { ...defaultConf.scoring?.factual, ...userConf.scoring.factual },
|
|
68
65
|
assistant_preference: { ...defaultConf.scoring?.assistant_preference, ...userConf.scoring.assistant_preference },
|
|
66
|
+
discussion: { ...defaultConf.scoring?.discussion, ...userConf.scoring.discussion },
|
|
69
67
|
default: { ...defaultConf.scoring?.default, ...userConf.scoring.default },
|
|
70
68
|
} : defaultConf.scoring,
|
|
71
69
|
recencyCleanupThreshold: userConf?.recencyCleanupThreshold ?? defaultConf.recencyCleanupThreshold, // Merge cleanup threshold
|
package/dist/memory/index.d.ts
CHANGED
|
@@ -18,9 +18,20 @@ export declare class MemoriesLite {
|
|
|
18
18
|
private _getTelemetryId;
|
|
19
19
|
private _captureEvent;
|
|
20
20
|
private $t;
|
|
21
|
+
/**
|
|
22
|
+
* Capture une discussion et génère une synthèse (title + summary)
|
|
23
|
+
* Utilise getDiscussionSynthesisMessages pour produire la synthèse
|
|
24
|
+
*/
|
|
21
25
|
private addToVectorStore;
|
|
22
26
|
static fromConfig(configDict: Record<string, any>): MemoriesLite;
|
|
23
27
|
getVectorStore(userId: string): Promise<VectorStore>;
|
|
28
|
+
/**
|
|
29
|
+
* Capture une discussion et génère une mémoire (title + summary)
|
|
30
|
+
*
|
|
31
|
+
* @param messages - Messages de la discussion ou texte brut
|
|
32
|
+
* @param userId - ID utilisateur
|
|
33
|
+
* @param config - Options incluant capturePrompt pour personnaliser la synthèse
|
|
34
|
+
*/
|
|
24
35
|
capture(messages: string | Message[], userId: string, config: AddMemoryOptions): Promise<SearchResult>;
|
|
25
36
|
get(memoryId: string, userId: string): Promise<MemoryItem | null>;
|
|
26
37
|
retrieve(query: string, userId: string, config: SearchMemoryOptions): Promise<SearchResult>;
|
package/dist/memory/index.js
CHANGED
|
@@ -93,133 +93,68 @@ class MemoriesLite {
|
|
|
93
93
|
// return text.replace(/<thinking>[\s\S]*?(?:<\/thinking>)/g,'').replace(/^<step.*$/g,'');
|
|
94
94
|
return text.replace(/<thinking>[\s\S]*?<\/thinking>/g, '').replace(/^<step.*$/gm, '').replace(/<memories>[\s\S]*?<\/memories>/g, '');
|
|
95
95
|
}
|
|
96
|
-
|
|
96
|
+
/**
|
|
97
|
+
* Capture une discussion et génère une synthèse (title + summary)
|
|
98
|
+
* Utilise getDiscussionSynthesisMessages pour produire la synthèse
|
|
99
|
+
*/
|
|
100
|
+
async addToVectorStore(messages, metadata, userId, filters, capturePrompt) {
|
|
97
101
|
const $t = this.$t;
|
|
98
102
|
const vectorStore = await this.getVectorStore(userId);
|
|
99
|
-
|
|
100
|
-
//
|
|
101
|
-
const
|
|
103
|
+
//
|
|
104
|
+
// Formater les messages pour la synthèse
|
|
105
|
+
const parsedMessages = messages
|
|
106
|
+
.filter((m) => typeof m.content === 'string')
|
|
107
|
+
.map((m) => `**${m.role.toUpperCase()}**: ${$t(m.content)}`)
|
|
108
|
+
.join("\n\n");
|
|
109
|
+
//
|
|
110
|
+
// Générer la synthèse via LLM
|
|
111
|
+
const [systemPrompt, userPrompt] = (0, prompts_1.getDiscussionSynthesisMessages)(parsedMessages, capturePrompt || this.customPrompt);
|
|
102
112
|
const response = await this.llm.generateResponse([
|
|
103
113
|
{ role: "system", content: systemPrompt },
|
|
104
114
|
{ role: "user", content: userPrompt },
|
|
105
|
-
], { ...(0, zod_1.zodResponseFormat)(prompts_1.
|
|
106
|
-
|
|
115
|
+
], { ...(0, zod_1.zodResponseFormat)(prompts_1.DiscussionSynthesisSchema, "DiscussionSynthesis") }, [], false);
|
|
116
|
+
//
|
|
117
|
+
// Parser la réponse
|
|
118
|
+
const parsedResponse = (res) => {
|
|
107
119
|
try {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
return response;
|
|
120
|
+
if (typeof res === 'object') {
|
|
121
|
+
return res;
|
|
111
122
|
}
|
|
112
|
-
const cleanResponse = (0, prompts_1.removeCodeBlocks)(
|
|
123
|
+
const cleanResponse = (0, prompts_1.removeCodeBlocks)(res);
|
|
113
124
|
return JSON.parse(cleanResponse);
|
|
114
125
|
}
|
|
115
126
|
catch (e) {
|
|
116
|
-
console.error("Failed to parse
|
|
117
|
-
return
|
|
127
|
+
console.error("Failed to parse synthesis from LLM response:", res, e);
|
|
128
|
+
return { title: "Sans titre", summary: "" };
|
|
118
129
|
}
|
|
119
130
|
};
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
const facts = parsedResponse(response).facts?.filter((f) => !f.existing) || [];
|
|
125
|
-
// console.log("-- DBG extract:", userPrompt);
|
|
126
|
-
// console.log("-- DBG facts:", facts);
|
|
127
|
-
// Get embeddings for new facts
|
|
128
|
-
const newMessageEmbeddings = {};
|
|
129
|
-
const retrievedOldMemory = [];
|
|
130
|
-
//
|
|
131
|
-
// add the userId to the filters
|
|
132
|
-
filters.userId = userId;
|
|
133
|
-
// Create embeddings and search for similar memories
|
|
134
|
-
for (const elem of facts) {
|
|
135
|
-
const fact = elem.fact;
|
|
136
|
-
const embedding = await this.embedder.embed(fact);
|
|
137
|
-
newMessageEmbeddings[fact] = embedding;
|
|
138
|
-
const existingMemories = await vectorStore.search(embedding, 5, filters);
|
|
139
|
-
for (const mem of existingMemories) {
|
|
140
|
-
retrievedOldMemory.push({ id: mem.id, text: mem.payload.data, type: mem.payload.type });
|
|
141
|
-
}
|
|
131
|
+
const { title, summary } = parsedResponse(response);
|
|
132
|
+
if (!summary) {
|
|
133
|
+
console.warn("-- ⚠️ Empty summary from LLM, skipping memory creation");
|
|
134
|
+
return [];
|
|
142
135
|
}
|
|
143
|
-
//
|
|
144
|
-
//
|
|
145
|
-
const
|
|
146
|
-
//
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
//
|
|
157
|
-
const
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
continue;
|
|
166
|
-
}
|
|
167
|
-
if (action.reason === "undefined") {
|
|
168
|
-
console.log(`-- ⛔ LLM Error: ${action.event}, ${action.type}, "${action.text}"`);
|
|
169
|
-
continue;
|
|
170
|
-
}
|
|
171
|
-
console.log(`-- DBG memory "${userId}": ${action.event}, ${action.type}, "${action.text}", why: "${action.reason}"`);
|
|
172
|
-
try {
|
|
173
|
-
switch (action.event) {
|
|
174
|
-
case "ADD": {
|
|
175
|
-
if (!action.type) {
|
|
176
|
-
// log error
|
|
177
|
-
console.error("Type is mandatory to manage memories:", action);
|
|
178
|
-
continue;
|
|
179
|
-
}
|
|
180
|
-
metadata.type = action.type;
|
|
181
|
-
const memoryId = await this.createMemory(action.text, newMessageEmbeddings, metadata, userId);
|
|
182
|
-
results.push({
|
|
183
|
-
id: memoryId,
|
|
184
|
-
memory: action.text,
|
|
185
|
-
type: action.type,
|
|
186
|
-
metadata: { event: action.event },
|
|
187
|
-
});
|
|
188
|
-
break;
|
|
189
|
-
}
|
|
190
|
-
case "UPDATE": {
|
|
191
|
-
const realMemoryId = tempUuidMapping[action.id];
|
|
192
|
-
const type = metadata.type = uniqueOldMemories[action.id].type || action.type;
|
|
193
|
-
await this.updateMemory(realMemoryId, action.text, newMessageEmbeddings, metadata, userId);
|
|
194
|
-
results.push({
|
|
195
|
-
id: realMemoryId,
|
|
196
|
-
memory: action.text,
|
|
197
|
-
type,
|
|
198
|
-
metadata: {
|
|
199
|
-
event: action.event,
|
|
200
|
-
previousMemory: action.old_memory,
|
|
201
|
-
},
|
|
202
|
-
});
|
|
203
|
-
break;
|
|
204
|
-
}
|
|
205
|
-
case "DELETE": {
|
|
206
|
-
const realMemoryId = tempUuidMapping[action.id];
|
|
207
|
-
await this.deleteMemory(realMemoryId, userId);
|
|
208
|
-
results.push({
|
|
209
|
-
id: realMemoryId,
|
|
210
|
-
memory: action.text,
|
|
211
|
-
type: action.type,
|
|
212
|
-
metadata: { event: action.event },
|
|
213
|
-
});
|
|
214
|
-
break;
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
catch (error) {
|
|
219
|
-
console.error(`Error processing memory action: ${error}`);
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
return results;
|
|
136
|
+
//
|
|
137
|
+
// Créer l'embedding sur le summary (pour recherche sémantique)
|
|
138
|
+
const embedding = await this.embedder.embed(summary);
|
|
139
|
+
//
|
|
140
|
+
// Préparer les métadonnées
|
|
141
|
+
const memoryType = metadata.type || 'discussion';
|
|
142
|
+
const memoryMetadata = {
|
|
143
|
+
...metadata,
|
|
144
|
+
title,
|
|
145
|
+
type: memoryType,
|
|
146
|
+
userId,
|
|
147
|
+
};
|
|
148
|
+
//
|
|
149
|
+
// Stocker la mémoire
|
|
150
|
+
const memoryId = await this.createMemory(summary, { [summary]: embedding }, memoryMetadata, userId);
|
|
151
|
+
console.log(`-- 🧠 Memory created: "${title}" (${memoryType})`);
|
|
152
|
+
return [{
|
|
153
|
+
id: memoryId,
|
|
154
|
+
memory: summary,
|
|
155
|
+
type: memoryType,
|
|
156
|
+
metadata: { title, event: "ADD" },
|
|
157
|
+
}];
|
|
223
158
|
}
|
|
224
159
|
static fromConfig(configDict) {
|
|
225
160
|
try {
|
|
@@ -234,14 +169,15 @@ class MemoriesLite {
|
|
|
234
169
|
async getVectorStore(userId) {
|
|
235
170
|
return lite_1.LiteVectorStore.from(userId, this.vectorStoreConfig);
|
|
236
171
|
}
|
|
172
|
+
/**
|
|
173
|
+
* Capture une discussion et génère une mémoire (title + summary)
|
|
174
|
+
*
|
|
175
|
+
* @param messages - Messages de la discussion ou texte brut
|
|
176
|
+
* @param userId - ID utilisateur
|
|
177
|
+
* @param config - Options incluant capturePrompt pour personnaliser la synthèse
|
|
178
|
+
*/
|
|
237
179
|
async capture(messages, userId, config) {
|
|
238
|
-
|
|
239
|
-
// message_count: Array.isArray(messages) ? messages.length : 1,
|
|
240
|
-
// has_metadata: !!config.metadata,
|
|
241
|
-
// has_filters: !!config.filters,
|
|
242
|
-
// infer: config.infer,
|
|
243
|
-
// });
|
|
244
|
-
const { agentId, runId, metadata = {}, filters = {}, infer = true, customFacts } = config;
|
|
180
|
+
const { agentId, runId, metadata = {}, filters = {}, capturePrompt } = config;
|
|
245
181
|
if (agentId)
|
|
246
182
|
filters.agentId = metadata.agentId = agentId;
|
|
247
183
|
if (runId)
|
|
@@ -253,9 +189,11 @@ class MemoriesLite {
|
|
|
253
189
|
? messages
|
|
254
190
|
: [{ role: "user", content: messages }];
|
|
255
191
|
const final_parsedMessages = await (0, memory_1.parse_vision_messages)(parsedMessages);
|
|
256
|
-
//
|
|
257
|
-
|
|
258
|
-
|
|
192
|
+
//
|
|
193
|
+
// Générer synthèse et stocker
|
|
194
|
+
const vectorStoreResult = await this.addToVectorStore(final_parsedMessages, metadata, userId, filters, capturePrompt);
|
|
195
|
+
//
|
|
196
|
+
// Graph store (si configuré)
|
|
259
197
|
let graphResult;
|
|
260
198
|
if (this.graphMemory) {
|
|
261
199
|
try {
|
|
@@ -8,8 +8,7 @@ export interface Entity {
|
|
|
8
8
|
export interface AddMemoryOptions extends Entity {
|
|
9
9
|
metadata?: Record<string, any>;
|
|
10
10
|
filters?: SearchFilters;
|
|
11
|
-
|
|
12
|
-
infer?: boolean;
|
|
11
|
+
capturePrompt?: string;
|
|
13
12
|
}
|
|
14
13
|
export interface SearchMemoryOptions extends Entity {
|
|
15
14
|
limit?: number;
|
package/dist/prompts/index.d.ts
CHANGED
|
@@ -1,5 +1,34 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { MemoryItem } from "../types";
|
|
3
|
+
/**
|
|
4
|
+
* Schema pour la synthèse de discussion
|
|
5
|
+
* Produit un titre court et une synthèse opérationnelle
|
|
6
|
+
*/
|
|
7
|
+
export declare const DiscussionSynthesisSchema: z.ZodObject<{
|
|
8
|
+
title: z.ZodString;
|
|
9
|
+
summary: z.ZodString;
|
|
10
|
+
}, "strip", z.ZodTypeAny, {
|
|
11
|
+
title: string;
|
|
12
|
+
summary: string;
|
|
13
|
+
}, {
|
|
14
|
+
title: string;
|
|
15
|
+
summary: string;
|
|
16
|
+
}>;
|
|
17
|
+
/**
|
|
18
|
+
* Prompt par défaut pour la synthèse de discussion
|
|
19
|
+
* Peut être remplacé via capturePrompt dans AddMemoryOptions
|
|
20
|
+
*/
|
|
21
|
+
export declare const DEFAULT_DISCUSSION_PROMPT = "Tu es un expert en synth\u00E8se op\u00E9rationnelle.\n\n\u00C0 partir de cette discussion, g\u00E9n\u00E8re :\n1. TITRE: Un titre court et descriptif (6-10 mots) qui capture l'essence de la demande\n2. SUMMARY: Les points cl\u00E9s du chemin de r\u00E9solution (50-100 mots)\n\nCette synth\u00E8se servira \u00E0 retrouver et r\u00E9appliquer ce pattern de r\u00E9solution similaire.\nUtilise la m\u00EAme langue que la discussion.\n\nDiscussion \u00E0 synth\u00E9tiser:\n";
|
|
22
|
+
/**
|
|
23
|
+
* Génère les messages pour la synthèse de discussion
|
|
24
|
+
* @param discussion - Contenu de la discussion formatée
|
|
25
|
+
* @param capturePrompt - Prompt custom optionnel (remplace DEFAULT_DISCUSSION_PROMPT)
|
|
26
|
+
* @returns [systemPrompt, userPrompt]
|
|
27
|
+
*/
|
|
28
|
+
export declare function getDiscussionSynthesisMessages(discussion: string, capturePrompt?: string): [string, string];
|
|
29
|
+
/**
|
|
30
|
+
* @deprecated Use DiscussionSynthesisSchema instead
|
|
31
|
+
*/
|
|
3
32
|
export declare const FactRetrievalSchema_simple: z.ZodObject<{
|
|
4
33
|
facts: z.ZodArray<z.ZodString, "many">;
|
|
5
34
|
}, "strip", z.ZodTypeAny, {
|
|
@@ -7,33 +36,40 @@ export declare const FactRetrievalSchema_simple: z.ZodObject<{
|
|
|
7
36
|
}, {
|
|
8
37
|
facts: string[];
|
|
9
38
|
}>;
|
|
39
|
+
/**
|
|
40
|
+
* @deprecated Use DiscussionSynthesisSchema instead
|
|
41
|
+
* Types todo et factual supprimés - seul assistant_preference reste pour compatibilité
|
|
42
|
+
*/
|
|
10
43
|
export declare const FactRetrievalSchema_extended: z.ZodObject<{
|
|
11
44
|
facts: z.ZodArray<z.ZodObject<{
|
|
12
45
|
fact: z.ZodString;
|
|
13
46
|
existing: z.ZodBoolean;
|
|
14
|
-
type: z.ZodEnum<["assistant_preference"
|
|
47
|
+
type: z.ZodEnum<["assistant_preference"]>;
|
|
15
48
|
}, "strip", z.ZodTypeAny, {
|
|
16
|
-
type: "
|
|
49
|
+
type: "assistant_preference";
|
|
17
50
|
fact: string;
|
|
18
51
|
existing: boolean;
|
|
19
52
|
}, {
|
|
20
|
-
type: "
|
|
53
|
+
type: "assistant_preference";
|
|
21
54
|
fact: string;
|
|
22
55
|
existing: boolean;
|
|
23
56
|
}>, "many">;
|
|
24
57
|
}, "strip", z.ZodTypeAny, {
|
|
25
58
|
facts: {
|
|
26
|
-
type: "
|
|
59
|
+
type: "assistant_preference";
|
|
27
60
|
fact: string;
|
|
28
61
|
existing: boolean;
|
|
29
62
|
}[];
|
|
30
63
|
}, {
|
|
31
64
|
facts: {
|
|
32
|
-
type: "
|
|
65
|
+
type: "assistant_preference";
|
|
33
66
|
fact: string;
|
|
34
67
|
existing: boolean;
|
|
35
68
|
}[];
|
|
36
69
|
}>;
|
|
70
|
+
/**
|
|
71
|
+
* @deprecated Memory updates are disabled - use capture() for new memories
|
|
72
|
+
*/
|
|
37
73
|
export declare const MemoryUpdateSchema: z.ZodObject<{
|
|
38
74
|
memory: z.ZodArray<z.ZodObject<{
|
|
39
75
|
id: z.ZodString;
|
|
@@ -41,16 +77,16 @@ export declare const MemoryUpdateSchema: z.ZodObject<{
|
|
|
41
77
|
event: z.ZodEnum<["ADD", "UPDATE", "DELETE", "NONE"]>;
|
|
42
78
|
old_memory: z.ZodNullable<z.ZodString>;
|
|
43
79
|
reason: z.ZodString;
|
|
44
|
-
type: z.ZodEnum<["
|
|
80
|
+
type: z.ZodEnum<["assistant_preference"]>;
|
|
45
81
|
}, "strict", z.ZodTypeAny, {
|
|
46
|
-
type: "
|
|
82
|
+
type: "assistant_preference";
|
|
47
83
|
id: string;
|
|
48
84
|
text: string;
|
|
49
85
|
event: "ADD" | "UPDATE" | "DELETE" | "NONE";
|
|
50
86
|
old_memory: string | null;
|
|
51
87
|
reason: string;
|
|
52
88
|
}, {
|
|
53
|
-
type: "
|
|
89
|
+
type: "assistant_preference";
|
|
54
90
|
id: string;
|
|
55
91
|
text: string;
|
|
56
92
|
event: "ADD" | "UPDATE" | "DELETE" | "NONE";
|
|
@@ -59,7 +95,7 @@ export declare const MemoryUpdateSchema: z.ZodObject<{
|
|
|
59
95
|
}>, "many">;
|
|
60
96
|
}, "strip", z.ZodTypeAny, {
|
|
61
97
|
memory: {
|
|
62
|
-
type: "
|
|
98
|
+
type: "assistant_preference";
|
|
63
99
|
id: string;
|
|
64
100
|
text: string;
|
|
65
101
|
event: "ADD" | "UPDATE" | "DELETE" | "NONE";
|
|
@@ -68,7 +104,7 @@ export declare const MemoryUpdateSchema: z.ZodObject<{
|
|
|
68
104
|
}[];
|
|
69
105
|
}, {
|
|
70
106
|
memory: {
|
|
71
|
-
type: "
|
|
107
|
+
type: "assistant_preference";
|
|
72
108
|
id: string;
|
|
73
109
|
text: string;
|
|
74
110
|
event: "ADD" | "UPDATE" | "DELETE" | "NONE";
|
|
@@ -76,16 +112,16 @@ export declare const MemoryUpdateSchema: z.ZodObject<{
|
|
|
76
112
|
reason: string;
|
|
77
113
|
}[];
|
|
78
114
|
}>;
|
|
79
|
-
/**
|
|
80
|
-
* Practical Application:
|
|
81
|
-
*
|
|
82
|
-
* If the task is "factual" (e.g., "Where do I live?", "What's my job?") → retrieve factual memory.
|
|
83
|
-
* If the task is about assistant behavior (e.g., "How should I respond?") → retrieve assistant_preference memory.
|
|
84
|
-
* If the task is a user task/reminder (e.g., "Add a reminder to call the bank tomorrow") → retrieve todo memory.
|
|
85
|
-
*/
|
|
86
115
|
export declare const MEMORY_STRING_SYSTEM = "# DIRECTIVES FOR MEMORIES\n- Information stored in memory is always enclosed within the <memories> tag.\n- Prioritize the latest user message over memories (the user's current question is authoritative).\n- Select at most the top-5 relevant memories using cosine similarity and recency; ignore the rest.\n- Adapt your answer based strictly on the <memories> section when relevant.\n- If the memories are irrelevant to the user's query, ignore them.\n- By default, do not reference this section or the memories in your response.\n- Use memories only to guide reasoning; do not respond to the memories themselves.";
|
|
87
116
|
export declare const MEMORY_STRING_PREFIX = "Use these contextual memories to guide your response. Prioritize the user's question. Ignore irrelevant memories.";
|
|
117
|
+
/**
|
|
118
|
+
* @deprecated Use getDiscussionSynthesisMessages instead
|
|
119
|
+
* Cette fonction est conservée pour compatibilité avec l'ancien système
|
|
120
|
+
*/
|
|
88
121
|
export declare function getFactRetrievalMessages(parsedMessages: string, customRules?: string, defaultLanguage?: string): [string, string];
|
|
122
|
+
/**
|
|
123
|
+
* @deprecated Memory updates are disabled by config
|
|
124
|
+
*/
|
|
89
125
|
export declare function getUpdateMemoryMessages(retrievedOldMemory: Array<{
|
|
90
126
|
id: string;
|
|
91
127
|
text: string;
|
package/dist/prompts/index.js
CHANGED
|
@@ -1,35 +1,76 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getMemoriesAsSystem = exports.getMemoriesAsPrefix = exports.MEMORY_STRING_PREFIX = exports.MEMORY_STRING_SYSTEM = exports.MemoryUpdateSchema = exports.FactRetrievalSchema_extended = exports.FactRetrievalSchema_simple = void 0;
|
|
3
|
+
exports.getMemoriesAsSystem = exports.getMemoriesAsPrefix = exports.MEMORY_STRING_PREFIX = exports.MEMORY_STRING_SYSTEM = exports.MemoryUpdateSchema = exports.FactRetrievalSchema_extended = exports.FactRetrievalSchema_simple = exports.DEFAULT_DISCUSSION_PROMPT = exports.DiscussionSynthesisSchema = void 0;
|
|
4
|
+
exports.getDiscussionSynthesisMessages = getDiscussionSynthesisMessages;
|
|
4
5
|
exports.getFactRetrievalMessages = getFactRetrievalMessages;
|
|
5
6
|
exports.getUpdateMemoryMessages = getUpdateMemoryMessages;
|
|
6
7
|
exports.parseMessages = parseMessages;
|
|
7
8
|
exports.removeCodeBlocks = removeCodeBlocks;
|
|
8
9
|
const zod_1 = require("zod");
|
|
9
|
-
//
|
|
10
|
+
// ══════════════════════════════════════════════════════════════════════════════
|
|
11
|
+
// DISCUSSION SYNTHESIS - Nouveau système de mémoire
|
|
12
|
+
// ══════════════════════════════════════════════════════════════════════════════
|
|
13
|
+
/**
|
|
14
|
+
* Schema pour la synthèse de discussion
|
|
15
|
+
* Produit un titre court et une synthèse opérationnelle
|
|
16
|
+
*/
|
|
17
|
+
exports.DiscussionSynthesisSchema = zod_1.z.object({
|
|
18
|
+
title: zod_1.z.string().describe("Titre court et descriptif (6-10 mots)"),
|
|
19
|
+
summary: zod_1.z.string().describe("Synthèse opérationnelle des points clés (50-100 mots)")
|
|
20
|
+
});
|
|
21
|
+
/**
|
|
22
|
+
* Prompt par défaut pour la synthèse de discussion
|
|
23
|
+
* Peut être remplacé via capturePrompt dans AddMemoryOptions
|
|
24
|
+
*/
|
|
25
|
+
exports.DEFAULT_DISCUSSION_PROMPT = `Tu es un expert en synthèse opérationnelle.
|
|
26
|
+
|
|
27
|
+
À partir de cette discussion, génère :
|
|
28
|
+
1. TITRE: Un titre court et descriptif (6-10 mots) qui capture l'essence de la demande
|
|
29
|
+
2. SUMMARY: Les points clés du chemin de résolution (50-100 mots)
|
|
30
|
+
|
|
31
|
+
Cette synthèse servira à retrouver et réappliquer ce pattern de résolution similaire.
|
|
32
|
+
Utilise la même langue que la discussion.
|
|
33
|
+
|
|
34
|
+
Discussion à synthétiser:
|
|
35
|
+
`;
|
|
36
|
+
/**
|
|
37
|
+
* Génère les messages pour la synthèse de discussion
|
|
38
|
+
* @param discussion - Contenu de la discussion formatée
|
|
39
|
+
* @param capturePrompt - Prompt custom optionnel (remplace DEFAULT_DISCUSSION_PROMPT)
|
|
40
|
+
* @returns [systemPrompt, userPrompt]
|
|
41
|
+
*/
|
|
42
|
+
function getDiscussionSynthesisMessages(discussion, capturePrompt) {
|
|
43
|
+
const systemPrompt = capturePrompt || exports.DEFAULT_DISCUSSION_PROMPT;
|
|
44
|
+
return [systemPrompt, discussion];
|
|
45
|
+
}
|
|
46
|
+
// ══════════════════════════════════════════════════════════════════════════════
|
|
47
|
+
// @deprecated - Ancien système de capture (todo, factual)
|
|
48
|
+
// Ces exports sont conservés pour compatibilité mais ne doivent plus être utilisés
|
|
49
|
+
// ══════════════════════════════════════════════════════════════════════════════
|
|
50
|
+
/**
|
|
51
|
+
* @deprecated Use DiscussionSynthesisSchema instead
|
|
52
|
+
*/
|
|
10
53
|
exports.FactRetrievalSchema_simple = zod_1.z.object({
|
|
11
54
|
facts: zod_1.z
|
|
12
55
|
.array(zod_1.z.string())
|
|
13
56
|
.describe("An array of distinct facts extracted from the conversation."),
|
|
14
57
|
});
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
58
|
+
/**
|
|
59
|
+
* @deprecated Use DiscussionSynthesisSchema instead
|
|
60
|
+
* Types todo et factual supprimés - seul assistant_preference reste pour compatibilité
|
|
61
|
+
*/
|
|
19
62
|
exports.FactRetrievalSchema_extended = zod_1.z.object({
|
|
20
63
|
facts: zod_1.z
|
|
21
64
|
.array(zod_1.z.object({
|
|
22
65
|
fact: zod_1.z.string().describe("The fact extracted from the conversation."),
|
|
23
66
|
existing: zod_1.z.boolean().describe("Whether the fact is already present"),
|
|
24
|
-
type: zod_1.z.enum(["assistant_preference"
|
|
25
|
-
.describe(`The type of the fact.
|
|
26
|
-
Use 'assistant_preference' for Assistant behavior preferences (style/language/constraints/commands).
|
|
27
|
-
Use 'factual' for stable user facts (identity, preferences, beliefs, work context).
|
|
28
|
-
Use 'todo' ONLY if the user explicitly asks to save/keep as a todo (e.g., « garde/enregistre en todo », « ajoute un todo »). Do not infer todos.
|
|
29
|
-
`),
|
|
67
|
+
type: zod_1.z.enum(["assistant_preference"])
|
|
68
|
+
.describe(`The type of the fact. Only 'assistant_preference' is supported.`),
|
|
30
69
|
}))
|
|
31
70
|
});
|
|
32
|
-
|
|
71
|
+
/**
|
|
72
|
+
* @deprecated Memory updates are disabled - use capture() for new memories
|
|
73
|
+
*/
|
|
33
74
|
exports.MemoryUpdateSchema = zod_1.z.object({
|
|
34
75
|
memory: zod_1.z
|
|
35
76
|
.array(zod_1.z.strictObject({
|
|
@@ -46,18 +87,11 @@ exports.MemoryUpdateSchema = zod_1.z.object({
|
|
|
46
87
|
.string()
|
|
47
88
|
.describe("The reason why you selected this event."),
|
|
48
89
|
type: zod_1.z
|
|
49
|
-
.enum(["
|
|
50
|
-
.describe("Type of the memory.
|
|
90
|
+
.enum(["assistant_preference"])
|
|
91
|
+
.describe("Type of the memory. Only 'assistant_preference' is supported."),
|
|
51
92
|
}))
|
|
52
93
|
.describe("An array representing the state of memory items after processing new facts."),
|
|
53
94
|
});
|
|
54
|
-
/**
|
|
55
|
-
* Practical Application:
|
|
56
|
-
*
|
|
57
|
-
* If the task is "factual" (e.g., "Where do I live?", "What's my job?") → retrieve factual memory.
|
|
58
|
-
* If the task is about assistant behavior (e.g., "How should I respond?") → retrieve assistant_preference memory.
|
|
59
|
-
* If the task is a user task/reminder (e.g., "Add a reminder to call the bank tomorrow") → retrieve todo memory.
|
|
60
|
-
*/
|
|
61
95
|
exports.MEMORY_STRING_SYSTEM = `# DIRECTIVES FOR MEMORIES
|
|
62
96
|
- Information stored in memory is always enclosed within the <memories> tag.
|
|
63
97
|
- Prioritize the latest user message over memories (the user's current question is authoritative).
|
|
@@ -67,7 +101,10 @@ exports.MEMORY_STRING_SYSTEM = `# DIRECTIVES FOR MEMORIES
|
|
|
67
101
|
- By default, do not reference this section or the memories in your response.
|
|
68
102
|
- Use memories only to guide reasoning; do not respond to the memories themselves.`;
|
|
69
103
|
exports.MEMORY_STRING_PREFIX = "Use these contextual memories to guide your response. Prioritize the user's question. Ignore irrelevant memories.";
|
|
70
|
-
|
|
104
|
+
/**
|
|
105
|
+
* @deprecated Use getDiscussionSynthesisMessages instead
|
|
106
|
+
* Cette fonction est conservée pour compatibilité avec l'ancien système
|
|
107
|
+
*/
|
|
71
108
|
function getFactRetrievalMessages(parsedMessages, customRules = "", defaultLanguage = "French") {
|
|
72
109
|
const injectCustomRules = (customRules) => customRules ? `\n# PRE-EXISTING FACTS\n${customRules}` : "";
|
|
73
110
|
const systemPrompt = `You are a Personal Information Organizer, specialized in extracting and structuring user facts and preferences for AI personalization. You also handle explicit task extraction (todos only).
|
|
@@ -108,6 +145,9 @@ Remember the following:
|
|
|
108
145
|
const userPrompt = `Extract exact facts from the following conversation in the same language as the user. If the user expresses disinterest or asks to ignore the topic, return {"facts":[]}. Limit output to ≤ 12 triplets and strictly follow the JSON schema.\n${parsedMessages}`;
|
|
109
146
|
return [systemPrompt, userPrompt];
|
|
110
147
|
}
|
|
148
|
+
/**
|
|
149
|
+
* @deprecated Memory updates are disabled by config
|
|
150
|
+
*/
|
|
111
151
|
function getUpdateMemoryMessages(retrievedOldMemory, newRetrievedFacts, defaultLanguage = "French", userInstruction) {
|
|
112
152
|
const serializeFacts = (facts) => {
|
|
113
153
|
if (facts.length === 0)
|