Skip to content
Open
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
45 changes: 28 additions & 17 deletions src/app/components/chat/chat.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -775,9 +775,29 @@ export class ChatComponent implements OnInit, AfterViewInit, OnDestroy {
return parts;
}

private getArtifactDelta(actions: any): {[key: string]: any}|undefined {
const artifactDelta = actions?.artifactDelta ?? actions?.artifact_delta;
if (!artifactDelta || Object.keys(artifactDelta).length === 0) {
return undefined;
}
return artifactDelta;
}

private renderArtifactsFromActions(actions: any, prepend: boolean = false) {
const artifactDelta = this.getArtifactDelta(actions);
if (!artifactDelta) {
return;
}

for (const key in artifactDelta) {
if (Object.prototype.hasOwnProperty.call(artifactDelta, key)) {
this.renderArtifact(key, artifactDelta[key], prepend);
}
}
}

private processActionArtifact(e: AdkEvent) {
if (e.actions && e.actions.artifactDelta &&
Object.keys(e.actions.artifactDelta).length > 0) {
if (this.getArtifactDelta(e.actions)) {
this.storeEvents(null, e);
this.storeMessage(null, e, 'bot');
}
Expand Down Expand Up @@ -954,13 +974,7 @@ export class ChatComponent implements OnInit, AfterViewInit, OnDestroy {
this.functionCallEventId = e.id;
}
}
if (e?.actions && e.actions.artifactDelta) {
for (const key in e.actions.artifactDelta) {
if (e.actions.artifactDelta.hasOwnProperty(key)) {
this.renderArtifact(key, e.actions.artifactDelta[key], prepend);
}
}
}
this.renderArtifactsFromActions(e?.actions, prepend);

if (e?.evalStatus) {
this.isChatMode.set(false);
Expand Down Expand Up @@ -1018,13 +1032,6 @@ export class ChatComponent implements OnInit, AfterViewInit, OnDestroy {
message.executableCode = part.executableCode;
} else if (part.codeExecutionResult) {
message.codeExecutionResult = part.codeExecutionResult;
if (e.actions && e.actions.artifact_delta) {
for (const key in e.actions.artifact_delta) {
if (e.actions.artifact_delta.hasOwnProperty(key)) {
this.renderArtifact(key, e.actions.artifact_delta[key], prepend);
}
}
}
}
}

Expand Down Expand Up @@ -1232,7 +1239,7 @@ export class ChatComponent implements OnInit, AfterViewInit, OnDestroy {

private storeEvents(part: any, e: any) {
let title = '';
if (part == null && e.actions.artifactDelta) {
if (part == null && this.getArtifactDelta(e?.actions)) {
title += 'eventAction: artifact';
} else if (part) {
if (part.text) {
Expand Down Expand Up @@ -1602,6 +1609,8 @@ export class ChatComponent implements OnInit, AfterViewInit, OnDestroy {
this.processPartIntoMessage(part, event, botMessage);
});

this.renderArtifactsFromActions(event?.actions, reverseOrder);

if (reverseOrder) {
this.messages.update((messages) => [botMessage, ...messages]);
} else {
Expand Down Expand Up @@ -1667,6 +1676,8 @@ export class ChatComponent implements OnInit, AfterViewInit, OnDestroy {
this.processPartIntoMessage(part, event, botMessage);
});

this.renderArtifactsFromActions(event?.actions, false);

this.messages.update((messages) => [...messages, botMessage]);

// Store the event in eventData
Expand Down