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
5 changes: 5 additions & 0 deletions .changeset/quiet-inboxes-link.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@electric-ax/agents-server-ui": patch
---

Render lightweight markdown links and formatting in inbox messages.
17 changes: 16 additions & 1 deletion packages/agents-server-ui/src/components/UserMessage.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,25 @@
.body {
font-size: var(--ds-chat-text);
line-height: var(--ds-chat-text-lh);
white-space: pre-wrap;
overflow-wrap: anywhere;
}

/* User-authored text gets Slack/Discord-style lightweight markdown: links
(including bare URLs), emphasis, inline/fenced code, lists and quotes. Keep
it compact inside the message bubble and preserve plain newline behavior so
ordinary chat messages still look like chat, not documents. */
.body > div > *:first-child {
margin-top: 0;
}

.body > div > *:last-child {
margin-bottom: 0;
}

.body p {
white-space: pre-wrap;
}

.attachments {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(min(176px, 100%), 240px));
Expand Down
47 changes: 42 additions & 5 deletions packages/agents-server-ui/src/components/UserMessage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { memo, useState } from 'react'
import { Streamdown } from 'streamdown'
import {
Download,
File as FileIcon,
Expand All @@ -8,6 +9,10 @@ import {
import type { EntityTimelineSection } from '@electric-ax/agents-runtime/client'
import { Icon, Stack, Text } from '../ui'
import { downloadAttachment, formatAttachmentSize } from '../lib/attachments'
import {
streamdownComponents,
streamdownControls,
} from '../lib/streamdownConfig'
import {
AttachmentImagePreviewDialog,
useAttachmentObjectUrl,
Expand Down Expand Up @@ -82,11 +87,7 @@ export const UserMessage = memo(function UserMessage({
))}
</div>
)}
{section.text ? (
<Text size={2} className={styles.body}>
{section.text}
</Text>
) : null}
{section.text ? <UserMessageBody text={section.text} /> : null}
</Stack>
<Stack gap={2} align="center" className={styles.meta}>
<Text size={1} tone="muted" title={sender.title}>
Expand All @@ -105,6 +106,42 @@ export const UserMessage = memo(function UserMessage({
)
})

const userMessageAllowedMarkdownElements = [
`p`,
`br`,
`a`,
`strong`,
`em`,
`del`,
`code`,
`pre`,
`blockquote`,
`ul`,
`ol`,
`li`,
] as const

const UserMessageBody = memo(function UserMessageBody({
text,
}: {
text: string
}): React.ReactElement {
return (
<div className={`agent-ui-markdown ${styles.body}`}>
<Streamdown
isAnimating={false}
linkSafety={{ enabled: false }}
allowedElements={userMessageAllowedMarkdownElements}
unwrapDisallowed
controls={streamdownControls}
components={streamdownComponents}
>
{text}
</Streamdown>
</div>
)
})

function AttachmentPreview({
attachment,
}: {
Expand Down
Loading