Skip to content

Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.

fix(chat): address backend review — wire vector search, fix types, remove dead code

Gabriel Stein04505e9b4f35
diff --git a/src/helpers/conversationChunker.js b/src/helpers/conversationChunker.js
index 76548acf7..0ec4cb014 100644
--- a/src/helpers/conversationChunker.js
+++ b/src/helpers/conversationChunker.js
@@ -23,4 +23,4 @@ function formatChunkText(title, messages) {
return `${title}\n${body}`.slice(0, 1500);
}
-module.exports = { chunkConversation, CHUNK_SIZE };
+module.exports = { chunkConversation };
diff --git a/src/helpers/ipcHandlers.js b/src/helpers/ipcHandlers.js
index 3fc7aa46f..c2e0f301b 100644
--- a/src/helpers/ipcHandlers.js
+++ b/src/helpers/ipcHandlers.js
@@ -733,7 +733,11 @@ class IPCHandlers {
});
ipcMain.handle("db-delete-agent-conversation", async (event, id) => {
- return this.databaseManager.deleteAgentConversation(id);
+ const result = this.databaseManager.deleteAgentConversation(id);
+ if (this.vectorIndex?.isReady?.()) {
+ this.vectorIndex.deleteConversationChunks(id).catch(() => {});
+ }
+ return result;
});
ipcMain.handle("db-update-agent-conversation-title", async (event, id, title) => {
@@ -743,7 +747,16 @@ class IPCHandlers {
ipcMain.handle(
"db-add-agent-message",
async (event, conversationId, role, content, metadata) => {
- return this.databaseManager.addAgentMessage(conversationId, role, content, metadata);
+ const result = this.databaseManager.addAgentMessage(conversationId, role, content, metadata);
+ if (this.vectorIndex?.isReady?.()) {
+ const conv = this.databaseManager.getAgentConversation(conversationId);
+ if (conv && conv.messages?.length % 3 === 0) {
+ this.vectorIndex
+ .upsertConversationChunks(conversationId, conv.title, conv.messages)
+ .catch(() => {});
+ }
+ }
+ return result;
}
);
@@ -779,6 +792,25 @@ class IPCHandlers {
});
ipcMain.handle("db-semantic-search-conversations", async (event, query, limit) => {
+ if (this.vectorIndex?.isReady?.()) {
+ try {
+ const vectorResults = await this.vectorIndex.searchConversations(query, limit);
+ if (vectorResults?.length > 0) {
+ const ids = vectorResults.map((r) => r.conversationId);
+ const previews = ids
+ .map((id) => this.databaseManager.getAgentConversation(id))
+ .filter(Boolean)
+ .map((c) => ({
+ ...c,
+ message_count: c.messages?.length ?? 0,
+ last_message: c.messages?.[c.messages.length - 1]?.content,
+ }));
+ if (previews.length > 0) return previews;
+ }
+ } catch {
+ // fall through to keyword search
+ }
+ }
return this.databaseManager.searchAgentConversations(query, limit);
});
diff --git a/src/stores/chatStore.ts b/src/stores/chatStore.ts
index 96b9df065..0b118e518 100644
--- a/src/stores/chatStore.ts
+++ b/src/stores/chatStore.ts
@@ -4,6 +4,7 @@ interface ConversationItem {
id: number;
title: string;
cloud_id?: string | null;
+ archived_at?: string | null;
created_at: string;
updated_at: string;
}
@@ -20,18 +21,7 @@ const useChatStore = create<ChatState>()(() => ({
migration: null,
}));
-let hasBoundIpcListeners = false;
-const DEFAULT_LIMIT = 50;
-
-function ensureIpcListeners() {
- if (hasBoundIpcListeners || typeof window === "undefined") {
- return;
- }
- hasBoundIpcListeners = true;
-}
-
-export async function initializeConversations(limit = DEFAULT_LIMIT): Promise<ConversationItem[]> {
- ensureIpcListeners();
+export async function initializeConversations(limit = 50): Promise<ConversationItem[]> {
const items = (await window.electronAPI?.getAgentConversations?.(limit)) ?? [];
useChatStore.setState({ conversations: items });
return items;
@@ -146,16 +136,14 @@ export async function syncConversationDeleteToCloud(cloudId: string): Promise<vo
export async function startConversationMigration(): Promise<void> {
const allConversations = (await window.electronAPI?.getAgentConversations?.(9999)) ?? [];
- const unsynced = allConversations.filter(
- (c: ConversationItem) => !(c as ConversationItem).cloud_id
- );
+ const unsynced = allConversations.filter((c) => !c.cloud_id);
if (unsynced.length === 0) return;
useChatStore.setState({ migration: { total: unsynced.length, done: 0 } });
for (const conv of unsynced) {
try {
- await syncConversationToCloud(conv as ConversationItem);
+ await syncConversationToCloud(conv);
useChatStore.setState((s) => ({
migration: s.migration
? {
diff --git a/src/types/electron.ts b/src/types/electron.ts
index e27974439..8227680f5 100644
--- a/src/types/electron.ts
+++ b/src/types/electron.ts
@@ -1012,6 +1012,8 @@ declare global {
Array<{
id: number;
title: string;
+ archived_at?: string;
+ cloud_id?: string;
created_at: string;
updated_at: string;
}>
@@ -1019,6 +1021,8 @@ declare global {
getAgentConversation?: (id: number) => Promise<{
id: number;
title: string;
+ archived_at?: string;
+ cloud_id?: string;
created_at: string;
updated_at: string;
messages: Array<{