@hasna/mementos 0.4.6 → 0.4.8

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/mcp/index.js CHANGED
@@ -6668,6 +6668,57 @@ server.tool("clean_expired", "Remove expired memories from the database", {}, as
6668
6668
  return { content: [{ type: "text", text: formatError(e) }], isError: true };
6669
6669
  }
6670
6670
  });
6671
+ server.tool("session_extract", "Extract memories from a session summary. Auto-creates structured memories from title, topics, notes.", {
6672
+ session_id: exports_external.string(),
6673
+ title: exports_external.string().optional(),
6674
+ project: exports_external.string().optional(),
6675
+ model: exports_external.string().optional(),
6676
+ messages: exports_external.coerce.number().optional(),
6677
+ key_topics: exports_external.array(exports_external.string()).optional(),
6678
+ summary: exports_external.string().optional(),
6679
+ agent_id: exports_external.string().optional(),
6680
+ project_id: exports_external.string().optional()
6681
+ }, async (args) => {
6682
+ try {
6683
+ let saveExtracted = function(key, value, category, importance) {
6684
+ try {
6685
+ const mem = createMemory({
6686
+ key,
6687
+ value,
6688
+ category,
6689
+ scope: "shared",
6690
+ importance,
6691
+ source: "auto",
6692
+ agent_id,
6693
+ project_id,
6694
+ session_id
6695
+ });
6696
+ created.push(mem.id);
6697
+ } catch {}
6698
+ };
6699
+ const { session_id, title, project, model, messages, key_topics, summary, agent_id, project_id } = args;
6700
+ const created = [];
6701
+ if (title) {
6702
+ const meta = [project && `project: ${project}`, model && `model: ${model}`, messages && `messages: ${messages}`].filter(Boolean).join(", ");
6703
+ saveExtracted(`session-${session_id}-summary`, `${title}${meta ? ` (${meta})` : ""}`, "history", 6);
6704
+ }
6705
+ if (key_topics?.length) {
6706
+ saveExtracted(`session-${session_id}-topics`, `Key topics: ${key_topics.join(", ")}`, "knowledge", 5);
6707
+ }
6708
+ if (summary) {
6709
+ saveExtracted(`session-${session_id}-notes`, summary, "knowledge", 7);
6710
+ }
6711
+ return {
6712
+ content: [{
6713
+ type: "text",
6714
+ text: `Extracted ${created.length} memor${created.length === 1 ? "y" : "ies"} from session ${session_id}.${created.length > 0 ? `
6715
+ IDs: ${created.join(", ")}` : ""}`
6716
+ }]
6717
+ };
6718
+ } catch (e) {
6719
+ return { content: [{ type: "text", text: formatError(e) }], isError: true };
6720
+ }
6721
+ });
6671
6722
  server.tool("memory_context", "Get memories relevant to current context, filtered by scope/importance/recency.", {
6672
6723
  agent_id: exports_external.string().optional(),
6673
6724
  project_id: exports_external.string().optional(),
@@ -7075,6 +7126,22 @@ var FULL_SCHEMAS = {
7075
7126
  },
7076
7127
  example: '{"project_id":"proj-uuid","max_tokens":300,"min_importance":5,"format":"compact"}'
7077
7128
  },
7129
+ session_extract: {
7130
+ description: "Auto-create memories from a session summary (title, topics, notes, project). Designed for sessions\u2192mementos integration.",
7131
+ category: "memory",
7132
+ params: {
7133
+ session_id: { type: "string", description: "Session ID to link memories to", required: true },
7134
+ title: { type: "string", description: "Session title" },
7135
+ project: { type: "string", description: "Project name" },
7136
+ model: { type: "string", description: "Model used" },
7137
+ messages: { type: "number", description: "Message count" },
7138
+ key_topics: { type: "array", description: "Key topics extracted from session", items: { type: "string" } },
7139
+ summary: { type: "string", description: "Free-form session summary text" },
7140
+ agent_id: { type: "string", description: "Agent ID to associate memories with" },
7141
+ project_id: { type: "string", description: "Project ID to scope memories to" }
7142
+ },
7143
+ example: '{"session_id":"abc123","title":"Fix auth middleware","project":"alumia","key_topics":["jwt","compliance"],"agent_id":"galba-id"}'
7144
+ },
7078
7145
  memory_context: {
7079
7146
  description: "Get active memories for the current context (agent/project/scope).",
7080
7147
  category: "memory",
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":";AACA;;;GAGG;AAy+BH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAoG9C"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":";AACA;;;GAGG;AAikCH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAoG9C"}
@@ -2079,6 +2079,10 @@ addRoute("GET", "/api/memories", (_req, url) => {
2079
2079
  filter.agent_id = q["agent_id"];
2080
2080
  if (q["project_id"])
2081
2081
  filter.project_id = q["project_id"];
2082
+ if (q["session_id"])
2083
+ filter.session_id = q["session_id"];
2084
+ if (q["status"])
2085
+ filter.status = q["status"];
2082
2086
  if (q["limit"])
2083
2087
  filter.limit = parseInt(q["limit"], 10);
2084
2088
  if (q["offset"])
@@ -2218,6 +2222,73 @@ addRoute("POST", "/api/memories/bulk-update", async (req) => {
2218
2222
  }
2219
2223
  return json({ updated, errors, total: ids.length });
2220
2224
  });
2225
+ addRoute("POST", "/api/memories/extract", async (req) => {
2226
+ const body = await readJson(req);
2227
+ if (!body)
2228
+ return errorResponse("Invalid JSON body", 400);
2229
+ const sessionId = body["session_id"];
2230
+ const agentId = body["agent_id"];
2231
+ const projectId = body["project_id"];
2232
+ const title = body["title"];
2233
+ const project = body["project"];
2234
+ const model = body["model"];
2235
+ const messages = body["messages"];
2236
+ const keyTopics = Array.isArray(body["key_topics"]) ? body["key_topics"] : [];
2237
+ const summary = body["summary"];
2238
+ const extraMemories = Array.isArray(body["memories"]) ? body["memories"] : [];
2239
+ const created = [];
2240
+ const errors = [];
2241
+ function saveExtracted(key, value, category, importance) {
2242
+ try {
2243
+ const mem = createMemory({
2244
+ key,
2245
+ value,
2246
+ category,
2247
+ scope: "shared",
2248
+ importance,
2249
+ source: "auto",
2250
+ agent_id: agentId,
2251
+ project_id: projectId,
2252
+ session_id: sessionId
2253
+ });
2254
+ created.push(mem.id);
2255
+ } catch (e) {
2256
+ errors.push(`${key}: ${e instanceof Error ? e.message : String(e)}`);
2257
+ }
2258
+ }
2259
+ if (title && sessionId) {
2260
+ const meta = [
2261
+ `title: ${title}`,
2262
+ project ? `project: ${project}` : null,
2263
+ model ? `model: ${model}` : null,
2264
+ messages ? `messages: ${messages}` : null
2265
+ ].filter(Boolean).join(", ");
2266
+ saveExtracted(`session-${sessionId}-summary`, `${title} (${meta})`, "history", 6);
2267
+ }
2268
+ if (keyTopics.length > 0 && sessionId) {
2269
+ saveExtracted(`session-${sessionId}-topics`, `Key topics: ${keyTopics.join(", ")}`, "knowledge", 5);
2270
+ }
2271
+ if (summary && sessionId) {
2272
+ saveExtracted(`session-${sessionId}-notes`, summary, "knowledge", 7);
2273
+ }
2274
+ for (const mem of extraMemories) {
2275
+ if (!mem["key"] || !mem["value"])
2276
+ continue;
2277
+ try {
2278
+ const created_mem = createMemory({
2279
+ ...mem,
2280
+ source: "auto",
2281
+ agent_id: agentId,
2282
+ project_id: projectId,
2283
+ session_id: sessionId
2284
+ });
2285
+ created.push(created_mem.id);
2286
+ } catch (e) {
2287
+ errors.push(`${String(mem["key"])}: ${e instanceof Error ? e.message : String(e)}`);
2288
+ }
2289
+ }
2290
+ return json({ created: created.length, memory_ids: created, errors, session_id: sessionId }, 201);
2291
+ });
2221
2292
  addRoute("POST", "/api/memories/clean", () => {
2222
2293
  const cleaned = cleanExpiredMemories();
2223
2294
  return json({ cleaned });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hasna/mementos",
3
- "version": "0.4.6",
3
+ "version": "0.4.8",
4
4
  "description": "Universal memory system for AI agents - CLI + MCP server + library API",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",