mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-18 23:07:02 +08: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:
@@ -57,6 +57,7 @@ export const buildDocContentGetter = (
|
|||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
docId,
|
||||||
title: content.title,
|
title: content.title,
|
||||||
markdown: content.markdown,
|
markdown: content.markdown,
|
||||||
createdAt: docMeta.createdAt,
|
createdAt: docMeta.createdAt,
|
||||||
|
|||||||
@@ -220,6 +220,8 @@ export class ChatContentStreamObjects extends WithDisposable(
|
|||||||
return html`<doc-read-result
|
return html`<doc-read-result
|
||||||
.data=${streamObject}
|
.data=${streamObject}
|
||||||
.width=${this.width}
|
.width=${this.width}
|
||||||
|
.peekViewService=${this.peekViewService}
|
||||||
|
.onOpenDoc=${this.onOpenDoc}
|
||||||
></doc-read-result>`;
|
></doc-read-result>`;
|
||||||
case 'section_edit':
|
case 'section_edit':
|
||||||
return html`
|
return html`
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import type { PeekViewService } from '@affine/core/modules/peek-view';
|
||||||
import { WithDisposable } from '@blocksuite/global/lit';
|
import { WithDisposable } from '@blocksuite/global/lit';
|
||||||
import { PageIcon, ViewIcon } from '@blocksuite/icons/lit';
|
import { PageIcon, ViewIcon } from '@blocksuite/icons/lit';
|
||||||
import { ShadowlessElement } from '@blocksuite/std';
|
import { ShadowlessElement } from '@blocksuite/std';
|
||||||
@@ -18,6 +19,8 @@ interface DocReadToolResult {
|
|||||||
toolName: string;
|
toolName: string;
|
||||||
args: { doc_id: string };
|
args: { doc_id: string };
|
||||||
result: {
|
result: {
|
||||||
|
/** Old result may not have docId */
|
||||||
|
docId?: string;
|
||||||
title: string;
|
title: string;
|
||||||
markdown: string;
|
markdown: string;
|
||||||
};
|
};
|
||||||
@@ -30,6 +33,9 @@ export class DocReadResult extends WithDisposable(ShadowlessElement) {
|
|||||||
@property({ attribute: false })
|
@property({ attribute: false })
|
||||||
accessor width: Signal<number | undefined> | undefined;
|
accessor width: Signal<number | undefined> | undefined;
|
||||||
|
|
||||||
|
@property({ attribute: false })
|
||||||
|
accessor peekViewService!: PeekViewService;
|
||||||
|
|
||||||
renderToolCall() {
|
renderToolCall() {
|
||||||
// TODO: get document name by doc_id
|
// TODO: get document name by doc_id
|
||||||
return html`<tool-call-card
|
return html`<tool-call-card
|
||||||
@@ -53,6 +59,18 @@ export class DocReadResult extends WithDisposable(ShadowlessElement) {
|
|||||||
title: this.data.result.title,
|
title: this.data.result.title,
|
||||||
icon: PageIcon(),
|
icon: PageIcon(),
|
||||||
content: this.data.result.markdown,
|
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>`;
|
></tool-result-card>`;
|
||||||
|
|||||||
Reference in New Issue
Block a user