Skip to content

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

refactor(store): extract follow-up suggestion mapping into a shared function

Steven Enamakela5e6f4348e1e
diff --git a/app/src/providers/useOpenHumanExternalStore.ts b/app/src/providers/useOpenHumanExternalStore.ts
index b045a49e37..ccf26fb1a8 100644
--- a/app/src/providers/useOpenHumanExternalStore.ts
+++ b/app/src/providers/useOpenHumanExternalStore.ts
@@ -20,6 +20,7 @@ import {
type ToolTimelineEntry,
} from '../store/chatRuntimeSlice';
import { useAppDispatch, useAppSelector } from '../store/hooks';
+import { toThreadSuggestions } from '../store/followupSuggestionsSlice';
import {
FEEDBACK_ROW_IDS_METADATA_KEY,
persistMessageFeedback,
@@ -249,10 +250,6 @@ function useWelcomeSuggestions(
* the transcript ends on an assistant reply, because the chips follow that
* reply. The set comes from `chat_suggestions` via `followupSuggestionsSlice`,
* which also drops it the moment the next turn starts.
- *
- * The core's `label` is "a short 2-4 word button label" for the prompt
- * (`web_chat/suggestions.rs`), which is assistant-ui's `title` (the chip's
- * text), not its `label` (secondary text appended after the title).
*/
function useFollowupSuggestions(
threadId: string | null,
@@ -267,9 +264,7 @@ function useFollowupSuggestions(
if (!stored || messageCount === 0 || isRunning || lastRole !== 'assistant') {
return EMPTY_SUGGESTIONS;
}
- return stored.suggestions.map(({ prompt, label }) =>
- label ? { prompt, title: label } : { prompt }
- );
+ return toThreadSuggestions(stored.suggestions);
}, [stored, messageCount, lastRole, isRunning]);
}
diff --git a/app/src/store/followupSuggestionsSlice.ts b/app/src/store/followupSuggestionsSlice.ts
index ad43bd33ab..7a9137e761 100644
--- a/app/src/store/followupSuggestionsSlice.ts
+++ b/app/src/store/followupSuggestionsSlice.ts
@@ -15,6 +15,7 @@
* See `useThreadSuggestions` there for why the welcome and follow-up chips
* must never show together.
*/
+import type { ThreadSuggestion } from '@assistant-ui/react';
import { createSlice, type PayloadAction } from '@reduxjs/toolkit';
import {
@@ -57,6 +58,18 @@ function normalize(
return out;
}
+/**
+ * Stored follow-ups as assistant-ui chips. The core's `label` is "a short 2-4
+ * word button label" for the prompt (`web_chat/suggestions.rs`), which is
+ * assistant-ui's `title` (the chip's text), not its `label` (secondary text
+ * appended after the title).
+ */
+export function toThreadSuggestions(
+ suggestions: readonly FollowupSuggestion[]
+): ThreadSuggestion[] {
+ return suggestions.map(({ prompt, label }) => (label ? { prompt, title: label } : { prompt }));
+}
+
function clearThread(state: FollowupSuggestionsState, threadId: string) {
delete state.byThread[threadId];
}