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 ownerRequestId tagging

Sanil2864e84d3279
diff --git a/app/src/features/conversations/aui/MessageArtifactCards.tsx b/app/src/features/conversations/aui/MessageArtifactCards.tsx
new file mode 100644
index 0000000000..4ec61aa1fe
--- /dev/null
+++ b/app/src/features/conversations/aui/MessageArtifactCards.tsx
@@ -0,0 +1,43 @@
+'use client';
+
+import { useAuiState } from '@assistant-ui/react';
+import { useMemo } from 'react';
+
+import { useAppSelector } from '../../../store/hooks';
+import { ArtifactCardAdapter } from './ArtifactCardAdapter';
+
+/**
+ * Renders artifact cards inside the exact assistant message that produced
+ * them. Matches the current message's `metadata.custom.requestId` against
+ * each artifact's `ownerRequestId` (tagged by `chatRuntimeSlice` when the
+ * pending/ready socket event lands while that turn is live).
+ *
+ * Only artifacts WITHOUT an owning tool call (`!toolCallId`) are shown
+ * here — ones WITH a tool call id already render inline next to their
+ * tool call via `MediaAndDocumentCalls`.
+ */
+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 artifactsByThread = useAppSelector(s => s.chatRuntime.artifactsByThread);
+ const cards = useMemo(() => {
+ if (!threadId || !requestId) return [];
+ const list = artifactsByThread[threadId] ?? [];
+ return list.filter(
+ a => !a.toolCallId && a.ownerRequestId === requestId && (a.status === 'in_progress' || a.status === 'ready')
+ );
+ }, [artifactsByThread, threadId, requestId]);
+
+ if (cards.length === 0) return null;
+
+ return (
+ <div className="mt-3 flex flex-col gap-2" data-testid="message-artifact-cards">
+ {cards.map(artifact => (
+ <ArtifactCardAdapter key={artifact.artifactId} artifact={artifact} />
+ ))}
+ </div>
+ );
+}
+
+export default MessageArtifactCards;
diff --git a/app/src/store/chatRuntimeSlice.ts b/app/src/store/chatRuntimeSlice.ts
index 3532c1331b..a97301802e 100644
--- a/app/src/store/chatRuntimeSlice.ts
+++ b/app/src/store/chatRuntimeSlice.ts
@@ -892,6 +892,13 @@ export interface ArtifactSnapshot {
* with no owning tool call — those keep rendering in the header deck.
*/
toolCallId?: string;
+ /**
+ * The `request_id` of the chat turn that was live when this artifact's
+ * pending/ready event landed. Lets the transcript render the card inside
+ * the exact assistant message that produced it (MessageArtifactCards
+ * matches message metadata.requestId against this).
+ */
+ ownerRequestId?: string;
}
/**
@@ -1064,6 +1071,7 @@ interface ChatRuntimeState {
*/
usageByThread: Record<string, SessionTokenUsage>;
queueStatusByThread: Record<string, QueueStatus>;
+ previewArtifactId: string | null;
}
/** Snapshot of the active-run queue depth per lane. */
@@ -1100,6 +1108,7 @@ const initialState: ChatRuntimeState = {
sessionTokenUsage: emptySessionTokenUsage(),
usageByThread: {},
queueStatusByThread: {},
+ previewArtifactId: null,
};
/**
@@ -2650,6 +2659,7 @@ const chatRuntimeSlice = createSlice({
status: 'in_progress',
updatedAt: Date.now(),
toolCallId: toolCallId ?? existing?.toolCallId,
+ ownerRequestId: state.liveRequestIdByThread[threadId],
};
state.artifactsByThread[threadId] = upsertArtifact(
state.artifactsByThread[threadId],
@@ -2686,6 +2696,7 @@ const chatRuntimeSlice = createSlice({
sizeBytes,
updatedAt: Date.now(),
toolCallId: toolCallId ?? existing?.toolCallId,
+ ownerRequestId: state.liveRequestIdByThread[threadId],
};
state.artifactsByThread[threadId] = upsertArtifact(
state.artifactsByThread[threadId],
@@ -2726,6 +2737,15 @@ const chatRuntimeSlice = createSlice({
snapshot
);
},
+ /**
+ * Set the artifact currently shown in the right-side preview panel, or
+ * null to close it. Kept in Redux (not local Conversations state) so
+ * artifact cards rendered inside assistant messages (`MessageArtifactCards`)
+ * can open the panel from anywhere in the thread.
+ */
+ setPreviewArtifactId: (state, action: PayloadAction<string | null>) => {
+ state.previewArtifactId = action.payload;
+ },
clearArtifactsForThread: (state, action: PayloadAction<{ threadId: string }>) => {
delete state.artifactsByThread[action.payload.threadId];
},