@hasna/mementos 0.4.25 → 0.4.26
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/server/index.d.ts.map +1 -1
- package/dist/server/index.js +34 -0
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":";AACA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":";AACA;;;GAGG;AA2qCH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAsH9C"}
|
package/dist/server/index.js
CHANGED
|
@@ -2293,6 +2293,40 @@ addRoute("GET", "/api/activity", (_req, url) => {
|
|
|
2293
2293
|
`).all(...params);
|
|
2294
2294
|
return json({ activity: rows, days, total: rows.reduce((s, r) => s + r.memories_created, 0) });
|
|
2295
2295
|
});
|
|
2296
|
+
addRoute("GET", "/api/report", (_req, url) => {
|
|
2297
|
+
const q = getSearchParams(url);
|
|
2298
|
+
const days = Math.min(parseInt(q["days"] || "7", 10), 365);
|
|
2299
|
+
const projectId = q["project_id"];
|
|
2300
|
+
const agentId = q["agent_id"];
|
|
2301
|
+
const db = getDatabase();
|
|
2302
|
+
const cond = [
|
|
2303
|
+
projectId ? "AND project_id = ?" : "",
|
|
2304
|
+
agentId ? "AND agent_id = ?" : ""
|
|
2305
|
+
].filter(Boolean).join(" ");
|
|
2306
|
+
const params = [...projectId ? [projectId] : [], ...agentId ? [agentId] : []];
|
|
2307
|
+
const total = db.query(`SELECT COUNT(*) as c FROM memories WHERE status = 'active' ${cond}`).get(...params).c;
|
|
2308
|
+
const pinned = db.query(`SELECT COUNT(*) as c FROM memories WHERE status = 'active' AND pinned = 1 ${cond}`).get(...params).c;
|
|
2309
|
+
const actRows = db.query(`
|
|
2310
|
+
SELECT date(created_at) AS date, COUNT(*) AS memories_created
|
|
2311
|
+
FROM memories WHERE status = 'active' AND date(created_at) >= date('now', '-${days} days') ${cond}
|
|
2312
|
+
GROUP BY date(created_at) ORDER BY date(created_at) ASC
|
|
2313
|
+
`).all(...params);
|
|
2314
|
+
const recentTotal = actRows.reduce((s, r) => s + r.memories_created, 0);
|
|
2315
|
+
const byScopeRows = db.query(`SELECT scope, COUNT(*) as c FROM memories WHERE status = 'active' ${cond} GROUP BY scope`).all(...params);
|
|
2316
|
+
const byCatRows = db.query(`SELECT category, COUNT(*) as c FROM memories WHERE status = 'active' ${cond} GROUP BY category`).all(...params);
|
|
2317
|
+
const topMems = db.query(`SELECT id, key, value, importance, scope, category FROM memories WHERE status = 'active' ${cond} ORDER BY importance DESC, access_count DESC LIMIT 5`).all(...params);
|
|
2318
|
+
const topAgents = db.query(`SELECT agent_id, COUNT(*) as c FROM memories WHERE status = 'active' AND agent_id IS NOT NULL ${cond} GROUP BY agent_id ORDER BY c DESC LIMIT 5`).all(...params);
|
|
2319
|
+
return json({
|
|
2320
|
+
total,
|
|
2321
|
+
pinned,
|
|
2322
|
+
days,
|
|
2323
|
+
recent: { total: recentTotal, activity: actRows },
|
|
2324
|
+
by_scope: Object.fromEntries(byScopeRows.map((r) => [r.scope, r.c])),
|
|
2325
|
+
by_category: Object.fromEntries(byCatRows.map((r) => [r.category, r.c])),
|
|
2326
|
+
top_memories: topMems,
|
|
2327
|
+
top_agents: topAgents
|
|
2328
|
+
});
|
|
2329
|
+
});
|
|
2296
2330
|
addRoute("POST", "/api/memories/search", async (req) => {
|
|
2297
2331
|
const body = await readJson(req);
|
|
2298
2332
|
if (!body || typeof body["query"] !== "string") {
|