Skip to content

There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.

chore(server): not allow to update action's prompt (#9615)

darkskygit755cebfb1807
diff --git a/packages/backend/server/src/plugins/copilot/session.ts b/packages/backend/server/src/plugins/copilot/session.ts
index 6987ce012d..16b53f6262 100644
--- a/packages/backend/server/src/plugins/copilot/session.ts
+++ b/packages/backend/server/src/plugins/copilot/session.ts
@@ -1,7 +1,7 @@
import { randomUUID } from 'node:crypto';
import { Injectable, Logger } from '@nestjs/common';
-import { AiPromptRole, PrismaClient } from '@prisma/client';
+import { AiPromptRole, Prisma, PrismaClient } from '@prisma/client';
import {
CopilotActionTaken,
@@ -203,7 +203,8 @@ export class ChatSessionService {
private async haveSession(
sessionId: string,
userId: string,
- tx?: PrismaTransaction
+ tx?: PrismaTransaction,
+ params?: Prisma.AiSessionCountArgs['where']
) {
const executor = tx ?? this.db;
return await executor.aiSession
@@ -211,6 +212,7 @@ export class ChatSessionService {
where: {
id: sessionId,
userId,
+ ...params,
},
})
.then(c => c > 0);
@@ -590,7 +592,12 @@ export class ChatSessionService {
}
return await this.db.$transaction(async tx => {
let sessionId = options.sessionId;
- const haveSession = await this.haveSession(sessionId, options.userId, tx);
+ const haveSession = await this.haveSession(
+ sessionId,
+ options.userId,
+ tx,
+ { prompt: { action: null } }
+ );
if (haveSession) {
await tx.aiSession.update({
where: { id: sessionId },