Spaces:
Build error
Build error
Luis Milke commited on
Commit ·
d4b8bab
1
Parent(s): 3180829
Fix memory.ts old SQLite references
Browse files- src/tools/memory.ts +12 -9
src/tools/memory.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
import {
|
| 2 |
|
| 3 |
export const saveMemoryTool = {
|
| 4 |
type: 'function',
|
|
@@ -36,24 +36,27 @@ export const searchMemoryTool = {
|
|
| 36 |
}
|
| 37 |
};
|
| 38 |
|
| 39 |
-
export function executeSaveMemory(content: string): string {
|
| 40 |
try {
|
| 41 |
-
const stmt = db.prepare('INSERT INTO memory (content, timestamp) VALUES (?, ?)');
|
| 42 |
const now = new Date().toISOString();
|
| 43 |
-
|
| 44 |
return `Successfully saved memory: ${content}`;
|
| 45 |
} catch (e: any) {
|
| 46 |
return `Failed to save memory: ${e.message}`;
|
| 47 |
}
|
| 48 |
}
|
| 49 |
|
| 50 |
-
export function executeSearchMemory(query: string): string {
|
| 51 |
try {
|
| 52 |
-
//
|
| 53 |
-
const stmt = db.prepare('SELECT content, timestamp FROM memory WHERE memory MATCH ? ORDER BY rank LIMIT 10');
|
| 54 |
-
// Simple safety: strip quotes from query
|
| 55 |
const safeQuery = query.replace(/"/g, '');
|
| 56 |
-
const rows =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
|
| 58 |
if (rows.length === 0) {
|
| 59 |
return `No memories found matching "${query}"`;
|
|
|
|
| 1 |
+
import { MemoryModel } from '../memory/db.js';
|
| 2 |
|
| 3 |
export const saveMemoryTool = {
|
| 4 |
type: 'function',
|
|
|
|
| 36 |
}
|
| 37 |
};
|
| 38 |
|
| 39 |
+
export async function executeSaveMemory(content: string): Promise<string> {
|
| 40 |
try {
|
|
|
|
| 41 |
const now = new Date().toISOString();
|
| 42 |
+
await MemoryModel.create({ content, timestamp: now });
|
| 43 |
return `Successfully saved memory: ${content}`;
|
| 44 |
} catch (e: any) {
|
| 45 |
return `Failed to save memory: ${e.message}`;
|
| 46 |
}
|
| 47 |
}
|
| 48 |
|
| 49 |
+
export async function executeSearchMemory(query: string): Promise<string> {
|
| 50 |
try {
|
| 51 |
+
// Use MongoDB text search
|
|
|
|
|
|
|
| 52 |
const safeQuery = query.replace(/"/g, '');
|
| 53 |
+
const rows = await MemoryModel.find(
|
| 54 |
+
{ $text: { $search: safeQuery } },
|
| 55 |
+
{ score: { $meta: "textScore" } }
|
| 56 |
+
)
|
| 57 |
+
.sort({ score: { $meta: "textScore" } })
|
| 58 |
+
.limit(10)
|
| 59 |
+
.lean();
|
| 60 |
|
| 61 |
if (rows.length === 0) {
|
| 62 |
return `No memories found matching "${query}"`;
|