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
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