@hasna/mementos 0.4.6 → 0.4.7

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;AA+jCH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAoG9C"}
@@ -2218,6 +2218,73 @@ addRoute("POST", "/api/memories/bulk-update", async (req) => {
2218
2218
  }
2219
2219
  return json({ updated, errors, total: ids.length });
2220
2220
  });
2221
+ addRoute("POST", "/api/memories/extract", async (req) => {
2222
+ const body = await readJson(req);
2223
+ if (!body)
2224
+ return errorResponse("Invalid JSON body", 400);
2225
+ const sessionId = body["session_id"];
2226
+ const agentId = body["agent_id"];
2227
+ const projectId = body["project_id"];
2228
+ const title = body["title"];
2229
+ const project = body["project"];
2230
+ const model = body["model"];
2231
+ const messages = body["messages"];
2232
+ const keyTopics = Array.isArray(body["key_topics"]) ? body["key_topics"] : [];
2233
+ const summary = body["summary"];
2234
+ const extraMemories = Array.isArray(body["memories"]) ? body["memories"] : [];
2235
+ const created = [];
2236
+ const errors = [];
2237
+ function saveExtracted(key, value, category, importance) {
2238
+ try {
2239
+ const mem = createMemory({
2240
+ key,
2241
+ value,
2242
+ category,
2243
+ scope: "shared",
2244
+ importance,
2245
+ source: "auto",
2246
+ agent_id: agentId,
2247
+ project_id: projectId,
2248
+ session_id: sessionId
2249
+ });
2250
+ created.push(mem.id);
2251
+ } catch (e) {
2252
+ errors.push(`${key}: ${e instanceof Error ? e.message : String(e)}`);
2253
+ }
2254
+ }
2255
+ if (title && sessionId) {
2256
+ const meta = [
2257
+ `title: ${title}`,
2258
+ project ? `project: ${project}` : null,
2259
+ model ? `model: ${model}` : null,
2260
+ messages ? `messages: ${messages}` : null
2261
+ ].filter(Boolean).join(", ");
2262
+ saveExtracted(`session-${sessionId}-summary`, `${title} (${meta})`, "history", 6);
2263
+ }
2264
+ if (keyTopics.length > 0 && sessionId) {
2265
+ saveExtracted(`session-${sessionId}-topics`, `Key topics: ${keyTopics.join(", ")}`, "knowledge", 5);
2266
+ }
2267
+ if (summary && sessionId) {
2268
+ saveExtracted(`session-${sessionId}-notes`, summary, "knowledge", 7);
2269
+ }
2270
+ for (const mem of extraMemories) {
2271
+ if (!mem["key"] || !mem["value"])
2272
+ continue;
2273
+ try {
2274
+ const created_mem = createMemory({
2275
+ ...mem,
2276
+ source: "auto",
2277
+ agent_id: agentId,
2278
+ project_id: projectId,
2279
+ session_id: sessionId
2280
+ });
2281
+ created.push(created_mem.id);
2282
+ } catch (e) {
2283
+ errors.push(`${String(mem["key"])}: ${e instanceof Error ? e.message : String(e)}`);
2284
+ }
2285
+ }
2286
+ return json({ created: created.length, memory_ids: created, errors, session_id: sessionId }, 201);
2287
+ });
2221
2288
  addRoute("POST", "/api/memories/clean", () => {
2222
2289
  const cleaned = cleanExpiredMemories();
2223
2290
  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.7",
4
4
  "description": "Universal memory system for AI agents - CLI + MCP server + library API",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",