From d17f5651f1b49a914bebad700a5e6855f825337a Mon Sep 17 00:00:00 2001 From: akumatus Date: Thu, 13 Feb 2025 03:28:27 +0000 Subject: [PATCH] feat(core): add with your docs label to ai answer (#10124) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix issue [BS-2425](https://linear.app/affine-design/issue/BS-2425). ![截屏2025-02-12 16.34.20.png](https://graphite-user-uploaded-assets-prod.s3.amazonaws.com/sJGviKxfE3Ap685cl5bj/89576eac-e176-4890-8d58-7c39d0ae1d9b.png) --- .../presets/ai/chat-panel/chat-panel-messages.ts | 15 +++++++++++++++ tests/affine-cloud-copilot/e2e/copilot.spec.ts | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/packages/frontend/core/src/blocksuite/presets/ai/chat-panel/chat-panel-messages.ts b/packages/frontend/core/src/blocksuite/presets/ai/chat-panel/chat-panel-messages.ts index 42149fbb8..d1c954a94 100644 --- a/packages/frontend/core/src/blocksuite/presets/ai/chat-panel/chat-panel-messages.ts +++ b/packages/frontend/core/src/blocksuite/presets/ai/chat-panel/chat-panel-messages.ts @@ -71,6 +71,12 @@ export class ChatPanelMessages extends WithDisposable(ShadowlessElement) { user-select: none; } + .message-info { + color: var(--affine-placeholder-color); + font-size: 12px; + font-weight: 400; + } + .avatar-container { width: 24px; height: 24px; @@ -370,6 +376,12 @@ export class ChatPanelMessages extends WithDisposable(ShadowlessElement) { renderAvatar(item: ChatItem) { const isUser = 'role' in item && item.role === 'user'; + const isAssistant = 'role' in item && item.role === 'assistant'; + const isWithDocs = + isAssistant && + item.content && + item.content.includes('[^') && + /\[\^\d+\]:{"type":"doc","docId":"[^"]+"}/.test(item.content); return html`
${isUser @@ -380,6 +392,9 @@ export class ChatPanelMessages extends WithDisposable(ShadowlessElement) {
` : AffineAvatarIcon} ${isUser ? 'You' : 'AFFiNE AI'} + ${isWithDocs + ? html`with your docs` + : nothing} `; } diff --git a/tests/affine-cloud-copilot/e2e/copilot.spec.ts b/tests/affine-cloud-copilot/e2e/copilot.spec.ts index 504f86f63..4d233ec15 100644 --- a/tests/affine-cloud-copilot/e2e/copilot.spec.ts +++ b/tests/affine-cloud-copilot/e2e/copilot.spec.ts @@ -865,7 +865,7 @@ test.describe('chat with doc', () => { name: 'You', content: 'What is AFFiNE AI?', }); - expect(history[1].name).toBe('AFFiNE AI'); + expect(history[1].name).toBe(`AFFiNE AI\nwith your docs`); expect( await page.locator('chat-panel affine-footnote-node').count() ).toBeGreaterThan(0);