feat(server): update session after doc deletion (#13028)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Sessions associated with a deleted document are now automatically updated to remove the document reference. * **Improvements** * Enhanced session management to better handle documents that have been deleted. No visible changes to the user interface; these updates improve backend handling of session and document relationships. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -91,7 +91,7 @@ export type ListSessionOptions = Pick<
|
|||||||
Partial<ChatSession>,
|
Partial<ChatSession>,
|
||||||
'sessionId' | 'workspaceId' | 'docId' | 'pinned'
|
'sessionId' | 'workspaceId' | 'docId' | 'pinned'
|
||||||
> & {
|
> & {
|
||||||
userId: string;
|
userId: string | undefined;
|
||||||
action?: boolean;
|
action?: boolean;
|
||||||
fork?: boolean;
|
fork?: boolean;
|
||||||
limit?: number;
|
limit?: number;
|
||||||
|
|||||||
@@ -47,6 +47,10 @@ declare global {
|
|||||||
'copilot.session.generateTitle': {
|
'copilot.session.generateTitle': {
|
||||||
sessionId: string;
|
sessionId: string;
|
||||||
};
|
};
|
||||||
|
'copilot.session.deleteDoc': {
|
||||||
|
workspaceId: string;
|
||||||
|
docId: string;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -580,6 +584,24 @@ export class ChatSessionService {
|
|||||||
return provider.text(cond, [...prompt.finish({}), msg], config);
|
return provider.text(cond, [...prompt.finish({}), msg], config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@OnJob('copilot.session.deleteDoc')
|
||||||
|
async deleteDocSessions(doc: Jobs['copilot.session.deleteDoc']) {
|
||||||
|
const sessionIds = await this.models.copilotSession
|
||||||
|
.list({
|
||||||
|
userId: undefined,
|
||||||
|
workspaceId: doc.workspaceId,
|
||||||
|
docId: doc.docId,
|
||||||
|
})
|
||||||
|
.then(s => s.map(s => [s.userId, s.id]));
|
||||||
|
for (const [userId, sessionId] of sessionIds) {
|
||||||
|
await this.models.copilotSession.update({
|
||||||
|
userId,
|
||||||
|
sessionId,
|
||||||
|
docId: null,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@OnJob('copilot.session.generateTitle')
|
@OnJob('copilot.session.generateTitle')
|
||||||
async generateSessionTitle(job: Jobs['copilot.session.generateTitle']) {
|
async generateSessionTitle(job: Jobs['copilot.session.generateTitle']) {
|
||||||
const { sessionId } = job;
|
const { sessionId } = job;
|
||||||
|
|||||||
@@ -322,6 +322,10 @@ export class IndexerService {
|
|||||||
);
|
);
|
||||||
|
|
||||||
await this.deleteBlocksByDocId(workspaceId, docId, options);
|
await this.deleteBlocksByDocId(workspaceId, docId, options);
|
||||||
|
await this.queue.add('copilot.session.deleteDoc', {
|
||||||
|
workspaceId,
|
||||||
|
docId,
|
||||||
|
});
|
||||||
await this.queue.add('copilot.embedding.deleteDoc', {
|
await this.queue.add('copilot.embedding.deleteDoc', {
|
||||||
workspaceId,
|
workspaceId,
|
||||||
docId,
|
docId,
|
||||||
|
|||||||
Reference in New Issue
Block a user