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, { @Field(() => String, {
description: 'An mark identifying which view to use to display the session', description: 'An mark identifying which view to use to display the session',
nullable: true,
}) })
action!: string; action!: string | undefined;
@Field(() => Number, { @Field(() => Number, {
description: 'The number of tokens used in the session', description: 'The number of tokens used in the session',

View File

@@ -138,6 +138,11 @@ export class ChatSessionService {
if (id) sessionId = id; if (id) sessionId = id;
} }
const messages = state.messages.map(m => ({
...m,
params: m.params || undefined,
}));
await tx.aiSession.upsert({ await tx.aiSession.upsert({
where: { where: {
id: sessionId, id: sessionId,
@@ -145,12 +150,9 @@ export class ChatSessionService {
}, },
update: { update: {
messages: { messages: {
// delete old messages // skip delete old messages if no new messages
deleteMany: {}, deleteMany: messages.length ? {} : undefined,
create: state.messages.map(m => ({ create: messages,
...m,
params: m.params || undefined,
})),
}, },
}, },
create: { create: {
@@ -158,10 +160,7 @@ export class ChatSessionService {
workspaceId: state.workspaceId, workspaceId: state.workspaceId,
docId: state.docId, docId: state.docId,
messages: { messages: {
create: state.messages.map(m => ({ create: messages,
...m,
params: m.params || undefined,
})),
}, },
// connect // connect
user: { connect: { id: state.userId } }, user: { connect: { id: state.userId } },

View File

@@ -24,7 +24,7 @@ type Copilot {
type CopilotHistories { type CopilotHistories {
"""An mark identifying which view to use to display the session""" """An mark identifying which view to use to display the session"""
action: String! action: String
messages: [ChatMessage!]! messages: [ChatMessage!]!
sessionId: String! sessionId: String!