refactor(core): simplify chat panel user message rendering (#10910)

### TL;DR
Refactor style of  user chat message

> CLOSE AF-2323 AF-2324 AF-2325

### What Changed
* Refactor style of user message.
* Refactor style of image message.
This commit is contained in:
yoyoyohamapi
2025-03-20 04:59:10 +00:00
parent e83f7eba00
commit 5aa36efab0
3 changed files with 117 additions and 86 deletions

View File

@@ -106,13 +106,25 @@ const clearChat = async (page: Page) => {
const collectHistory = async (page: Page) => {
const chatPanel = await page.waitForSelector('.chat-panel-messages');
return Promise.all(
Array.from(await chatPanel.$$('.message')).map(async m => ({
name: await m.$('.user-info').then(i => i?.innerText()),
content: await m
.$('chat-text')
.then(t => t?.$('editor-host'))
.then(e => e?.innerText()),
}))
Array.from(
await chatPanel.$$('chat-panel-user-message,chat-panel-assistant-message')
).map(async m => {
const isAssistant = await m.evaluate(
el => el.tagName === 'CHAT-PANEL-ASSISTANT-MESSAGE'
);
return isAssistant
? {
name: await m.$('.user-info').then(i => i?.innerText()),
content: await m
.$('chat-text')
.then(t => t?.$('editor-host'))
.then(e => e?.innerText()),
}
: {
name: 'You',
content: await m.$('.text-content').then(i => i?.innerText()),
};
})
);
};
@@ -123,12 +135,17 @@ const collectChat = async (page: Page) => {
return [];
}
// wait ai response
await page.waitForSelector('.chat-panel-messages .message chat-copy-more', {
timeout: ONE_MINUTE,
});
await page.waitForSelector(
'.chat-panel-messages chat-panel-assistant-message chat-copy-more',
{
timeout: ONE_MINUTE,
}
);
await page.waitForTimeout(200);
const lastMessage = await chatPanel.$$('.message').then(m => m[m.length - 1]);
await lastMessage.waitForSelector('chat-copy-more');
await page
.locator('.chat-panel-messages > chat-panel-assistant-message')
.last()
.locator('chat-copy-more');
await page.waitForTimeout(200);
return collectHistory(page);
};