import { contextBridge, ipcRenderer } from 'electron'; import type { LLMConfig, DocumentMetadata } from './types'; interface Directory { name: string; path: string; } interface IpcResponse { success: boolean; data?: T; error?: string; } // Expose protected methods that allow the renderer process to use // the ipcRenderer without exposing the entire object contextBridge.exposeInMainWorld('electron', { // File System Operations startWatching: async (dirPath: string): Promise => ipcRenderer.invoke('start-watching', dirPath), stopWatching: async (dirPath: string): Promise => ipcRenderer.invoke('stop-watching', dirPath), addExcludedPath: async (path: string): Promise => ipcRenderer.invoke('add-excluded-path', path), // LLM Operations queryLLM: async (question: string): Promise<{ answer: string; sources: DocumentMetadata[]; }> => ipcRenderer.invoke('query-llm', question), updateLLMConfig: async (config: LLMConfig): Promise => ipcRenderer.invoke('update-llm-config', config), getLLMConfig: async (): Promise => ipcRenderer.invoke('get-llm-config'), getOllamaModels: async (): Promise> => ipcRenderer.invoke('get-ollama-models'), // Vector Store Operations getDocuments: async (): Promise> => ipcRenderer.invoke('get-documents'), addDocument: async (content: string, metadata: DocumentMetadata): Promise => ipcRenderer.invoke('add-document', content, metadata), deleteDocument: async (path: string): Promise => ipcRenderer.invoke('delete-document', path), updateDocument: async (content: string, metadata: DocumentMetadata): Promise => ipcRenderer.invoke('update-document', content, metadata), // File Processing processFile: async (filePath: string): Promise => ipcRenderer.invoke('process-file', filePath), // System Paths getUserHome: async (): Promise> => ipcRenderer.invoke('get-user-home'), getAppPath: async (): Promise => ipcRenderer.invoke('get-app-path'), // Directory Operations listDirectories: async (dirPath: string): Promise> => ipcRenderer.invoke('list-directories', dirPath), // Event Handling on: (channel: string, callback: (event: unknown, ...args: any[]) => void) => { ipcRenderer.on(channel, callback); }, off: (channel: string, callback: (event: unknown, ...args: any[]) => void) => { ipcRenderer.removeListener(channel, callback); }, // Window Controls minimizeWindow: () => ipcRenderer.invoke('window-minimize'), maximizeWindow: () => ipcRenderer.invoke('window-maximize'), closeWindow: () => ipcRenderer.invoke('window-close'), }); export type { Directory, IpcResponse };