From 9cda655c9e576f874531b17f8d0671caaf1029fc Mon Sep 17 00:00:00 2001 From: Peng Xiao Date: Fri, 11 Jul 2025 17:53:04 +0800 Subject: [PATCH] fix(core): artifact rendering issue in standalone ai chat panel (#13166) ## Summary by CodeRabbit * **New Features** * Improved chat component to support document link navigation directly from chat messages, allowing users to open documents in the workbench when links are clicked. * **Refactor** * Streamlined notification handling and property access in document composition tools for a cleaner user experience. * Updated import statements for improved code clarity and maintainability. * Enhanced code artifact tool rendering to ensure consistent theming. --- .../ai/components/ai-chat-content/ai-chat-content.ts | 10 +--------- .../ai/components/ai-chat-messages/ai-chat-messages.ts | 10 +--------- .../ai/components/ai-message-content/stream-objects.ts | 1 + .../blocksuite/ai/components/ai-tools/doc-compose.ts | 1 + .../core/src/desktop/pages/workspace/chat/index.tsx | 6 ++++-- 5 files changed, 8 insertions(+), 20 deletions(-) diff --git a/packages/frontend/core/src/blocksuite/ai/components/ai-chat-content/ai-chat-content.ts b/packages/frontend/core/src/blocksuite/ai/components/ai-chat-content/ai-chat-content.ts index 1bddb83376..40ba931913 100644 --- a/packages/frontend/core/src/blocksuite/ai/components/ai-chat-content/ai-chat-content.ts +++ b/packages/frontend/core/src/blocksuite/ai/components/ai-chat-content/ai-chat-content.ts @@ -6,11 +6,7 @@ import type { CopilotChatHistoryFragment, } from '@affine/graphql'; import { SignalWatcher, WithDisposable } from '@blocksuite/affine/global/lit'; -import { - type BlockStdScope, - type EditorHost, - ShadowlessElement, -} from '@blocksuite/affine/std'; +import { type EditorHost, ShadowlessElement } from '@blocksuite/affine/std'; import type { ExtensionType } from '@blocksuite/affine/store'; import type { NotificationService } from '@blocksuite/affine-shared/services'; import { type Signal } from '@preact/signals-core'; @@ -138,9 +134,6 @@ export class AIChatContent extends SignalWatcher( @property({ attribute: false }) accessor host: EditorHost | null | undefined; - @property({ attribute: false }) - accessor std: BlockStdScope | null | undefined; - @property({ attribute: false }) accessor session!: CopilotChatHistoryFragment | null | undefined; @@ -414,7 +407,6 @@ export class AIChatContent extends SignalWatcher( })} ${ref(this.chatMessagesRef)} .host=${this.host} - .std=${this.std} .workspaceId=${this.workspaceId} .docId=${this.docId} .session=${this.session} diff --git a/packages/frontend/core/src/blocksuite/ai/components/ai-chat-messages/ai-chat-messages.ts b/packages/frontend/core/src/blocksuite/ai/components/ai-chat-messages/ai-chat-messages.ts index 48d3ebb4c8..7333b57abf 100644 --- a/packages/frontend/core/src/blocksuite/ai/components/ai-chat-messages/ai-chat-messages.ts +++ b/packages/frontend/core/src/blocksuite/ai/components/ai-chat-messages/ai-chat-messages.ts @@ -6,11 +6,7 @@ import { type FeatureFlagService, type NotificationService, } from '@blocksuite/affine/shared/services'; -import { - type BlockStdScope, - type EditorHost, - ShadowlessElement, -} from '@blocksuite/affine/std'; +import { type EditorHost, ShadowlessElement } from '@blocksuite/affine/std'; import type { BaseSelection, ExtensionType } from '@blocksuite/affine/store'; import { ArrowDownBigIcon as ArrowDownIcon } from '@blocksuite/icons/lit'; import type { Signal } from '@preact/signals-core'; @@ -162,9 +158,6 @@ export class AIChatMessages extends WithDisposable(ShadowlessElement) { @property({ attribute: false }) accessor host: EditorHost | null | undefined; - @property({ attribute: false }) - accessor std: BlockStdScope | null | undefined; - @property({ attribute: false }) accessor workspaceId!: string; @@ -323,7 +316,6 @@ export class AIChatMessages extends WithDisposable(ShadowlessElement) { } else if (isChatMessage(item) && item.role === 'assistant') { return html` `; case 'doc_edit': diff --git a/packages/frontend/core/src/blocksuite/ai/components/ai-tools/doc-compose.ts b/packages/frontend/core/src/blocksuite/ai/components/ai-tools/doc-compose.ts index 417a508ee1..66794fa79f 100644 --- a/packages/frontend/core/src/blocksuite/ai/components/ai-tools/doc-compose.ts +++ b/packages/frontend/core/src/blocksuite/ai/components/ai-tools/doc-compose.ts @@ -109,6 +109,7 @@ export class DocComposeTool extends ArtifactTool< } protected override getPreviewContent() { + if (!this.std) return html``; const resultData = this.data; const title = this.data.args.title; const result = resultData.type === 'tool-result' ? resultData.result : null; diff --git a/packages/frontend/core/src/desktop/pages/workspace/chat/index.tsx b/packages/frontend/core/src/desktop/pages/workspace/chat/index.tsx index 70bac3b59a..c8643ca44f 100644 --- a/packages/frontend/core/src/desktop/pages/workspace/chat/index.tsx +++ b/packages/frontend/core/src/desktop/pages/workspace/chat/index.tsx @@ -58,7 +58,9 @@ function useCopilotClient() { function createMockStd(workspace: Workspace) { workspace.meta.initialize(); - const store = workspace.createDoc().getStore(); + // just pick a random doc for now + const store = workspace.docs.values().next().value?.getStore(); + if (!store) return null; const std = new BlockStdScope({ store, extensions: [...getViewManager().config.init().value.get('page')], @@ -187,7 +189,7 @@ export const Component = () => { content.session = currentSession; content.workspaceId = workspaceId; content.extensions = specs; - content.std = mockStd; + content.host = mockStd?.host; content.docDisplayConfig = docDisplayConfig; content.searchMenuConfig = searchMenuConfig; content.networkSearchConfig = networkSearchConfig;