Skip to content

Commit 334d94c

Browse files
authored
chore: use message metadata in UI to render citations and trajectory (#995)
1 parent c640aa6 commit 334d94c

File tree

7 files changed

+31
-33
lines changed

7 files changed

+31
-33
lines changed

apps/beeai-ui/src/api/a2a/client.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { getBaseUrl } from '#utils/api/getBaseUrl.ts';
1515
import { isNotNull } from '#utils/helpers.ts';
1616

1717
import { AGENT_ERROR_MESSAGE } from './constants';
18-
import { processFilePart, processTextPart } from './part-processors';
18+
import { processFilePart, processMessageMetadata, processTextPart } from './part-processors';
1919
import type { ChatRun } from './types';
2020
import { createUserMessage, extractTextFromMessage } from './utils';
2121

@@ -32,10 +32,12 @@ function handleStatusUpdate(event: TaskStatusUpdateEvent): UIMessagePart[] {
3232
return [];
3333
}
3434

35-
const parts = message.parts
35+
const metadataParts = processMessageMetadata(message);
36+
37+
const contentParts = message.parts
3638
.flatMap((part) => {
3739
const processedParts = match(part)
38-
.with({ kind: 'text' }, (part) => processTextPart(part, message.messageId))
40+
.with({ kind: 'text' }, (part) => processTextPart(part))
3941
.with({ kind: 'file' }, processFilePart)
4042
.otherwise((otherPart) => {
4143
console.warn(`Unsupported part - ${otherPart.kind}`);
@@ -47,7 +49,7 @@ function handleStatusUpdate(event: TaskStatusUpdateEvent): UIMessagePart[] {
4749
})
4850
.filter(isNotNull);
4951

50-
return parts;
52+
return [...metadataParts, ...contentParts];
5153
}
5254

5355
export const buildA2AClient = (providerId: string) => {

apps/beeai-ui/src/api/a2a/extensions/trajectory.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@ const URI = 'https://a2a-extensions.beeai.dev/ui/trajectory/v1';
1111

1212
const schema = z
1313
.object({
14-
message: z.string(),
15-
tool_name: z.string(),
16-
tool_input: z.record(z.string(), z.unknown()),
17-
tool_outpyut: z.record(z.string(), z.unknown()),
14+
title: z.string(),
15+
content: z.string(),
1816
})
1917
.partial();
2018

apps/beeai-ui/src/api/a2a/part-processors.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
import type { FilePart, TextPart } from '@a2a-js/sdk';
6+
import type { FilePart, Message, TextPart } from '@a2a-js/sdk';
77
import { v4 as uuid } from 'uuid';
88

99
import type { UIFilePart, UIMessagePart } from '#modules/messages/types.ts';
@@ -18,25 +18,25 @@ import {
1818
getFileUri,
1919
} from './utils';
2020

21-
export function processTextPart(part: TextPart, messageId: string): UIMessagePart[] {
22-
const parts: UIMessagePart[] = [];
23-
const { metadata, text } = part;
24-
const trajectory = extractTrajectory(metadata);
25-
const citation = extractCitation(metadata);
21+
export function processMessageMetadata(message: Message): UIMessagePart[] {
22+
const trajectory = extractTrajectory(message.metadata);
23+
const citation = extractCitation(message.metadata);
2624

2725
if (trajectory) {
28-
parts.push(createTrajectoryPart(trajectory));
26+
return [createTrajectoryPart(trajectory)];
2927
} else if (citation) {
30-
const sourcePart = createSourcePart(citation, messageId);
28+
const sourcePart = createSourcePart(citation, message.messageId);
3129

3230
if (sourcePart) {
33-
parts.push(sourcePart);
31+
return [sourcePart];
3432
}
3533
}
3634

37-
parts.push(createTextPart(text));
35+
return [];
36+
}
3837

39-
return parts;
38+
export function processTextPart({ text }: TextPart): UIMessagePart[] {
39+
return [createTextPart(text)];
4040
}
4141

4242
export function processFilePart(part: FilePart): UIMessagePart[] {

apps/beeai-ui/src/api/a2a/utils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,13 @@ export function createSourcePart(metadata: CitationMetadata, messageId: string):
113113
}
114114

115115
export function createTrajectoryPart(metadata: TrajectoryMetadata): UITrajectoryPart {
116-
const { message, tool_name } = metadata;
116+
const { title, content } = metadata;
117117

118118
const trajectoryPart: UITrajectoryPart = {
119119
kind: UIMessagePartKind.Trajectory,
120120
id: uuid(),
121-
message: message ?? undefined,
122-
toolName: tool_name ?? undefined,
121+
title,
122+
content,
123123
};
124124

125125
return trajectoryPart;

apps/beeai-ui/src/modules/messages/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ export type UISourcePart = {
5353
export type UITrajectoryPart = {
5454
kind: UIMessagePartKind.Trajectory;
5555
id: string;
56-
message?: string;
57-
toolName?: string;
56+
title?: string;
57+
content?: string;
5858
};
5959

6060
export type UITransformPart = {

apps/beeai-ui/src/modules/trajectories/components/TrajectoryItem.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ interface Props {
2121
export function TrajectoryItem({ trajectory }: Props) {
2222
const [isOpen, setIsOpen] = useState(false);
2323

24-
const { toolName, message } = trajectory;
24+
const { title, content } = trajectory;
2525

26-
const isToggleable = isNotNull(message);
26+
const isToggleable = isNotNull(content);
2727

2828
return (
2929
<div className={clsx(classes.root, { [classes.isOpen]: isOpen })}>
@@ -40,17 +40,17 @@ export function TrajectoryItem({ trajectory }: Props) {
4040
</IconButton>
4141
)}
4242

43-
{toolName && (
43+
{title && (
4444
<h3 className={classes.name}>
4545
{/* <span className={classes.icon}>
4646
<Icon />
4747
</span> */}
4848

49-
<span>{toolName}</span>
49+
<span>{title}</span>
5050
</h3>
5151
)}
5252

53-
{message && <div className={classes.message}>{message}</div>}
53+
{content && <div className={classes.message}>{content}</div>}
5454
</header>
5555

5656
{isToggleable && (

apps/beeai-ui/src/modules/trajectories/components/TrajectoryItemContent.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,12 @@ interface Props {
1212
}
1313

1414
export function TrajectoryItemContent({ trajectory }: Props) {
15-
const { message } = trajectory;
15+
const { content } = trajectory;
1616

1717
return (
1818
<div className={classes.root}>
1919
<div className={classes.group}>
20-
<p className={classes.label}>Thought</p>
21-
22-
<p className={classes.content}>{message}</p>
20+
<p className={classes.content}>{content}</p>
2321
</div>
2422
</div>
2523
);

0 commit comments

Comments
 (0)