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

This commit is contained in:
DarkSky
2024-04-11 12:22:45 +08:00
committed by GitHub
parent 5cd4c051fd
commit db1206dbd5
3 changed files with 12 additions and 12 deletions

View File

@@ -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',

View File

@@ -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 } },