mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-04 19:11:57 +08:00
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:
@@ -6,7 +6,7 @@ import type {
|
||||
} from '@affine/core/modules/search-menu/services';
|
||||
import type { Collection } from '@affine/env/filter';
|
||||
import type { LinkedMenuGroup } from '@blocksuite/affine/blocks/root';
|
||||
import type { Store } from '@blocksuite/affine/store';
|
||||
import type { DocMeta, Store } from '@blocksuite/affine/store';
|
||||
import type { Signal } from '@preact/signals-core';
|
||||
|
||||
export interface AppSidebarConfig {
|
||||
@@ -33,6 +33,7 @@ export interface DocDisplayConfig {
|
||||
signal: Signal<string>;
|
||||
cleanup: () => void;
|
||||
};
|
||||
getDocMeta: (docId: string) => Partial<DocMeta> | null;
|
||||
getDoc: (docId: string) => Store | null;
|
||||
getReferenceDocs: (docIds: string[]) => {
|
||||
signal: Signal<
|
||||
@@ -47,6 +48,7 @@ export interface DocDisplayConfig {
|
||||
signal: Signal<TagMeta[]>;
|
||||
cleanup: () => void;
|
||||
};
|
||||
getTagTitle: (tagId: string) => string;
|
||||
getTagPageIds: (tagId: string) => string[];
|
||||
getCollections: () => {
|
||||
signal: Signal<Collection[]>;
|
||||
|
||||
@@ -36,7 +36,11 @@ export type ChatStatus =
|
||||
|
||||
export interface DocContext {
|
||||
docId: string;
|
||||
docTitle: string;
|
||||
docContent: string;
|
||||
tags: string;
|
||||
createDate: string;
|
||||
updatedDate: string;
|
||||
}
|
||||
|
||||
export interface FileContext {
|
||||
|
||||
@@ -18,7 +18,7 @@ import type { AIError } from '../components/ai-item/types';
|
||||
import { AIProvider } from '../provider';
|
||||
import { reportResponse } from '../utils/action-reporter';
|
||||
import { readBlobAsURL } from '../utils/image';
|
||||
import type { AINetworkSearchConfig } from './chat-config';
|
||||
import type { AINetworkSearchConfig, DocDisplayConfig } from './chat-config';
|
||||
import type {
|
||||
ChatContextValue,
|
||||
ChatMessage,
|
||||
@@ -217,6 +217,9 @@ export class ChatPanelInput extends SignalWatcher(WithDisposable(LitElement)) {
|
||||
@property({ attribute: false })
|
||||
accessor networkSearchConfig!: AINetworkSearchConfig;
|
||||
|
||||
@property({ attribute: false })
|
||||
accessor docDisplayConfig!: DocDisplayConfig;
|
||||
|
||||
private get _isNetworkActive() {
|
||||
return (
|
||||
!!this.networkSearchConfig.visible.value &&
|
||||
@@ -561,7 +564,10 @@ export class ChatPanelInput extends SignalWatcher(WithDisposable(LitElement)) {
|
||||
return { files: [], docs: [] };
|
||||
}
|
||||
|
||||
const docContexts = new Map<string, DocContext>();
|
||||
const docContexts = new Map<
|
||||
string,
|
||||
{ docId: string; docContent: string }
|
||||
>();
|
||||
const fileContexts = new Map<string, FileContext>();
|
||||
|
||||
const { files: matchedFiles = [], docs: matchedDocs = [] } =
|
||||
@@ -602,8 +608,30 @@ export class ChatPanelInput extends SignalWatcher(WithDisposable(LitElement)) {
|
||||
}
|
||||
});
|
||||
|
||||
const docs: DocContext[] = Array.from(docContexts.values()).map(doc => {
|
||||
const docMeta = this.docDisplayConfig.getDocMeta(doc.docId);
|
||||
const docTitle = this.docDisplayConfig.getTitle(doc.docId);
|
||||
const tags = docMeta?.tags
|
||||
? docMeta.tags
|
||||
.map(tagId => this.docDisplayConfig.getTagTitle(tagId))
|
||||
.join(',')
|
||||
: '';
|
||||
return {
|
||||
docId: doc.docId,
|
||||
docContent: doc.docContent,
|
||||
docTitle,
|
||||
tags,
|
||||
createDate: docMeta?.createDate
|
||||
? new Date(docMeta.createDate).toISOString()
|
||||
: '',
|
||||
updatedDate: docMeta?.updatedDate
|
||||
? new Date(docMeta.updatedDate).toISOString()
|
||||
: '',
|
||||
};
|
||||
});
|
||||
|
||||
return {
|
||||
docs: Array.from(docContexts.values()),
|
||||
docs,
|
||||
files: Array.from(fileContexts.values()),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -629,6 +629,7 @@ export class ChatPanel extends SignalWatcher(
|
||||
.getSessionId=${this._getSessionId}
|
||||
.getContextId=${this._getContextId}
|
||||
.networkSearchConfig=${this.networkSearchConfig}
|
||||
.docDisplayConfig=${this.docDisplayConfig}
|
||||
.updateContext=${this.updateContext}
|
||||
.host=${this.host}
|
||||
.cleanupHistories=${this._cleanupHistories}
|
||||
|
||||
Reference in New Issue
Block a user