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.

fix: re-create session should skip rewrite messages (#6513)

DarkSkydb1206dbd57a
diff --git a/packages/backend/server/src/plugins/copilot/resolver.ts b/packages/backend/server/src/plugins/copilot/resolver.ts
index ae0a544485..7d767a2591 100644
--- a/packages/backend/server/src/plugins/copilot/resolver.ts
+++ b/packages/backend/server/src/plugins/copilot/resolver.ts
@@ -111,8 +111,9 @@ class CopilotHistoriesType implements Partial<ChatHistory> {
@Field(() => String, {
description: 'An mark identifying which view to use to display the session',
+ nullable: true,
})
- action!: string;
+ action!: string | undefined;
@Field(() => Number, {
description: 'The number of tokens used in the session',
diff --git a/packages/backend/server/src/plugins/copilot/session.ts b/packages/backend/server/src/plugins/copilot/session.ts
index 6fca6d688e..9de9b83980 100644
--- a/packages/backend/server/src/plugins/copilot/session.ts
+++ b/packages/backend/server/src/plugins/copilot/session.ts
@@ -138,6 +138,11 @@ export class ChatSessionService {
if (id) sessionId = id;
}
+ const messages = state.messages.map(m => ({
+ ...m,
+ params: m.params || undefined,
+ }));
+
await tx.aiSession.upsert({
where: {
id: sessionId,
@@ -145,12 +150,9 @@ export class ChatSessionService {
},
update: {
messages: {
- // delete old messages
- deleteMany: {},
- create: state.messages.map(m => ({
- ...m,
- params: m.params || undefined,
- })),
+ // skip delete old messages if no new messages
+ deleteMany: messages.length ? {} : undefined,
+ create: messages,
},
},
create: {
@@ -158,10 +160,7 @@ export class ChatSessionService {
workspaceId: state.workspaceId,
docId: state.docId,
messages: {
- create: state.messages.map(m => ({
- ...m,
- params: m.params || undefined,
- })),
+ create: messages,
},
// connect
user: { connect: { id: state.userId } },
diff --git a/packages/backend/server/src/schema.gql b/packages/backend/server/src/schema.gql
index ba1e50db18..bea9322f39 100644
--- a/packages/backend/server/src/schema.gql
+++ b/packages/backend/server/src/schema.gql
@@ -24,7 +24,7 @@ type Copilot {
type CopilotHistories {
"""An mark identifying which view to use to display the session"""
- action: String!
+ action: String
messages: [ChatMessage!]!
sessionId: String!