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, CopilotChatHistoryFragment,
} from '@affine/graphql'; } from '@affine/graphql';
import { SignalWatcher, WithDisposable } from '@blocksuite/affine/global/lit'; import { SignalWatcher, WithDisposable } from '@blocksuite/affine/global/lit';
import { import { type EditorHost, ShadowlessElement } from '@blocksuite/affine/std';
type BlockStdScope,
type EditorHost,
ShadowlessElement,
} from '@blocksuite/affine/std';
import type { ExtensionType } from '@blocksuite/affine/store'; import type { ExtensionType } from '@blocksuite/affine/store';
import type { NotificationService } from '@blocksuite/affine-shared/services'; import type { NotificationService } from '@blocksuite/affine-shared/services';
import { type Signal } from '@preact/signals-core'; import { type Signal } from '@preact/signals-core';
@@ -138,9 +134,6 @@ export class AIChatContent extends SignalWatcher(
@property({ attribute: false }) @property({ attribute: false })
accessor host: EditorHost | null | undefined; accessor host: EditorHost | null | undefined;
@property({ attribute: false })
accessor std: BlockStdScope | null | undefined;
@property({ attribute: false }) @property({ attribute: false })
accessor session!: CopilotChatHistoryFragment | null | undefined; accessor session!: CopilotChatHistoryFragment | null | undefined;
@@ -414,7 +407,6 @@ export class AIChatContent extends SignalWatcher(
})} })}
${ref(this.chatMessagesRef)} ${ref(this.chatMessagesRef)}
.host=${this.host} .host=${this.host}
.std=${this.std}
.workspaceId=${this.workspaceId} .workspaceId=${this.workspaceId}
.docId=${this.docId} .docId=${this.docId}
.session=${this.session} .session=${this.session}

View File

@@ -6,11 +6,7 @@ import {
type FeatureFlagService, type FeatureFlagService,
type NotificationService, type NotificationService,
} from '@blocksuite/affine/shared/services'; } from '@blocksuite/affine/shared/services';
import { import { type EditorHost, ShadowlessElement } from '@blocksuite/affine/std';
type BlockStdScope,
type EditorHost,
ShadowlessElement,
} from '@blocksuite/affine/std';
import type { BaseSelection, ExtensionType } from '@blocksuite/affine/store'; import type { BaseSelection, ExtensionType } from '@blocksuite/affine/store';
import { ArrowDownBigIcon as ArrowDownIcon } from '@blocksuite/icons/lit'; import { ArrowDownBigIcon as ArrowDownIcon } from '@blocksuite/icons/lit';
import type { Signal } from '@preact/signals-core'; import type { Signal } from '@preact/signals-core';
@@ -162,9 +158,6 @@ export class AIChatMessages extends WithDisposable(ShadowlessElement) {
@property({ attribute: false }) @property({ attribute: false })
accessor host: EditorHost | null | undefined; accessor host: EditorHost | null | undefined;
@property({ attribute: false })
accessor std: BlockStdScope | null | undefined;
@property({ attribute: false }) @property({ attribute: false })
accessor workspaceId!: string; accessor workspaceId!: string;
@@ -323,7 +316,6 @@ export class AIChatMessages extends WithDisposable(ShadowlessElement) {
} else if (isChatMessage(item) && item.role === 'assistant') { } else if (isChatMessage(item) && item.role === 'assistant') {
return html`<chat-message-assistant return html`<chat-message-assistant
.host=${this.host} .host=${this.host}
.std=${this.std}
.session=${this.session} .session=${this.session}
.item=${item} .item=${item}
.isLast=${isLast} .isLast=${isLast}

View File

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

View File

@@ -109,6 +109,7 @@ export class DocComposeTool extends ArtifactTool<
} }
protected override getPreviewContent() { protected override getPreviewContent() {
if (!this.std) return html``;
const resultData = this.data; const resultData = this.data;
const title = this.data.args.title; const title = this.data.args.title;
const result = resultData.type === 'tool-result' ? resultData.result : null; const result = resultData.type === 'tool-result' ? resultData.result : null;

View File

@@ -58,7 +58,9 @@ function useCopilotClient() {
function createMockStd(workspace: Workspace) { function createMockStd(workspace: Workspace) {
workspace.meta.initialize(); 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({ const std = new BlockStdScope({
store, store,
extensions: [...getViewManager().config.init().value.get('page')], extensions: [...getViewManager().config.init().value.get('page')],
@@ -187,7 +189,7 @@ export const Component = () => {
content.session = currentSession; content.session = currentSession;
content.workspaceId = workspaceId; content.workspaceId = workspaceId;
content.extensions = specs; content.extensions = specs;
content.std = mockStd; content.host = mockStd?.host;
content.docDisplayConfig = docDisplayConfig; content.docDisplayConfig = docDisplayConfig;
content.searchMenuConfig = searchMenuConfig; content.searchMenuConfig = searchMenuConfig;
content.networkSearchConfig = networkSearchConfig; content.networkSearchConfig = networkSearchConfig;