agentgui 1.0.734 → 1.0.735
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/database.js +18 -22
- package/package.json +1 -1
package/database.js
CHANGED
|
@@ -1523,29 +1523,25 @@ export const queries = {
|
|
|
1523
1523
|
},
|
|
1524
1524
|
|
|
1525
1525
|
getRecentConversationChunks(conversationId, limit = 500) {
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
const
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
const remaining = limit - latestRows.length;
|
|
1538
|
-
let olderRows = [];
|
|
1539
|
-
if (remaining > 0) {
|
|
1540
|
-
const oldestLatest = latestRows.length ? latestRows[0].created_at : Date.now();
|
|
1541
|
-
olderRows = prep(
|
|
1542
|
-
`SELECT id, sessionId, conversationId, sequence, type, data, created_at
|
|
1543
|
-
FROM chunks WHERE conversationId = ? AND sessionId != ? AND created_at < ?
|
|
1544
|
-
ORDER BY created_at DESC LIMIT ?`
|
|
1545
|
-
).all(conversationId, latestSid, oldestLatest, remaining);
|
|
1546
|
-
olderRows.reverse();
|
|
1526
|
+
const sessions = prep(
|
|
1527
|
+
`SELECT sessionId, COUNT(*) as n FROM chunks WHERE conversationId = ?
|
|
1528
|
+
GROUP BY sessionId ORDER BY MAX(created_at) DESC`
|
|
1529
|
+
).all(conversationId);
|
|
1530
|
+
if (!sessions.length) return [];
|
|
1531
|
+
const included = [];
|
|
1532
|
+
let total = 0;
|
|
1533
|
+
for (const s of sessions) {
|
|
1534
|
+
if (total + s.n > limit && included.length > 0) break;
|
|
1535
|
+
included.unshift(s.sessionId);
|
|
1536
|
+
total += s.n;
|
|
1547
1537
|
}
|
|
1548
|
-
|
|
1538
|
+
const placeholders = included.map(() => '?').join(',');
|
|
1539
|
+
const rows = prep(
|
|
1540
|
+
`SELECT id, sessionId, conversationId, sequence, type, data, created_at
|
|
1541
|
+
FROM chunks WHERE conversationId = ? AND sessionId IN (${placeholders})
|
|
1542
|
+
ORDER BY created_at ASC`
|
|
1543
|
+
).all(conversationId, ...included);
|
|
1544
|
+
return rows.map(row => {
|
|
1549
1545
|
try { return { ...row, data: typeof row.data === 'string' ? JSON.parse(row.data) : row.data }; }
|
|
1550
1546
|
catch (e) { return row; }
|
|
1551
1547
|
});
|