refactor(core): reorganize chat-panel components (#10935)

### TL;DR
Split complex chat message component into smaller, reusable units with ​finer granularity

> CLOSE AF-2323 AF-2326

### What Changed
* Split messages into components:
  * `<chat-message-assistant />`
  * `<chat-message-user />`
  * `<chat-message-action />`
* Split message content into types:
  * `<chat-content-images />`
  * `<chat-content-rich-text />`
  * `<chat-content-pure-text />`
This commit is contained in:
yoyoyohamapi
2025-03-20 06:39:27 +00:00
parent 1f2caca3f5
commit 99491eb3c5
15 changed files with 404 additions and 276 deletions

View File

@@ -107,22 +107,30 @@ const collectHistory = async (page: Page) => {
const chatPanel = await page.waitForSelector('.chat-panel-messages');
return Promise.all(
Array.from(
await chatPanel.$$('chat-panel-user-message,chat-panel-assistant-message')
await chatPanel.$$(
'chat-message-user,chat-message-assistant,chat-message-action'
)
).map(async m => {
const isAssistant = await m.evaluate(
el => el.tagName === 'CHAT-PANEL-ASSISTANT-MESSAGE'
el => el.tagName.toLocaleLowerCase() === 'chat-message-assistant'
);
return isAssistant
const isChatAction = await m.evaluate(
el => el.tagName.toLocaleLowerCase() === 'chat-message-action'
);
return isAssistant || isChatAction
? {
name: await m.$('.user-info').then(i => i?.innerText()),
content: await m
.$('chat-text')
.$('chat-content-rich-text')
.then(t => t?.$('editor-host'))
.then(e => e?.innerText()),
}
: {
name: 'You',
content: await m.$('.text-content').then(i => i?.innerText()),
content: await m
.$('chat-content-pure-text')
.then(i => i?.innerText()),
};
})
);
@@ -136,14 +144,14 @@ const collectChat = async (page: Page) => {
}
// wait ai response
await page.waitForSelector(
'.chat-panel-messages chat-panel-assistant-message chat-copy-more',
'.chat-panel-messages chat-message-assistant chat-copy-more',
{
timeout: ONE_MINUTE,
}
);
await page.waitForTimeout(200);
await page
.locator('.chat-panel-messages > chat-panel-assistant-message')
.locator('.chat-panel-messages > chat-message-assistant')
.last()
.locator('chat-copy-more');
await page.waitForTimeout(200);