fix: re-create session should skip rewrite messages (#6513)
This commit is contained in:
@@ -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',
|
||||||
|
|||||||
@@ -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 } },
|
||||||
|
|||||||
@@ -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!
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user