Conform to ActivitySnapshot update using the same message_id
This commit is contained in:
parent
ba83779bb2
commit
8f5b6c299d
1 changed files with 13 additions and 4 deletions
|
|
@ -468,11 +468,20 @@ function ChatContentInner({
|
||||||
}
|
}
|
||||||
}, [JSON.stringify(agent.messages), ragState, sessionId]);
|
}, [JSON.stringify(agent.messages), ragState, sessionId]);
|
||||||
|
|
||||||
|
// Deduplicate messages by id, keeping the last occurrence.
|
||||||
|
// haiku.skills 0.10.0+ sends activity snapshots with the same id
|
||||||
|
// and replace=true — CopilotKit doesn't deduplicate these, so we
|
||||||
|
// must do it to avoid React duplicate key warnings.
|
||||||
// biome-ignore lint/correctness/useExhaustiveDependencies: stable identity via agent ref
|
// biome-ignore lint/correctness/useExhaustiveDependencies: stable identity via agent ref
|
||||||
const messages = useMemo(
|
const messages = useMemo(() => {
|
||||||
() => [...agent.messages],
|
const seen = new Map<string, number>();
|
||||||
[JSON.stringify(agent.messages)],
|
const msgs = agent.messages;
|
||||||
);
|
for (let i = 0; i < msgs.length; i++) {
|
||||||
|
const id = msgs[i].id;
|
||||||
|
if (id) seen.set(id, i);
|
||||||
|
}
|
||||||
|
return msgs.filter((msg, i) => !msg.id || seen.get(msg.id) === i);
|
||||||
|
}, [JSON.stringify(agent.messages)]);
|
||||||
|
|
||||||
const onSubmitMessage = useCallback(
|
const onSubmitMessage = useCallback(
|
||||||
async (text: string) => {
|
async (text: string) => {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue