Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

feat(ui): render artifact cards inline inside producing message via requestId tagging

Sanil54b4a0344594
diff --git a/app/src/components/assistant-ui/thread.tsx b/app/src/components/assistant-ui/thread.tsx
index 5451829ac0..0f5fb3365a 100644
--- a/app/src/components/assistant-ui/thread.tsx
+++ b/app/src/components/assistant-ui/thread.tsx
@@ -150,6 +150,13 @@ export type ThreadComponents = {
* inline tool-call renderer. Always mounted (not gated on isRunning).
*/
AfterMessages?: ComponentType | undefined;
+ /**
+ * Host-owned artifact cards rendered inside each assistant message's
+ * content area (matched by requestId). Unlike AfterMessages which
+ * renders once at the end of the transcript, MessageArtifacts renders
+ * per-message so cards appear attached to the message that created them.
+ */
+ MessageArtifacts?: ComponentType | undefined;
/** Host-owned attachment previews rendered above the editor. */
ComposerAttachments?: ComponentType | undefined;
/** Host-owned attachment picker rendered in the action row. */
@@ -347,7 +354,12 @@ const ThreadComponentsContext = createContext<ThreadComponents>(EMPTY_COMPONENTS
// in a separate context so that change does not invalidate the full transcript.
type MessageComponents = Pick<
ThreadComponents,
- 'AssistantMessage' | 'ToolFallback' | 'ActivityGroup' | 'SourceGroup' | 'MessageTasks'
+ | 'AssistantMessage'
+ | 'ToolFallback'
+ | 'ActivityGroup'
+ | 'SourceGroup'
+ | 'MessageTasks'
+ | 'MessageArtifacts'
>;
const MessageComponentsContext = createContext<MessageComponents>(EMPTY_COMPONENTS);
@@ -409,6 +421,7 @@ export const Thread: FC<ThreadProps> = ({
ActivityGroup: components.ActivityGroup,
SourceGroup: components.SourceGroup,
MessageTasks: components.MessageTasks,
+ MessageArtifacts: components.MessageArtifacts,
}),
[
components.AssistantMessage,
@@ -416,6 +429,7 @@ export const Thread: FC<ThreadProps> = ({
components.ActivityGroup,
components.SourceGroup,
components.MessageTasks,
+ components.MessageArtifacts,
]
);
@@ -1168,6 +1182,7 @@ const AssistantMessage: FC = () => {
ActivityGroup = DefaultActivityGroup,
SourceGroup,
MessageTasks,
+ MessageArtifacts,
} = useContext(MessageComponentsContext);
const stopped = useAuiState(isStoppedRun);
@@ -1275,6 +1290,11 @@ const AssistantMessage: FC = () => {
<MessageTasks />
</div>
)}
+ {MessageArtifacts && (
+ <div className="mt-2">
+ <MessageArtifacts />
+ </div>
+ )}
</div>
<div
diff --git a/app/src/features/conversations/Conversations.tsx b/app/src/features/conversations/Conversations.tsx
index 82cbd2e25b..ddd215a950 100644
--- a/app/src/features/conversations/Conversations.tsx
+++ b/app/src/features/conversations/Conversations.tsx
@@ -69,6 +69,7 @@ import {
fetchAndHydrateTurnState,
hydrateThreadUsage,
markThreadSendPending,
+ setPreviewArtifactId,
type ProcessingTranscriptItem,
setToolTimelineForThread,
type ToolTimelineEntry,
@@ -260,7 +261,7 @@ const Conversations = ({
projectThreadList = false,
}: ConversationsProps = {}) => {
const [composerOverride, setComposerOverride] = useState<'mic-cloud' | 'text' | null>(null);
- const [previewArtifactId, setPreviewArtifactId] = useState<string | null>(null);
+ const previewArtifactId = useAppSelector(s => s.chatRuntime.previewArtifactId);
const composer = composerOverride ?? composerProp;
const { t } = useT();
const dispatch = useAppDispatch();
@@ -2159,7 +2160,14 @@ const Conversations = ({
// ChatFilesChip count) so the user can open live artifact previews.
const liveArtifacts = artifactDeckThreadId
? (artifactsByThread[artifactDeckThreadId] ?? []).filter(
- a => !a.toolCallId && (a.status === 'in_progress' || a.status === 'ready')
+ a =>
+ // Cards with a producing turn now render inline inside that
+ // message (MessageArtifactCards); only artifacts without an
+ // owning requestId (older cores / persisted snapshots) fall
+ // back to the end-of-transcript deck.
+ !a.ownerRequestId &&
+ !a.toolCallId &&
+ (a.status === 'in_progress' || a.status === 'ready')
)
: [];
const liveArtifactDeck =
@@ -2174,7 +2182,7 @@ const Conversations = ({
console.warn('[artifact] regenerate failed:', err);
});
}}
- onOpenPreview={setPreviewArtifactId}
+ onOpenPreview={id => dispatch(setPreviewArtifactId(id))}
/>
))}
</div>
@@ -2399,7 +2407,7 @@ const Conversations = ({
{previewArtifactId && (
<ArtifactPreviewPanel
artifactId={previewArtifactId}
- onClose={() => setPreviewArtifactId(null)}
+ onClose={() => dispatch(setPreviewArtifactId(null))}
/>
)}
</div>
diff --git a/app/src/features/conversations/aui/MessageArtifactCards.tsx b/app/src/features/conversations/aui/MessageArtifactCards.tsx
index 4ec61aa1fe..1f440fa263 100644
--- a/app/src/features/conversations/aui/MessageArtifactCards.tsx
+++ b/app/src/features/conversations/aui/MessageArtifactCards.tsx
@@ -3,7 +3,8 @@
import { useAuiState } from '@assistant-ui/react';
import { useMemo } from 'react';
-import { useAppSelector } from '../../../store/hooks';
+import { useAppSelector, useAppDispatch } from '../../../store/hooks';
+import { setPreviewArtifactId } from '../../../store/chatRuntimeSlice';
import { ArtifactCardAdapter } from './ArtifactCardAdapter';
/**
@@ -19,6 +20,7 @@ import { ArtifactCardAdapter } from './ArtifactCardAdapter';
export function MessageArtifactCards() {
const requestId = useAuiState(s => s.message.metadata?.custom?.requestId as string | undefined);
const threadId = useAppSelector(s => s.thread.selectedThreadId as string | undefined);
+ const dispatch = useAppDispatch();
const artifactsByThread = useAppSelector(s => s.chatRuntime.artifactsByThread);
const cards = useMemo(() => {
@@ -34,7 +36,11 @@ export function MessageArtifactCards() {
return (
<div className="mt-3 flex flex-col gap-2" data-testid="message-artifact-cards">
{cards.map(artifact => (
- <ArtifactCardAdapter key={artifact.artifactId} artifact={artifact} />
+ <ArtifactCardAdapter
+ key={artifact.artifactId}
+ artifact={artifact}
+ onOpenPreview={id => dispatch(setPreviewArtifactId(id))}
+ />
))}
</div>
);
diff --git a/app/src/features/conversations/components/AssistantUiChat.tsx b/app/src/features/conversations/components/AssistantUiChat.tsx
index 721c092bf3..24317530e9 100644
--- a/app/src/features/conversations/components/AssistantUiChat.tsx
+++ b/app/src/features/conversations/components/AssistantUiChat.tsx
@@ -17,6 +17,7 @@ import { ComposerTriggers } from '../aui/ComposerTriggers';
import { ContextUsage } from '../aui/ContextUsage';
import { InterruptedTurnNotice } from '../aui/InterruptedTurnNotice';
import { ActiveTurnTaskCards, TurnTaskCards, TurnTaskProvider } from '../aui/TurnTaskCards';
+import { MessageArtifactCards } from '../aui/MessageArtifactCards';
import { ChatSources } from './aui/ChatSources';
import { ChatToolFallback } from './ChatToolParts';
@@ -339,6 +340,9 @@ export function AssistantUiChat({
// Versioned-artifact cards live in the transcript after the last
// message (see `AfterMessages` slot in thread.tsx).
AfterMessages,
+ // Artifact cards render INSIDE the message that produced them
+ // (matched by requestId), not just at the end of the transcript.
+ MessageArtifacts: () => <MessageArtifactCards />,
// The web pages the turn fetched, grouped from its `source` parts into
// one collapsed disclosure under the answer.
SourceGroup: ChatSources,
diff --git a/app/src/store/chatRuntimeSlice.ts b/app/src/store/chatRuntimeSlice.ts
index a97301802e..f2bcf2bdbb 100644
--- a/app/src/store/chatRuntimeSlice.ts
+++ b/app/src/store/chatRuntimeSlice.ts
@@ -3291,6 +3291,7 @@ export const {
upsertArtifactFailedForThread,
clearArtifactsForThread,
removeArtifactForThread,
+ setPreviewArtifactId,
setQueueStatusForThread,
clearQueueStatusForThread,
beginInferenceTurn,