File tree Expand file tree Collapse file tree 3 files changed +54
-22
lines changed
bytebot-ui/src/components/messages Expand file tree Collapse file tree 3 files changed +54
-22
lines changed Original file line number Diff line number Diff line change @@ -180,8 +180,18 @@ export async function handleComputerToolUse(
180180 } ;
181181 }
182182 }
183+
184+ let image : string | null = null ;
185+ try {
186+ logger . debug ( 'Taking screenshot' ) ;
187+ image = await screenshot ( ) ;
188+ logger . debug ( 'Screenshot captured successfully' ) ;
189+ } catch ( error ) {
190+ logger . error ( 'Failed to take screenshot' , error ) ;
191+ }
192+
183193 logger . debug ( `Tool execution successful for tool_use_id: ${ block . id } ` ) ;
184- return {
194+ const toolResult : ToolResultContentBlock = {
185195 type : MessageContentType . ToolResult ,
186196 tool_use_id : block . id ,
187197 content : [
@@ -191,6 +201,19 @@ export async function handleComputerToolUse(
191201 } ,
192202 ] ,
193203 } ;
204+
205+ if ( image ) {
206+ toolResult . content . push ( {
207+ type : MessageContentType . Image ,
208+ source : {
209+ data : image ,
210+ media_type : 'image/png' ,
211+ type : 'base64' ,
212+ } ,
213+ } ) ;
214+ }
215+
216+ return toolResult ;
194217 } catch ( error ) {
195218 logger . error (
196219 `Error executing ${ block . name } tool: ${ error . message } ` ,
@@ -591,7 +614,7 @@ export async function writeFile(input: {
591614 try {
592615 // Content is always base64 encoded
593616 const base64Data = content ;
594-
617+
595618 const response = await fetch ( `${ BYTEBOT_DESKTOP_BASE_URL } /computer-use` , {
596619 method : 'POST' ,
597620 headers : { 'Content-Type' : 'application/json' } ,
Original file line number Diff line number Diff line change @@ -44,22 +44,23 @@ export function AssistantMessage({
4444 block . content &&
4545 block . content . length > 0
4646 ) {
47- const imageBlock = block . content [ 0 ] ;
48- if ( isImageContentBlock ( imageBlock ) ) {
49- return (
50- < div
51- key = { blockIndex }
52- data-message-index = { messageIdToIndex [ message . id ] }
53- data-block-index = { blockIndex }
54- style = { {
55- position : "absolute" ,
56- width : 0 ,
57- height : 0 ,
58- overflow : "hidden" ,
59- } }
60- />
61- ) ;
62- }
47+ block . content . map ( ( contentBlock ) => {
48+ if ( isImageContentBlock ( contentBlock ) ) {
49+ return (
50+ < div
51+ key = { blockIndex }
52+ data-message-index = { messageIdToIndex [ message . id ] }
53+ data-block-index = { blockIndex }
54+ style = { {
55+ position : "absolute" ,
56+ width : 0 ,
57+ height : 0 ,
58+ overflow : "hidden" ,
59+ } }
60+ />
61+ ) ;
62+ }
63+ } ) ;
6364 }
6465 return null ;
6566 } ) }
Original file line number Diff line number Diff line change @@ -25,7 +25,8 @@ export function MessageContent({
2525 // Filter logic from the original code
2626 if (
2727 isToolResultContentBlock ( block ) &&
28- isImageContentBlock ( block . content ?. [ 0 ] )
28+ block . content &&
29+ block . content . some ( ( contentBlock ) => isImageContentBlock ( contentBlock ) )
2930 ) {
3031 return true ;
3132 }
@@ -50,9 +51,16 @@ export function MessageContent({
5051 < div key = { index } >
5152 { isTextContentBlock ( block ) && < TextContent block = { block } /> }
5253
53- { isImageContentBlock ( block . content ?. [ 0 ] ) && (
54- < ImageContent block = { block . content [ 0 ] } />
55- ) }
54+ { isToolResultContentBlock ( block ) &&
55+ ! block . is_error &&
56+ block . content . map ( ( contentBlock , contentBlockIndex ) => {
57+ if ( isImageContentBlock ( contentBlock ) ) {
58+ return (
59+ < ImageContent key = { contentBlockIndex } block = { contentBlock } />
60+ ) ;
61+ }
62+ return null ;
63+ } ) }
5664
5765 { isComputerToolUseContentBlock ( block ) && (
5866 < ComputerToolContent block = { block } isTakeOver = { isTakeOver } />
You can’t perform that action at this time.
0 commit comments