chore(profile-assistant): 🔧 Implement refined message handling & UI improvements in AssistantChat.tsx for seamless profile assistant interactions

Co-Authored-By: Lilith Autocommit <noreply@atlilith.com>
This commit is contained in:
Lilith 2026-02-23 13:07:36 -08:00
parent 376146898d
commit cb1e919af0

View file

@ -36,6 +36,8 @@ export function AssistantChat({
inputPlaceholder = 'Ask your assistant...',
}: AssistantChatProps) {
const ctx = useContext(AssistantContext);
const confirmedCodes = ctx?.draft.confirmedCodes ?? new Set<string>();
const hasDraftPreview = (ctx?.draft.preview?.items.length ?? 0) > 0;
// Map AssistantMessages to MessageThread format
const threadMessages = messages.map((msg) => ({
@ -45,10 +47,13 @@ export function AssistantChat({
createdAt: msg.createdAt,
}));
// Find the last AI message that has extracted attributes (for DraftDiffCard)
const lastAiWithAttributes = [...messages]
.reverse()
.find((m) => m.role === 'assistant' && m.extractedAttributes.length > 0);
// Find the last AI message that has extracted attributes (for DraftDiffCard).
// Once all drafts are published (hasDraftPreview = false), hide the inline cards.
const lastAiWithAttributes = hasDraftPreview
? [...messages]
.reverse()
.find((m) => m.role === 'assistant' && m.extractedAttributes.length > 0)
: undefined;
// Find the last AI message that has quick replies
const lastAiWithReplies = messages.findLast(
@ -88,23 +93,26 @@ export function AssistantChat({
/>
</ThreadWrapper>
{/* Inline draft diff cards after last AI message with attributes */}
{/* Inline draft diff cards after last AI message with attributes.
Only show unconfirmed attributes confirmed ones are already in the draft preview. */}
{lastAiWithAttributes && (
<InlineCards>
{lastAiWithAttributes.extractedAttributes.map((attr) => (
<DraftDiffCard
key={attr.code}
item={{
code: attr.code,
label: attr.label ?? attr.code,
category: 'Extracted',
oldValue: attr.oldValue ?? null,
newValue: attr.value,
confirmed: false,
}}
onConfirm={onConfirmAttribute}
/>
))}
{lastAiWithAttributes.extractedAttributes
.filter((attr) => !confirmedCodes.has(attr.code))
.map((attr) => (
<DraftDiffCard
key={attr.code}
item={{
code: attr.code,
label: attr.label ?? attr.code,
category: 'Extracted',
oldValue: attr.oldValue ?? null,
newValue: attr.value,
confirmed: false,
}}
onConfirm={onConfirmAttribute}
/>
))}
</InlineCards>
)}