mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-14 21:27:20 +00:00
feat(core): peek doc in ai doc-read tool result (#13424)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Enhanced document read results with clickable cards that open a peek view of the referenced document. * Added support for displaying document identifiers in document read results. * **Bug Fixes** * Improved compatibility with older document read results that may lack a document identifier. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -220,6 +220,8 @@ export class ChatContentStreamObjects extends WithDisposable(
|
||||
return html`<doc-read-result
|
||||
.data=${streamObject}
|
||||
.width=${this.width}
|
||||
.peekViewService=${this.peekViewService}
|
||||
.onOpenDoc=${this.onOpenDoc}
|
||||
></doc-read-result>`;
|
||||
case 'section_edit':
|
||||
return html`
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import type { PeekViewService } from '@affine/core/modules/peek-view';
|
||||
import { WithDisposable } from '@blocksuite/global/lit';
|
||||
import { PageIcon, ViewIcon } from '@blocksuite/icons/lit';
|
||||
import { ShadowlessElement } from '@blocksuite/std';
|
||||
@@ -18,6 +19,8 @@ interface DocReadToolResult {
|
||||
toolName: string;
|
||||
args: { doc_id: string };
|
||||
result: {
|
||||
/** Old result may not have docId */
|
||||
docId?: string;
|
||||
title: string;
|
||||
markdown: string;
|
||||
};
|
||||
@@ -30,6 +33,9 @@ export class DocReadResult extends WithDisposable(ShadowlessElement) {
|
||||
@property({ attribute: false })
|
||||
accessor width: Signal<number | undefined> | undefined;
|
||||
|
||||
@property({ attribute: false })
|
||||
accessor peekViewService!: PeekViewService;
|
||||
|
||||
renderToolCall() {
|
||||
// TODO: get document name by doc_id
|
||||
return html`<tool-call-card
|
||||
@@ -53,6 +59,18 @@ export class DocReadResult extends WithDisposable(ShadowlessElement) {
|
||||
title: this.data.result.title,
|
||||
icon: PageIcon(),
|
||||
content: this.data.result.markdown,
|
||||
onClick: () => {
|
||||
const docId = (this.data as DocReadToolResult).result.docId;
|
||||
if (!docId) {
|
||||
return;
|
||||
}
|
||||
this.peekViewService.peekView
|
||||
.open({
|
||||
type: 'doc',
|
||||
docRef: { docId },
|
||||
})
|
||||
.catch(console.error);
|
||||
},
|
||||
},
|
||||
]}
|
||||
></tool-result-card>`;
|
||||
|
||||
Reference in New Issue
Block a user