chore(server): ignore non-exists doc embedding (#11153)

This commit is contained in:
darkskygit
2025-03-25 15:10:56 +00:00
parent db4406f950
commit 4bf9161e57
3 changed files with 81 additions and 49 deletions

View File

@@ -1,6 +1,5 @@
import { nanoid } from 'nanoid';
import { CopilotDocsNotFound } from '../../../base';
import {
ContextCategories,
ContextCategory,
@@ -63,22 +62,35 @@ export class ContextSession implements AsyncDisposable {
}
async addCategoryRecord(type: ContextCategories, id: string, docs: string[]) {
const existDocs = await this.models.doc.existsAll(this.workspaceId, docs);
if (!existDocs) {
throw new CopilotDocsNotFound();
}
const category = this.config.categories.find(
c => c.type === type && c.id === id
);
if (category) {
const missingDocs = docs.filter(
docId => !category.docs.some(d => d.id === docId)
);
if (missingDocs.length) {
category.docs.push(
...missingDocs.map(id => ({
id,
createdAt: Date.now(),
status: ContextEmbedStatus.processing,
}))
);
await this.save();
}
return category;
}
const createdAt = Date.now();
const record = {
id,
type,
docs: docs.map(id => ({ id, createdAt, status: null })),
docs: docs.map(id => ({
id,
createdAt,
status: ContextEmbedStatus.processing,
})),
createdAt,
};
this.config.categories.push(record);