MCPcopy Create free account
hub / github.com/Noumena-Network/code / MessageSelector

Function MessageSelector

src/components/MessageSelector.tsx:47–402  ·  view source on GitHub ↗
({
  messages,
  onPreRestore,
  onRestoreMessage,
  onRestoreCode,
  onSummarize,
  onClose,
  preselectedMessage
}: Props)

Source from the content-addressed store, hash-verified

45};
46const MAX_VISIBLE_MESSAGES = 7;
47export function MessageSelector({
48 messages,
49 onPreRestore,
50 onRestoreMessage,
51 onRestoreCode,
52 onSummarize,
53 onClose,
54 preselectedMessage
55}: Props): React.ReactNode {
56 const fileHistory = useAppState(s => s.fileHistory);
57 const [error, setError] = useState<string | undefined>(undefined);
58 const isFileHistoryEnabled = fileHistoryEnabled();
59
60 // Add current prompt as a virtual message
61 const currentUUID = useMemo(randomUUID, []);
62 const messageOptions = useMemo(() => [...messages.filter(selectableUserMessagesFilter), {
63 ...createUserMessage({
64 content: ''
65 }),
66 uuid: currentUUID
67 } as UserMessage], [messages, currentUUID]);
68 const [selectedIndex, setSelectedIndex] = useState(messageOptions.length - 1);
69
70 // Orient the selected message as the middle of the visible options
71 const firstVisibleIndex = Math.max(0, Math.min(selectedIndex - Math.floor(MAX_VISIBLE_MESSAGES / 2), messageOptions.length - MAX_VISIBLE_MESSAGES));
72 const hasMessagesToSelect = messageOptions.length > 1;
73 const [messageToRestore, setMessageToRestore] = useState<UserMessage | undefined>(preselectedMessage);
74 const [diffStatsForRestore, setDiffStatsForRestore] = useState<DiffStats | undefined>(undefined);
75 useEffect(() => {
76 if (!preselectedMessage || !isFileHistoryEnabled) return;
77 let cancelled = false;
78 void fileHistoryGetDiffStats(fileHistory, preselectedMessage.uuid).then(stats => {
79 if (!cancelled) setDiffStatsForRestore(stats);
80 });
81 return () => {
82 cancelled = true;
83 };
84 }, [preselectedMessage, isFileHistoryEnabled, fileHistory]);
85 const [isRestoring, setIsRestoring] = useState(false);
86 const [restoringOption, setRestoringOption] = useState<RestoreOption | null>(null);
87 const [selectedRestoreOption, setSelectedRestoreOption] = useState<RestoreOption>('both');
88 // Per-option feedback state; Select's internal inputValues Map persists
89 // per-option text independently, so sharing one variable would desync.
90 const [summarizeFromFeedback, setSummarizeFromFeedback] = useState('');
91 const [summarizeUpToFeedback, setSummarizeUpToFeedback] = useState('');
92
93 // Generate options with summarize as input type for inline context
94 function getRestoreOptions(canRestoreCode: boolean): OptionWithDescription<RestoreOption>[] {
95 const baseOptions: OptionWithDescription<RestoreOption>[] = canRestoreCode ? [{
96 value: 'both',
97 label: 'Restore code and conversation'
98 }, {
99 value: 'conversation',
100 label: 'Restore conversation'
101 }, {
102 value: 'code',
103 label: 'Restore code'
104 }] : [{

Callers

nothing calls this directly

Calls 15

useAppStateFunction · 0.85
fileHistoryEnabledFunction · 0.85
fileHistoryGetDiffStatsFunction · 0.85
useKeybindingFunction · 0.85
useKeybindingsFunction · 0.85
loadFileHistoryMetadataFunction · 0.85
formatRelativeTimeAgoFunction · 0.85
isSummarizeOptionFunction · 0.85
getRestoreOptionsFunction · 0.85
onSelectRestoreOptionFunction · 0.85
maxMethod · 0.80

Tested by

no test coverage detected