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
39 changes: 18 additions & 21 deletions src/app/components/chat-panel/chat-panel.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -224,28 +224,25 @@
}
</mat-card>
} @if (message.functionCall) {
<button
mat-stroked-button
[ngClass]="{'function-event-button-highlight': shouldMessageHighlighted(i)}"
class="function-event-button"
(click)="clickEvent.emit(i)"
>
<mat-icon>bolt</mat-icon>
{{ message.functionCall.name }}
</button>
} @if (message.functionResponse) {
@if (isComputerUseResponse(message)) {
<div class="computer-use-container" (click)="clickEvent.emit(i)">
<div class="computer-use-header">
<span class="computer-use-tool-name">{{ message.functionResponse.name }}</span>
</div>
<img [src]="getComputerUseScreenshot(message)" class="computer-use-screenshot" alt="Computer Use Screenshot" />
<div class="computer-use-footprint">
<mat-icon class="computer-icon">computer</mat-icon>
<span class="url-text">{{ getComputerUseUrl(message) }}</span>
</div>
</div>
@if (isComputerUseClick(message)) {
<app-computer-action [message]="message" [allMessages]="messages" [index]="i" (clickEvent)="clickEvent.emit($event)"></app-computer-action>
} @else {
<button
mat-stroked-button
[ngClass]="{'function-event-button-highlight': shouldMessageHighlighted(i)}"
class="function-event-button"
(click)="clickEvent.emit(i)"
>
<mat-icon>bolt</mat-icon>
{{ message.functionCall.name }}
</button>
}
}
@if (message.functionResponse) {
@if (isComputerUseResponse(message)) {
<app-computer-action [message]="message" [allMessages]="messages" [index]="i" (clickEvent)="clickEvent.emit($event)"></app-computer-action>
}
@else {
<button mat-stroked-button [ngClass]="{'function-event-button-highlight': shouldMessageHighlighted(i)}"
class="function-event-button" (click)="clickEvent.emit(i)">
<mat-icon>check</mat-icon>
Expand Down
49 changes: 0 additions & 49 deletions src/app/components/chat-panel/chat-panel.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -441,52 +441,3 @@ button.video-rec-btn {
margin-top: 1em;
margin-bottom: 1em;
}

.computer-use-container {
display: flex;
flex-direction: column;
max-width: 400px;
border-radius: 12px;
border: 1px solid var(--chat-panel-input-field-mat-mdc-text-field-wrapper-border-color);
overflow: hidden;
cursor: pointer;
margin: 5px 5px 10px;
background-color: var(--chat-panel-bot-message-message-card-background-color);
transition: opacity 0.2s;

&:hover {
opacity: 0.9;
}
}

.computer-use-screenshot {
width: 100%;
height: auto;
display: block;
border-bottom: 1px solid var(--chat-panel-input-field-mat-mdc-text-field-wrapper-border-color);
}

.computer-use-footprint {
display: flex;
align-items: center;
padding: 8px 12px;
gap: 8px;
background-color: var(--chat-panel-thought-chip-background-color);
}

.computer-icon {
font-size: 18px;
width: 18px;
height: 18px;
color: var(--chat-panel-header-expected-color);
}

.url-text {
font-size: 11px;
font-family: monospace;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
color: var(--chat-panel-input-field-textarea-color);
opacity: 0.8;
}
51 changes: 4 additions & 47 deletions src/app/components/chat-panel/chat-panel.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,7 @@ describe('ChatPanelComponent', () => {
expect(component.feedback.emit).toHaveBeenCalledWith({direction: 'down'});
});
});

describe('Computer Use', () => {
it(
'isComputerUseResponse should return true when image data and url are present',
Expand All @@ -721,50 +722,6 @@ describe('ChatPanelComponent', () => {
}
};
expect(component.isComputerUseResponse(message)).toBeFalse();
});

it(
'isComputerUseResponse should return false when url is missing', () => {
const message = {
functionResponse: {
name: 'computer_use',
response:
{image: {data: 'base64data', mimetype: 'image/png'}, url: ''}
}
};
expect(component.isComputerUseResponse(message)).toBeFalse();
});

it(
'should render computer use container and screenshot', async () => {
component.messages = [{
role: 'bot',
functionResponse: {
name: 'computer',
response: {
image: {data: 'base64data', mimetype: 'image/png'},
url: 'http://google.com'
}
}
}];
fixture.detectChanges();
await fixture.whenStable();

const container =
fixture.debugElement.query(By.css('.computer-use-container'));
expect(container).toBeTruthy();

const img =
fixture.debugElement.query(By.css('.computer-use-screenshot'));
expect(img.nativeElement.src)
.toContain('data:image/png;base64,base64data');

const url = fixture.debugElement.query(By.css('.url-text'));
expect(url.nativeElement.textContent).toContain('http://google.com');

const toolName =
fixture.debugElement.query(By.css('.computer-use-tool-name'));
expect(toolName.nativeElement.textContent).toContain('computer');
});
});
});
});
});
});
31 changes: 8 additions & 23 deletions src/app/components/chat-panel/chat-panel.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import {EMPTY, merge, NEVER, of, Subject} from 'rxjs';
import {catchError, filter, first, switchMap, tap} from 'rxjs/operators';

import type {EvalCase} from '../../core/models/Eval';
import {ComputerUsePayload, FunctionResponse} from '../../core/models/types';
import {FunctionCall, FunctionResponse} from '../../core/models/types';
import {AGENT_SERVICE} from '../../core/services/interfaces/agent';
import {FEATURE_FLAG_SERVICE} from '../../core/services/interfaces/feature-flag';
import {SESSION_SERVICE} from '../../core/services/interfaces/session';
Expand All @@ -45,8 +45,9 @@ import {UI_STATE_SERVICE} from '../../core/services/interfaces/ui-state';
import {MediaType,} from '../artifact-tab/artifact-tab.component';
import {AudioPlayerComponent} from '../audio-player/audio-player.component';
import {MARKDOWN_COMPONENT, MarkdownComponentInterface} from '../markdown/markdown.component.interface';

import {ComputerActionComponent} from '../computer-action/computer-action.component';
import {ChatPanelMessagesInjectionToken} from './chat-panel.component.i18n';
import {isComputerUseResponse, isVisibleComputerUseClick} from '../../core/models/ComputerUse';

const ROOT_AGENT = 'root_agent';

Expand All @@ -71,6 +72,7 @@ const ROOT_AGENT = 'root_agent';
AudioPlayerComponent,
MatTooltipModule,
NgClass,
ComputerActionComponent,
],
})
export class ChatPanelComponent implements OnChanges, AfterViewInit {
Expand Down Expand Up @@ -276,28 +278,11 @@ export class ChatPanelComponent implements OnChanges, AfterViewInit {
}
}

isComputerUseResponse(message: {functionResponse?: FunctionResponse}):
boolean {
const response = message.functionResponse?.response as ComputerUsePayload;
return !!(response?.image?.data && response?.url);
}

getComputerUseScreenshot(message: {functionResponse?: FunctionResponse}):
string {
const response = message.functionResponse?.response as ComputerUsePayload;
const imageInfo = response?.image;

if (!imageInfo?.data) return '';

const screenshot = imageInfo.data;
if (screenshot.startsWith('data:')) return screenshot;

const mimeType = imageInfo.mimetype || 'image/png';
return `data:${mimeType};base64,${screenshot}`;
isComputerUseClick(message: {functionCall?: FunctionCall}): boolean {
return isVisibleComputerUseClick(message);
}

getComputerUseUrl(message: {functionResponse?: FunctionResponse}): string {
const response = message.functionResponse?.response as ComputerUsePayload;
return response?.url || '';
isComputerUseResponse(message: {functionResponse?: FunctionResponse}): boolean {
return isComputerUseResponse(message);
}
}
39 changes: 39 additions & 0 deletions src/app/components/computer-action/computer-action.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
@if (message.functionCall && isComputerUseClick()) {
@let screenshot = getPreviousComputerUseScreenshot();
@if (screenshot) {
<div class="computer-use-container click-visualization-container" (click)="clickEvent.emit(index)">
<div class="computer-use-header">
<span class="computer-use-tool-name">
{{ message.functionCall.name }}
@if (message.functionCall.args['action']) {
({{ message.functionCall.args['action'] }})
}
@let actualCoords = getActualPixelCoordinates();
@if (actualCoords) {
<span class="actual-pixels" [matTooltip]="actualCoords.isVirtual ? 'Virtual (1000x1000)' : 'Hardware Mapping'">
[&#64; {{ actualCoords.x }}{{ actualCoords.isVirtual ? 'v' : 'px' }}, {{ actualCoords.y }}{{
actualCoords.isVirtual
? 'v' : 'px' }}]
</span>
}
</span>
</div>
<div class="image-wrapper">
<img [src]="screenshot" class="computer-use-screenshot" alt="Computer Use Screenshot"
(load)="onImageLoad($event)" />
<div class="click-overlay-box" [ngStyle]="getClickBoxStyle()"></div>
</div>
</div>
}
} @else if (message.functionResponse && isComputerUseResponse()) {
<div class="computer-use-container" (click)="clickEvent.emit(index)">
<div class="computer-use-header">
<span class="computer-use-tool-name">{{ message.functionResponse.name }}</span>
</div>
<img [src]="getComputerUseScreenshot()" class="computer-use-screenshot" alt="Computer Use Screenshot" />
<div class="computer-use-footprint">
<mat-icon class="computer-icon">computer</mat-icon>
<span class="url-text">{{ getComputerUseUrl() }}</span>
</div>
</div>
}
105 changes: 105 additions & 0 deletions src/app/components/computer-action/computer-action.component.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
:host {
display: block;
}

.computer-use-container {
display: flex;
flex-direction: column;
max-width: 600px;
border-radius: 12px;
border: 1px solid var(--chat-panel-input-field-mat-mdc-text-field-wrapper-border-color);
overflow: hidden;
cursor: pointer;
margin: 5px 5px 10px;
background-color: var(--chat-panel-bot-message-message-card-background-color);
transition: opacity 0.2s;
&:hover {
opacity: 0.9;
}
}

.computer-use-tool-name {
font-size: 12px;
font-family: monospace;
font-weight: 600;
color: var(--chat-panel-input-field-textarea-color);
opacity: 0.9;
padding: 12px;
.actual-pixels {
opacity: 0.6;
margin-left: 8px;
font-weight: 400;
}
}

.computer-use-screenshot {
width: 100%;
height: auto;
display: block;
border-bottom: 1px solid var(--chat-panel-input-field-mat-mdc-text-field-wrapper-border-color);
}

.computer-use-footprint {
display: flex;
align-items: center;
padding: 8px 12px;
gap: 8px;
background-color: var(--chat-panel-thought-chip-background-color);
}

.computer-icon {
font-size: 18px;
width: 18px;
height: 18px;
flex-shrink: 0;
}

.url-text {
font-size: 11px;
font-family: monospace;
white-space: normal;
word-break: break-all;
color: var(--chat-panel-input-field-textarea-color);
opacity: 0.8;
min-width: 0;
}

.image-wrapper {
position: relative;
width: 100%;
}

.click-overlay-box {
position: absolute;
width: 24px;
height: 24px;
border: 1px solid rgba(255, 255, 255, 0.8);
border-radius: 50%;
transform: translate(-50%, -50%);
background-color: rgba(255, 0, 0, 0.3);
box-shadow: 0 0 4px rgba(0, 0, 0, 0.5);
pointer-events: none;
z-index: 10;
display: flex;
align-items: center;
justify-content: center;
&::before {
content: '';
width: 2px;
height: 2px;
background-color: #ff0000;
border-radius: 50%;
box-shadow: 0 0 2px white;
z-index: 11;
}
&::after {
content: '';
position: absolute;
width: 100%;
height: 100%;
background:
linear-gradient(to right, transparent 48%, rgba(255, 255, 255, 0.6) 48%, rgba(255, 255, 255, 0.6) 52%, transparent 52%),
linear-gradient(to bottom, transparent 48%, rgba(255, 255, 255, 0.6) 48%, rgba(255, 255, 255, 0.6) 52%, transparent 52%);
border-radius: 50%;
}
}
Loading
Loading