Skip to content

Commit ba9fc33

Browse files
committed
fix(copilot): options selection strikethrough
1 parent 842d37c commit ba9fc33

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
@@ -291,6 +291,7 @@ export function OptionsSelector({
291291
disabled = false,
292292
enableKeyboardNav = false,
293293
streaming = false,
294+
selectedOptionKey = null,
294295
}: {
295296
options: Record<string, OptionItem>
296297
onSelect: (optionKey: string, optionText: string) => void
@@ -299,6 +300,8 @@ export function OptionsSelector({
299300
enableKeyboardNav?: boolean
300301
/** When true, looks enabled but interaction is disabled (for streaming state) */
301302
streaming?: boolean
303+
/** Pre-selected option key (for restoring selection from history) */
304+
selectedOptionKey?: string | null
302305
}) {
303306
const isInteractionDisabled = disabled || streaming
304307
const sortedOptions = useMemo(() => {
@@ -317,7 +320,7 @@ export function OptionsSelector({
317320
}, [options])
318321

319322
const [hoveredIndex, setHoveredIndex] = useState(0)
320-
const [chosenKey, setChosenKey] = useState<string | null>(null)
323+
const [chosenKey, setChosenKey] = useState<string | null>(selectedOptionKey)
321324
const containerRef = useRef<HTMLDivElement>(null)
322325

323326
const isLocked = chosenKey !== null

0 commit comments

Comments
 (0)