8000 fix(chat): label a chat artifact with its name, not its MIME type by burrows99 · Pull Request #566 · google/adk-web · GitHub
[go: up one dir, main page]

Skip to content
Open
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
31 changes: 31 additions & 0 deletions src/app/components/chat/chat.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1648,6 +1648,37 @@ describe('ChatComponent', () => {
.toHaveBeenCalledTimes(1);
},
);

const renderJsonArtifact = async (inlineData: object) => {
mockArtifactService.getArtifactVersion.and.returnValue(
of({inlineData: {mimeType: 'application/json', data: 'e30=', ...inlineData}}),
);
component.userInput = 'test message';
await component.sendMessage(
new KeyboardEvent('keydown', {key: 'Enter'}),
);
mockAgentService.runSseResponse.next({
id: 'event-1',
author: 'bot',
content: {role: 'bot', parts: []},
actions: {artifactDelta: {'incident_data.json': 0}},
});
fixture.detectChanges();
return component.uiEvents().find(e => e.event?.id === 'event-1')!;
};

it('should label a chat artifact with its filename', async () => {
const uiEvent = await renderJsonArtifact({});

expect(uiEvent.inlineData!.name).toBe('incident_data.json');
});

it('should prefer the display name of a chat artifact', async () => {
const uiEvent =
await renderJsonArtifact({displayName: 'Full data for incident 42'});

expect(uiEvent.inlineData!.name).toBe('Full data for incident 42');
});
});

describe('isEventA2aResponse', () => {
Expand Down
10 changes: 1 addition & 9 deletions src/app/components/chat/chat.component.ts
51FD
Original file line number Diff line number Diff line change
Expand Up @@ -2120,7 +2120,7 @@ export class ChatComponent implements OnInit, AfterViewInit, OnDestroy {
const mediaType = getMediaTypeFromMimetype(mimeType);

const inlineData = {
name: this.createDefaultArtifactName(mimeType),
name: res.inlineData?.displayName || artifactId,
data: base64Data,
mimeType: mimeType,
mediaType,
Expand Down Expand Up @@ -4957,14 +4957,6 @@ export class ChatComponent implements OnInit, AfterViewInit, OnDestroy {
});
}

private createDefaultArtifactName(mimeType: string): string {
if (!mimeType || !mimeType.includes('/')) {
return '';
}

return mimeType.replace('/', '.');
}

protected exportSession() {
this.sessionService.getSession(this.userId, this.appName, this.sessionId)
.subscribe((res) => {
Expand Down
Loading
0