mirror of
https://github.com/toeverything/AFFiNE.git
synced 2024-11-29 15:04:06 +03:00
fix(server): always return created timestamp of chat messages (#6658)
This commit is contained in:
parent
b7ade43c2e
commit
94de6f5853
@ -103,8 +103,8 @@ class ChatMessageType implements Partial<ChatMessage> {
|
||||
@Field(() => GraphQLJSON, { nullable: true })
|
||||
params!: Record<string, string> | undefined;
|
||||
|
||||
@Field(() => Date, { nullable: true })
|
||||
createdAt!: Date | undefined;
|
||||
@Field(() => Date)
|
||||
createdAt!: Date;
|
||||
}
|
||||
|
||||
@ObjectType('CopilotHistories')
|
||||
|
@ -18,7 +18,6 @@ import {
|
||||
getTokenEncoder,
|
||||
ListHistoriesOptions,
|
||||
PromptMessage,
|
||||
PromptMessageSchema,
|
||||
PromptParams,
|
||||
SubmittedMessage,
|
||||
} from './types';
|
||||
@ -324,6 +323,7 @@ export class ChatSessionService {
|
||||
role: true,
|
||||
content: true,
|
||||
params: true,
|
||||
createdAt: true,
|
||||
},
|
||||
orderBy: {
|
||||
createdAt: 'asc',
|
||||
@ -338,7 +338,7 @@ export class ChatSessionService {
|
||||
Promise.all(
|
||||
sessions.map(async ({ id, promptName, messages, createdAt }) => {
|
||||
try {
|
||||
const ret = PromptMessageSchema.array().safeParse(messages);
|
||||
const ret = ChatMessageSchema.array().safeParse(messages);
|
||||
if (ret.success) {
|
||||
const prompt = await this.prompt.get(promptName);
|
||||
if (!prompt) {
|
||||
@ -356,6 +356,13 @@ export class ChatSessionService {
|
||||
.filter(({ role }) => role !== 'system')
|
||||
: [];
|
||||
|
||||
// `createdAt` is required for history sorting in frontend, let's fake the creating time of prompt messages
|
||||
(preload as ChatMessage[]).forEach((msg, i) => {
|
||||
msg.createdAt = new Date(
|
||||
createdAt.getTime() - preload.length - i - 1
|
||||
);
|
||||
});
|
||||
|
||||
return {
|
||||
sessionId: id,
|
||||
action: prompt.action || undefined,
|
||||
|
@ -5,7 +5,7 @@
|
||||
type ChatMessage {
|
||||
attachments: [String!]
|
||||
content: String!
|
||||
createdAt: DateTime
|
||||
createdAt: DateTime!
|
||||
params: JSON
|
||||
role: String!
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user