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
Binary file modified shell/src/app/agent-chat/__snapshots__/a2a-full-chat-view.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion shell/src/app/agent-chat/a2a-chat-view.ng.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
(samplePromptClicked)="submitSamplePrompt($event)"
(openCanvas)="openCanvasSurface($event)"
(closeCanvas)="closeCanvasSurface()"
(openInspector)="toggleInspectorDrawer()"
(openInspector)="inspectMessage($event)"
></a2ui-composer-chat-history>
</div>

Expand Down Expand Up @@ -105,6 +105,7 @@ <h3>A2UI Surface Canvas</h3>
<div class="inspector-column" [style.width.px]="inspectorWidth()">
<a2ui-composer-message-inspector
[events]="inspectorEvents()"
[(searchQuery)]="inspectorSearchQuery"
(closeDrawer)="toggleInspectorDrawer()"
(clearEvents)="clearInspectorEvents()"
></a2ui-composer-message-inspector>
Expand Down
41 changes: 41 additions & 0 deletions shell/src/app/agent-chat/a2a-chat-view.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1026,4 +1026,45 @@ describe('A2aChatView', () => {
}
});
});

it('opens inspector and filters events to the inspected message', async () => {
fixture.componentInstance['sendUserMessage']({text: 'First prompt', images: []});
await fixture.whenStable();

mockA2aTransport.sendMessageStream = vi.fn().mockImplementation(async function* () {
throw new Error('Second turn failed');
});
fixture.componentInstance['sendUserMessage']({text: 'Second prompt', images: []});
await fixture.whenStable();
fixture.detectChanges();

const messages = fixture.componentInstance['messages']();
const firstAgentMessage = messages[1];
const secondErrorMessage = messages[3];
expect(firstAgentMessage.sender).toBe('agent');
expect(secondErrorMessage.sender).toBe('error');
expect(await harness.isInspectorOpen()).toBe(false);

// Inspecting a received agent message filters by its message id.
fixture.componentInstance['inspectMessage'](firstAgentMessage.id);
fixture.detectChanges();

expect(await harness.isInspectorOpen()).toBe(true);
expect(fixture.componentInstance['inspectorSearchQuery']()).toBe(firstAgentMessage.id);

const inspector = await harness.getInspector();
expect(inspector).not.toBeNull();
expect(await inspector!.getPanelCount()).toBe(1);

// Inspecting an error message filters by its message id.
fixture.componentInstance['inspectMessage'](secondErrorMessage.id);
fixture.detectChanges();

expect(fixture.componentInstance['inspectorSearchQuery']()).toBe(secondErrorMessage.id);
expect(await inspector!.getPanelCount()).toBe(1);

// Closing the inspector drawer closes the drawer.
fixture.componentInstance['toggleInspectorDrawer']();
expect(fixture.componentInstance['isInspectorOpen']()).toBe(false);
});
});
13 changes: 11 additions & 2 deletions shell/src/app/agent-chat/a2a-chat-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ export class A2aChatView implements OnInit {
protected readonly connectionError = signal<string | null>(null);
/** Whether the message inspector side drawer is open. */
protected readonly isInspectorOpen = signal<boolean>(false);
/** Search query applied in the message inspector side drawer. */
protected readonly inspectorSearchQuery = signal<string>('');
/** Whether the agent configuration modal is open. */
protected readonly isConfigPanelOpen = signal<boolean>(false);
/** Whether the A2UI Canvas surface preview panel is open. */
Expand Down Expand Up @@ -246,6 +248,7 @@ export class A2aChatView implements OnInit {
this.agentInfo.set(null);
this.messages.set([]);
this.inspectorEvents.set([]);
this.inspectorSearchQuery.set('');
this.activeTaskId.set(null);
this.activeContextId.set(undefined);
this.activeCanvasPayload.set(null);
Expand Down Expand Up @@ -470,14 +473,14 @@ export class A2aChatView implements OnInit {

for await (const chunk of stream) {
if (controller.signal.aborted) break;
this.recordInspectorEvent(createReceivedEvent(chunk));
this.recordInspectorEvent(createReceivedEvent(chunk, agentMessageId));
this.handleStreamEvent(chunk, agentMessageId);
}
}

private handleStreamingError(err: unknown, agentMessageId: string): void {
const errText = err instanceof Error ? err.message : 'Unknown communication error';
this.recordInspectorEvent(createErrorEvent(errText));
this.recordInspectorEvent(createErrorEvent(errText, agentMessageId));

this.messages.update(msgs =>
msgs.map(m =>
Expand Down Expand Up @@ -671,6 +674,7 @@ export class A2aChatView implements OnInit {
protected resetActiveSession(): void {
this.cancelActiveGeneration();
this.messages.set([]);
this.inspectorSearchQuery.set('');
this.activeTaskId.set(null);
this.activeContextId.set(undefined);
this.activeCanvasPayload.set(null);
Expand All @@ -691,6 +695,11 @@ export class A2aChatView implements OnInit {
this.isInspectorOpen.update(v => !v);
}

protected inspectMessage(messageId: string): void {
this.inspectorSearchQuery.set(messageId);
this.isInspectorOpen.set(true);
}

protected startInspectorResize(event: MouseEvent): void {
event.preventDefault();
this.isResizingInspector.set(true);
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion shell/src/app/agent-chat/chat-history/chat-history.ng.html
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ <h3 class="welcome-title">{{ getAgentDisplayName() }}</h3>
[activeCanvasPayload]="activeCanvasPayload()"
(openCanvas)="openCanvas.emit($event)"
(closeCanvas)="closeCanvas.emit()"
(openInspector)="openInspector.emit()"
(openInspector)="openInspector.emit($event)"
></a2ui-composer-chat-message>
}
</div>
Expand Down
4 changes: 2 additions & 2 deletions shell/src/app/agent-chat/chat-history/chat-history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ export class A2aChatHistory implements AfterViewChecked {
readonly openCanvas = output<RenderA2uiItem[]>();
/** Emitted when the user closes the Canvas panel. */
readonly closeCanvas = output<void>();
/** Emitted when the user clicks to open the protocol inspector drawer. */
readonly openInspector = output<void>();
/** Emitted with the message ID when the user clicks to open the protocol inspector drawer. */
readonly openInspector = output<string>();

protected readonly scrollContainerRef = viewChild<ElementRef<HTMLDivElement>>('scrollContainer');

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 4 additions & 22 deletions shell/src/app/agent-chat/chat-message/chat-message.ng.html
Original file line number Diff line number Diff line change
Expand Up @@ -133,29 +133,11 @@
mat-icon-button
type="button"
class="action-btn"
matTooltip="Good response"
aria-label="Good response"
matTooltip="Inspect message"
aria-label="Inspect message"
(click)="openMessageInspector()"
>
<mat-icon class="action-icon">thumb_up</mat-icon>
</button>
<button
mat-icon-button
type="button"
class="action-btn"
matTooltip="Bad response"
aria-label="Bad response"
>
<mat-icon class="action-icon">thumb_down</mat-icon>
</button>
<button
mat-icon-button
type="button"
class="action-btn"
matTooltip="Copy text"
aria-label="Copy text"
(click)="copyMessageText()"
>
<mat-icon class="action-icon">content_copy</mat-icon>
<mat-icon class="action-icon">manage_search</mat-icon>
</button>
</div>
}
Expand Down
8 changes: 8 additions & 0 deletions shell/src/app/agent-chat/chat-message/chat-message.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -630,4 +630,12 @@ describe('A2aChatMessage', () => {
expect(await harness.hasStreamingCursor()).toBe(true);
expect(await harness.hasPendingIndicator()).toBe(false);
});

it('emits openInspector with message id when inspect message button is clicked', async () => {
const inspectSpy = vi.spyOn(fixture.componentInstance.openInspector, 'emit');

await harness.clickInspectMessage();

expect(inspectSpy).toHaveBeenCalledWith('msg-1');
});
});
14 changes: 4 additions & 10 deletions shell/src/app/agent-chat/chat-message/chat-message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ export class A2aChatMessage {
readonly openCanvas = output<RenderA2uiItem[]>();
/** Emitted when the user clicks the close canvas button on the active message card. */
readonly closeCanvas = output<void>();
/** Emitted when the user clicks to open the protocol message inspector. */
readonly openInspector = output<void>();
/** Emitted with the message ID when the user clicks to open the protocol message inspector. */
readonly openInspector = output<string>();

/**
* Records the user's last manual expand/collapse action along with the content state
Expand Down Expand Up @@ -314,14 +314,8 @@ export class A2aChatMessage {
});
}

protected copyMessageText(): void {
const text = this.message().text;
if (!text || typeof navigator === 'undefined' || !navigator.clipboard) {
return;
}
navigator.clipboard.writeText(text).catch((err: unknown) => {
this.logger.warn('Failed to copy message text to clipboard', err);
});
protected openMessageInspector(): void {
this.openInspector.emit(this.message().id);
}
Comment thread
dustinwhuang marked this conversation as resolved.
Resolved

protected openCanvasArtifact(payload: RenderA2uiItem[]): void {
Expand Down
10 changes: 10 additions & 0 deletions shell/src/app/agent-chat/chat-message/test/chat-message.harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ export class A2aChatMessageHarness extends ComponentHarness {
private getStreamingCursor = this.locatorForOptional('.streaming-cursor');
private getInlineSurface = this.locatorForOptional('.inline-surface-card');
private getBodyBlocks = this.locatorForAll('.agent-text-content, .inline-surface-card');
private getInspectMessageButton = this.locatorForOptional(
MatButtonHarness.with({selector: 'button[aria-label="Inspect message"]'}),
);

async hasInlineSurface(): Promise<boolean> {
const el = await this.getInlineSurface();
Expand Down Expand Up @@ -136,4 +139,11 @@ export class A2aChatMessageHarness extends ComponentHarness {
const el = await this.getStreamingCursor();
return el !== null;
}

async clickInspectMessage(): Promise<void> {
const btn = await this.getInspectMessageButton();
if (btn) {
return btn.click();
}
}
}
3 changes: 2 additions & 1 deletion shell/src/app/agent-chat/converters/a2a-ui-converter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,10 @@ describe('A2aUiConverter', () => {
expect(event.summary).toContain('Connection refused');
expect((event.payload as {message: string}).message).toBe('Connection refused');

const strEvent = createErrorEvent('String error');
const strEvent = createErrorEvent('String error', 'msg-err-1');
expect(strEvent.summary).toContain('String error');
expect(strEvent.payload).toBe('String error');
expect(strEvent.messageId).toBe('msg-err-1');
});
});

Expand Down
9 changes: 7 additions & 2 deletions shell/src/app/agent-chat/converters/a2a-ui-converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,10 @@ export function createSentActionEvent(taskId: string, action: unknown): MessageI
/**
* Creates an InspectorEvent recording an incoming streaming event chunk with validation.
*/
export function createReceivedEvent(event: TaskStatusUpdateEvent): MessageInspectorEvent {
export function createReceivedEvent(
event: TaskStatusUpdateEvent,
messageId?: string,
): MessageInspectorEvent {
const eventRecord = event as Record<string, unknown>;
const taskId =
event.taskId || event.task_id || event.contextId || event.context_id || event.id || 'event';
Expand All @@ -133,6 +136,7 @@ export function createReceivedEvent(event: TaskStatusUpdateEvent): MessageInspec

return {
id: uuid(),
messageId,
timestamp: Date.now(),
direction: 'received',
kind,
Expand All @@ -145,10 +149,11 @@ export function createReceivedEvent(event: TaskStatusUpdateEvent): MessageInspec
/**
* Creates an InspectorEvent recording an error event.
*/
export function createErrorEvent(err: unknown): MessageInspectorEvent {
export function createErrorEvent(err: unknown, messageId?: string): MessageInspectorEvent {
const msg = err instanceof Error ? err.message : String(err);
return {
id: uuid(),
messageId,
timestamp: Date.now(),
direction: 'error',
kind: 'error',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
export interface MessageInspectorEvent {
/** Unique identifier for the recorded protocol trace event. */
id: string;
/** Identifier of the chat UI message associated with this event, if any. */
messageId?: string;
/** Timestamp when the event was transmitted or received. */
timestamp: Date | number;
/** Transport direction indicating whether the event was sent, received, or errored. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,23 @@ describe('A2aMessageInspector', () => {
const mockEvents = [
{
id: '1',
messageId: 'msg-1',
timestamp: Date.now(),
direction: 'sent' as const,
summary: 'Sent [user]: Hello',
payload: {role: 'user', content: 'Hello'},
},
{
id: '2',
messageId: 'msg-2',
timestamp: Date.now() + 1000,
direction: 'received' as const,
summary: 'Received text response',
payload: {role: 'agent', content: 'Hi there!'},
},
{
id: '3',
messageId: 'msg-3',
timestamp: Date.now() + 2000,
direction: 'error' as const,
summary: 'Transport Error: Timeout',
Expand Down Expand Up @@ -107,6 +110,13 @@ describe('A2aMessageInspector', () => {
expect(fixture.componentInstance['filteredEvents']().length).toBe(3);
});

it('filters events by messageId when searchQuery is set', () => {
fixture.componentRef.setInput('searchQuery', 'msg-2');
fixture.detectChanges();

expect(fixture.componentInstance['filteredEvents']().map(e => e.id)).toEqual(['2']);
});

it('formats JSON into lines with line numbers correctly', () => {
const lines = fixture.componentInstance['getFormattedJsonLines']({key: 'value'});
expect(lines.length).toBeGreaterThan(1);
Expand Down
19 changes: 16 additions & 3 deletions shell/src/app/agent-chat/message-inspector/message-inspector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import {Component, computed, inject, input, output, signal} from '@angular/core';
import {Component, computed, inject, input, model, output, signal} from '@angular/core';
import {FormsModule} from '@angular/forms';
import {MatButtonModule} from '@angular/material/button';
import {MatIconModule} from '@angular/material/icon';
Expand Down Expand Up @@ -45,16 +45,19 @@ import {ErrorLogger} from '../../debug/error-logger.service';
export class A2aMessageInspector {
/** Recorded raw A2A protocol events and JSON-RPC transport traces. */
readonly events = input<MessageInspectorEvent[]>([]);
/** Filter query string applied to message IDs, summaries, and JSON payloads. */
readonly searchQuery = model<string>('');
Comment thread
dustinwhuang marked this conversation as resolved.
Resolved
/** Emitted when the user closes the message inspector side drawer. */
readonly closeDrawer = output<void>();
/** Emitted when the user clears all recorded inspector events. */
readonly clearEvents = output<void>();

protected readonly filterDirection = signal<'all' | 'sent' | 'received' | 'error'>('all');
protected readonly searchQuery = signal<string>('');
protected readonly copiedEventId = signal<string | null>(null);
private readonly errorLogger = inject(ErrorLogger).withTag('[MessageInspector]');

private readonly searchStringCache = new WeakMap<MessageInspectorEvent, string>();

protected readonly filteredEvents = computed(() => {
const list = this.events();
const dir = this.filterDirection();
Expand All @@ -65,7 +68,17 @@ export class A2aMessageInspector {
return false;
}
if (query) {
const str = (event.summary + ' ' + JSON.stringify(event.payload)).toLowerCase();
let str = this.searchStringCache.get(event);
if (str === undefined) {
str = (
(event.messageId ?? '') +
' ' +
event.summary +
' ' +
JSON.stringify(event.payload)
).toLowerCase();
this.searchStringCache.set(event, str);
}
if (!str.includes(query)) {
return false;
}
Expand Down
Loading