fix(core): artifact rendering issue in standalone ai chat panel (#13166)

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## 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.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
Peng Xiao
2025-07-11 17:53:04 +08:00
committed by GitHub
parent 15726bd522
commit 9cda655c9e
5 changed files with 8 additions and 20 deletions

View File

@@ -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}

View File

@@ -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`<chat-message-assistant
.host=${this.host}
.std=${this.std}
.session=${this.session}
.item=${item}
.isLast=${isLast}

View File

@@ -90,6 +90,7 @@ export class ChatContentStreamObjects extends WithDisposable(
.std=${this.std || this.host?.std}
.data=${streamObject}
.width=${this.width}
.theme=${this.theme}
></code-artifact-tool>
`;
case 'doc_edit':

View File

@@ -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;

View File

@@ -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;