mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-09 05:05:52 +08:00
feat: refactor doc write in native (#14272)
This commit is contained in:
@@ -9,7 +9,7 @@ import {
|
||||
CopilotProviderNotSupported,
|
||||
OnEvent,
|
||||
} from '../../../base';
|
||||
import { DocReader } from '../../../core/doc';
|
||||
import { DocReader, DocWriter } from '../../../core/doc';
|
||||
import { AccessController } from '../../../core/permission';
|
||||
import { Models } from '../../../models';
|
||||
import { IndexerService } from '../../indexer';
|
||||
@@ -19,16 +19,22 @@ import {
|
||||
buildBlobContentGetter,
|
||||
buildContentGetter,
|
||||
buildDocContentGetter,
|
||||
buildDocCreateHandler,
|
||||
buildDocKeywordSearchGetter,
|
||||
buildDocSearchGetter,
|
||||
buildDocUpdateHandler,
|
||||
buildDocUpdateMetaHandler,
|
||||
createBlobReadTool,
|
||||
createCodeArtifactTool,
|
||||
createConversationSummaryTool,
|
||||
createDocComposeTool,
|
||||
createDocCreateTool,
|
||||
createDocEditTool,
|
||||
createDocKeywordSearchTool,
|
||||
createDocReadTool,
|
||||
createDocSemanticSearchTool,
|
||||
createDocUpdateMetaTool,
|
||||
createDocUpdateTool,
|
||||
createExaCrawlTool,
|
||||
createExaSearchTool,
|
||||
createSectionEditTool,
|
||||
@@ -163,6 +169,7 @@ export abstract class CopilotProvider<C = any> {
|
||||
strict: false,
|
||||
});
|
||||
const docReader = this.moduleRef.get(DocReader, { strict: false });
|
||||
const docWriter = this.moduleRef.get(DocWriter, { strict: false });
|
||||
const models = this.moduleRef.get(Models, { strict: false });
|
||||
const prompt = this.moduleRef.get(PromptService, {
|
||||
strict: false,
|
||||
@@ -177,6 +184,12 @@ export abstract class CopilotProvider<C = any> {
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (
|
||||
!(env.dev || env.namespaces.canary) &&
|
||||
['docCreate', 'docUpdate', 'docUpdateMeta'].includes(tool)
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
switch (tool) {
|
||||
case 'blobRead': {
|
||||
const docContext = options.session
|
||||
@@ -244,6 +257,27 @@ export abstract class CopilotProvider<C = any> {
|
||||
tools.doc_read = createDocReadTool(getDoc.bind(null, options));
|
||||
break;
|
||||
}
|
||||
case 'docCreate': {
|
||||
const createDoc = buildDocCreateHandler(ac, docWriter);
|
||||
tools.doc_create = createDocCreateTool(
|
||||
createDoc.bind(null, options)
|
||||
);
|
||||
break;
|
||||
}
|
||||
case 'docUpdate': {
|
||||
const updateDoc = buildDocUpdateHandler(ac, docWriter);
|
||||
tools.doc_update = createDocUpdateTool(
|
||||
updateDoc.bind(null, options)
|
||||
);
|
||||
break;
|
||||
}
|
||||
case 'docUpdateMeta': {
|
||||
const updateDocMeta = buildDocUpdateMetaHandler(ac, docWriter);
|
||||
tools.doc_update_meta = createDocUpdateMetaTool(
|
||||
updateDocMeta.bind(null, options)
|
||||
);
|
||||
break;
|
||||
}
|
||||
case 'webSearch': {
|
||||
tools.web_search_exa = createExaSearchTool(this.AFFiNEConfig);
|
||||
tools.web_crawl_exa = createExaCrawlTool(this.AFFiNEConfig);
|
||||
|
||||
@@ -66,6 +66,9 @@ export const PromptToolsSchema = z
|
||||
'docEdit',
|
||||
// work with indexer
|
||||
'docRead',
|
||||
'docCreate',
|
||||
'docUpdate',
|
||||
'docUpdateMeta',
|
||||
'docKeywordSearch',
|
||||
// work with embeddings
|
||||
'docSemanticSearch',
|
||||
|
||||
Reference in New Issue
Block a user