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
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
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 } },

View File

@ -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!