The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
fix(ui): artifact panel driven by Redux open/close/activate tab actions (cross closes reliably)
Sanil3bf2e543db32
diff --git a/app/src/features/conversations/Conversations.tsx b/app/src/features/conversations/Conversations.tsxindex ddd215a950..514bea33e0 100644--- a/app/src/features/conversations/Conversations.tsx+++ b/app/src/features/conversations/Conversations.tsx@@ -69,7 +69,7 @@ import {fetchAndHydrateTurnState,hydrateThreadUsage,markThreadSendPending,- setPreviewArtifactId,+ openArtifact,type ProcessingTranscriptItem,setToolTimelineForThread,type ToolTimelineEntry,@@ -261,7 +261,7 @@ const Conversations = ({projectThreadList = false,}: ConversationsProps = {}) => {const [composerOverride, setComposerOverride] = useState<'mic-cloud' | 'text' | null>(null);- const previewArtifactId = useAppSelector(s => s.chatRuntime.previewArtifactId);+ const activeArtifactId = useAppSelector(s => s.chatRuntime.activeArtifactId);const composer = composerOverride ?? composerProp;const { t } = useT();const dispatch = useAppDispatch();@@ -2182,7 +2182,7 @@ const Conversations = ({console.warn('[artifact] regenerate failed:', err);});}}- onOpenPreview={id => dispatch(setPreviewArtifactId(id))}+ onOpenPreview={id => dispatch(openArtifact(id))}/>))}</div>@@ -2404,10 +2404,8 @@ const Conversations = ({</SidebarContent><div className="flex h-full w-full min-w-0">{mainPanel}- {previewArtifactId && (+ {activeArtifactId && (<ArtifactPreviewPanel- artifactId={previewArtifactId}- onClose={() => dispatch(setPreviewArtifactId(null))}/>)}</div>diff --git a/app/src/features/conversations/aui/ArtifactPreviewPanel.tsx b/app/src/features/conversations/aui/ArtifactPreviewPanel.tsxindex af494e3f41..6f70164b04 100644--- a/app/src/features/conversations/aui/ArtifactPreviewPanel.tsx+++ b/app/src/features/conversations/aui/ArtifactPreviewPanel.tsx@@ -20,16 +20,15 @@ import {} from 'react';import { useT } from '../../../lib/i18n/I18nContext';-import { useAppSelector } from '../../../store/hooks';+import { useAppDispatch, useAppSelector } from '../../../store/hooks';import type { ArtifactSnapshot } from '../../../store/chatRuntimeSlice';+import { activateArtifactTab, closeArtifactTab } from '../../../store/chatRuntimeSlice';import { invoke } from '@tauri-apps/api/core';// ─── Types ──────────────────────────────────────────────────────interface ArtifactPreviewPanelProps {- /** If set, panel opens scoped to this single artifact. */- artifactId: string;- onClose: () => void;+ /** No props: the panel reads openArtifactIds/activeArtifactId from Redux. */}interface ArtifactBodyResponse {@@ -48,8 +47,9 @@ const DEFAULT_WIDTH = 520;// ─── Main panel ─────────────────────────────────────────────────-export function ArtifactPreviewPanel({ artifactId, onClose }: ArtifactPreviewPanelProps) {+export function ArtifactPreviewPanel(_props: ArtifactPreviewPanelProps) {const { t } = useT();+ const dispatch = useAppDispatch();const [panelWidth, setPanelWidth] = useState(DEFAULT_WIDTH);const dragRef = useRef(false);const startXRef = useRef(0);@@ -67,16 +67,14 @@ export function ArtifactPreviewPanel({ artifactId, onClose }: ArtifactPreviewPanreturn list.sort((a, b) => (b.updatedAt ?? 0) - (a.updatedAt ?? 0));}, [artifactsByThread]);- // Active tab — start with the requested artifact, or the first one- const [activeId, setActiveId] = useState(artifactId);+ // Active tab and open-tab list come from Redux — single source of truth.+ const openArtifactIds = useAppSelector(s => s.chatRuntime.openArtifactIds);+ const activeId = useAppSelector(s => s.chatRuntime.activeArtifactId);const activeArtifact = useMemo(() => allArtifacts.find(a => a.artifactId === activeId),[allArtifacts, activeId],);- // Keep activeId in sync if the parent passes a new artifactId- useEffect(() => { setActiveId(artifactId); }, [artifactId]);-// ── Resize ──const handleMouseDown = useCallback((e: React.MouseEvent) => {e.preventDefault();@@ -104,29 +102,20 @@ export function ArtifactPreviewPanel({ artifactId, onClose }: ArtifactPreviewPanreturn () => { window.removeEventListener('mousemove', onMove); window.removeEventListener('mouseup', onUp); };}, []);- // Tab close: remove from local tab list, close panel if last- const [closedIds, setClosedIds] = useState<Set<string>>(new Set());+ // Tabs = the artifacts currently open in the panel, in open order.const visibleTabs = useMemo(- () => allArtifacts.filter(a => !closedIds.has(a.artifactId)),- [allArtifacts, closedIds],+ () =>+ openArtifactIds+ .map(id => allArtifacts.find(a => a.artifactId === id))+ .filter((a): a is ArtifactSnapshot => a !== undefined),+ [openArtifactIds, allArtifacts],+ );+ const handleCloseTab = useCallback(+ (id: string) => {+ dispatch(closeArtifactTab(id));+ },+ [dispatch],);- const handleCloseTab = useCallback((id: string) => {- setClosedIds(prev => {- const next = new Set(prev);- next.add(id);- return next;- });- setActiveId(prev => {- if (prev !== id) return prev;- // Compute the next active tab excluding the one being closed- // (allArtifacts is always current from the memo)- const nextTab = allArtifacts.find(a => a.artifactId !== id);- return nextTab ? nextTab.artifactId : '';- });- if (allArtifacts.length <= 1) {- onClose();- }- }, [allArtifacts, onClose]);const showTabs = visibleTabs.length > 1;@@ -155,7 +144,7 @@ export function ArtifactPreviewPanel({ artifactId, onClose }: ArtifactPreviewPan}`}><button- onClick={() => setActiveId(a.artifactId)}+ onClick={() => dispatch(activateArtifactTab(a.artifactId))}className={`flex min-w-0 items-center gap-1.5 text-xs font-medium transition-colors ${a.artifactId === activeId? 'text-foreground'@@ -183,7 +172,7 @@ export function ArtifactPreviewPanel({ artifactId, onClose }: ArtifactPreviewPan</div>)}</div>- <button onClick={onClose} className="mr-2 shrink-0 inline-flex items-center justify-center rounded p-1 text-muted-foreground hover:bg-accent hover:text-foreground">+ <button onClick={() => dispatch(closeArtifactTab(activeId as string))} className="mr-2 shrink-0 inline-flex items-center justify-center rounded p-1 text-muted-foreground hover:bg-accent hover:text-foreground"><X className="h-4 w-4" /></button></div>diff --git a/app/src/features/conversations/aui/MessageArtifactCards.tsx b/app/src/features/conversations/aui/MessageArtifactCards.tsxindex c7899d406e..d64153230e 100644--- a/app/src/features/conversations/aui/MessageArtifactCards.tsx+++ b/app/src/features/conversations/aui/MessageArtifactCards.tsx@@ -4,7 +4,7 @@ import { useAuiState } from '@assistant-ui/react';import { useMemo } from 'react';import { useAppSelector, useAppDispatch } from '../../../store/hooks';-import { setPreviewArtifactId } from '../../../store/chatRuntimeSlice';+import { openArtifact } from '../../../store/chatRuntimeSlice';import { ArtifactCardAdapter } from './ArtifactCardAdapter';/**@@ -46,7 +46,7 @@ export function MessageArtifactCards() {<ArtifactCardAdapterkey={artifact.artifactId}artifact={artifact}- onOpenPreview={id => dispatch(setPreviewArtifactId(id))}+ onOpenPreview={id => dispatch(openArtifact(id))}/>))}</div>diff --git a/app/src/store/chatRuntimeSlice.ts b/app/src/store/chatRuntimeSlice.tsindex f2bcf2bdbb..694b665052 100644--- a/app/src/store/chatRuntimeSlice.ts+++ b/app/src/store/chatRuntimeSlice.ts@@ -1071,7 +1071,10 @@ interface ChatRuntimeState {*/usageByThread: Record<string, SessionTokenUsage>;queueStatusByThread: Record<string, QueueStatus>;- previewArtifactId: string | null;+ /** Artifacts the user has opened in the right-side preview panel (tab list). */+ openArtifactIds: string[];+ /** Which of the open artifacts is the active tab. */+ activeArtifactId: string | null;}/** Snapshot of the active-run queue depth per lane. */@@ -1108,7 +1111,8 @@ const initialState: ChatRuntimeState = {sessionTokenUsage: emptySessionTokenUsage(),usageByThread: {},queueStatusByThread: {},- previewArtifactId: null,+ openArtifactIds: [],+ activeArtifactId: null,};/**@@ -2738,13 +2742,35 @@ const chatRuntimeSlice = createSlice({);},/**- * 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.+ * Open an artifact in the right-side preview panel: append its id to the+ * tab list (idempotent) and make it the active tab. Clicking a card calls+ * this — if the artifact is already open it just re-activates it.*/- setPreviewArtifactId: (state, action: PayloadAction<string | null>) => {- state.previewArtifactId = action.payload;+ openArtifact: (state, action: PayloadAction<string>) => {+ const id = action.payload;+ if (!state.openArtifactIds.includes(id)) {+ state.openArtifactIds.push(id);+ }+ state.activeArtifactId = id;+ },+ /**+ * Close one artifact tab. Removes it from the tab list; if it was active,+ * the next remaining tab becomes active, and closing the last tab clears+ * `activeArtifactId` so the panel unmounts.+ */+ closeArtifactTab: (state, action: PayloadAction<string>) => {+ const id = action.payload;+ const idx = state.openArtifactIds.indexOf(id);+ if (idx !== -1) {+ state.openArtifactIds.splice(idx, 1);+ }+ if (state.activeArtifactId === id) {+ state.activeArtifactId = state.openArtifactIds[0] ?? null;+ }+ },+ /** Set the active tab explicitly (clicking a tab). */+ activateArtifactTab: (state, action: PayloadAction<string>) => {+ state.activeArtifactId = action.payload;},clearArtifactsForThread: (state, action: PayloadAction<{ threadId: string }>) => {delete state.artifactsByThread[action.payload.threadId];@@ -3291,7 +3317,9 @@ export const {upsertArtifactFailedForThread,clearArtifactsForThread,removeArtifactForThread,- setPreviewArtifactId,+ openArtifact,+ closeArtifactTab,+ activateArtifactTab,setQueueStatusForThread,clearQueueStatusForThread,beginInferenceTurn,