Skip to content

Commit a7189e4

Browse files
committed
fix(ui): keep attributed avatars beside sent messages
1 parent 9f263b2 commit a7189e4

3 files changed

Lines changed: 202 additions & 6 deletions

File tree

‎ui/src/e2e/chat-attributed-identity.e2e.test.ts‎

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,122 @@ suite.define(() => {
143143
await context.close();
144144
});
145145

146+
it("keeps attributed user avatars beside their bubbles through send reconciliation", async () => {
147+
const context = await suite.browser.newContext({
148+
viewport: { height: 900, width: 860 },
149+
});
150+
const page = await context.newPage();
151+
const localSenderId = "c3e32452-0467-47e5-aafa-233cd5dae29f";
152+
const peerSenderId = "315ee057-302f-45b4-829d-2c5db1bfed75";
153+
const localAvatarUrl = `/api/users/${localSenderId}/avatar?v=7`;
154+
const priorPrompt = "A prior attributed prompt.";
155+
const peerPrompt = "A peer attributed prompt.";
156+
const prompt = "A newly sent attributed prompt.";
157+
await page.route(`**/api/users/${localSenderId}/avatar*`, async (route) => {
158+
await route.fulfill({
159+
body: `<svg xmlns="http://www.w3.org/2000/svg" width="36" height="36"><rect width="36" height="36" fill="purple"/></svg>`,
160+
contentType: "image/svg+xml",
161+
status: 200,
162+
});
163+
});
164+
const gateway = await installMockGateway(page, {
165+
historyMessages: [
166+
{
167+
__openclaw: { senderId: localSenderId, senderName: "Collin Johnson" },
168+
content: [{ text: priorPrompt, type: "text" }],
169+
role: "user",
170+
timestamp: Date.now() - 3_000,
171+
},
172+
{
173+
__openclaw: { senderId: peerSenderId, senderName: "Riley Chen" },
174+
content: [{ text: peerPrompt, type: "text" }],
175+
role: "user",
176+
timestamp: Date.now() - 2_000,
177+
},
178+
{
179+
content: [{ text: "Ready for the next message.", type: "text" }],
180+
role: "assistant",
181+
timestamp: Date.now() - 1_000,
182+
},
183+
],
184+
presenceUsers: [
185+
{ self: true, id: localSenderId, name: "Collin Johnson", avatarUrl: localAvatarUrl },
186+
{ id: peerSenderId, name: "Riley Chen" },
187+
],
188+
});
189+
190+
const readUserAvatarLayout = async (message: string) => {
191+
const bubble = page.locator(".chat-group.user .chat-bubble", { hasText: message });
192+
await bubble.waitFor();
193+
return await bubble.evaluate((bubbleElement) => {
194+
const group = bubbleElement.closest<HTMLElement>(".chat-group.user");
195+
const avatar = group
196+
? [...group.querySelectorAll<HTMLElement>(".chat-avatar")].find(
197+
(candidate) => getComputedStyle(candidate).display !== "none",
198+
)
199+
: null;
200+
if (!group || !avatar) {
201+
throw new Error("Expected a visible attributed user avatar");
202+
}
203+
const bubbleRect = bubbleElement.getBoundingClientRect();
204+
const avatarRect = avatar.getBoundingClientRect();
205+
return {
206+
avatarLeft: avatarRect.left,
207+
avatarRight: avatarRect.right,
208+
bubbleLeft: bubbleRect.left,
209+
bubbleRight: bubbleRect.right,
210+
isPeer: group.classList.contains("chat-group--peer"),
211+
};
212+
});
213+
};
214+
215+
try {
216+
await page.goto(controlUiSessionUrl(suite.server.baseUrl, "agent:main:main"));
217+
const before = await readUserAvatarLayout(priorPrompt);
218+
const peerBefore = await readUserAvatarLayout(peerPrompt);
219+
220+
await page.locator(".agent-chat__composer-combobox textarea").fill(prompt);
221+
await page.getByRole("button", { name: "Send message" }).click();
222+
const sendRequest = await gateway.waitForRequest("chat.send");
223+
const afterSend = await readUserAvatarLayout(prompt);
224+
const priorAfterSend = await readUserAvatarLayout(priorPrompt);
225+
const peerAfterSend = await readUserAvatarLayout(peerPrompt);
226+
227+
const params = sendRequest.params;
228+
if (!params || typeof params !== "object" || !("idempotencyKey" in params)) {
229+
throw new Error("Expected chat send idempotency key");
230+
}
231+
const runId = params.idempotencyKey;
232+
if (typeof runId !== "string" || !runId.trim()) {
233+
throw new Error("Expected non-empty chat send idempotency key");
234+
}
235+
await gateway.emitChatFinal({ runId, text: "The attributed send completed." });
236+
await page
237+
.locator(".chat-thread .chat-bubble", { hasText: "The attributed send completed." })
238+
.waitFor();
239+
const afterFinal = await readUserAvatarLayout(prompt);
240+
241+
for (const [phase, layout] of [
242+
["initial history", before],
243+
["optimistic send", afterSend],
244+
["prior message after send", priorAfterSend],
245+
["final response", afterFinal],
246+
] as const) {
247+
expect(layout.isPeer, phase).toBe(false);
248+
expect(layout.avatarLeft, phase).toBeGreaterThanOrEqual(layout.bubbleRight + 9);
249+
}
250+
for (const [phase, layout] of [
251+
["peer initial history", peerBefore],
252+
["peer message after send", peerAfterSend],
253+
] as const) {
254+
expect(layout.isPeer, phase).toBe(true);
255+
expect(layout.avatarRight, phase).toBeLessThanOrEqual(layout.bubbleLeft - 9);
256+
}
257+
} finally {
258+
await context.close();
259+
}
260+
});
261+
146262
it("keeps missing local-viewer avatar initials through a live rerender", async () => {
147263
const artifactDir = resolveArtifactDir();
148264
if (artifactDir) {

‎ui/src/pages/chat/chat-responsive.browser.test.ts‎

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1578,6 +1578,72 @@ describeBrowserLayout.concurrent("chat responsive browser layout", () => {
15781578
}
15791579
});
15801580

1581+
it("keeps attributed user avatar fallbacks beside the message after identity resolution", async () => {
1582+
const page = await openBrowserPage(860, 900);
1583+
try {
1584+
await page.setContent(
1585+
`<!doctype html><html><head><style>${readUiCss()}</style></head><body>
1586+
<div class="chat-thread" style="width: 768px;">
1587+
<div class="chat-thread-inner" style="width: 768px;">
1588+
<div class="chat-group user chat-group--with-footer">
1589+
<span class="chat-avatar-slot">
1590+
<img
1591+
class="chat-avatar user"
1592+
alt="Collin Johnson"
1593+
src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='36' height='36'%3E%3Crect width='36' height='36' fill='purple'/%3E%3C/svg%3E"
1594+
/>
1595+
<div class="chat-avatar user chat-avatar--sender-initials">C</div>
1596+
</span>
1597+
<div class="chat-group-messages">
1598+
<div class="chat-bubble"><div class="chat-text">A newly sent message.</div></div>
1599+
</div>
1600+
<div class="chat-group-footer">
1601+
<div class="chat-group-footer__meta">
1602+
<span class="chat-sender-name">collinjohnsonw</span>
1603+
<span class="chat-group-timestamp">now</span>
1604+
</div>
1605+
</div>
1606+
</div>
1607+
</div>
1608+
</div>
1609+
</body></html>`,
1610+
);
1611+
await page.locator(".chat-avatar-slot > img").waitFor();
1612+
1613+
const readLayout = async () =>
1614+
await page.evaluate(() => {
1615+
const group = document.querySelector<HTMLElement>(".chat-group.user")!;
1616+
const bubble = group.querySelector<HTMLElement>(".chat-bubble")!;
1617+
const visibleAvatar = [...group.querySelectorAll<HTMLElement>(".chat-avatar")].find(
1618+
(avatar) => getComputedStyle(avatar).display !== "none",
1619+
)!;
1620+
const groupRect = group.getBoundingClientRect();
1621+
const bubbleRect = bubble.getBoundingClientRect();
1622+
const avatarRect = visibleAvatar.getBoundingClientRect();
1623+
return {
1624+
avatarLeft: avatarRect.left,
1625+
avatarRight: avatarRect.right,
1626+
bubbleRight: bubbleRect.right,
1627+
groupRight: groupRect.right,
1628+
};
1629+
});
1630+
1631+
const imageLayout = await readLayout();
1632+
expect(
1633+
await page.locator(".chat-avatar-slot").evaluate((slot) => getComputedStyle(slot).display),
1634+
).toBe("grid");
1635+
await page.locator(".chat-avatar-slot").evaluate((slot) => slot.classList.add("is-fallback"));
1636+
const fallbackLayout = await readLayout();
1637+
1638+
for (const layout of [imageLayout, fallbackLayout]) {
1639+
expect(layout.avatarLeft).toBeGreaterThanOrEqual(layout.bubbleRight + 9);
1640+
expect(layout.avatarRight).toBeLessThanOrEqual(layout.groupRight + 1);
1641+
}
1642+
} finally {
1643+
await closeBrowserPage(page);
1644+
}
1645+
});
1646+
15811647
it("keeps attached images within narrow message lanes", async () => {
15821648
const page = await openBrowserPage(320, 568);
15831649
try {

‎ui/src/styles/chat/grouped.css‎

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@
6969
justify-content: start;
7070
}
7171

72-
.chat-group.chat-group--with-footer .chat-avatar {
72+
.chat-group.chat-group--with-footer > .chat-avatar,
73+
.chat-group.chat-group--with-footer > .chat-avatar-slot {
7374
grid-column: var(--chat-group-avatar-column);
7475
grid-row: 1;
7576
}
@@ -502,10 +503,21 @@ img.chat-avatar.user {
502503
object-fit: cover;
503504
}
504505

505-
/* Sender avatars pair the route image with an initials fallback; the slot
506-
swaps them when the canonical route has no avatar (404). */
506+
/* Keep the image and initials fallback in one stable grid item. display: contents
507+
can lose the avatar column when Lit reconciles an attributed message. */
507508
.chat-avatar-slot {
508-
display: contents;
509+
display: grid;
510+
width: 36px;
511+
height: 36px;
512+
flex: 0 0 36px;
513+
align-self: flex-end;
514+
margin-bottom: 4px;
515+
}
516+
517+
.chat-avatar-slot > .chat-avatar {
518+
grid-area: 1 / 1;
519+
align-self: stretch;
520+
margin-bottom: 0;
509521
}
510522

511523
.chat-avatar-slot > .chat-avatar--sender-initials {
@@ -638,7 +650,8 @@ img.chat-avatar.chat-avatar--logo {
638650
the repeated identity icons pure decoration. Group threads (any labeled
639651
foreign sender) keep avatars as the always-visible identity marker. */
640652
.chat-thread--direct .chat-avatar,
641-
.chat-thread--direct img.chat-avatar {
653+
.chat-thread--direct img.chat-avatar,
654+
.chat-thread--direct .chat-avatar-slot {
642655
display: none;
643656
}
644657

@@ -1100,7 +1113,8 @@ details.msg-meta:not([open]) .msg-meta__details {
11001113
}
11011114

11021115
.chat-avatar,
1103-
img.chat-avatar {
1116+
img.chat-avatar,
1117+
.chat-avatar-slot {
11041118
display: none;
11051119
}
11061120

0 commit comments

Comments
 (0)