mr-memory 2.3.0 → 2.4.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/index.ts +13 -8
- package/package.json +1 -1
package/index.ts
CHANGED
|
@@ -28,6 +28,15 @@ type MemoryRouterConfig = {
|
|
|
28
28
|
mode?: "relay" | "proxy";
|
|
29
29
|
};
|
|
30
30
|
|
|
31
|
+
// ──────────────────────────────────────────────────────
|
|
32
|
+
// Memory Context Formatting (matches proxy formatters)
|
|
33
|
+
// ──────────────────────────────────────────────────────
|
|
34
|
+
|
|
35
|
+
function wrapMemoryContext(context: string): string {
|
|
36
|
+
if (!context) return context;
|
|
37
|
+
return `<memory_context>\n${context}\n</memory_context>\n\nUse the above context from previous conversations to inform your response. Do not explicitly mention that you're using memory unless directly asked.`;
|
|
38
|
+
}
|
|
39
|
+
|
|
31
40
|
// ──────────────────────────────────────────────────────
|
|
32
41
|
// Helpers
|
|
33
42
|
// ──────────────────────────────────────────────────────
|
|
@@ -186,8 +195,6 @@ const memoryRouterPlugin = {
|
|
|
186
195
|
}
|
|
187
196
|
contextPayload.push({ role: "user", content: prompt });
|
|
188
197
|
|
|
189
|
-
const densityMap: Record<string, number> = { low: 40, high: 80, xhigh: 160 };
|
|
190
|
-
const contextLimit = densityMap[density] || 80;
|
|
191
198
|
|
|
192
199
|
const res = await fetch(`${endpoint}/v1/memory/prepare`, {
|
|
193
200
|
method: "POST",
|
|
@@ -198,7 +205,7 @@ const memoryRouterPlugin = {
|
|
|
198
205
|
body: JSON.stringify({
|
|
199
206
|
messages: contextPayload,
|
|
200
207
|
density,
|
|
201
|
-
|
|
208
|
+
|
|
202
209
|
}),
|
|
203
210
|
});
|
|
204
211
|
|
|
@@ -214,7 +221,7 @@ const memoryRouterPlugin = {
|
|
|
214
221
|
api.logger.info?.(
|
|
215
222
|
`memoryrouter: injected ${data.memories_found || 0} memories on tool iteration (${data.tokens_billed || 0} tokens billed)`,
|
|
216
223
|
);
|
|
217
|
-
return { prependContext: data.context };
|
|
224
|
+
return { prependContext: wrapMemoryContext(data.context) };
|
|
218
225
|
}
|
|
219
226
|
} catch {
|
|
220
227
|
// Silent fail on tool iterations — don't block the agent
|
|
@@ -283,8 +290,6 @@ const memoryRouterPlugin = {
|
|
|
283
290
|
contextPayload.push({ role: "user", content: prompt });
|
|
284
291
|
|
|
285
292
|
// 4. Call /v1/memory/prepare
|
|
286
|
-
const densityMap: Record<string, number> = { low: 40, high: 80, xhigh: 160 };
|
|
287
|
-
const contextLimit = densityMap[density] || 80;
|
|
288
293
|
|
|
289
294
|
const res = await fetch(`${endpoint}/v1/memory/prepare`, {
|
|
290
295
|
method: "POST",
|
|
@@ -295,7 +300,7 @@ const memoryRouterPlugin = {
|
|
|
295
300
|
body: JSON.stringify({
|
|
296
301
|
messages: contextPayload,
|
|
297
302
|
density,
|
|
298
|
-
|
|
303
|
+
|
|
299
304
|
}),
|
|
300
305
|
});
|
|
301
306
|
|
|
@@ -314,7 +319,7 @@ const memoryRouterPlugin = {
|
|
|
314
319
|
api.logger.info?.(
|
|
315
320
|
`memoryrouter: injected ${data.memories_found || 0} memories (${data.tokens_billed || 0} tokens billed)`,
|
|
316
321
|
);
|
|
317
|
-
return { prependContext: data.context };
|
|
322
|
+
return { prependContext: wrapMemoryContext(data.context) };
|
|
318
323
|
}
|
|
319
324
|
} catch (err) {
|
|
320
325
|
api.logger.warn?.(
|