Skip to content

Commit bf616f8

Browse files
committed
fix(copilot): options selection strikethrough
1 parent 4db6bf2 commit bf616f8

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/copilot/components/copilot-message/copilot-message.tsx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,32 @@ const CopilotMessage: FC<CopilotMessageProps> = memo(
183183
return message.content ? parseSpecialTags(message.content) : null
184184
}, [message.content, message.contentBlocks, isUser, isStreaming])
185185

186+
// Detect previously selected option by checking if the next user message matches an option
187+
const selectedOptionKey = useMemo(() => {
188+
if (!parsedTags?.options || isStreaming) return null
189+
190+
// Find the index of this message in the messages array
191+
const currentIndex = messages.findIndex((m) => m.id === message.id)
192+
if (currentIndex === -1 || currentIndex >= messages.length - 1) return null
193+
194+
// Get the next message
195+
const nextMessage = messages[currentIndex + 1]
196+
if (!nextMessage || nextMessage.role !== 'user') return null
197+
198+
const nextContent = nextMessage.content?.trim()
199+
if (!nextContent) return null
200+
201+
// Check if the next user message content matches any option title
202+
for (const [key, option] of Object.entries(parsedTags.options)) {
203+
const optionTitle = typeof option === 'string' ? option : option.title
204+
if (nextContent === optionTitle) {
205+
return key
206+
}
207+
}
208+
209+
return null
210+
}, [parsedTags?.options, messages, message.id, isStreaming])
211+
186212
// Get sendMessage from store for continuation actions
187213
const sendMessage = useCopilotStore((s) => s.sendMessage)
188214

@@ -448,6 +474,7 @@ const CopilotMessage: FC<CopilotMessageProps> = memo(
448474
isLastMessage && !isStreaming && parsedTags.optionsComplete === true
449475
}
450476
streaming={isStreaming || !parsedTags.optionsComplete}
477+
selectedOptionKey={selectedOptionKey}
451478
/>
452479
)}
453480
</div>

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/copilot/components/tool-call/tool-call.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ export function OptionsSelector({
244244
disabled = false,
245245
enableKeyboardNav = false,
246246
streaming = false,
247+
selectedOptionKey = null,
247248
}: {
248249
options: Record<string, OptionItem>
249250
onSelect: (optionKey: string, optionText: string) => void
@@ -252,6 +253,8 @@ export function OptionsSelector({
252253
enableKeyboardNav?: boolean
253254
/** When true, looks enabled but interaction is disabled (for streaming state) */
254255
streaming?: boolean
256+
/** Pre-selected option key (for restoring selection from history) */
257+
selectedOptionKey?: string | null
255258
}) {
256259
const isInteractionDisabled = disabled || streaming
257260
const sortedOptions = useMemo(() => {
@@ -270,7 +273,7 @@ export function OptionsSelector({
270273
}, [options])
271274

272275
const [hoveredIndex, setHoveredIndex] = useState(0)
273-
const [chosenKey, setChosenKey] = useState<string | null>(null)
276+
const [chosenKey, setChosenKey] = useState<string | null>(selectedOptionKey)
274277
const containerRef = useRef<HTMLDivElement>(null)
275278

276279
const isLocked = chosenKey !== null

0 commit comments

Comments
 (0)