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
feat(chat): thumbs up/down on an assistant reply
M3gA-Mind4c39841696db
diff --git a/app/src/components/assistant-ui/thread.tsx b/app/src/components/assistant-ui/thread.tsxindex 5f005899dc..a2f372e700 100644--- a/app/src/components/assistant-ui/thread.tsx+++ b/app/src/components/assistant-ui/thread.tsx@@ -69,6 +69,8 @@ import {RefreshCwIcon,SlashIcon,SquareIcon,+ ThumbsDownIcon,+ ThumbsUpIcon,} from 'lucide-react';import {type ComponentType,@@ -1113,6 +1115,36 @@ const AssistantActionBar: FC = () => {</TooltipIconButton></ActionBarPrimitive.Copy>{reloadAction}+ {/* Thumbs render only because the external store now supplies+ `adapters.feedback`; the runtime gates them on that key alone. The+ pressed state comes from `message.submittedFeedback`, which our message+ converter re-emits from the persisted rating — see the Defect A note+ there, without which a pressed thumb silently un-presses on the next+ store update.++ Deliberately NOT gated the way `reloadAction` above is. That gate+ exists because assistant-ui's Reload ignores `capabilities.reload` and+ the runtime *throws* on click when the adapter supplies no `onReload`.+ These primitives instead compute `disabled = disabled || !callback`+ from the adapter's own hook, so with no adapter they render disabled+ rather than throwing — and we supply `adapters.feedback`+ unconditionally, so they are always live here. */}+ <ActionBarPrimitive.FeedbackPositive asChild>+ <TooltipIconButton+ tooltip="Good response"+ data-testid="assistant-feedback-positive"+ className="data-[submitted=true]:text-primary-600 dark:data-[submitted=true]:text-primary-400">+ <ThumbsUpIcon />+ </TooltipIconButton>+ </ActionBarPrimitive.FeedbackPositive>+ <ActionBarPrimitive.FeedbackNegative asChild>+ <TooltipIconButton+ tooltip="Bad response"+ data-testid="assistant-feedback-negative"+ className="data-[submitted=true]:text-coral-600 dark:data-[submitted=true]:text-coral-400">+ <ThumbsDownIcon />+ </TooltipIconButton>+ </ActionBarPrimitive.FeedbackNegative><ActionBarMorePrimitive.Root><ActionBarMorePrimitive.Trigger asChild><TooltipIconButton tooltip="More" className="data-[state=open]:bg-accent">diff --git a/app/src/providers/__tests__/assistantUiMessages.test.ts b/app/src/providers/__tests__/assistantUiMessages.test.tsindex d248070a03..6f00fbb725 100644--- a/app/src/providers/__tests__/assistantUiMessages.test.ts+++ b/app/src/providers/__tests__/assistantUiMessages.test.ts@@ -724,3 +724,50 @@ describe('narration merged into the final answer', () => {expect(texts).toEqual([finalText]);});});++describe('feedback round-trip (Defect A)', () => {+ // These assert `metadata.submittedFeedback`, which is what the runtime's+ // pressed state reads (`s.message.metadata.submittedFeedback?.type`, see+ // `ActionBarFeedbackPositive.js`). Asserting the persisted `extraMetadata`+ // instead would be vacuous: that value already survives without this fix, and+ // the bug is precisely that it never reaches the runtime.+ it('re-emits a persisted rating as submittedFeedback so a pressed thumb survives a rebuild', () => {+ const converted = toThreadMessageLike(+ msg({ id: 'a1', sender: 'agent', extraMetadata: { feedback: 'positive' } })+ );+ expect(converted.metadata?.submittedFeedback).toEqual({ type: 'positive' });+ });++ it('re-emits a negative rating', () => {+ const converted = toThreadMessageLike(+ msg({ id: 'a1', sender: 'agent', extraMetadata: { feedback: 'negative' } })+ );+ expect(converted.metadata?.submittedFeedback).toEqual({ type: 'negative' });+ });++ it('leaves an unrated message with no submittedFeedback at all', () => {+ // Absent, not `{ type: undefined }` — the runtime reads+ // `submittedFeedback?.type`, so an empty object would still be falsy, but+ // emitting one would mean every message claims a rating field it lacks.+ const converted = toThreadMessageLike(msg({ id: 'a1', sender: 'agent' }));+ expect(converted.metadata?.submittedFeedback).toBeUndefined();+ });++ it('ignores a rating value the runtime cannot accept', () => {+ // `extraMetadata` is untyped JSON from disk. A stale or hand-edited value+ // must read as unrated rather than reach the runtime as a bad type.+ for (const bad of ['up', '', 'POSITIVE', 1, true, null, {}]) {+ const converted = toThreadMessageLike(+ msg({ id: 'a1', sender: 'agent', extraMetadata: { feedback: bad } })+ );+ expect(converted.metadata?.submittedFeedback).toBeUndefined();+ }+ });++ it('does not rate a user message even if its metadata carries one', () => {+ const converted = toThreadMessageLike(+ msg({ id: 'u1', sender: 'user', extraMetadata: { feedback: 'positive' } })+ );+ expect(converted.metadata?.submittedFeedback).toBeUndefined();+ });+});diff --git a/app/src/providers/assistantUiMessages.ts b/app/src/providers/assistantUiMessages.tsindex 7ef23c9df8..64cc9fd88c 100644--- a/app/src/providers/assistantUiMessages.ts+++ b/app/src/providers/assistantUiMessages.ts@@ -14,6 +14,11 @@ import {type StreamingAssistantState,type ToolTimelineEntry,} from '../store/chatRuntimeSlice';+import {+ FEEDBACK_METADATA_KEY,+ FEEDBACK_ROW_IDS_METADATA_KEY,+ type MessageFeedback,+} from '../store/threadSlice';import type { ThreadMessage } from '../types/thread';/**@@ -50,6 +55,19 @@ const EMPTY_TRANSCRIPT: readonly ProcessingTranscriptItem[] = [];const RECOVERED_TOOL_NAMES_KEY = 'assistantUiToolNames';+/**+ * The rating persisted on a message, when it is one of the two values the+ * runtime accepts.+ *+ * `extraMetadata` is untyped JSON from disk, so this narrows rather than casts:+ * a stale or hand-edited value must render as "unrated" instead of reaching the+ * runtime as a bad `submittedFeedback`.+ */+function persistedFeedback(msg: ThreadMessage): MessageFeedback | undefined {+ const value = msg.extraMetadata?.[FEEDBACK_METADATA_KEY];+ return value === 'positive' || value === 'negative' ? value : undefined;+}+/** Synthetic id for the live streaming tail. Stable so React reconciles it. */export const STREAMING_TAIL_ID = '__openhuman_streaming_tail__';@@ -401,6 +419,16 @@ function mergeAssistantRun(messages: readonly ThreadMessage[]): ThreadMessage {);if (requestId) extraMetadata.requestId = requestId;if (toolNames.length > 0) extraMetadata[RECOVERED_TOOL_NAMES_KEY] = toolNames;+ // Defect B: this one visible message is several persisted rows, and the+ // feedback adapter is only ever handed the last row's id (`...last` below).+ // Carry the whole set so a rating written against that id stays attributable+ // to what the user actually saw, rather than to the final fragment of it.+ extraMetadata[FEEDBACK_ROW_IDS_METADATA_KEY] = messages.map(message => message.id);+ // A merged run inherits a rating from ANY of its rows: the row the adapter+ // wrote to is the last one, but an earlier persist (or a re-merge with+ // different boundaries) can leave it elsewhere.+ const merged = messages.map(persistedFeedback).find(Boolean);+ if (merged) extraMetadata[FEEDBACK_METADATA_KEY] = merged;return {...last,content: mergedAssistantText(messages),@@ -519,6 +547,7 @@ export function toThreadMessageLike(...stringArray(msg.extraMetadata?.[RECOVERED_TOOL_NAMES_KEY]),];const effectiveTimeline = recoverTimelineToolNames(timeline, recoveredToolNames);+ const feedback = msg.sender === 'agent' ? persistedFeedback(msg) : undefined;const converted: ThreadMessageLike = {id: msg.id,@@ -530,6 +559,15 @@ export function toThreadMessageLike(? { status: { type: 'incomplete' as const, reason: 'cancelled' as const } }: {}),metadata: {+ // Defect A (#6459-adjacent, but its own bug): the runtime writes+ // `submittedFeedback` onto its OWN repository copy when a thumb is+ // pressed, and we supply `messages` rather than `messageRepository` — so+ // the runtime rebuilds from this converter's output on every store update+ // (`external-store-thread-runtime-core.js`) and that write is discarded.+ // Re-emitting it from the persisted value is what makes a pressed thumb+ // survive the next turn, a thread switch and a reload. Without this the+ // control silently un-presses, which is worse than having no control.+ ...(feedback ? { submittedFeedback: { type: feedback } } : {}),custom: {extraMetadata: msg.extraMetadata ?? {},sourceType: msg.type,diff --git a/app/src/providers/useOpenHumanExternalStore.ts b/app/src/providers/useOpenHumanExternalStore.tsindex f1a939e306..7b76c38c48 100644--- a/app/src/providers/useOpenHumanExternalStore.ts+++ b/app/src/providers/useOpenHumanExternalStore.ts@@ -1,5 +1,6 @@import type {AppendMessage,+ ThreadMessage as AuiThreadMessage,RespondToToolApprovalOptions,ThreadSuggestion,} from '@assistant-ui/react';@@ -16,9 +17,10 @@ import {type ToolTimelineEntry,} from '../store/chatRuntimeSlice';import { useAppDispatch, useAppSelector } from '../store/hooks';+import { FEEDBACK_ROW_IDS_METADATA_KEY, persistMessageFeedback } from '../store/threadSlice';import type { DerivedDisplayItem } from '../types/derivedTranscript';import type { ThreadMessage } from '../types/thread';-import { buildRuntimeMessages } from './assistantUiMessages';+import { buildRuntimeMessages, STREAMING_TAIL_ID } from './assistantUiMessages';import { getChatSurface } from './chatSurfaceHandlers';const EMPTY_MESSAGES: ThreadMessage[] = [];@@ -333,6 +335,45 @@ export function useOpenHumanExternalStore(threadId: string | null) {[threadId]);+ /**+ * Thumbs on a settled assistant reply.+ *+ * Supplying this key is what turns the capability on at all — the runtime+ * computes `capabilities.feedback` as `!!adapters?.feedback` and renders+ * nothing without it.+ *+ * `submit` returns `void` by contract: there is no promise for the runtime to+ * await and no error channel back to it. A failed persist therefore cannot+ * surface through the adapter, so the thunk owns the failure, and the+ * optimistic value is only committed by its `fulfilled` reducer — a rejected+ * write leaves the thumb unpressed rather than showing a rating that was never+ * stored.+ */+ const feedbackAdapter = useMemo(+ () => ({+ submit: ({ message, type }: { message: AuiThreadMessage; type: 'positive' | 'negative' }) => {+ // The live tail is not a persisted row; there is nothing to attach a+ // rating to until the turn settles.+ if (!threadId || message.id === STREAMING_TAIL_ID) return;+ const custom = message.metadata?.custom as+ | { extraMetadata?: Record<string, unknown> }+ | undefined;+ const rowIds = custom?.extraMetadata?.[FEEDBACK_ROW_IDS_METADATA_KEY];+ void dispatch(+ persistMessageFeedback({+ threadId,+ // `toThreadMessageLike` carries our own row id through unchanged, and+ // for a merged run that is the LAST row's (see `mergeAssistantRun`).+ messageId: message.id,+ feedback: type,+ rowIds: Array.isArray(rowIds) ? (rowIds as string[]) : undefined,+ })+ );+ },+ }),+ [dispatch, threadId]+ );+const onCancel = useCallback(async () => {await getChatSurface(threadId)?.cancel?.();}, [threadId]);@@ -409,6 +450,7 @@ export function useOpenHumanExternalStore(threadId: string | null) {suggestions,// Already `ThreadMessageLike`; the runtime's converter is the identity.convertMessage: (m: (typeof runtimeMessages)[number]) => m,+ adapters: { feedback: feedbackAdapter },onNew,onCancel,onRespondToToolApproval,@@ -419,6 +461,7 @@ export function useOpenHumanExternalStore(threadId: string | null) {isLoading,extras,suggestions,+ feedbackAdapter,onNew,onCancel,onRespondToToolApproval,diff --git a/app/src/store/threadSlice.ts b/app/src/store/threadSlice.tsindex e8387988a5..8e0df20805 100644--- a/app/src/store/threadSlice.ts+++ b/app/src/store/threadSlice.ts@@ -377,6 +377,71 @@ export const persistReaction = createAsyncThunk(});+/** The rating a user gave one assistant reply. */+export type MessageFeedback = 'positive' | 'negative';++/** `extraMetadata` key holding the rating. */+export const FEEDBACK_METADATA_KEY = 'feedback';++/**+ * `extraMetadata` key holding every persisted row id that made up the assistant+ * run the user actually rated.+ *+ * One visible assistant message is often several persisted rows (see+ * `mergeAssistantRun`), and the adapter only ever hands us the last row's id.+ * Recording the whole set means the rating stays attributable to what was on+ * screen rather than to the fragment that happened to be last.+ */+export const FEEDBACK_ROW_IDS_METADATA_KEY = 'feedbackRowIds';++/**+ * Persist a thumbs rating on one assistant message, modelled on+ * [`persistReaction`] — same read-from-Redux, patch-`extraMetadata`,+ * write-back-the-persisted-row shape.+ *+ * Pressing the same rating again clears it, so a mis-click is recoverable: the+ * assistant-ui action bar has no third "unrated" control to offer.+ */+export const persistMessageFeedback = createAsyncThunk(+ 'thread/persistMessageFeedback',+ async (+ payload: {+ threadId: string;+ messageId: string;+ feedback: MessageFeedback;+ /** Row ids of the merged run, when the rated message spans several. */+ rowIds?: readonly string[];+ },+ { getState, rejectWithValue }+ ) => {+ const state = getState() as { thread: ThreadState };+ const stored = state.thread.messagesByThreadId[payload.threadId] ?? [];+ const message = stored.find(e => e.id === payload.messageId);+ if (!message) return rejectWithValue('Message not found');++ const previous = message.extraMetadata[FEEDBACK_METADATA_KEY];+ const next = previous === payload.feedback ? undefined : payload.feedback;+ const extraMetadata: Record<string, unknown> = {+ ...message.extraMetadata,+ [FEEDBACK_METADATA_KEY]: next,+ };+ if (payload.rowIds && payload.rowIds.length > 1) {+ extraMetadata[FEEDBACK_ROW_IDS_METADATA_KEY] = [...payload.rowIds];+ }++ try {+ const persisted = await threadApi.updateMessage(+ payload.threadId,+ payload.messageId,+ extraMetadata+ );+ return { threadId: payload.threadId, message: persisted };+ } catch (error) {+ return rejectWithValue(error instanceof Error ? error.message : 'Failed to save feedback');+ }+ }+);+export const updateThreadTitle = createAsyncThunk('thread/updateThreadTitle',async (payload: { threadId: string; title: string }, { rejectWithValue }) => {@@ -575,6 +640,9 @@ const threadSlice = createSlice({.addCase(persistReaction.fulfilled, (state, action) => {appendMessageToCache(state, action.payload.threadId, action.payload.message, true);})+ .addCase(persistMessageFeedback.fulfilled, (state, action) => {+ appendMessageToCache(state, action.payload.threadId, action.payload.message, true);+ }).addCase(deleteThread.fulfilled, (state, action) => {delete state.messagesByThreadId[action.payload.threadId];})