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
72 changes: 72 additions & 0 deletions src/app/components/chat/chat.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1238,4 +1238,76 @@ describe('ChatComponent', () => {
},
);
});

it('should not duplicate artifact message when event has both content and artifact delta', async () => {
mockArtifactService.getArtifactVersion.and.returnValue(
of({
inlineData: {
mimeType: 'image/png',
data: 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=',
},
}),
);
const sseEvent = {
id: 'event-1',
author: 'bot',
content: {
role: 'bot',
parts: [{ functionCall: { name: 'save_artifact', args: {} } }]
},
actions: {
artifactDelta: { 'artifact-1': 'version-1' },
},
};
component.userInput = 'test message';

await component.sendMessage(new KeyboardEvent('keydown', { key: 'Enter' }));
mockAgentService.runSseResponse.next(sseEvent);
fixture.detectChanges();

const botMessages = component.messages().filter((m) => m.role === 'bot');
expect(botMessages.length).toBe(2);

const hasFunctionCall = botMessages.some(m => m.functionCall?.name === 'save_artifact');
const hasArtifact = botMessages.some(m => m.inlineData !== undefined);

expect(hasFunctionCall).toBeTrue();
expect(hasArtifact).toBeTrue();
});

it('should render artifact for text-only response', async () => {
mockArtifactService.getArtifactVersion.and.returnValue(
of({
inlineData: {
mimeType: 'image/png',
data: 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=',
},
}),
);
const sseEvent = {
id: 'event-2',
author: 'bot',
content: {
role: 'bot',
parts: [{ text: 'Some text' }]
},
actions: {
artifactDelta: { 'artifact-2': 'version-1' },
},
};
component.userInput = 'test message';

await component.sendMessage(new KeyboardEvent('keydown', { key: 'Enter' }));
mockAgentService.runSseResponse.next(sseEvent);
fixture.detectChanges();

const botMessages = component.messages().filter((m) => m.role === 'bot');
expect(botMessages.length).toBe(2);

const hasText = botMessages.some(m => m.text === 'Some text');
const hasArtifact = botMessages.some(m => m.inlineData !== undefined);

expect(hasText).toBeTrue();
expect(hasArtifact).toBeTrue();
});
});
2 changes: 1 addition & 1 deletion src/app/components/chat/chat.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ export class ChatComponent implements OnInit, AfterViewInit, OnDestroy {
this.functionCallEventId = e.id;
}
}
if (e?.actions && e.actions.artifactDelta) {
if (e?.actions && e.actions.artifactDelta && !part) {
for (const key in e.actions.artifactDelta) {
if (e.actions.artifactDelta.hasOwnProperty(key)) {
this.renderArtifact(key, e.actions.artifactDelta[key]);
Expand Down