@@ -824,7 +824,7 @@ function resolveFileReferences(query) {
824824
825825let activeQueryId = 0 ;
826826
827- async function handleAIQuery ( event , query , usePro , forceShowOutput , followUp ) {
827+ async function handleAIQuery ( event , query , usePro , forceShowOutput , followUp , pastedImages ) {
828828 const queryId = ++ activeQueryId ;
829829
830830 if ( ! ai ) {
@@ -846,6 +846,17 @@ async function handleAIQuery(event, query, usePro, forceShowOutput, followUp) {
846846
847847 // Build contents: continue existing conversation or start fresh
848848 const userParts = [ { text : resolvedQuery } , ...extraParts ] ;
849+
850+ // Add pasted images
851+ if ( Array . isArray ( pastedImages ) && pastedImages . length > 0 ) {
852+ for ( const img of pastedImages ) {
853+ if ( img . dataUri && img . mimeType ) {
854+ const base64 = img . dataUri . replace ( / ^ d a t a : [ ^ ; ] + ; b a s e 6 4 , / , '' ) ;
855+ userParts . push ( { inlineData : { mimeType : img . mimeType , data : base64 } } ) ;
856+ }
857+ }
858+ userParts [ 0 ] = { text : resolvedQuery + '\n\n[Pasted image attached]' } ;
859+ }
849860 let contents ;
850861 if ( followUp && chatHistory && chatHistory . model === modelName ) {
851862 contents = [ ...chatHistory . contents , { role : 'user' , parts : userParts } ] ;
@@ -1443,8 +1454,8 @@ function registerHandlers(ipcMain) {
14431454 }
14441455 } ) ;
14451456
1446- ipcMain . handle ( IPC . AI_QUERY , async ( event , query , usePro , forceShowOutput , followUp ) => {
1447- return handleAIQuery ( event , query , usePro , forceShowOutput , followUp ) ;
1457+ ipcMain . handle ( IPC . AI_QUERY , async ( event , query , usePro , forceShowOutput , followUp , pastedImages ) => {
1458+ return handleAIQuery ( event , query , usePro , forceShowOutput , followUp , pastedImages ) ;
14481459 } ) ;
14491460
14501461 ipcMain . handle ( 'trim:copy-image' , async ( _e , dataUri ) => {
@@ -1458,6 +1469,19 @@ function registerHandlers(ipcMain) {
14581469 }
14591470 } ) ;
14601471
1472+ ipcMain . handle ( 'trim:read-clipboard-image' , async ( ) => {
1473+ try {
1474+ const { nativeImage, clipboard } = require ( 'electron' ) ;
1475+ const img = clipboard . readImage ( ) ;
1476+ if ( img . isEmpty ( ) ) return null ;
1477+ const pngBuffer = img . toPNG ( ) ;
1478+ const dataUri = `data:image/png;base64,${ pngBuffer . toString ( 'base64' ) } ` ;
1479+ return { dataUri, mimeType : 'image/png' } ;
1480+ } catch {
1481+ return null ;
1482+ }
1483+ } ) ;
1484+
14611485 ipcMain . handle ( IPC . SEARCH_FOLDERS , async ( _e , query ) => {
14621486 try {
14631487 const sender = _e . sender ;
0 commit comments