Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions electron/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,7 @@ ipcMain.handle('assistant:create', async (_event, profileId: string, params: { n
}
const assistantService = service.getAssistantService()
const assistant = await assistantService.createAssistant(params)
track('assistant_created', { region: params.region || 'us' })
return { success: true, data: assistant }
} catch (error) {
const message = error instanceof Error ? error.message : 'Failed to create assistant'
Expand Down Expand Up @@ -910,6 +911,7 @@ ipcMain.handle('assistant:delete', async (_event, profileId: string, name: strin
}
const assistantService = service.getAssistantService()
await assistantService.deleteAssistant(name)
track('assistant_deleted')
return { success: true }
} catch (error) {
const message = error instanceof Error ? error.message : 'Failed to delete assistant'
Expand Down Expand Up @@ -959,6 +961,7 @@ ipcMain.handle('assistant:files:upload', async (_event, profileId: string, assis
}
const assistantService = service.getAssistantService()
const file = await assistantService.uploadFile(assistantName, params)
track('file_uploaded', { multimodal: params.multimodal || false })
return { success: true, data: file }
} catch (error) {
const message = error instanceof Error ? error.message : 'Failed to upload file'
Expand All @@ -974,6 +977,7 @@ ipcMain.handle('assistant:files:delete', async (_event, profileId: string, assis
}
const assistantService = service.getAssistantService()
await assistantService.deleteFile(assistantName, fileId)
track('file_deleted')
return { success: true }
} catch (error) {
const message = error instanceof Error ? error.message : 'Failed to delete file'
Expand All @@ -996,6 +1000,7 @@ ipcMain.handle('assistant:chat', async (_event, profileId: string, assistantName
}
const assistantService = service.getAssistantService()
const response = await assistantService.chat(assistantName, params)
track('chat_message_sent', { model: params.model, messageCount: params.messages.length })
return { success: true, data: response }
} catch (error) {
const message = error instanceof Error ? error.message : 'Failed to send chat message'
Expand Down Expand Up @@ -1039,6 +1044,7 @@ ipcMain.handle('assistant:chat:stream:start', async (event, profileId: string, a
activeChatStreams.delete(streamId)
})

track('chat_stream_started', { model: params.model })
return { success: true, data: { streamId } }
} catch (error) {
const message = error instanceof Error ? error.message : 'Failed to start chat stream'
Expand Down
8 changes: 8 additions & 0 deletions electron/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,14 @@ contextBridge.exposeInMainWorld('electronAPI', {
ipcRenderer.on('context-menu:assistant-action', handler)
return () => ipcRenderer.removeListener('context-menu:assistant-action', handler)
},
showFileMenu: (assistantName: string, fileId: string, fileName: string): void => {
ipcRenderer.send('context-menu:show-file', assistantName, fileId, fileName)
},
onFileAction: (callback: (action: { action: string; assistantName: string; fileId: string; fileName: string }) => void): (() => void) => {
const handler = (_event: any, data: { action: string; assistantName: string; fileId: string; fileName: string }) => callback(data)
ipcRenderer.on('context-menu:file-action', handler)
return () => ipcRenderer.removeListener('context-menu:file-action', handler)
},
},
profiles: {
getAll: async (): Promise<ConnectionProfile[]> => {
Expand Down
48 changes: 47 additions & 1 deletion src/components/files/FilesPanel.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState, useMemo, useCallback } from 'react'
import { useState, useMemo, useCallback, useEffect } from 'react'
import { FileText, Upload, Check, AlertCircle, Loader2, Trash2 } from 'lucide-react'
import { usePinecone } from '../../providers/PineconeProvider'
import { useAssistantSelection } from '../../context/AssistantSelectionContext'
Expand Down Expand Up @@ -119,6 +119,51 @@ export function FilesPanel({ className }: FilesPanelProps) {
setActiveFile(fileId)
}, [setActiveFile])

// Handle right-click context menu on file items
const handleFileContextMenu = useCallback((e: React.MouseEvent, file: AssistantFile) => {
e.preventDefault()
if (!activeAssistant) return
window.electronAPI.contextMenu.showFileMenu(activeAssistant, file.id, file.name)
}, [activeAssistant])

// Listen for file context menu actions
useEffect(() => {
if (!currentProfile?.id || !activeAssistant) return

const cleanup = window.electronAPI.contextMenu.onFileAction(async (data) => {
if (data.assistantName !== activeAssistant) return

if (data.action === 'delete') {
// Confirm deletion
const confirmed = window.confirm(`Delete "${data.fileName}"?\n\nThis action cannot be undone.`)
if (!confirmed) return

try {
await window.electronAPI.assistant.files.delete(currentProfile.id, activeAssistant, data.fileId)
// Clear selection if deleted file was selected
if (activeFile === data.fileId) {
setActiveFile(null)
}
refetch()
} catch (err) {
console.error('Failed to delete file:', err)
}
} else if (data.action === 'download') {
// Get file details to get signed URL
try {
const file = await window.electronAPI.assistant.files.describe(currentProfile.id, activeAssistant, data.fileId)
if (file.signedUrl) {
await window.electronAPI.shell.openExternal(file.signedUrl)
}
} catch (err) {
console.error('Failed to download file:', err)
}
}
})

return cleanup
}, [currentProfile?.id, activeAssistant, activeFile, setActiveFile, refetch])

// If no assistant is selected, show prompt
if (!activeAssistant) {
return (
Expand Down Expand Up @@ -254,6 +299,7 @@ export function FilesPanel({ className }: FilesPanelProps) {
<button
key={file.id}
onClick={() => handleFileClick(file.id)}
onContextMenu={(e) => handleFileContextMenu(e, file)}
className={`w-full px-3 py-1.5 text-left transition-colors duration-100 mx-1 rounded-md ${
isActive
? 'bg-black/[0.08] dark:bg-white/[0.10]'
Expand Down
2 changes: 2 additions & 0 deletions src/types/electron.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,8 @@ declare global {
onNamespaceAction: (callback: (action: { action: string; namespace: string }) => void) => () => void
showAssistantMenu: (assistantName: string) => void
onAssistantAction: (callback: (action: { action: string; assistantName: string }) => void) => () => void
showFileMenu: (assistantName: string, fileId: string, fileName: string) => void
onFileAction: (callback: (action: { action: string; assistantName: string; fileId: string; fileName: string }) => void) => () => void
}
profiles: {
getAll: () => Promise<ConnectionProfile[]>
Expand Down