@@ -502,6 +502,33 @@ export const useSendMessage = ({
502502 filename : img . filename || 'image' ,
503503 } ) )
504504
505+ // Build message content array for SDK
506+ let messageContent : MessageContent [ ] | undefined
507+ if ( validImageParts . length > 0 ) {
508+ messageContent = [
509+ { type : 'text' as const , text : content } ,
510+ ...validImageParts . map ( ( img ) => ( {
511+ type : 'image' as const ,
512+ image : img . image ,
513+ mediaType : img . mediaType ,
514+ } ) ) ,
515+ ]
516+
517+ logger . info (
518+ {
519+ imageCount : validImageParts . length ,
520+ totalSize : validImageParts . reduce (
521+ ( sum , part ) => sum + ( part . size || 0 ) ,
522+ 0 ,
523+ ) ,
524+ } ,
525+ `📎 ${ validImageParts . length } image(s) attached` ,
526+ )
527+
528+ // Clear pending images after successful processing
529+ useChatStore . getState ( ) . clearPendingImages ( )
530+ }
531+
505532 // Create user message and capture its ID for later updates
506533 const userMessage = getUserMessage ( content , attachments )
507534 const userMessageId = userMessage . id
@@ -985,85 +1012,7 @@ export const useSendMessage = ({
9851012 ? 'base2-max'
9861013 : 'base2-plan'
9871014
988- // Auto-detect and process image paths in the content
989- const imagePaths = extractImagePaths ( content )
990- const imagePartsPromises = imagePaths . map ( async ( imagePath ) => {
991- const cwd = getProjectRoot ( )
992- const result = await processImageFile ( imagePath , cwd )
993- if ( result . success && result . imagePart ) {
994- return {
995- type : 'image' as const ,
996- image : result . imagePart . image ,
997- mediaType : result . imagePart . mediaType ,
998- filename : result . imagePart . filename ,
999- size : result . imagePart . size ,
1000- }
1001- }
1002- // Log failed image processing
1003- if ( ! result . success ) {
1004- logger . warn (
1005- { imagePath, error : result . error } ,
1006- 'Failed to process image' ,
1007- )
1008- }
1009- return null
1010- } )
1011-
1012- const imagePartsResults = await Promise . all ( imagePartsPromises )
1013- const validImageParts = imagePartsResults . filter (
1014- ( part ) : part is NonNullable < typeof part > => part !== null ,
1015- )
1016-
1017- // Also include pending images from /image command
1018- const pendingImages = useChatStore . getState ( ) . pendingImages
1019- for ( const pendingImage of pendingImages ) {
1020- const result = await processImageFile ( pendingImage . path , getProjectRoot ( ) )
1021- if ( result . success && result . imagePart ) {
1022- validImageParts . push ( {
1023- type : 'image' as const ,
1024- image : result . imagePart . image ,
1025- mediaType : result . imagePart . mediaType ,
1026- filename : result . imagePart . filename ,
1027- size : result . imagePart . size ,
1028- } )
1029- } else {
1030- logger . warn (
1031- { path : pendingImage . path , error : result . error } ,
1032- 'Failed to process pending image' ,
1033- )
1034- }
1035- }
1036-
1037- // Build message content array
1038- let messageContent : MessageContent [ ] | undefined
1039- if ( validImageParts . length > 0 ) {
1040- messageContent = [
1041- { type : 'text' as const , text : content } ,
1042- ...validImageParts . map ( ( img ) => ( {
1043- type : 'image' as const ,
1044- image : img . image ,
1045- mediaType : img . mediaType ,
1046- } ) ) ,
1047- ]
1048-
1049- // Calculate total size for logging
1050- const totalSize = validImageParts . reduce (
1051- ( sum , part ) => sum + ( part . size || 0 ) ,
1052- 0 ,
1053- )
1054-
1055- logger . info (
1056- {
1057- imageCount : validImageParts . length ,
1058- totalSize,
1059- totalSizeKB : ( totalSize / 1024 ) . toFixed ( 1 ) ,
1060- } ,
1061- `📎 ${ validImageParts . length } image(s) attached` ,
1062- )
1063-
1064- // Clear pending images after successful attachment
1065- useChatStore . getState ( ) . clearPendingImages ( )
1066- }
1015+ // Note: Image processing is done earlier in sendMessage, messageContent is already built
10671016
10681017 let runState : RunState
10691018 try {
0 commit comments