chore(cleanup): remove document drag-and-drop

Remove the feature that let a user drop a .txt/.md/.csv/.docx/.pdf file
onto the avatar to feed its text into the chat: the dropped-files IPC
handler and extractText() in main, and getPathForFile/sendDroppedFiles
in the preload API and renderer App.tsx. This fed documents into the
general-purpose chat loop, which is being phased out in favor of the
server-side coach pipeline. Uninstall mammoth and pdf-parse, now unused.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
william
2026-10-31 20:38:19 +01:00
co-authored by Claude Sonnet 5
parent 6cb38a2f36
commit acdd8a08d3
8 changed files with 12 additions and 266 deletions
+1 -31
View File
@@ -4,8 +4,7 @@ import { join } from 'path'
import { electronApp, optimizer, is } from '@electron-toolkit/utils'
import { transcribeAudio, synthesizeSpeech } from './ai/elevenlabs'
import { getAssistantReply } from './ai/openrouter'
import { setMainWindow, sendToRenderer } from './windowBridge'
import { extractText } from './skills/documents/extractText'
import { setMainWindow } from './windowBridge'
import { stripWakeWord } from './wakeWord'
import { loginAndLoadKeys } from './auth/authClient'
import { openLoginWindow, closeLoginWindow } from './auth/loginWindow'
@@ -167,35 +166,6 @@ app
if (window) menu.popup({ window })
})
ipcMain.on('dropped-files', (_event, paths: string[]) => {
void (async () => {
const path = paths[0]
if (!path) return
let prompt: string
try {
const doc = await extractText(path)
const note = doc.truncated ? ' (contenu tronque, document tres long)' : ''
prompt = `[Evenement systeme] L'utilisateur vient de deposer le fichier "${doc.name}" sur ton avatar${note}. Voici son contenu :\n\n${doc.text}\n\nPresente en une phrase ce que tu as recu et demande-lui ce qu'il veut que tu en fasses (resume, traduction, correction orthographique, conversion de format, restructuration, ou autre chose). N'effectue aucune action pour l'instant, attends sa reponse.`
} catch (error) {
const message = error instanceof Error ? error.message : String(error)
prompt = `[Evenement systeme] L'utilisateur vient de deposer un fichier sur ton avatar mais tu n'as pas pu le lire (${message}). Explique-lui brievement le probleme.`
}
try {
const reply = await getAssistantReply(prompt)
const speech = await synthesizeSpeech(reply)
const audio = speech.buffer.slice(
speech.byteOffset,
speech.byteOffset + speech.byteLength
) as ArrayBuffer
sendToRenderer('proactive-speech', audio)
} catch (error) {
console.error('[dropped-files]', error)
}
})()
})
ipcMain.handle(
'voice-turn',
async (_event, inputAudio: ArrayBuffer, mimeType: string): Promise<VoiceTurnResult> => {
@@ -1,44 +0,0 @@
import { readFile } from 'fs/promises'
import { extname, basename } from 'path'
import mammoth from 'mammoth'
import pdfParse from 'pdf-parse'
// Garde le contenu dans une taille raisonnable pour le contexte de conversation (cout/latence).
const MAX_CHARS = 12000
export interface ExtractedDocument {
name: string
text: string
truncated: boolean
}
export async function extractText(filePath: string): Promise<ExtractedDocument> {
const name = basename(filePath)
const ext = extname(filePath).toLowerCase()
let text: string
switch (ext) {
case '.txt':
case '.md':
case '.csv':
text = await readFile(filePath, 'utf-8')
break
case '.docx': {
const buffer = await readFile(filePath)
const result = await mammoth.extractRawText({ buffer })
text = result.value
break
}
case '.pdf': {
const buffer = await readFile(filePath)
const result = await pdfParse(buffer)
text = result.text
break
}
default:
throw new Error(`Format de fichier non supporte : ${ext || '(sans extension)'}`)
}
const truncated = text.length > MAX_CHARS
return { name, text: truncated ? text.slice(0, MAX_CHARS) : text, truncated }
}
-2
View File
@@ -10,8 +10,6 @@ export interface ForgeAvatarApi {
showContextMenu: (listening: boolean) => void
onToggleListening: (callback: (listening: boolean) => void) => () => void
onProactiveSpeech: (callback: (audio: ArrayBuffer) => void) => () => void
getPathForFile: (file: File) => string
sendDroppedFiles: (paths: string[]) => void
onUpdateAvailable: (callback: () => void) => () => void
onUpdateReady: (callback: () => void) => () => void
login: (email: string, password: string) => Promise<LoginResult>
+1 -5
View File
@@ -1,4 +1,4 @@
import { contextBridge, ipcRenderer, webUtils } from 'electron'
import { contextBridge, ipcRenderer } from 'electron'
import { electronAPI } from '@electron-toolkit/preload'
import type { VoiceTurnResult } from '../shared/voice'
import type { AuthStatus, LoginResult } from '../shared/auth'
@@ -28,10 +28,6 @@ const api = {
ipcRenderer.on('proactive-speech', handler)
return () => ipcRenderer.removeListener('proactive-speech', handler)
},
getPathForFile: (file: File): string => webUtils.getPathForFile(file),
sendDroppedFiles: (paths: string[]): void => {
ipcRenderer.send('dropped-files', paths)
},
onUpdateAvailable: (callback: () => void): (() => void) => {
const handler = (): void => callback()
ipcRenderer.on('update:available', handler)
-16
View File
@@ -46,20 +46,6 @@ function App(): React.JSX.Element {
}, [])
useEffect(() => window.api.onProactiveSpeech(() => setVoiceState('speaking')), [])
const onDragOver = useCallback((event: React.DragEvent) => {
event.preventDefault()
}, [])
const onDrop = useCallback((event: React.DragEvent) => {
event.preventDefault()
const paths = Array.from(event.dataTransfer.files).map((file) =>
window.api.getPathForFile(file)
)
if (paths.length === 0) return
setVoiceState('processing')
window.api.sendDroppedFiles(paths)
}, [])
const onContextMenu = useCallback((event: React.MouseEvent) => {
event.preventDefault()
window.api.showContextMenu(listeningRef.current)
@@ -124,8 +110,6 @@ function App(): React.JSX.Element {
style={{ width: '100%', height: '100%', cursor: 'grab', position: 'relative' }}
onMouseDown={handleMouseDown}
onContextMenu={onContextMenu}
onDragOver={onDragOver}
onDrop={onDrop}
>
<AvatarViewer onReady={handleReady} />
{voiceState === 'processing' && <ThinkingIndicator />}