agentgui 1.0.745 → 1.0.746
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 +32 -0
- package/lib/ws-handlers-conv.js +47 -0
- package/package.json +1 -1
package/database.js
CHANGED
|
@@ -595,6 +595,21 @@ try {
|
|
|
595
595
|
console.error('[Migration] Backfill error:', err.message);
|
|
596
596
|
}
|
|
597
597
|
|
|
598
|
+
try {
|
|
599
|
+
const hasFts = db.prepare("SELECT name FROM sqlite_master WHERE type='table' AND name='messages_fts'").get();
|
|
600
|
+
if (!hasFts) {
|
|
601
|
+
db.exec("CREATE VIRTUAL TABLE messages_fts USING fts5(content, conversationId UNINDEXED, role UNINDEXED, content_rowid='rowid')");
|
|
602
|
+
const msgs = db.prepare("SELECT rowid, content, conversationId, role FROM messages").all();
|
|
603
|
+
if (msgs.length > 0) {
|
|
604
|
+
const ins = db.prepare("INSERT INTO messages_fts(rowid, content, conversationId, role) VALUES (?, ?, ?, ?)");
|
|
605
|
+
const tx = db.transaction(() => { for (const m of msgs) ins.run(m.rowid, m.content, m.conversationId, m.role); });
|
|
606
|
+
tx();
|
|
607
|
+
console.log(`[Migration] FTS5 index created with ${msgs.length} messages`);
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
} catch (err) {
|
|
611
|
+
console.error('[Migration] FTS5 error:', err.message);
|
|
612
|
+
}
|
|
598
613
|
|
|
599
614
|
const stmtCache = new Map();
|
|
600
615
|
function prep(sql) {
|
|
@@ -774,6 +789,8 @@ export const queries = {
|
|
|
774
789
|
);
|
|
775
790
|
stmt.run(id, conversationId, role, storedContent, now);
|
|
776
791
|
|
|
792
|
+
try { prep('INSERT INTO messages_fts(rowid, content, conversationId, role) VALUES ((SELECT rowid FROM messages WHERE id = ?), ?, ?, ?)').run(id, storedContent, conversationId, role); } catch (_) {}
|
|
793
|
+
|
|
777
794
|
const updateConvStmt = prep('UPDATE conversations SET updated_at = ? WHERE id = ?');
|
|
778
795
|
updateConvStmt.run(now, conversationId);
|
|
779
796
|
|
|
@@ -1924,6 +1941,21 @@ export const queries = {
|
|
|
1924
1941
|
return stmt.run(toolId, toolId, keepCount).changes;
|
|
1925
1942
|
},
|
|
1926
1943
|
|
|
1944
|
+
searchMessages(query, limit = 50) {
|
|
1945
|
+
try {
|
|
1946
|
+
const stmt = prep(`
|
|
1947
|
+
SELECT m.id, m.conversationId, m.role, m.content, m.created_at,
|
|
1948
|
+
c.title as conversationTitle, c.agentType
|
|
1949
|
+
FROM messages_fts fts
|
|
1950
|
+
JOIN messages m ON m.rowid = fts.rowid
|
|
1951
|
+
JOIN conversations c ON c.id = m.conversationId
|
|
1952
|
+
WHERE messages_fts MATCH ?
|
|
1953
|
+
ORDER BY m.created_at DESC LIMIT ?
|
|
1954
|
+
`);
|
|
1955
|
+
return stmt.all(query, limit);
|
|
1956
|
+
} catch (_) { return []; }
|
|
1957
|
+
},
|
|
1958
|
+
|
|
1927
1959
|
// ============ ACP-COMPATIBLE QUERIES ============
|
|
1928
1960
|
...createACPQueries(db, prep)
|
|
1929
1961
|
};
|
package/lib/ws-handlers-conv.js
CHANGED
|
@@ -135,6 +135,53 @@ export function register(router, deps) {
|
|
|
135
135
|
return { markdown: md, title: conv.title };
|
|
136
136
|
});
|
|
137
137
|
|
|
138
|
+
router.handle('conv.sync', (p) => {
|
|
139
|
+
const conv = queries.getConversation(p.id);
|
|
140
|
+
if (!conv) notFound();
|
|
141
|
+
const machineSnap = execMachine.snapshot(p.id);
|
|
142
|
+
const executionState = machineSnap?.value || 'idle';
|
|
143
|
+
const latestSession = queries.getLatestSession(p.id);
|
|
144
|
+
const sinceSeq = parseInt(p.sinceSeq || '-1');
|
|
145
|
+
const since = parseInt(p.since || '0');
|
|
146
|
+
let missedChunks = [];
|
|
147
|
+
if (latestSession && sinceSeq >= 0) {
|
|
148
|
+
missedChunks = queries.getChunksSinceSeq(latestSession.id, sinceSeq);
|
|
149
|
+
} else if (latestSession && since > 0) {
|
|
150
|
+
missedChunks = queries.getConversationChunksSince(p.id, since);
|
|
151
|
+
}
|
|
152
|
+
return {
|
|
153
|
+
conversation: conv,
|
|
154
|
+
executionState,
|
|
155
|
+
isActivelyStreaming: execMachine.isActive(p.id),
|
|
156
|
+
latestSession,
|
|
157
|
+
missedChunks,
|
|
158
|
+
missedCount: missedChunks.length,
|
|
159
|
+
queueLength: machineSnap?.context?.queue?.length || 0
|
|
160
|
+
};
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
router.handle('conv.search', (p) => {
|
|
164
|
+
if (!p.query || typeof p.query !== 'string' || p.query.trim().length < 2) return { results: [] };
|
|
165
|
+
const limit = Math.min(parseInt(p.limit || '50'), 200);
|
|
166
|
+
return { results: queries.searchMessages(p.query.trim(), limit) };
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
router.handle('conv.prune', (p) => {
|
|
170
|
+
const conv = queries.getConversation(p.id);
|
|
171
|
+
if (!conv) notFound();
|
|
172
|
+
const keep = Math.max(parseInt(p.keep || '500'), 100);
|
|
173
|
+
const sessions = queries.getConversationSessions(p.id);
|
|
174
|
+
if (!sessions || sessions.length === 0) return { pruned: 0 };
|
|
175
|
+
const latestSessionId = sessions[0]?.id;
|
|
176
|
+
let pruned = 0;
|
|
177
|
+
for (const sess of sessions) {
|
|
178
|
+
if (sess.id === latestSessionId) continue;
|
|
179
|
+
const count = queries.getSessionChunks(sess.id)?.length || 0;
|
|
180
|
+
if (count > 0) { queries.deleteSessionChunks(sess.id); pruned += count; }
|
|
181
|
+
}
|
|
182
|
+
return { pruned, kept: latestSessionId, sessionsProcessed: sessions.length };
|
|
183
|
+
});
|
|
184
|
+
|
|
138
185
|
router.handle('conv.cancel', (p) => {
|
|
139
186
|
if (!execMachine.isActive(p.id)) notFound('No active execution to cancel');
|
|
140
187
|
const ctx = execMachine.getContext(p.id);
|