@illli-studio/mory 0.1.4 → 0.1.6
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/bundle/server.mjs +1 -1
- package/bundle/web/assets/{index-CJ5unMda.js → index-CEbRwYQi.js} +10 -10
- package/bundle/web/index.html +1 -1
- package/client/index.d.ts +4 -0
- package/client/index.js +1 -0
- package/package.json +1 -1
- package/src/cli.mjs +1 -1
- package/src/mcp.mjs +3 -1
package/bundle/server.mjs
CHANGED
|
@@ -77,7 +77,7 @@ const server = createServer(async (request, response) => { if (request.method ==
|
|
|
77
77
|
if (request.method === "POST" && url.pathname === "/v1/memories") { const memory = makeMemory(await requestBody(request)); const duplicate = allMemories(memory.scope).find((item) => item.hash === memory.hash); if (duplicate) return send(response, 200, { memory: duplicate, duplicate: true }); insert(memory); addEvent("ADD", memory); linkEntities(memory); return send(response, 201, { memory, duplicate: false }); }
|
|
78
78
|
const match = url.pathname.match(/^\/v1\/memories\/([^/]+)$/);
|
|
79
79
|
if (match && request.method === "GET") { const memory = getMemory(match[1]); return memory ? send(response, 200, { memory }) : send(response, 404, { error: "memory not found" }); }
|
|
80
|
-
if (match && request.method === "PATCH") { const current = getMemory(match[1]); if (!current) return send(response, 404, { error: "memory not found" });
|
|
80
|
+
if (match && request.method === "PATCH") { const current = getMemory(match[1]); if (!current) return send(response, 404, { error: "memory not found" }); const input = await requestBody(request); const nextText = String(input.text || input.content || input.payload?.content || current.text).trim(); const contentChanged = nextText !== current.text || String(input.title || current.title) !== current.title; const next = makeMemory({ ...current, ...input, id: current.id, text: nextText, hash: undefined, contentHash: undefined, embedding: contentChanged ? await embed(nextText) : current.embedding, sourceEventIds: [...current.sourceEventIds, randomUUID()] }, current.source); db.exec("BEGIN"); try { db.prepare("DELETE FROM memory_fts WHERE memory_id = ?").run(current.id); db.prepare("DELETE FROM memories WHERE id = ?").run(current.id); insert(next); addEvent("UPDATE", next, { oldHash: current.hash, newHash: next.hash }); db.exec("COMMIT"); } catch (error) { db.exec("ROLLBACK"); throw error; } return send(response, 200, { memory: next }); }
|
|
81
81
|
if (match && request.method === "DELETE") { const memory = getMemory(match[1]); if (!memory) return send(response, 404, { error: "memory not found" }); db.prepare("UPDATE memories SET status = 'deleted', updated_at = ? WHERE id = ?").run(new Date().toISOString(), memory.id); db.prepare("DELETE FROM memory_fts WHERE memory_id = ?").run(memory.id); addEvent("DELETE", memory); return send(response, 200, { ok: true }); }
|
|
82
82
|
if (request.method === "GET" && url.pathname === "/v1/export") return send(response, 200, { schemaVersion: 1, exportedAt: new Date().toISOString(), memories: allMemories({}) });
|
|
83
83
|
if (request.method === "POST" && url.pathname === "/v1/import") { const input = await requestBody(request); if (!Array.isArray(input.memories)) return send(response, 400, { error: "memories array is required" }); const added = [], duplicates = []; for (const item of input.memories.slice(0, 10000)) { const memory = makeMemory(item); const duplicate = allMemories(memory.scope).find((candidate) => candidate.hash === memory.hash); if (duplicate) { duplicates.push(duplicate.id); continue; } if (getMemory(memory.id)) { duplicates.push(memory.id); continue; } insert(memory); addEvent("IMPORT", memory); linkEntities(memory); added.push(memory); } return send(response, 201, { addedCount: added.length, duplicateCount: duplicates.length, memories: added }); }
|