Skip to content

Commit 537bcff

Browse files
wyf7107copybara-github
authored andcommitted
ADK changes
PiperOrigin-RevId: 987076873
1 parent 3696705 commit 537bcff

9 files changed

Lines changed: 879 additions & 0 deletions

‎src/app/components/event-content/event-content.component.html‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@
8383
@for (functionCall of uiEvent.functionCalls; track functionCall.id) {
8484
@if (isComputerUseClick(functionCall)) {
8585
<app-computer-action [functionCall]="functionCall" [allMessages]="uiEvents" [index]="index" (clickEvent)="clickEvent.emit($event)" (openImage)="openViewImageDialog.emit($event)"></app-computer-action>
86+
} @else if (isShellCommandCall(functionCall)) {
87+
<app-shell-command [functionCall]="functionCall"></app-shell-command>
8688
}
8789
}
8890
</div>
@@ -110,6 +112,9 @@
110112
</button>
111113
</mat-menu>
112114
</div>
115+
@if (isShellCommandResponse(functionResponse)) {
116+
<app-shell-command [functionResponse]="functionResponse"></app-shell-command>
117+
}
113118
}
114119
}
115120
}

‎src/app/components/event-content/event-content.component.spec.ts‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {By} from '@angular/platform-browser';
2121
import {NoopAnimationsModule} from '@angular/platform-browser/animations';
2222
// 1p-ONLY-IMPORTS: import {beforeEach, describe, expect, it}
2323

24+
import type {Event as AdkEvent} from '../../core/models/types';
2425
import {UiEvent} from '../../core/models/UiEvent';
2526
import {initTestBed} from '../../testing/utils';
2627
import {ChatPanelMessagesInjectionToken, CHAT_PANEL_MESSAGES} from '../chat-panel/chat-panel.component.i18n';
@@ -112,4 +113,49 @@ describe('EventContentComponent', () => {
112113
expect(startBtn?.componentInstance.tooltipContent).toBe('Started');
113114
});
114115
});
116+
117+
describe('Shell commands', () => {
118+
it('renders a shell command call under its function call chip', () => {
119+
component.uiEvent = new UiEvent({
120+
role: 'bot',
121+
event: {id: 'call-1'} as AdkEvent,
122+
functionCalls: [
123+
{id: 'fc-1', name: 'Execute', args: {command: 'echo hi'}},
124+
{id: 'fc-2', name: 'get_weather', args: {city: 'Paris'}},
125+
],
126+
});
127+
component.index = 0;
128+
fixture.detectChanges();
129+
130+
const shellCommands = fixture.debugElement.queryAll(By.css('app-shell-command'));
131+
expect(shellCommands.length).toBe(1);
132+
expect(shellCommands[0].nativeElement.textContent).toContain('$ echo hi');
133+
134+
const chipTexts = fixture.debugElement.queryAll(By.css('app-hover-info-button'))
135+
.map(b => b.componentInstance.text);
136+
expect(chipTexts).toEqual(['Execute("echo hi")', 'get_weather("Paris")']);
137+
});
138+
139+
it('renders a shell command response as output under its chip', () => {
140+
component.uiEvent = new UiEvent({
141+
role: 'bot',
142+
event: {id: 'response-1'} as AdkEvent,
143+
functionResponses: [
144+
{id: 'fc-1', name: 'Execute', response: {status: 'ok', stdout: 'hi\n'}},
145+
],
146+
});
147+
component.index = 1;
148+
fixture.detectChanges();
149+
150+
const chip = fixture.debugElement.query(By.css('.function-response-chip-container'));
151+
expect(chip.query(By.css('app-hover-info-button')).componentInstance.text)
152+
.toBe('Execute');
153+
expect(chip.query(By.css('.menu-trigger-btn'))).toBeTruthy();
154+
155+
const output = fixture.debugElement.query(By.css('app-shell-command'));
156+
expect(output.nativeElement.textContent).toContain('hi');
157+
// The output comes right after the chip, so it renders underneath it.
158+
expect(chip.nativeElement.nextElementSibling).toBe(output.nativeElement);
159+
});
160+
});
115161
});

‎src/app/components/event-content/event-content.component.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { EditJsonDialogComponent } from '../edit-json-dialog/edit-json-dialog.co
2828
import { AgentRunRequest } from '../../core/models/AgentRunRequest';
2929
import { isComputerUseResponse, isVisibleComputerUseClick } from '../../core/models/ComputerUse';
3030
import type { EvalCase } from '../../core/models/Eval';
31+
import { isShellCommandCall, isShellCommandResponse } from '../../core/models/ShellCommand';
3132
import { UiEvent } from '../../core/models/UiEvent';
3233
import { WorkflowGraphTooltipDirective } from '../../directives/workflow-graph-tooltip.directive';
3334
import { JsonTooltipDirective } from '../../directives/html-tooltip.directive';
@@ -36,6 +37,7 @@ import { HoverInfoButtonComponent } from '../hover-info-button/hover-info-button
3637
import { LongRunningResponseComponent } from '../long-running-response/long-running-response';
3738
import { ChatPanelMessagesInjectionToken } from '../chat-panel/chat-panel.component.i18n';
3839
import { ContentBubbleComponent } from '../content-bubble/content-bubble.component';
40+
import { ShellCommandComponent } from '../shell-command/shell-command.component';
3941
import { SystemInstructionDiffDialogComponent } from '../system-instruction-diff-dialog/system-instruction-diff-dialog.component';
4042

4143
@Component({
@@ -56,6 +58,7 @@ import { SystemInstructionDiffDialogComponent } from '../system-instruction-diff
5658
ContentBubbleComponent,
5759
MatMenuModule,
5860
JsonTooltipDirective,
61+
ShellCommandComponent,
5962
],
6063
})
6164
export class EventContentComponent {
@@ -172,6 +175,14 @@ export class EventContentComponent {
172175
return isComputerUseResponse(input);
173176
}
174177

178+
isShellCommandCall(functionCall: FunctionCall): boolean {
179+
return isShellCommandCall(functionCall);
180+
}
181+
182+
isShellCommandResponse(functionResponse: FunctionResponse): boolean {
183+
return isShellCommandResponse(functionResponse);
184+
}
185+
175186
getFilteredStateKeys(stateDelta: any): string[] {
176187
if (!stateDelta) return [];
177188
return Object.keys(stateDelta).filter(key => key !== '__llm_request_key__');
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<!--
2+
Copyright 2026 Google LLC
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
-->
16+
17+
@if (command()) {
18+
<div class="shell-block shell-command">
19+
<!-- Kept on one line: whitespace between the spans would show up in the command. -->
20+
<div class="shell-command-line"><span class="shell-prompt">$ </span>@for (token of tokens(); track $index) {<span [class]="'shell-token-' + token.type">{{ token.text }}</span>}</div>
21+
</div>
22+
} @else if (result(); as shellResult) {
23+
<div class="shell-block shell-output">
24+
@if (stdout()) {
25+
<pre class="shell-stream shell-stdout">{{ stdout() }}</pre>
26+
}
27+
@if (stderr()) {
28+
<pre class="shell-stream shell-stderr">{{ stderr() }}</pre>
29+
}
30+
@if (shellResult.error) {
31+
<pre class="shell-stream shell-error">{{ shellResult.error }}</pre>
32+
}
33+
@if (!hasOutput()) {
34+
<div class="shell-empty">(no output)</div>
35+
}
36+
@if (status()) {
37+
<div class="shell-status">{{ status() }}</div>
38+
}
39+
</div>
40+
}
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
/**
2+
* @license
3+
* Copyright 2026 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
:host {
19+
display: block;
20+
width: 100%;
21+
min-width: 0;
22+
margin: 4px 0;
23+
24+
--shell-command-color: #e5e1a6;
25+
--shell-arg-color: #ee9b8e;
26+
--shell-flag-color: #8ab4f8;
27+
--shell-operator-color: #c58af9;
28+
--shell-stderr-color: #f6ae6c;
29+
}
30+
31+
:host-context(html.light-theme) {
32+
--shell-command-color: #795e26;
33+
--shell-arg-color: #a31515;
34+
--shell-flag-color: #0b57d0;
35+
--shell-operator-color: #8430ce;
36+
--shell-stderr-color: #b45309;
37+
}
38+
39+
// Sized to the content, wrapping once it reaches the full row width.
40+
.shell-block {
41+
box-sizing: border-box;
42+
width: fit-content;
43+
max-width: 100%;
44+
border: 1px solid var(--mat-sys-outline-variant);
45+
border-radius: 8px;
46+
background-color: var(--mat-sys-surface-container);
47+
color: var(--mat-sys-on-surface);
48+
font-family: 'Roboto Mono', monospace;
49+
font-size: 13px;
50+
line-height: 1.5;
51+
}
52+
53+
.shell-command {
54+
padding: 8px 12px;
55+
}
56+
57+
.shell-command-line {
58+
white-space: pre-wrap;
59+
overflow-wrap: anywhere;
60+
}
61+
62+
.shell-prompt {
63+
color: var(--mat-sys-on-surface-variant);
64+
user-select: none;
65+
}
66+
67+
.shell-token-command {
68+
color: var(--shell-command-color);
69+
}
70+
71+
.shell-token-arg {
72+
color: var(--shell-arg-color);
73+
}
74+
75+
.shell-token-flag {
76+
color: var(--shell-flag-color);
77+
}
78+
79+
.shell-token-operator {
80+
color: var(--shell-operator-color);
81+
}
82+
83+
.shell-output {
84+
max-height: 360px;
85+
overflow: auto;
86+
padding: 8px 12px;
87+
}
88+
89+
.shell-stream {
90+
margin: 0;
91+
font: inherit;
92+
white-space: pre-wrap;
93+
overflow-wrap: anywhere;
94+
}
95+
96+
.shell-stream + .shell-stream {
97+
margin-top: 4px;
98+
}
99+
100+
.shell-stderr {
101+
color: var(--shell-stderr-color);
102+
}
103+
104+
.shell-error {
105+
color: var(--mat-sys-error);
106+
}
107+
108+
.shell-empty {
109+
color: var(--mat-sys-on-surface-variant);
110+
font-style: italic;
111+
}
112+
113+
.shell-status {
114+
margin-top: 6px;
115+
font-size: 11px;
116+
color: var(--mat-sys-error);
117+
}
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/**
2+
* @license
3+
* Copyright 2026 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
import {ComponentFixture, TestBed} from '@angular/core/testing';
19+
// 1p-ONLY-IMPORTS: import {beforeEach, describe, expect, it}
20+
21+
import {initTestBed} from '../../testing/utils';
22+
import {ShellCommandComponent} from './shell-command.component';
23+
24+
describe('ShellCommandComponent', () => {
25+
let fixture: ComponentFixture<ShellCommandComponent>;
26+
27+
beforeEach(async () => {
28+
initTestBed();
29+
await TestBed.configureTestingModule({
30+
imports: [ShellCommandComponent],
31+
}).compileComponents();
32+
fixture = TestBed.createComponent(ShellCommandComponent);
33+
});
34+
35+
function query(selector: string): HTMLElement|null {
36+
return fixture.nativeElement.querySelector(selector);
37+
}
38+
39+
it('renders a function call as a prompt line', () => {
40+
fixture.componentRef.setInput(
41+
'functionCall', {name: 'Execute', args: {command: 'echo hi'}});
42+
fixture.detectChanges();
43+
44+
expect(query('.shell-command-line')?.textContent).toBe('$ echo hi');
45+
expect(query('.shell-token-command')?.textContent).toBe('echo');
46+
expect(query('.shell-token-arg')?.textContent).toBe('hi');
47+
expect(query('.shell-output')).toBeNull();
48+
});
49+
50+
it('renders a function response as the command output', () => {
51+
fixture.componentRef.setInput('functionResponse', {
52+
name: 'Execute',
53+
response: {status: 'ok', stdout: 'hi\n'},
54+
});
55+
fixture.detectChanges();
56+
57+
expect(query('.shell-stdout')?.textContent).toBe('hi');
58+
expect(query('.shell-stderr')).toBeNull();
59+
expect(query('.shell-status')).toBeNull();
60+
expect(query('.shell-command')).toBeNull();
61+
});
62+
63+
it('shows stderr, tool errors, and a non-zero exit code', () => {
64+
fixture.componentRef.setInput('functionResponse', {
65+
name: 'execute_bash',
66+
response: {
67+
stdout: '<no stdout captured>',
68+
stderr: 'ls: cannot access',
69+
returncode: 2,
70+
},
71+
});
72+
fixture.detectChanges();
73+
74+
expect(query('.shell-stdout')).toBeNull();
75+
expect(query('.shell-stderr')?.textContent).toBe('ls: cannot access');
76+
expect(query('.shell-status')?.textContent).toBe('Exit code 2');
77+
});
78+
79+
it('shows the tool error when the command did not run', () => {
80+
fixture.componentRef.setInput('functionResponse', {
81+
name: 'execute_bash',
82+
response: {error: 'This tool call is rejected.'},
83+
});
84+
fixture.detectChanges();
85+
86+
expect(query('.shell-error')?.textContent)
87+
.toBe('This tool call is rejected.');
88+
expect(query('.shell-empty')).toBeNull();
89+
});
90+
91+
it('shows a placeholder when the command printed nothing', () => {
92+
fixture.componentRef.setInput('functionResponse', {
93+
name: 'Execute',
94+
response: {status: 'ok'},
95+
});
96+
fixture.detectChanges();
97+
98+
expect(query('.shell-empty')?.textContent).toBe('(no output)');
99+
});
100+
101+
it('marks timed out commands', () => {
102+
fixture.componentRef.setInput('functionResponse', {
103+
name: 'run_skill_script',
104+
response: {stdout: 'partial', stderr: '', exit_code: -1, timed_out: true},
105+
});
106+
fixture.detectChanges();
107+
108+
expect(query('.shell-status')?.textContent).toBe('Timed out');
109+
});
110+
});

0 commit comments

Comments
 (0)