feat(core): provide document title, tags, createTime and updateTime to llm (#11205)

Close [BS-2915](https://linear.app/affine-design/issue/BS-2915).
This commit is contained in:
akumatus
2025-03-27 04:34:45 +00:00
parent 0c73fde44a
commit 22ef32f5c2
6 changed files with 54 additions and 4 deletions
@@ -3,6 +3,7 @@ import type { AffineEditorContainer } from '@affine/core/blocksuite/block-suite-
import { enableFootnoteConfigExtension } from '@affine/core/blocksuite/extensions';
import { AINetworkSearchService } from '@affine/core/modules/ai-button/services/network-search';
import { CollectionService } from '@affine/core/modules/collection';
import { DocsService } from '@affine/core/modules/doc';
import { DocDisplayMetaService } from '@affine/core/modules/doc-display-meta';
import { DocsSearchService } from '@affine/core/modules/docs-search';
import { SearchMenuService } from '@affine/core/modules/search-menu/services';
@@ -66,6 +67,8 @@ export const EditorChatPanel = forwardRef(function EditorChatPanel(
const docsSearchService = framework.get(DocsSearchService);
const tagService = framework.get(TagService);
const collectionService = framework.get(CollectionService);
const docsService = framework.get(DocsService);
chatPanelRef.current.appSidebarConfig = {
getWidth: () => {
const width$ = workbench.sidebarWidth$;
@@ -94,6 +97,10 @@ export const EditorChatPanel = forwardRef(function EditorChatPanel(
const title$ = docDisplayMetaService.title$(docId);
return createSignalFromObservable(title$, '');
},
getDocMeta: (docId: string) => {
const docRecord = docsService.list.doc$(docId).value;
return docRecord?.meta$.value ?? null;
},
getDoc: (docId: string) => {
const doc = workspaceService.workspace.docCollection.getDoc(docId);
return doc?.getStore() ?? null;
@@ -106,6 +113,10 @@ export const EditorChatPanel = forwardRef(function EditorChatPanel(
const tagMetas$ = tagService.tagList.tagMetas$;
return createSignalFromObservable(tagMetas$, []);
},
getTagTitle: (tagId: string) => {
const tag$ = tagService.tagList.tagByTagId$(tagId);
return tag$.value?.value$.value ?? '';
},
getTagPageIds: (tagId: string) => {
const tag$ = tagService.tagList.tagByTagId$(tagId);
if (!tag$) return [];